comparison test/testime.c @ 4638:08d22c54a21f

Don't need to use strlen() to determine if there's text. Use the SDL safe strcpy() function
author Sam Lantinga <slouken@libsdl.org>
date Sun, 22 Aug 2010 11:56:07 -0700
parents 8c229370ddba
children 518d1679d2d0
comparison
equal deleted inserted replaced
4637:8c229370ddba 4638:08d22c54a21f
134 TTF_Font *font, 134 TTF_Font *font,
135 const char *text, 135 const char *text,
136 int x, int y, 136 int x, int y,
137 SDL_Color color) 137 SDL_Color color)
138 { 138 {
139 if (text && strlen(text)) { 139 if (text && *text) {
140 SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, color); 140 SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, color);
141 SDL_Rect dest = { x, y, textSur->w, textSur->h }; 141 SDL_Rect dest = { x, y, textSur->w, textSur->h };
142 142
143 SDL_BlitSurface(textSur, NULL, sur, &dest); 143 SDL_BlitSurface(textSur, NULL, sur, &dest);
144 SDL_FreeSurface(textSur); 144 SDL_FreeSurface(textSur);
152 SDL_Rect cursorRect, underlineRect; 152 SDL_Rect cursorRect, underlineRect;
153 153
154 SDL_FillRect(screen, &textRect, backColor); 154 SDL_FillRect(screen, &textRect, backColor);
155 155
156 #ifdef HAVE_SDL_TTF 156 #ifdef HAVE_SDL_TTF
157 if (strlen(text)) 157 if (*text)
158 { 158 {
159 RenderText(screen, font, text, textRect.x, textRect.y, textColor); 159 RenderText(screen, font, text, textRect.x, textRect.y, textColor);
160 TTF_SizeUTF8(font, text, &w, &h); 160 TTF_SizeUTF8(font, text, &w, &h);
161 } 161 }
162 #endif 162 #endif
293 break; 293 break;
294 294
295 fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text); 295 fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text);
296 296
297 if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) 297 if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
298 strcpy(text + SDL_strlen(text), event.text.text); 298 SDL_strlcpy(text + SDL_strlen(text), event.text.text, sizeof(text));
299 299
300 fprintf(stderr, "text inputed: %s\n", text); 300 fprintf(stderr, "text inputed: %s\n", text);
301 301
302 // After text inputed, we can clear up markedText because it 302 // After text inputed, we can clear up markedText because it
303 // is committed 303 // is committed