The text input state has been changed to be window-specific.
SDL_StartTextInput(), SDL_StopTextInput(), SDL_TextInputActive(), SDL_ClearComposition(), and SDL_SetTextInputRect() all now take a window parameter. This change also fixes IME candidate positioning when SDL_SetTextInputRect() is called before SDL_StartTextInput(), as is recommended in the documentation.
This commit is contained in:
@@ -252,28 +252,34 @@ static void loop(void)
|
||||
SDLTest_TextWindowAddText(textwin, "%s", event.text.text);
|
||||
break;
|
||||
case SDL_EVENT_FINGER_DOWN:
|
||||
if (SDL_TextInputActive()) {
|
||||
{
|
||||
SDL_Window *window = SDL_GetWindowFromID(event.tfinger.windowID);
|
||||
if (SDL_TextInputActive(window)) {
|
||||
SDL_Log("Stopping text input\n");
|
||||
SDL_StopTextInput();
|
||||
SDL_StopTextInput(window);
|
||||
} else {
|
||||
SDL_Log("Starting text input\n");
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(window);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
{
|
||||
SDL_Window *window = SDL_GetWindowFromID(event.button.windowID);
|
||||
/* Left button quits the app, other buttons toggles text input */
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
done = 1;
|
||||
} else {
|
||||
if (SDL_TextInputActive()) {
|
||||
if (SDL_TextInputActive(window)) {
|
||||
SDL_Log("Stopping text input\n");
|
||||
SDL_StopTextInput();
|
||||
SDL_StopTextInput(window);
|
||||
} else {
|
||||
SDL_Log("Starting text input\n");
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(window);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_KEYMAP_CHANGED:
|
||||
SDL_Log("Keymap changed!\n");
|
||||
PrintKeymap();
|
||||
@@ -356,9 +362,9 @@ int main(int argc, char *argv[])
|
||||
input_rect.y = h / 4;
|
||||
input_rect.w = w / 2;
|
||||
input_rect.h = h / 2;
|
||||
SDL_SetTextInputRect(&input_rect);
|
||||
SDL_SetTextInputRect(state->windows[0], &input_rect);
|
||||
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(state->windows[0]);
|
||||
|
||||
/* Print initial state */
|
||||
SDL_PumpEvents();
|
||||
|
||||
@@ -186,20 +186,24 @@ static void loop(void)
|
||||
PrintText("INPUT", event.text.text);
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
{
|
||||
SDL_Window *window = SDL_GetWindowFromID(event.button.windowID);
|
||||
|
||||
/* Left button quits the app, other buttons toggles text input */
|
||||
SDL_Log("mouse button down button: %d (LEFT=%d)\n", event.button.button, SDL_BUTTON_LEFT);
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
done = 1;
|
||||
} else {
|
||||
if (SDL_TextInputActive()) {
|
||||
if (SDL_TextInputActive(window)) {
|
||||
SDL_Log("Stopping text input\n");
|
||||
SDL_StopTextInput();
|
||||
SDL_StopTextInput(window);
|
||||
} else {
|
||||
SDL_Log("Starting text input\n");
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(window);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
@@ -278,7 +282,7 @@ int main(int argc, char *argv[])
|
||||
SDL_GL_CreateContext(window);
|
||||
#endif
|
||||
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(window);
|
||||
|
||||
/* Print initial modifier state */
|
||||
SDL_PumpEvents();
|
||||
|
||||
@@ -336,36 +336,38 @@ static int keyboard_getSetModState(void *arg)
|
||||
*/
|
||||
static int keyboard_startStopTextInput(void *arg)
|
||||
{
|
||||
SDL_Window *window = SDL_GetKeyboardFocus();
|
||||
|
||||
/* Start-Stop */
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(window);
|
||||
SDLTest_AssertPass("Call to SDL_StartTextInput()");
|
||||
SDL_StopTextInput();
|
||||
SDL_StopTextInput(window);
|
||||
SDLTest_AssertPass("Call to SDL_StopTextInput()");
|
||||
|
||||
/* Stop-Start */
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(window);
|
||||
SDLTest_AssertPass("Call to SDL_StartTextInput()");
|
||||
|
||||
/* Start-Start */
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(window);
|
||||
SDLTest_AssertPass("Call to SDL_StartTextInput()");
|
||||
|
||||
/* Stop-Stop */
|
||||
SDL_StopTextInput();
|
||||
SDL_StopTextInput(window);
|
||||
SDLTest_AssertPass("Call to SDL_StopTextInput()");
|
||||
SDL_StopTextInput();
|
||||
SDL_StopTextInput(window);
|
||||
SDLTest_AssertPass("Call to SDL_StopTextInput()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* Internal function to test SDL_SetTextInputRect */
|
||||
static void testSetTextInputRect(SDL_Rect refRect)
|
||||
static void testSetTextInputRect(SDL_Window *window, SDL_Rect refRect)
|
||||
{
|
||||
SDL_Rect testRect;
|
||||
|
||||
testRect = refRect;
|
||||
SDL_SetTextInputRect(&testRect);
|
||||
SDL_SetTextInputRect(window, &testRect);
|
||||
SDLTest_AssertPass("Call to SDL_SetTextInputRect with refRect(x:%d,y:%d,w:%d,h:%d)", refRect.x, refRect.y, refRect.w, refRect.h);
|
||||
SDLTest_AssertCheck(
|
||||
(refRect.x == testRect.x) && (refRect.y == testRect.y) && (refRect.w == testRect.w) && (refRect.h == testRect.h),
|
||||
@@ -381,6 +383,7 @@ static void testSetTextInputRect(SDL_Rect refRect)
|
||||
*/
|
||||
static int keyboard_setTextInputRect(void *arg)
|
||||
{
|
||||
SDL_Window *window = SDL_GetKeyboardFocus();
|
||||
SDL_Rect refRect;
|
||||
|
||||
/* Normal visible refRect, origin inside */
|
||||
@@ -388,66 +391,66 @@ static int keyboard_setTextInputRect(void *arg)
|
||||
refRect.y = SDLTest_RandomIntegerInRange(1, 50);
|
||||
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
|
||||
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
|
||||
testSetTextInputRect(refRect);
|
||||
testSetTextInputRect(window, refRect);
|
||||
|
||||
/* Normal visible refRect, origin 0,0 */
|
||||
refRect.x = 0;
|
||||
refRect.y = 0;
|
||||
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
|
||||
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
|
||||
testSetTextInputRect(refRect);
|
||||
testSetTextInputRect(window, refRect);
|
||||
|
||||
/* 1Pixel refRect */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(10, 50);
|
||||
refRect.y = SDLTest_RandomIntegerInRange(10, 50);
|
||||
refRect.w = 1;
|
||||
refRect.h = 1;
|
||||
testSetTextInputRect(refRect);
|
||||
testSetTextInputRect(window, refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 1;
|
||||
refRect.y = 1;
|
||||
refRect.w = 1;
|
||||
refRect.h = 0;
|
||||
testSetTextInputRect(refRect);
|
||||
testSetTextInputRect(window, refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 1;
|
||||
refRect.y = 1;
|
||||
refRect.w = 0;
|
||||
refRect.h = 1;
|
||||
testSetTextInputRect(refRect);
|
||||
testSetTextInputRect(window, refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 1;
|
||||
refRect.y = 1;
|
||||
refRect.w = 0;
|
||||
refRect.h = 0;
|
||||
testSetTextInputRect(refRect);
|
||||
testSetTextInputRect(window, refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 0;
|
||||
refRect.y = 0;
|
||||
refRect.w = 0;
|
||||
refRect.h = 0;
|
||||
testSetTextInputRect(refRect);
|
||||
testSetTextInputRect(window, refRect);
|
||||
|
||||
/* negative refRect */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(-200, -100);
|
||||
refRect.y = SDLTest_RandomIntegerInRange(-200, -100);
|
||||
refRect.w = 50;
|
||||
refRect.h = 50;
|
||||
testSetTextInputRect(refRect);
|
||||
testSetTextInputRect(window, refRect);
|
||||
|
||||
/* oversized refRect */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(1, 50);
|
||||
refRect.y = SDLTest_RandomIntegerInRange(1, 50);
|
||||
refRect.w = 5000;
|
||||
refRect.h = 5000;
|
||||
testSetTextInputRect(refRect);
|
||||
testSetTextInputRect(window, refRect);
|
||||
|
||||
/* NULL refRect */
|
||||
SDL_SetTextInputRect(NULL);
|
||||
SDL_SetTextInputRect(window, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
@@ -470,7 +473,7 @@ static int keyboard_setTextInputRectNegative(void *arg)
|
||||
#endif
|
||||
|
||||
/* NULL refRect */
|
||||
SDL_SetTextInputRect(NULL);
|
||||
SDL_SetTextInputRect(SDL_GetKeyboardFocus(), NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
|
||||
|
||||
/* Some platforms set also an error message; so check it */
|
||||
|
||||
@@ -440,12 +440,12 @@ static void InitInput(void)
|
||||
markedRect = textRect;
|
||||
markedText[0] = 0;
|
||||
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(state->windows[0]);
|
||||
}
|
||||
|
||||
static void CleanupVideo(void)
|
||||
{
|
||||
SDL_StopTextInput();
|
||||
SDL_StopTextInput(state->windows[0]);
|
||||
#ifdef HAVE_SDL_TTF
|
||||
TTF_CloseFont(font);
|
||||
TTF_Quit();
|
||||
@@ -507,10 +507,10 @@ static void _Redraw(int rendererID)
|
||||
markedRect.w = textRect.w - drawnTextRect.w;
|
||||
if (markedRect.w < 0) {
|
||||
/* Stop text input because we cannot hold any more characters */
|
||||
SDL_StopTextInput();
|
||||
SDL_StopTextInput(state->windows[0]);
|
||||
return;
|
||||
} else {
|
||||
SDL_StartTextInput();
|
||||
SDL_StartTextInput(state->windows[0]);
|
||||
}
|
||||
|
||||
cursorRect = drawnTextRect;
|
||||
@@ -602,7 +602,7 @@ static void _Redraw(int rendererID)
|
||||
inputrect.y = (int)markedRect.y;
|
||||
inputrect.w = (int)markedRect.w;
|
||||
inputrect.h = (int)markedRect.h;
|
||||
SDL_SetTextInputRect(&inputrect);
|
||||
SDL_SetTextInputRect(state->windows[0], &inputrect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user