From e8187a3f788b71743e0b90c280d7665bd7f4be2f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 14 Sep 2017 09:56:16 -0700 Subject: [PATCH] Updated iOS keyboard test to cover text input rect and orientation changes --- Xcode-iOS/Demos/src/keyboard.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Xcode-iOS/Demos/src/keyboard.c b/Xcode-iOS/Demos/src/keyboard.c index 4227c1924..cfbe4e66b 100644 --- a/Xcode-iOS/Demos/src/keyboard.c +++ b/Xcode-iOS/Demos/src/keyboard.c @@ -7,6 +7,8 @@ #include "SDL.h" #include "common.h" +#define TEST_INPUT_RECT + #define GLYPH_SIZE_IMAGE 16 /* size of glyphs (characters) in the bitmap font file */ #define GLYPH_SIZE_SCREEN 32 /* size of glyphs (characters) as shown on the screen */ @@ -140,7 +142,11 @@ getPositionForCharNumber(int n, int *x, int *y) int max_x_chars = (renderW - 2 * x_padding) / GLYPH_SIZE_SCREEN; int line_separation = 5; /* pixels between each line */ *x = (n % max_x_chars) * GLYPH_SIZE_SCREEN + x_padding; +#ifdef TEST_INPUT_RECT + *y = renderH - GLYPH_SIZE_SCREEN; +#else *y = (n / max_x_chars) * (GLYPH_SIZE_SCREEN + line_separation) + y_padding; +#endif } void @@ -213,12 +219,13 @@ main(int argc, char *argv[]) int width; int height; int done; + SDL_Rect textrect; if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Error initializing SDL: %s", SDL_GetError()); } /* create window */ - window = SDL_CreateWindow("iOS keyboard test", 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI); + window = SDL_CreateWindow("iOS keyboard test", 0, 0, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); /* create renderer */ renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC); @@ -227,6 +234,16 @@ main(int argc, char *argv[]) /* load up our font */ loadFont(); + + /* Show onscreen keyboard */ +#ifdef TEST_INPUT_RECT + textrect.x = 0; + textrect.y = height - GLYPH_SIZE_IMAGE; + textrect.w = width; + textrect.h = GLYPH_SIZE_IMAGE; + SDL_SetTextInputRect(&textrect); +#endif + SDL_StartTextInput(); done = 0; while (!done) { @@ -235,6 +252,20 @@ main(int argc, char *argv[]) case SDL_QUIT: done = 1; break; + case SDL_WINDOWEVENT: + if (event.window.event == SDL_WINDOWEVENT_RESIZED) { + width = event.window.data1; + height = event.window.data2; + SDL_RenderSetLogicalSize(renderer, width, height); +#ifdef TEST_INPUT_RECT + textrect.x = 0; + textrect.y = height - GLYPH_SIZE_IMAGE; + textrect.w = width; + textrect.h = GLYPH_SIZE_IMAGE; + SDL_SetTextInputRect(&textrect); +#endif + } + break; case SDL_KEYDOWN: if (event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE) { if (numChars > 0) {