draw.SimpleText for Chatbox

Hi there,

I’m in the process of creating a chat box, however I want to display the chat lines using draw.SimpleText so that I can make it look more professional and use outlined text in some instances. My problem is that I need to integrate the ability to use different colors on one line. What would be the most efficient way to do this, assuming that every time a chat message comes through, it is added to a table.

Really, you should be using RichText for this instead of SimpleText.


[editline]23rd July 2017[/editline]

You could do it without a panel element if you want though, but not with any of the standard draw functions. You’d have to do a bit of dodgy custom stuff like I did to draw rainbow text:

local function DrawRainbowText( multiplier, text, font, x, y )
	surface.SetFont( font )
	for i = 1, #text do
		local col = HSVToColor( i * multiplier % 360, 1, 1 )
		surface.SetTextColor( col )
		local w, h = surface.GetTextSize( string.sub( text, 1, i - 1 ) )
		surface.SetTextPos( x + w, y )
		local letter = string.sub( text, i, i )
		surface.DrawText( letter )