Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Draw cursor, underline marked text
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgod committed Jul 1, 2009
1 parent a6091bd commit efbfb29
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/testime.c
Expand Up @@ -63,8 +63,9 @@ int main(int argc, char *argv[])
}

/* Prepare a rect for text input */
SDL_Rect textRect = { 100, 80, 300, 50 }, markedRect;
SDL_Rect textRect = { 100, 80, 300, 50 }, markedRect, underlineRect, cursorRect;
Uint32 backColor = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF);
Uint32 lineColor = SDL_MapRGB(screen->format, 0x0, 0x0, 0x0);
SDL_Color textColor = { 0, 0, 0 };
SDL_FillRect(screen, &textRect, backColor);

Expand Down Expand Up @@ -106,6 +107,11 @@ int main(int argc, char *argv[])
render_text(screen, font, text, textRect.x, textRect.y, textColor);
TTF_SizeUTF8(font, text, &w, &h);
markedRect.x = textRect.x + w;

cursorRect = markedRect;
cursorRect.w = 2;
cursorRect.h = h;
SDL_FillRect(screen, &cursorRect, lineColor);
SDL_Flip(screen);

SDL_StartTextInput(&markedRect);
Expand All @@ -117,6 +123,13 @@ int main(int argc, char *argv[])

SDL_FillRect(screen, &markedRect, backColor);
render_text(screen, font, event.edit.text, markedRect.x, markedRect.y, textColor);
TTF_SizeUTF8(font, event.edit.text, &w, &h);
underlineRect = markedRect;
underlineRect.y += (h - 2);
underlineRect.h = 2;
underlineRect.w = w;
SDL_FillRect(screen, &underlineRect, lineColor);

SDL_Flip(screen);
break;

Expand Down

0 comments on commit efbfb29

Please sign in to comment.