[SDL] Drawing a caret in a text surface returned by TTF_RenderUTF8_Shaded

Erik esigra at gmail.com
Sun Mar 16 03:53:38 PDT 2008


Our application needs to draw a text cursor (see 
[http://en.wikipedia.org/wiki/Cursor_(computers)]) in a surface that is 
returned by TTF_RenderUTF8_Shaded. But how should it be done? Our 
current implementation blits a 1×10 png before a character (which will 
overwrite the last column of the preceding character). The problem is 
that if that character is the first in the string, the text cursor will 
be outside the surface returned by TTF_RenderUTF8_Shaded so it will not 
be visible.

I checked what ooffice does and came to the conclusion that a text 
cursor should be a rectangle, 2×lineheight, where foreground and 
background are inverted. It should cover the last column of the 
preceding character and the fist column of the following character. But 
in this case only half of the text cursor would be drawn on the surface 
if it is before the first character or after the last character.

Or would it be possible to insert an empty column between each character 
(and before the first character and after the last character) in the 
surface returned by TTF_RenderUTF8_Shaded? If so, it would be possible 
to use a 1×lineheight rectangle with foreground colour as the text cursor.

Has any other project solved this problem satisfactory?


More information about the SDL mailing list