Updated iOS keyboard test to cover text input rect and orientation changes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
diff --git a/Xcode-iOS/Demos/src/keyboard.c b/Xcode-iOS/Demos/src/keyboard.c
index 4227c19..cfbe4e6 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) {