testime.c fixes from SDL2 branch.

This commit is contained in:
Ozkan Sezer 2023-02-10 11:11:10 +03:00
parent adf31f6ec0
commit 853ee9a3e6
1 changed files with 34 additions and 46 deletions

View File

@ -679,7 +679,6 @@ int main(int argc, char *argv[])
return 2; return 2;
} }
#ifdef HAVE_SDL_TTF #ifdef HAVE_SDL_TTF
/* Initialize fonts */ /* Initialize fonts */
TTF_Init(); TTF_Init();
@ -714,51 +713,44 @@ int main(int argc, char *argv[])
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done); SDLTest_CommonEvent(state, &event, &done);
switch(event.type) { switch(event.type) {
case SDL_KEYDOWN: { case SDL_KEYDOWN:
switch (event.key.keysym.sym) switch (event.key.keysym.sym) {
{ case SDLK_RETURN:
case SDLK_RETURN: text[0] = 0x00;
text[0]=0x00; Redraw();
Redraw(); break;
break; case SDLK_BACKSPACE:
case SDLK_BACKSPACE: /* Only delete text if not in editing mode. */
/* Only delete text if not in editing mode. */ if (!markedText[0]) {
if (!markedText[0]) size_t textlen = SDL_strlen(text);
{
size_t textlen = SDL_strlen(text);
do { do {
if (textlen==0) if (textlen == 0) {
{ break;
break; }
} if ((text[textlen - 1] & 0x80) == 0x00) {
if ((text[textlen-1] & 0x80) == 0x00) /* One byte */
{ text[textlen - 1] = 0x00;
/* One byte */ break;
text[textlen-1]=0x00; }
break; if ((text[textlen - 1] & 0xC0) == 0x80) {
} /* Byte from the multibyte sequence */
if ((text[textlen-1] & 0xC0) == 0x80) text[textlen - 1] = 0x00;
{ textlen--;
/* Byte from the multibyte sequence */ }
text[textlen-1]=0x00; if ((text[textlen - 1] & 0xC0) == 0xC0) {
textlen--; /* First byte of multibyte sequence */
} text[textlen - 1] = 0x00;
if ((text[textlen-1] & 0xC0) == 0xC0) break;
{ }
/* First byte of multibyte sequence */ } while(1);
text[textlen-1]=0x00;
break;
}
} while(1);
Redraw(); Redraw();
} }
break; break;
} }
if (done) if (done) {
{
break; break;
} }
@ -796,9 +788,6 @@ int main(int argc, char *argv[])
Redraw(); Redraw();
break; break;
} }
break;
}
} }
} }
CleanupVideo(); CleanupVideo();
@ -806,5 +795,4 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */