From e2ada4cfe463e57302cef6d0bbd21d086832d38a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 18 Dec 2024 20:34:56 +1100 Subject: [PATCH] 3DS/VITA: Fix touching on-screen keyboard button repeatedly typing their button character in --- src/Input.c | 7 ++++++- src/Input.h | 11 +++++++---- src/InputHandler.c | 1 - src/VirtualKeyboard.h | 16 +++++++++++----- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Input.c b/src/Input.c index c353d0a85..131bb10e7 100644 --- a/src/Input.c +++ b/src/Input.c @@ -325,11 +325,16 @@ struct InputDevice TouchDevice = { *----------------------------------------------------------Mouse----------------------------------------------------------* *#########################################################################################################################*/ struct Pointer Pointers[INPUT_MAX_POINTERS]; +struct _PointerHooks PointerHooks; void Pointer_SetPressed(int idx, cc_bool pressed) { if (pressed) { + if (PointerHooks.DownHook && PointerHooks.DownHook(idx)) return; + Event_RaiseInt(&PointerEvents.Down, idx); } else { + if (PointerHooks.UpHook && PointerHooks.UpHook(idx)) return; + Event_RaiseInt(&PointerEvents.Up, idx); } } @@ -370,7 +375,7 @@ void Pointer_SetPosition(int idx, int x, int y) { /* TODO: reset to -1, -1 when pointer is removed */ Pointers[idx].x = x; Pointers[idx].y = y; - if (Pointers[0].DownHook && Pointers[0].DownHook(idx)) return; + if (PointerHooks.MoveHook && PointerHooks.MoveHook(idx)) return; #ifdef CC_BUILD_TOUCH if (Input_TouchMode && !(touches[idx].type & TOUCH_TYPE_GUI)) return; diff --git a/src/Input.h b/src/Input.h index 774d9c587..249a1a1fb 100644 --- a/src/Input.h +++ b/src/Input.h @@ -183,14 +183,17 @@ extern struct TouchPointer touches[INPUT_MAX_POINTERS]; #define TOUCH_TYPE_ALL (TOUCH_TYPE_GUI | TOUCH_TYPE_CAMERA | TOUCH_TYPE_BLOCKS) /* Data for mouse and touch */ -struct Pointer { - int x, y; +struct Pointer { int x, y; }; +CC_VAR extern struct Pointer Pointers[INPUT_MAX_POINTERS]; + +CC_VAR extern struct _PointerHooks { /* Function that overrides all normal pointer input press handling */ cc_bool (*DownHook)(int index); /* Function that overrides all normal pointer input release handling */ cc_bool (*UpHook) (int index); -}; -CC_VAR extern struct Pointer Pointers[INPUT_MAX_POINTERS]; + /* Function that overrides all normal pointer input press handling */ + cc_bool (*MoveHook)(int index); +} PointerHooks; /* Raises appropriate events for a mouse vertical scroll */ void Mouse_ScrollVWheel(float delta); diff --git a/src/InputHandler.c b/src/InputHandler.c index ef5cc29bb..6f94f5b32 100644 --- a/src/InputHandler.c +++ b/src/InputHandler.c @@ -821,7 +821,6 @@ static void OnPointerDown(void* obj, int idx) { static void OnPointerUp(void* obj, int idx) { struct Screen* s; int i, x, y; - if (Pointers[0].UpHook && Pointers[0].UpHook(idx)) return; #ifdef CC_BUILD_TOUCH CheckBlockTap(idx); diff --git a/src/VirtualKeyboard.h b/src/VirtualKeyboard.h index a23052762..65a4ea37a 100644 --- a/src/VirtualKeyboard.h +++ b/src/VirtualKeyboard.h @@ -19,6 +19,7 @@ static char kb_buffer[512]; static cc_string kb_str = String_FromArray(kb_buffer); static void (*KB_MarkDirty)(void); static int kb_yOffset; +static cc_bool kb_clicking; #define KB_TILE_SIZE 32 static int kb_tileWidth = KB_TILE_SIZE; @@ -317,10 +318,13 @@ static cc_bool VirtualKeyboard_GetPointerPosition(int idx, int* kbX, int* kbY) { return true; } -static cc_bool VirtualKeyboard_PointerDown(int idx) { +static cc_bool VirtualKeyboard_PointerMove(int idx) { int kbX, kbY; if (!VirtualKeyboard_GetPointerPosition(idx, &kbX, &kbY)) return false; + if (kb_clicking) return true; + kb_clicking = true; + kb_curX = kbX / kb_tileWidth; kb_curY = kbY / kb_tileHeight; if (kb_curX >= kb->cellsPerRow) kb_curX = kb->cellsPerRow - 1; @@ -332,6 +336,8 @@ static cc_bool VirtualKeyboard_PointerDown(int idx) { static cc_bool VirtualKeyboard_PointerUp(int idx) { int kbX, kbY; + kb_clicking = false; + kb_curX = -1; return VirtualKeyboard_GetPointerPosition(idx, &kbX, &kbY); } @@ -431,8 +437,8 @@ static void VirtualKeyboard_Hook(void) { /* the virtual keyboard in the first place gets mistakenly processed */ kb_needsHook = false; Event_Register_(&ControllerEvents.AxisUpdate, NULL, VirtualKeyboard_PadAxis); - Pointers[0].DownHook = VirtualKeyboard_PointerDown; - Pointers[0].UpHook = VirtualKeyboard_PointerUp; + PointerHooks.MoveHook = VirtualKeyboard_PointerMove; + PointerHooks.UpHook = VirtualKeyboard_PointerUp; } static void VirtualKeyboard_Open(struct OpenKeyboardArgs* args, cc_bool launcher) { @@ -480,8 +486,8 @@ static void VirtualKeyboard_Close(void) { VirtualKeyboard_Close3D(); Event_Unregister_(&ControllerEvents.AxisUpdate, NULL, VirtualKeyboard_PadAxis); - Pointers[0].DownHook = NULL; - Pointers[0].UpHook = NULL; + PointerHooks.MoveHook = NULL; + PointerHooks.UpHook = NULL; Window_Main.SoftKeyboardFocus = false; KB_MarkDirty = NULL;