Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile()
- // Split-color text //
- local function SplitColText( str, font, x,y, col1, col2, xAlign, yAlign )
- x = x or 0
- y = y or 0
- surface.SetFont( font )
- local txtWide,txtHigh = surface.GetTextSize( str )
- // Calculate position
- if xAlign==TEXT_ALIGN_CENTER then x = x-(txtWide/2) elseif xAlign==TEXT_ALIGN_RIGHT then x = x-txtWide end
- if yAlign==TEXT_ALIGN_CENTER then y = y-(txtHigh/2) elseif yAlign==TEXT_ALIGN_BOTTOM then y = y-txtHigh end
- y = math.ceil(y)
- x = math.ceil(x)
- render.SetScissorRect( x, y, x+txtWide, (y+(txtHigh/2)), true )
- surface.SetTextColor( col1 )
- surface.SetTextPos( x,y )
- surface.DrawText( tostring(str) )
- render.SetScissorRect( 0,0,0,0, false )
- render.SetScissorRect( x, y+txtHigh, x+txtWide, (y+(txtHigh/2)), true )
- surface.SetTextColor( col2 )
- surface.SetTextPos( x,y )
- surface.DrawText( tostring(str) )
- render.SetScissorRect( 0,0,0,0, false )
- end
- // Testing //
- local Col = {
- Red = Color(255,30,30), Red2 = Color(180,30,30),
- Green = Color(30,255,30), Green2 = Color(30,160,30),
- Blue = Color(0,0,255), White = Color(255,255,255),
- Black = Color(0,0,0), Yellow = Color(255,255,0),
- }
- hook.Add( "HUDPaint", "TestSplitcolText", function()
- local x,y = (ScrW()/2), (ScrH()/2)
- SplitColText( "Test 1", "JailBreakHUDTimer", x,y, Col.Red, Col.Red2, TEXT_ALIGN_RIGHT, TEXT_ALIGN_BOTTOM )
- SplitColText( "2 Test", "JailBreakHUDTimer", x,y, Col.Green, Col.Green2, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM )
- SplitColText( "Test 3", "JailBreakHUDTimer", x,y, Col.Black, Col.Yellow, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP )
- SplitColText( "4 Test", "JailBreakHUDTimer", x,y, Col.Blue, Col.White, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement