Jump to content

Colorcodes in Labels


BriGhtx3

Recommended Posts

Kenix, your work but color codes appears and not colors.

Cadu12, I've seen that r, g, b is nil then it sets r = 255, g = 255, b = 255.

My code:

function guiCreateColorLabel ( ax, ay, bx, by, str, relative, parent ) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find(pat, 1) 
    local last = 1 
    while s do 
        if cap == "" and col then r, g, b = tocolor( tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), 
        tonumber( "0x"..col:sub( 5, 6 ) ), 255 ) 
        end 
        last = e + 1 
        s, e, cap, col = str:find( pat, last ) 
    end 
    if r == nil then r = 211 end 
    if g == nil then g = 211 end 
    if b == nil then b = 211 end 
    if last <= #str then 
        cap = str:sub( last ) 
        string = string.gsub(cap,'%x%x%x%x%x%x','') 
        label = guiCreateLabel ( ax, ay, bx, by, string, relative, parent ) 
        guiLabelSetColor ( label, r, g, b ) 
        return label 
    end 
end 

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...