Recovering IM in a more generic way.

This commit is contained in:
Pere Pujal i Carabantes 2015-05-27 00:03:45 +02:00
parent ee3529b7bf
commit 356b503bdd
2 changed files with 27 additions and 11 deletions

View file

@ -712,6 +712,25 @@ int im_read(IM_DATA* im, SDL_Event event)
IM_EVENT_FN im_event_fp = NULL; IM_EVENT_FN im_event_fp = NULL;
int redraw = 0; int redraw = 0;
/* FIXME SDL2: This adds text to events that are not meant to carry text.
Right procedure would be to modify the different im_event_LL() functions,
but for now letting as this as it is what the functions expect. */
switch (event.key.keysym.sym)
{
case SDLK_BACKSPACE:
event.text.text[0] = L'\b';
event.text.text[1] = L'\0';
break;
case SDLK_RETURN:
event.text.text[0] = L'\r';
event.text.text[1] = L'\0';
break;
case SDLK_TAB:
event.text.text[0] = L'\t';
event.text.text[1] = L'\0';
break;
}
/* Sanity check */ /* Sanity check */
if(im->lang < 0 || im->lang >= NUM_LANGS) { if(im->lang < 0 || im->lang >= NUM_LANGS) {
fprintf(stderr, "im->lang out of range (%d), using default\n", im->lang); fprintf(stderr, "im->lang out of range (%d), using default\n", im->lang);
@ -905,12 +924,6 @@ static int im_event_zh_tw(IM_DATA* im, SDL_Event event)
case SDLK_MODE: case SDLK_APPLICATION: case SDLK_MODE: case SDLK_APPLICATION:
break; break;
/* This wasn't needed in SDL1.2 */
case SDLK_BACKSPACE:
im_fullreset(im);
im->s[0] = L'\b';
break;
/* Left-Alt & Right-Alt mapped to mode-switch */ /* Left-Alt & Right-Alt mapped to mode-switch */
case SDLK_RALT: case SDLK_LALT: case SDLK_RALT: case SDLK_LALT:
cm.section = (++cm.section % SEC_TOTAL); /* Change section */ cm.section = (++cm.section % SEC_TOTAL); /* Change section */
@ -935,7 +948,7 @@ static int im_event_zh_tw(IM_DATA* im, SDL_Event event)
/* Actual character processing */ /* Actual character processing */
default: default:
if (event.type == SDL_TEXTINPUT) if (event.type == SDL_TEXTINPUT|| ks.sym == SDLK_BACKSPACE|| ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
{ {
/* English mode */ /* English mode */
if(cm.section == SEC_ENGLISH) { if(cm.section == SEC_ENGLISH) {
@ -1317,6 +1330,8 @@ static int im_event_ja(IM_DATA* im, SDL_Event event)
/* Actual character processing */ /* Actual character processing */
default: default:
if (event.type == SDL_TEXTINPUT|| ks.sym == SDLK_BACKSPACE|| ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
{
/* English mode */ /* English mode */
if(cm.section == SEC_ENGLISH) { if(cm.section == SEC_ENGLISH) {
mbstowcs(im->s , event.text.text, 16); mbstowcs(im->s , event.text.text, 16);
@ -1403,7 +1418,7 @@ static int im_event_ja(IM_DATA* im, SDL_Event event)
} }
} }
} }
}
return im->redraw; return im->redraw;
} }
@ -1528,11 +1543,11 @@ static int im_event_ko(IM_DATA* im, SDL_Event event)
/* Actual character processing */ /* Actual character processing */
default: default:
if (event.type == SDL_TEXTINPUT|| ks.sym == SDLK_BACKSPACE|| ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
{
/* English mode */ /* English mode */
if(cm.section == SEC_ENGLISH) { if(cm.section == SEC_ENGLISH) {
mbstowcs(im->s , event.text.text, 16); mbstowcs(im->s , event.text.text, 16);
// im->s[0] = event.text.text[0];
// im->s[1] = L'\0';
im->buf[0] = L'\0'; im->buf[0] = L'\0';
} }
/* Hangul mode */ /* Hangul mode */
@ -1662,6 +1677,7 @@ static int im_event_ko(IM_DATA* im, SDL_Event event)
} }
} }
} }
}
return im->redraw; return im->redraw;
} }

View file

@ -2679,7 +2679,7 @@ static void mainloop(void)
if (texttool_len > 0) if (texttool_len > 0)
{ {
texttool_len--; texttool_len--;
texttool_str[texttool_len] = 0; texttool_str[texttool_len] = L'\0';
playsound(screen, 0, SND_KEYCLICK, 0, SNDPOS_CENTER, playsound(screen, 0, SND_KEYCLICK, 0, SNDPOS_CENTER,
SNDDIST_NEAR); SNDDIST_NEAR);