comparison test/testime.c @ 3133:84119fe89d26 gsoc2009_IME

Draw cursor, underline marked text
author Jiang Jiang <gzjjgod@gmail.com>
date Wed, 01 Jul 2009 16:12:00 +0000
parents 88861448961f
children f896821736fb
comparison
equal deleted inserted replaced
3132:88861448961f 3133:84119fe89d26
61 width, height, SDL_GetError()); 61 width, height, SDL_GetError());
62 return -1; 62 return -1;
63 } 63 }
64 64
65 /* Prepare a rect for text input */ 65 /* Prepare a rect for text input */
66 SDL_Rect textRect = { 100, 80, 300, 50 }, markedRect; 66 SDL_Rect textRect = { 100, 80, 300, 50 }, markedRect, underlineRect, cursorRect;
67 Uint32 backColor = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF); 67 Uint32 backColor = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF);
68 Uint32 lineColor = SDL_MapRGB(screen->format, 0x0, 0x0, 0x0);
68 SDL_Color textColor = { 0, 0, 0 }; 69 SDL_Color textColor = { 0, 0, 0 };
69 SDL_FillRect(screen, &textRect, backColor); 70 SDL_FillRect(screen, &textRect, backColor);
70 71
71 markedRect = textRect; 72 markedRect = textRect;
72 SDL_StartTextInput(&markedRect); 73 SDL_StartTextInput(&markedRect);
104 SDL_FillRect(screen, &textRect, backColor); 105 SDL_FillRect(screen, &textRect, backColor);
105 106
106 render_text(screen, font, text, textRect.x, textRect.y, textColor); 107 render_text(screen, font, text, textRect.x, textRect.y, textColor);
107 TTF_SizeUTF8(font, text, &w, &h); 108 TTF_SizeUTF8(font, text, &w, &h);
108 markedRect.x = textRect.x + w; 109 markedRect.x = textRect.x + w;
110
111 cursorRect = markedRect;
112 cursorRect.w = 2;
113 cursorRect.h = h;
114 SDL_FillRect(screen, &cursorRect, lineColor);
109 SDL_Flip(screen); 115 SDL_Flip(screen);
110 116
111 SDL_StartTextInput(&markedRect); 117 SDL_StartTextInput(&markedRect);
112 break; 118 break;
113 119
115 fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n", 121 fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n",
116 event.edit.text, event.edit.start, event.edit.length); 122 event.edit.text, event.edit.start, event.edit.length);
117 123
118 SDL_FillRect(screen, &markedRect, backColor); 124 SDL_FillRect(screen, &markedRect, backColor);
119 render_text(screen, font, event.edit.text, markedRect.x, markedRect.y, textColor); 125 render_text(screen, font, event.edit.text, markedRect.x, markedRect.y, textColor);
126 TTF_SizeUTF8(font, event.edit.text, &w, &h);
127 underlineRect = markedRect;
128 underlineRect.y += (h - 2);
129 underlineRect.h = 2;
130 underlineRect.w = w;
131 SDL_FillRect(screen, &underlineRect, lineColor);
132
120 SDL_Flip(screen); 133 SDL_Flip(screen);
121 break; 134 break;
122 135
123 case SDL_QUIT: 136 case SDL_QUIT:
124 done = 1; 137 done = 1;