Advertisement
my_hat_stinks

Untitled

Jun 15th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. // Split-color text //
  4. local function SplitColText( str, font, x,y, col1, col2, xAlign, yAlign )
  5.     x = x or 0
  6.     y = y or 0
  7.    
  8.     surface.SetFont( font )
  9.     local txtWide,txtHigh = surface.GetTextSize( str )
  10.    
  11.     // Calculate position
  12.     if xAlign==TEXT_ALIGN_CENTER then x = x-(txtWide/2) elseif xAlign==TEXT_ALIGN_RIGHT then x = x-txtWide end
  13.     if yAlign==TEXT_ALIGN_CENTER then y = y-(txtHigh/2) elseif yAlign==TEXT_ALIGN_BOTTOM then y = y-txtHigh end
  14.     y = math.ceil(y)
  15.     x = math.ceil(x)
  16.    
  17.    
  18.     render.SetScissorRect( x, y, x+txtWide, (y+(txtHigh/2)), true )
  19.         surface.SetTextColor( col1 )
  20.         surface.SetTextPos( x,y )
  21.         surface.DrawText( tostring(str) )
  22.     render.SetScissorRect( 0,0,0,0, false )
  23.     render.SetScissorRect( x, y+txtHigh, x+txtWide, (y+(txtHigh/2)), true )
  24.         surface.SetTextColor( col2 )
  25.         surface.SetTextPos( x,y )
  26.         surface.DrawText( tostring(str) )
  27.     render.SetScissorRect( 0,0,0,0, false )
  28. end
  29.  
  30. // Testing //
  31. local Col = {
  32.     Red = Color(255,30,30), Red2 = Color(180,30,30),
  33.     Green = Color(30,255,30), Green2 = Color(30,160,30),
  34.     Blue = Color(0,0,255), White = Color(255,255,255),
  35.     Black = Color(0,0,0), Yellow = Color(255,255,0),
  36. }
  37. hook.Add( "HUDPaint", "TestSplitcolText", function()
  38.     local x,y = (ScrW()/2), (ScrH()/2)
  39.    
  40.     SplitColText( "Test 1", "JailBreakHUDTimer", x,y, Col.Red, Col.Red2, TEXT_ALIGN_RIGHT, TEXT_ALIGN_BOTTOM )
  41.     SplitColText( "2 Test", "JailBreakHUDTimer", x,y, Col.Green, Col.Green2, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM )
  42.    
  43.     SplitColText( "Test 3", "JailBreakHUDTimer", x,y, Col.Black, Col.Yellow, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP )
  44.     SplitColText( "4 Test", "JailBreakHUDTimer", x,y, Col.Blue, Col.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
  45. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement