Drawing a caret in a text surface returned by TTF_RenderUTF8_Shaded

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?

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.

In all the times I have done this I had a target surface that had the
blinking cursor drawn into it and I drew the text into the surface
separately from the cursor. Personally, I always render the glyphs of the
font into their own surfaces on an “on demand” basis and save them and reuse
them as needed. Regenerating them each time you use them is just to costly.

Bob Pendleton

I checked what ooffice does and came to the conclusion that a textOn 3/16/08, Erik wrote:

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?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

±-------------------------------------+