Yoshi-Networks

color labels

Mar 17th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. text = { }
  2. text.__index = text
  3.  
  4. function text:Create ( aX, aY, aW, aH, aText, aRelative, aParent, aFont )
  5. if (
  6. type ( aX ) == "number"
  7. and
  8. type ( aY ) == "number"
  9. and
  10. type ( aW ) == "number"
  11. and
  12. type ( aH ) == "number"
  13. and
  14. type ( aText ) == "string"
  15. )
  16. then
  17. local vText = { }
  18. local pat = "(.-)#(%x%x%x%x%x%x)"
  19. local s, e, cap, col = aText:find(pat, 1)
  20. local last = 1
  21. while s do
  22. if ( cap == "" and col ) then r, g, b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ),
  23. tonumber( "0x"..col:sub( 5, 6 ) ) end
  24. if ( s ~= 1 or cap ~= "" ) then
  25. local w = dxGetTextWidth(cap, 1.0, aFont)
  26. local uLabel = guiCreateLabel ( aX, aY, aW + w, aH, cap, aRelative or false, aParent or nil )
  27. r, g, b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) )
  28. guiLabelSetColor ( uLabel, 255, 255, 255 )
  29. guiSetFont ( uLabel, aFont )
  30. table.insert ( vText, uLabel )
  31. aW = aW + w
  32. x = guiLabelGetTextExtent(uLabel) + 0.01
  33. end
  34. last = e + 1
  35. s, e, cap, col = aText:find( pat, last )
  36. end
  37. if last <= #aText then
  38. cap = aText:sub( last )
  39. local w = dxGetTextWidth(cap, 1.0, aFont)
  40. local utLabel = guiCreateLabel ( x, aY, aW + w, aH, cap, aRelative, aParent )
  41. guiLabelSetColor ( utLabel, r, g, b )
  42. guiSetFont ( utLabel, aFont )
  43. table.insert ( vText, utLabel )
  44. end
  45. end
  46. return vText
  47. end
Advertisement
Add Comment
Please, Sign In to add comment