From 0643c90f3a6516d69d9f406ea05cea2bf823a74c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 17 Nov 2020 21:11:44 +1100 Subject: [PATCH] Mobile: Make menu input overlay clearer and make it actually stay onscreen on an ipad (Thanks Isabella) --- src/Menus.c | 21 +++++++++++++++++++-- src/Screens.c | 2 +- src/Window.c | 5 +++-- src/Window.h | 6 +++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Menus.c b/src/Menus.c index 1eecc9909..5b9b12335 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -2043,8 +2043,12 @@ static void MenuInputOverlay_Init(void* screen) { s->maxVertices = MENUINPUT_MAX_VERTICES; TextInputWidget_Create(&s->input, 400, &s->value, s->desc); - ButtonWidget_Init(&s->ok, 40, MenuInputOverlay_OK); ButtonWidget_Init(&s->Default, 200, MenuInputOverlay_Default); +#ifdef CC_BUILD_TOUCH + ButtonWidget_Init(&s->ok, Input_TouchMode ? 200 : 40, MenuInputOverlay_OK); +#else + ButtonWidget_Init(&s->ok, 40, MenuInputOverlay_OK); +#endif Window_OpenKeyboard(&s->value, (s->desc->VTABLE == &IntInput_VTABLE || s->desc->VTABLE == &FloatInput_VTABLE) @@ -2078,6 +2082,19 @@ static void MenuInputOverlay_Layout(void* screen) { Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 110); Widget_SetLocation(&s->ok, ANCHOR_CENTRE, ANCHOR_CENTRE, 240, 110); Widget_SetLocation(&s->Default, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 150); + +#ifdef CC_BUILD_TOUCH + if (!Input_TouchMode) return; + if (WindowInfo.SoftKeyboard == SOFT_KEYBOARD_SHIFT) { + Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_MAX, 0, 65); + Widget_SetLocation(&s->ok, ANCHOR_CENTRE, ANCHOR_MAX, 120, 25); + Widget_SetLocation(&s->Default, ANCHOR_CENTRE, ANCHOR_MAX, -120, 25); + } else { + Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 110); + Widget_SetLocation(&s->ok, ANCHOR_CENTRE, ANCHOR_CENTRE, 120, 150); + Widget_SetLocation(&s->Default, ANCHOR_CENTRE, ANCHOR_CENTRE, -120, 150); + } +#endif } static void MenuInputOverlay_ContextLost(void* screen) { @@ -2306,7 +2323,7 @@ static void MenuOptionsScreen_Input(void* screen, void* widget) { String_InitArray(value, valueBuffer); btn->GetValue(&value); desc = &s->descs[s->activeI]; - MenuInputOverlay_Show(desc, &value, MenuOptionsScreen_OnDone, false); + MenuInputOverlay_Show(desc, &value, MenuOptionsScreen_OnDone, Input_TouchMode); } static void MenuOptionsScreen_OnHacksChanged(void* screen) { diff --git a/src/Screens.c b/src/Screens.c index df99363e8..7f4a43343 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1073,7 +1073,7 @@ static void ChatScreen_Layout(void* screen) { #ifdef CC_BUILD_TOUCH if (!Input_TouchMode) return; - if (WindowInfo._preferBottom) { + if (WindowInfo.SoftKeyboard == SOFT_KEYBOARD_SHIFT) { Widget_SetLocation(&s->send, ANCHOR_MAX, ANCHOR_MAX, 10, 60); Widget_SetLocation(&s->cancel, ANCHOR_MAX, ANCHOR_MAX, 10, 10); } else { diff --git a/src/Window.c b/src/Window.c index b24a60b22..0c1b81ebc 100644 --- a/src/Window.c +++ b/src/Window.c @@ -3424,7 +3424,8 @@ void Window_Init(void) { /* as the chat/send butons are positioned at the top of the canvas - they */ /* get pushed offscreen and can't be used at all anymore. So handle this */ /* case specially by positioning them at the bottom instead for iOS. */ - WindowInfo._preferBottom = EM_ASM_INT_V({ return /iPhone|iPad|iPod/i.test(navigator.userAgent); }); + WindowInfo.SoftKeyboard = EM_ASM_INT_V({ return /iPhone|iPad|iPod/i.test(navigator.userAgent); }) + ? SOFT_KEYBOARD_SHIFT : SOFT_KEYBOARD_RESIZE; } void Window_Create(int width, int height) { @@ -3911,7 +3912,7 @@ void Window_Init(void) { JavaGetCurrentEnv(env); JavaRegisterNatives(env, methods); - WindowInfo.SoftKeyboard = true; + WindowInfo.SoftKeyboard = SOFT_KEYBOARD_RESIZE; Input_TouchMode = true; DisplayInfo.Depth = 32; DisplayInfo.ScaleX = JavaCallFloat(env, "getDpiX", "()F", NULL); diff --git a/src/Window.h b/src/Window.h index 34e513642..da12a2c4f 100644 --- a/src/Window.h +++ b/src/Window.h @@ -35,6 +35,7 @@ struct DynamicLibSym; /* The states the window can be in. */ enum WindowState { WINDOW_STATE_NORMAL, WINDOW_STATE_FULLSCREEN, WINDOW_STATE_MINIMISED }; enum KeyboardType { KEYBOARD_TYPE_TEXT, KEYBOARD_TYPE_NUMBER, KEYBOARD_TYPE_PASSWORD }; +enum SoftKeyboard { SOFT_KEYBOARD_NONE, SOFT_KEYBOARD_RESIZE, SOFT_KEYBOARD_SHIFT }; /* Can't name these structs Window/Display, because it conflicts with X11's Window/Display typedef */ /* Data for the display monitor. */ @@ -70,9 +71,8 @@ CC_VAR extern struct _WinData { cc_bool Exists; /* Whether the user is interacting with the window. */ cc_bool Focused; - /* Whether the platform only supports on-screen keyboard. */ - cc_bool SoftKeyboard; - cc_bool _preferBottom; + /* The type of on-screen keyboard this platform supports. (usually SOFT_KEYBOARD_NONE) */ + cc_uint8 SoftKeyboard; } WindowInfo; /* Initialises state for window. Also sets Display_ members. */