Backport adding text argument to Window_OpenKeyboard from AndroidInputTouch branch

This commit is contained in:
UnknownShadow200 2020-10-13 19:21:32 +11:00
parent 9225aecfad
commit 6607e15100
8 changed files with 27 additions and 26 deletions

1
.gitignore vendored
View File

@ -11,6 +11,7 @@
*.VC.VC.opendb *.VC.VC.opendb
# Android build results # Android build results
android/.idea/
android/.gradle/ android/.gradle/
android/build/ android/build/
android/app/build/ android/app/build/

View File

@ -191,7 +191,7 @@ void Gfx_BeginFrame(void);
void Gfx_EndFrame(void); void Gfx_EndFrame(void);
/* Sets whether to synchronise with monitor refresh to avoid tearing, and maximum frame rate. */ /* Sets whether to synchronise with monitor refresh to avoid tearing, and maximum frame rate. */
/* NOTE: VSync setting may be unsupported or just ignored. */ /* 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. */ /* Updates state when the window's dimensions have changed. */
/* NOTE: This may require recreating the context depending on the backend. */ /* NOTE: This may require recreating the context depending on the backend. */
void Gfx_OnWindowResize(void); void Gfx_OnWindowResize(void);

View File

@ -67,8 +67,7 @@ struct ScreenVTABLE {
int (*HandlesInputUp)(void* elem, int key); int (*HandlesInputUp)(void* elem, int key);
/* Returns non-zero if a key character press is handled. */ /* Returns non-zero if a key character press is handled. */
int (*HandlesKeyPress)(void* elem, char keyChar); int (*HandlesKeyPress)(void* elem, char keyChar);
/* Returns non-zero if a key character press is handled. */ /* Returns non-zero if on-screen keyboard text changed is handled. */
/* Currently only raised by on-screen keyboard in web client. */
int (*HandlesTextChanged)(void* elem, const String* str); int (*HandlesTextChanged)(void* elem, const String* str);
/* Returns non-zero if a pointer press is handled. */ /* Returns non-zero if a pointer press is handled. */
int (*HandlesPointerDown)(void* elem, int id, int x, int y); int (*HandlesPointerDown)(void* elem, int id, int x, int y);

View File

@ -417,12 +417,13 @@ static void LInput_MoveCaretToCursor(struct LInput* w) {
} }
static void LInput_Select(void* widget, cc_bool wasSelected) { static void LInput_Select(void* widget, cc_bool wasSelected) {
struct LInput* w = (struct LInput*)widget;
caretStart = DateTime_CurrentUTC_MS(); caretStart = DateTime_CurrentUTC_MS();
LInput_MoveCaretToCursor((struct LInput*)widget); LInput_MoveCaretToCursor(w);
/* TODO: Only draw outer border */ /* TODO: Only draw outer border */
if (wasSelected) return; if (wasSelected) return;
LWidget_Draw(widget); LWidget_Draw(widget);
Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); Window_OpenKeyboard(&w->text, KEYBOARD_TYPE_TEXT);
} }
static void LInput_Unselect(void* widget) { static void LInput_Unselect(void* widget) {

View File

@ -944,8 +944,7 @@ static void EditHotkeyScreen_Init(void* screen) {
MenuInputWidget_Create(&s->input, 500, &text, &desc); MenuInputWidget_Create(&s->input, 500, &text, &desc);
Menu_InitBack(&s->cancel, Menu_SwitchHotkeys); Menu_InitBack(&s->cancel, Menu_SwitchHotkeys);
Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); Window_OpenKeyboard(&text, KEYBOARD_TYPE_TEXT);
Window_SetKeyboardText(&text);
} }
static const struct ScreenVTABLE EditHotkeyScreen_VTABLE = { 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->flatgrass, 200, GenLevelScreen_Flatgrass);
ButtonWidget_Init(&s->vanilla, 200, GenLevelScreen_Notchy); ButtonWidget_Init(&s->vanilla, 200, GenLevelScreen_Notchy);
Menu_InitBack(&s->cancel, Menu_SwitchPause); Menu_InitBack(&s->cancel, Menu_SwitchPause);
Window_OpenKeyboard(KEYBOARD_TYPE_NUMBER); Window_OpenKeyboard(&String_Empty, KEYBOARD_TYPE_NUMBER);
} }
static const struct ScreenVTABLE GenLevelScreen_VTABLE = { static const struct ScreenVTABLE GenLevelScreen_VTABLE = {
@ -1505,7 +1504,7 @@ static void SaveLevelScreen_Init(void* screen) {
Menu_InitBack(&s->cancel, Menu_SwitchPause); Menu_InitBack(&s->cancel, Menu_SwitchPause);
MenuInputWidget_Create(&s->input, 500, &String_Empty, &desc); MenuInputWidget_Create(&s->input, 500, &String_Empty, &desc);
TextWidget_Init(&s->desc); TextWidget_Init(&s->desc);
Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); Window_OpenKeyboard(&String_Empty, KEYBOARD_TYPE_TEXT);
} }
static const struct ScreenVTABLE SaveLevelScreen_VTABLE = { 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; s->numWidgets = MENUOPTS_MAX_OPTS + 1 + 3;
MenuOptionsScreen_Layout(screen); MenuOptionsScreen_Layout(screen);
MenuOptionsScreen_RedrawInput(s); MenuOptionsScreen_RedrawInput(s);
Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); Window_OpenKeyboard(&value, KEYBOARD_TYPE_TEXT);
Window_SetKeyboardText(&value);
} }
static void MenuOptionsScreen_OnHacksChanged(void* screen) { static void MenuOptionsScreen_OnHacksChanged(void* screen) {

View File

@ -1278,8 +1278,7 @@ void ChatScreen_OpenInput(const String* text) {
s->suppressNextPress = true; s->suppressNextPress = true;
s->grabsInput = true; s->grabsInput = true;
Camera_CheckFocus(); Camera_CheckFocus();
Window_OpenKeyboard(KEYBOARD_TYPE_TEXT); Window_OpenKeyboard(text, KEYBOARD_TYPE_TEXT);
Window_SetKeyboardText(text);
String_Copy(&s->input.base.text, text); String_Copy(&s->input.base.text, text);
InputWidget_UpdateText(&s->input.base); InputWidget_UpdateText(&s->input.base);

View File

@ -401,9 +401,9 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
/* TODO: Do we still need to unlock it though? */ /* 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_SetKeyboardText(const String* text) { }
void Window_CloseKeyboard(void) { SDL_StopTextInput(); } void Window_CloseKeyboard(void) { SDL_StopTextInput(); }
void Window_EnableRawMouse(void) { void Window_EnableRawMouse(void) {
RegrabMouse(); RegrabMouse();
@ -934,9 +934,9 @@ static void InitRawMouse(void) {
rawMouseSupported = false; rawMouseSupported = false;
} }
void Window_OpenKeyboard(int type) { } void Window_OpenKeyboard(const String* text, int type) { }
void Window_SetKeyboardText(const String* text) { } void Window_SetKeyboardText(const String* text) { }
void Window_CloseKeyboard(void) { } void Window_CloseKeyboard(void) { }
void Window_EnableRawMouse(void) { void Window_EnableRawMouse(void) {
DefaultEnableRawMouse(); DefaultEnableRawMouse();
@ -1818,9 +1818,9 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
Mem_Free(bmp->scan0); 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_SetKeyboardText(const String* text) { }
void Window_CloseKeyboard(void) { } void Window_CloseKeyboard(void) { }
static cc_bool rawMouseInited, rawMouseSupported; static cc_bool rawMouseInited, rawMouseSupported;
static int xiOpcode; 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_SetKeyboardText(const String* text) { }
void Window_CloseKeyboard(void) { } void Window_CloseKeyboard(void) { }
void Window_EnableRawMouse(void) { void Window_EnableRawMouse(void) {
DefaultEnableRawMouse(); DefaultEnableRawMouse();
@ -3500,9 +3500,11 @@ EMSCRIPTEN_KEEPALIVE void Window_OnTextChanged(const char* src) {
Event_RaiseString(&InputEvents.TextChanged, &str); 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; if (!Input_TouchMode) return;
keyboardOpen = true; keyboardOpen = true;
Platform_ConvertString(str, text);
Platform_LogConst("OPEN SESAME"); Platform_LogConst("OPEN SESAME");
EM_ASM_({ EM_ASM_({
@ -3510,6 +3512,7 @@ void Window_OpenKeyboard(int type) {
if (!elem) { if (!elem) {
elem = document.createElement('textarea'); 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.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", elem.addEventListener("input",
function(ev) { function(ev) {
@ -3521,7 +3524,7 @@ void Window_OpenKeyboard(int type) {
} }
elem.focus(); elem.focus();
elem.click(); elem.click();
}, type); }, str, type);
} }
void Window_SetKeyboardText(const String* text) { void Window_SetKeyboardText(const String* text) {
@ -3930,7 +3933,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
Mem_Free(bmp->scan0); Mem_Free(bmp->scan0);
} }
void Window_OpenKeyboard(int type) { void Window_OpenKeyboard(const String* text, int type) {
JNIEnv* env; JNIEnv* env;
JavaGetCurrentEnv(env); JavaGetCurrentEnv(env);
JavaCallVoid(env, "openKeyboard", "()V", NULL); JavaCallVoid(env, "openKeyboard", "()V", NULL);

View File

@ -34,7 +34,7 @@ struct Bitmap;
struct DynamicLibSym; struct DynamicLibSym;
/* The states the window can be in. */ /* The states the window can be in. */
enum WindowState { WINDOW_STATE_NORMAL, WINDOW_STATE_MINIMISED, WINDOW_STATE_FULLSCREEN }; 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 */ /* Can't name these structs Window/Display, because it conflicts with X11's Window/Display typedef */
/* Data for the display monitor. */ /* 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. */ /* Displays on-screen keyboard for platforms that lack physical keyboard input. */
/* NOTE: On desktop platforms, this won't do anything. */ /* 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. */ /* Sets the text used for keyboard input. */
/* NOTE: This is only used for mobile on-screen keyboard input with the web client, */ /* 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. */ /* because it is backed by a HTML input, rather than true keyboard input events. */