From ecddb28d343a9ec10f5c46133aef244ab235de3b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 10 Oct 2020 10:37:49 +1100 Subject: [PATCH] Add keyboard type to Window_OpenKeyboard (not used yet) --- src/LWidgets.c | 2 +- src/Menus.c | 8 ++++---- src/Screens.c | 2 +- src/Window.c | 24 ++++++++++++------------ src/Window.h | 5 +++-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/LWidgets.c b/src/LWidgets.c index 6523de16a..5da78aa26 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -422,7 +422,7 @@ static void LInput_Select(void* widget, cc_bool wasSelected) { /* TODO: Only draw outer border */ if (wasSelected) return; LWidget_Draw(widget); - Window_OpenKeyboard(); + Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); } static void LInput_Unselect(void* widget) { diff --git a/src/Menus.c b/src/Menus.c index e3221d0eb..4642945bc 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -944,7 +944,7 @@ static void EditHotkeyScreen_Init(void* screen) { MenuInputWidget_Create(&s->input, 500, &text, &desc); Menu_InitBack(&s->cancel, Menu_SwitchHotkeys); - Window_OpenKeyboard(); + Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); Window_SetKeyboardText(&text); } @@ -1149,7 +1149,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(); + Window_OpenKeyboard(KEYBOARD_TYPE_NUMBER); } static const struct ScreenVTABLE GenLevelScreen_VTABLE = { @@ -1505,7 +1505,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(); + Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); } static const struct ScreenVTABLE SaveLevelScreen_VTABLE = { @@ -2252,7 +2252,7 @@ static void MenuOptionsScreen_Input(void* screen, void* widget) { s->numWidgets = MENUOPTS_MAX_OPTS + 1 + 3; MenuOptionsScreen_Layout(screen); MenuOptionsScreen_RedrawInput(s); - Window_OpenKeyboard(); + Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); Window_SetKeyboardText(&value); } diff --git a/src/Screens.c b/src/Screens.c index 455a23392..cbe734a55 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1278,7 +1278,7 @@ void ChatScreen_OpenInput(const String* text) { s->suppressNextPress = true; s->grabsInput = true; Camera_CheckFocus(); - Window_OpenKeyboard(); + Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); Window_SetKeyboardText(text); String_Copy(&s->input.base.text, text); diff --git a/src/Window.c b/src/Window.c index d0fb6475c..f85ea2a79 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(void) { SDL_StartTextInput(); } +void Window_OpenKeyboard(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(void) { } +void Window_OpenKeyboard(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(void) { } +void Window_OpenKeyboard(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(void) { } +void Window_OpenKeyboard(int type) { } void Window_SetKeyboardText(const String* text) { } -void Window_CloseKeyboard(void) { } +void Window_CloseKeyboard(void) { } void Window_EnableRawMouse(void) { DefaultEnableRawMouse(); @@ -3500,12 +3500,12 @@ EMSCRIPTEN_KEEPALIVE void Window_OnTextChanged(const char* src) { Event_RaiseString(&InputEvents.TextChanged, &str); } -void Window_OpenKeyboard(void) { +void Window_OpenKeyboard(int type) { if (!Input_TouchMode) return; keyboardOpen = true; Platform_LogConst("OPEN SESAME"); - EM_ASM({ + EM_ASM_({ var elem = window.cc_inputElem; if (!elem) { elem = document.createElement('textarea'); @@ -3521,7 +3521,7 @@ void Window_OpenKeyboard(void) { } elem.focus(); elem.click(); - }); + }, type); } void Window_SetKeyboardText(const String* text) { @@ -3890,7 +3890,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { Mem_Free(bmp->scan0); } -void Window_OpenKeyboard(void) { +void Window_OpenKeyboard(int type) { JNIEnv* env; JavaGetCurrentEnv(env); JavaCallVoid(env, "openKeyboard", "()V", NULL); diff --git a/src/Window.h b/src/Window.h index a2f9c243a..ba03692bf 100644 --- a/src/Window.h +++ b/src/Window.h @@ -34,7 +34,8 @@ struct Bitmap; struct DynamicLibSym; /* The states the window can be in. */ enum WindowState { WINDOW_STATE_NORMAL, WINDOW_STATE_MINIMISED, WINDOW_STATE_FULLSCREEN }; -/* Can't name these Window/Display, because it conflicts with X11's Window/Display typedef */ +enum KeyboardType { KEYBOARD_TYPE_TEXT, KEYBOARD_TYPE_PASSWORD, KEYBOARD_TYPE_NUMBER }; +/* Can't name these structs Window/Display, because it conflicts with X11's Window/Display typedef */ /* Data for the display monitor. */ CC_VAR extern struct _DisplayData { @@ -129,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(void); +void Window_OpenKeyboard(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. */