comparison test/testime.c @ 4756:b99b1024607a

Changed markedText to have its own storage to resolve multiple bugs. Changed an odd strcpy to a more appropriate strcat.
author dewyatt
date Sat, 24 Jul 2010 20:48:50 -0400
parents 3e69e077cb95
children 140be6839185
comparison
equal deleted inserted replaced
4755:436183eb30c8 4756:b99b1024607a
23 TTF_Font *font; 23 TTF_Font *font;
24 #endif 24 #endif
25 SDL_Rect textRect, markedRect; 25 SDL_Rect textRect, markedRect;
26 Uint32 lineColor, backColor; 26 Uint32 lineColor, backColor;
27 SDL_Color textColor = { 0, 0, 0 }; 27 SDL_Color textColor = { 0, 0, 0 };
28 char text[MAX_TEXT_LENGTH], *markedText; 28 char text[MAX_TEXT_LENGTH], markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
29 29
30 void usage() 30 void usage()
31 { 31 {
32 printf("usage: testime [--font fontfile] [--fullscreen]\n"); 32 printf("usage: testime [--font fontfile] [--fullscreen]\n");
33 exit(0); 33 exit(0);
122 textRect.w = screen->w - 2 * textRect.x; 122 textRect.w = screen->w - 2 * textRect.x;
123 textRect.h = 50; 123 textRect.h = 50;
124 124
125 text[0] = 0; 125 text[0] = 0;
126 markedRect = textRect; 126 markedRect = textRect;
127 markedText = NULL; 127 markedText[0] = 0;
128 128
129 SDL_StartTextInput(); 129 SDL_StartTextInput();
130 } 130 }
131 131
132 #ifdef HAVE_SDL_TTF 132 #ifdef HAVE_SDL_TTF
176 cursorRect = markedRect; 176 cursorRect = markedRect;
177 cursorRect.w = 2; 177 cursorRect.w = 2;
178 cursorRect.h = h; 178 cursorRect.h = h;
179 179
180 SDL_FillRect(screen, &markedRect, backColor); 180 SDL_FillRect(screen, &markedRect, backColor);
181 if (markedText) 181 if (markedText[0])
182 { 182 {
183 #ifdef HAVE_SDL_TTF 183 #ifdef HAVE_SDL_TTF
184 RenderText(screen, font, markedText, markedRect.x, markedRect.y, textColor); 184 RenderText(screen, font, markedText, markedRect.x, markedRect.y, textColor);
185 TTF_SizeUTF8(font, markedText, &w, &h); 185 TTF_SizeUTF8(font, markedText, &w, &h);
186 #endif 186 #endif
291 break; 291 break;
292 292
293 fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text); 293 fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text);
294 294
295 if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) 295 if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
296 strcpy(text + SDL_strlen(text), event.text.text); 296 strcat(text, event.text.text);
297 297
298 fprintf(stderr, "text inputed: %s\n", text); 298 fprintf(stderr, "text inputed: %s\n", text);
299 299
300 // After text inputed, we can clear up markedText because it 300 // After text inputed, we can clear up markedText because it
301 // is committed 301 // is committed
302 markedText = NULL; 302 markedText[0] = 0;
303 Redraw(); 303 Redraw();
304 break; 304 break;
305 305
306 case SDL_TEXTEDITING: 306 case SDL_TEXTEDITING:
307 fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n", 307 fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n",
308 event.edit.text, event.edit.start, event.edit.length); 308 event.edit.text, event.edit.start, event.edit.length);
309 309
310 markedText = event.edit.text; 310 strcpy(markedText, event.edit.text);
311 Redraw(); 311 Redraw();
312 break; 312 break;
313 313
314 case SDL_QUIT: 314 case SDL_QUIT:
315 done = 1; 315 done = 1;