From 6607e15100128b6898e68fb3c9f00fddfeacf9f8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 13 Oct 2020 19:21:32 +1100 Subject: [PATCH] Backport adding text argument to Window_OpenKeyboard from AndroidInputTouch branch --- .gitignore | 1 + src/Graphics.h | 2 +- src/Gui.h | 3 +-- src/LWidgets.c | 5 +++-- src/Menus.c | 10 ++++------ src/Screens.c | 3 +-- src/Window.c | 25 ++++++++++++++----------- src/Window.h | 4 ++-- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index e8928e3da..4bc578484 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ *.VC.VC.opendb # Android build results +android/.idea/ android/.gradle/ android/build/ android/app/build/ diff --git a/src/Graphics.h b/src/Graphics.h index ff9d91a55..e87169519 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -191,7 +191,7 @@ void Gfx_BeginFrame(void); void Gfx_EndFrame(void); /* Sets whether to synchronise with monitor refresh to avoid tearing, and maximum frame rate. */ /* NOTE: VSync setting may be unsupported or just ignored. */ -void Gfx_SetFpsLimit(cc_bool value, float minFrameMillis); +void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMillis); /* Updates state when the window's dimensions have changed. */ /* NOTE: This may require recreating the context depending on the backend. */ void Gfx_OnWindowResize(void); diff --git a/src/Gui.h b/src/Gui.h index 029af0142..2f3a5a4d3 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -67,8 +67,7 @@ struct ScreenVTABLE { int (*HandlesInputUp)(void* elem, int key); /* Returns non-zero if a key character press is handled. */ int (*HandlesKeyPress)(void* elem, char keyChar); - /* Returns non-zero if a key character press is handled. */ - /* Currently only raised by on-screen keyboard in web client. */ + /* Returns non-zero if on-screen keyboard text changed is handled. */ int (*HandlesTextChanged)(void* elem, const String* str); /* Returns non-zero if a pointer press is handled. */ int (*HandlesPointerDown)(void* elem, int id, int x, int y); diff --git a/src/LWidgets.c b/src/LWidgets.c index 5da78aa26..07772f791 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -417,12 +417,13 @@ static void LInput_MoveCaretToCursor(struct LInput* w) { } static void LInput_Select(void* widget, cc_bool wasSelected) { + struct LInput* w = (struct LInput*)widget; caretStart = DateTime_CurrentUTC_MS(); - LInput_MoveCaretToCursor((struct LInput*)widget); + LInput_MoveCaretToCursor(w); /* TODO: Only draw outer border */ if (wasSelected) return; LWidget_Draw(widget); - Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); + Window_OpenKeyboard(&w->text, KEYBOARD_TYPE_TEXT); } static void LInput_Unselect(void* widget) { diff --git a/src/Menus.c b/src/Menus.c index 4642945bc..97fd40744 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -944,8 +944,7 @@ static void EditHotkeyScreen_Init(void* screen) { MenuInputWidget_Create(&s->input, 500, &text, &desc); Menu_InitBack(&s->cancel, Menu_SwitchHotkeys); - Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); - Window_SetKeyboardText(&text); + Window_OpenKeyboard(&text, KEYBOARD_TYPE_TEXT); } static const struct ScreenVTABLE EditHotkeyScreen_VTABLE = { @@ -1149,7 +1148,7 @@ static void GenLevelScreen_Init(void* screen) { ButtonWidget_Init(&s->flatgrass, 200, GenLevelScreen_Flatgrass); ButtonWidget_Init(&s->vanilla, 200, GenLevelScreen_Notchy); Menu_InitBack(&s->cancel, Menu_SwitchPause); - Window_OpenKeyboard(KEYBOARD_TYPE_NUMBER); + Window_OpenKeyboard(&String_Empty, KEYBOARD_TYPE_NUMBER); } static const struct ScreenVTABLE GenLevelScreen_VTABLE = { @@ -1505,7 +1504,7 @@ static void SaveLevelScreen_Init(void* screen) { Menu_InitBack(&s->cancel, Menu_SwitchPause); MenuInputWidget_Create(&s->input, 500, &String_Empty, &desc); TextWidget_Init(&s->desc); - Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); + Window_OpenKeyboard(&String_Empty, KEYBOARD_TYPE_TEXT); } static const struct ScreenVTABLE SaveLevelScreen_VTABLE = { @@ -2252,8 +2251,7 @@ static void MenuOptionsScreen_Input(void* screen, void* widget) { s->numWidgets = MENUOPTS_MAX_OPTS + 1 + 3; MenuOptionsScreen_Layout(screen); MenuOptionsScreen_RedrawInput(s); - Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); - Window_SetKeyboardText(&value); + Window_OpenKeyboard(&value, KEYBOARD_TYPE_TEXT); } static void MenuOptionsScreen_OnHacksChanged(void* screen) { diff --git a/src/Screens.c b/src/Screens.c index cbe734a55..af20c0e27 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1278,8 +1278,7 @@ void ChatScreen_OpenInput(const String* text) { s->suppressNextPress = true; s->grabsInput = true; Camera_CheckFocus(); - Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); - Window_SetKeyboardText(text); + Window_OpenKeyboard(text, KEYBOARD_TYPE_TEXT); String_Copy(&s->input.base.text, text); InputWidget_UpdateText(&s->input.base); diff --git a/src/Window.c b/src/Window.c index de604147d..a26769743 100644 --- a/src/Window.c +++ b/src/Window.c @@ -401,9 +401,9 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { /* TODO: Do we still need to unlock it though? */ } -void Window_OpenKeyboard(int type) { SDL_StartTextInput(); } +void Window_OpenKeyboard(const String* text, int type) { SDL_StartTextInput(); } void Window_SetKeyboardText(const String* text) { } -void Window_CloseKeyboard(void) { SDL_StopTextInput(); } +void Window_CloseKeyboard(void) { SDL_StopTextInput(); } void Window_EnableRawMouse(void) { RegrabMouse(); @@ -934,9 +934,9 @@ static void InitRawMouse(void) { rawMouseSupported = false; } -void Window_OpenKeyboard(int type) { } +void Window_OpenKeyboard(const String* text, int type) { } void Window_SetKeyboardText(const String* text) { } -void Window_CloseKeyboard(void) { } +void Window_CloseKeyboard(void) { } void Window_EnableRawMouse(void) { DefaultEnableRawMouse(); @@ -1818,9 +1818,9 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { Mem_Free(bmp->scan0); } -void Window_OpenKeyboard(int type) { } +void Window_OpenKeyboard(const String* text, int type) { } void Window_SetKeyboardText(const String* text) { } -void Window_CloseKeyboard(void) { } +void Window_CloseKeyboard(void) { } static cc_bool rawMouseInited, rawMouseSupported; static int xiOpcode; @@ -2034,9 +2034,9 @@ static void Cursor_DoSetVisible(cc_bool visible) { } } -void Window_OpenKeyboard(int type) { } +void Window_OpenKeyboard(const String* text, int type) { } void Window_SetKeyboardText(const String* text) { } -void Window_CloseKeyboard(void) { } +void Window_CloseKeyboard(void) { } void Window_EnableRawMouse(void) { DefaultEnableRawMouse(); @@ -3500,9 +3500,11 @@ EMSCRIPTEN_KEEPALIVE void Window_OnTextChanged(const char* src) { Event_RaiseString(&InputEvents.TextChanged, &str); } -void Window_OpenKeyboard(int type) { +void Window_OpenKeyboard(const String* text, int type) { + char str[NATIVE_STR_LEN]; if (!Input_TouchMode) return; keyboardOpen = true; + Platform_ConvertString(str, text); Platform_LogConst("OPEN SESAME"); EM_ASM_({ @@ -3510,6 +3512,7 @@ void Window_OpenKeyboard(int type) { if (!elem) { elem = document.createElement('textarea'); elem.setAttribute('style', 'position:absolute; left:0; top:0; width:100%; height:100%; opacity:0.3; resize:none; pointer-events:none;'); + elem.value = UTF8ToString($0); elem.addEventListener("input", function(ev) { @@ -3521,7 +3524,7 @@ void Window_OpenKeyboard(int type) { } elem.focus(); elem.click(); - }, type); + }, str, type); } void Window_SetKeyboardText(const String* text) { @@ -3930,7 +3933,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { Mem_Free(bmp->scan0); } -void Window_OpenKeyboard(int type) { +void Window_OpenKeyboard(const String* text, int type) { JNIEnv* env; JavaGetCurrentEnv(env); JavaCallVoid(env, "openKeyboard", "()V", NULL); diff --git a/src/Window.h b/src/Window.h index ba03692bf..ed99e59d2 100644 --- a/src/Window.h +++ b/src/Window.h @@ -34,7 +34,7 @@ struct Bitmap; struct DynamicLibSym; /* The states the window can be in. */ enum WindowState { WINDOW_STATE_NORMAL, WINDOW_STATE_MINIMISED, WINDOW_STATE_FULLSCREEN }; -enum KeyboardType { KEYBOARD_TYPE_TEXT, KEYBOARD_TYPE_PASSWORD, KEYBOARD_TYPE_NUMBER }; +enum KeyboardType { KEYBOARD_TYPE_TEXT, KEYBOARD_TYPE_NUMBER, KEYBOARD_TYPE_PASSWORD }; /* Can't name these structs Window/Display, because it conflicts with X11's Window/Display typedef */ /* Data for the display monitor. */ @@ -130,7 +130,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp); /* Displays on-screen keyboard for platforms that lack physical keyboard input. */ /* NOTE: On desktop platforms, this won't do anything. */ -void Window_OpenKeyboard(int type); +void Window_OpenKeyboard(const String* text, int type); /* Sets the text used for keyboard input. */ /* NOTE: This is only used for mobile on-screen keyboard input with the web client, */ /* because it is backed by a HTML input, rather than true keyboard input events. */