Jump to content

dxDrawTextColorCoded


Puma

Recommended Posts

I wanted the player nametags to display the colorcodes they got in their names, so I did a script for that. Thought it'd be nice to share it, I'm sure this script comes in very handy, as there is no colorcode support in the current dx-function to draw text. Made a util function of it.

___________________________________

Here it is:

http://pastebin.com/iFVC9dLT

Raw script (if you want to copy it, use this link!):

http://pastebin.com/raw.php?i=iFVC9dLT

NOTE: Be sure to include the 'hexToRGB'-function, the script won't work without it!

___________________________________

Syntax:

dxDrawTextColorCoded ( string text, int left, int top, [ int alpha = 255, float scale = 1, mixed font = "default", bool clip = false, bool postGUI = false ] ) 

Required arguments:

Text: Your text

Left: Left textbox limit

Top: Top textbox limit

Optional:

Alpha: Alpha (0-255)

Scale: Text scale

Font: Built in dx-font (string) or a dx font-element

Clip: Cut text off if it sticks out of the box

PostGUI: Set to true if text should be rendered after GUI

NOTE: Aligning text is not supported! You only supply an argument for the top left starting position and the script does the rest, according to the text scale and font.

___________________________________

Short example:

function render () 
    dxDrawTextColorCoded ( "Test no color yet #ffaa00yaay orange #00ff00and now friggin' green #0101ffand some blue stuff", 500, 500 ) 
  
    dxDrawTextColorCoded ( "B#ff0000L#00ff00A#0000ffH", 500, 500, 150, 4, "bankgothic" ) 
  
end 
addEventHandler ( "onClientRender", getRootElement(), render ) 

Result:

k1t9ba.jpg

___________________________________

Have fun with it, I hope it's useful :)! (maybe something for "Useful functions" page on wiki?)

Link to comment

well alignment is quite simple, you just need box size (meaning it'll require more than just starting x/y) and just calculate top/left offset using box size and textline size.

now word wrapping support — that's sophisticated :S

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...