I draw a string to the screen, and would like to add emoticons where acceptable.
I use string.find() to find what I want in the string, and get the position in the string. But using the returned position for x is off, obviously.
Anybody have any good ideas on how to get the best position?
To help clarify:
[url]https://docs.google.com/file/d/0B5T2T2AXWMVdLXVEaVRVSEp2alk/edit?usp=sharing[/url]
Position where text starts + text_size from the start to emoticon position.
You could explode the text from a smiley table, and then draw each part of the text from the resulting table, adding the smileys between each text part. (Although this requires some checking to get it right, sure there are better ways.)
EDIT: Thinking about it it's not a good idea. But concept is this one.
I got it working. Here's how, if anybody else is stupid like me:
[code]
function PANEL:Paint()
self.Str:Draw( 20, 0, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT );
if( ( self.Icon != "" ) ) then
surface.SetMaterial( GetIconMaterial( self.Icon ) );
surface.SetDrawColor( 255, 255, 255, 255 );
surface.DrawTexturedRect( 0, 0, 16, 16 );
end
-- render emoticons
if( ShowIcons:GetInt() ~= 0 ) then
if( self.Text == nil ) then return end
local sPos = 0
local ePos = 0
local pos = 1
local old = 0
for k, v in ipairs( aChat.Emoticons ) do
local StartPos, EndPos = 0, 0
while( sPos ~= nil ) do
StartPos, EndPos = string.find( self.Text, v[1], pos + 1 );
if( StartPos == nil ) then return end;
pos = StartPos
--local x, y = surface.GetTextSize( self.Text, "Font_Chat" );
local width = 0
for i = 0, #self.Text do
if( i > EndPos ) then break end
width = width + surface.GetTextSize( self.Text[ i ], "Font_Chat" );
end
MsgN(width)
MsgN(surface.GetTextSize( self.Text, "Font_Chat" ));
surface.SetMaterial( GetIconMaterial( v[2] ) );
surface.SetDrawColor( 255, 255, 255, 255 );
surface.DrawTexturedRect( width, 0, 16, 16 );
end
end
end
[/code]
Sorry, you need to Log In to post a reply to this thread.