From 42c4e1c841efd29d97859774fb34b35a1b7ac54a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 13 Dec 2020 21:58:21 +1100 Subject: [PATCH] Webclient: Fix being unable to change controls in some browser versions This was my fault for not implementing pressing buttons on mouse movement properly. Also fixes on Windows where if you pressed on a control and still held down left mouse for a bit, the game would set the control binding to LeftMouse. --- src/Input.c | 9 +++++++++ src/Input.h | 1 + src/Window.c | 14 +++++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Input.c b/src/Input.c index 8aa7bfae3..57e9bff97 100644 --- a/src/Input.c +++ b/src/Input.c @@ -245,6 +245,15 @@ void Input_Set(int key, int pressed) { } } +void Input_SetNonRepeatable(int key, int pressed) { + if (pressed) { + if (Input_Pressed[key]) return; + Input_SetPressed(key); + } else { + Input_SetReleased(key); + } +} + void Input_Clear(void) { int i; for (i = 0; i < INPUT_COUNT; i++) { diff --git a/src/Input.h b/src/Input.h index a63933bca..624f9435c 100644 --- a/src/Input.h +++ b/src/Input.h @@ -70,6 +70,7 @@ void Input_SetPressed(int key); void Input_SetReleased(int key); /* Calls either Input_SetPressed or Input_SetReleased */ void Input_Set(int key, int pressed); +void Input_SetNonRepeatable(int key, int pressed); /* Resets all keyboard buttons to released state. (Input_SetReleased) */ void Input_Clear(void); diff --git a/src/Window.c b/src/Window.c index d22a45b01..57a87a278 100644 --- a/src/Window.c +++ b/src/Window.c @@ -552,9 +552,9 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara case WM_MOUSEMOVE: /* Set before position change, in case mouse buttons changed when outside window */ - Input_Set(KEY_LMOUSE, wParam & 0x01); - Input_Set(KEY_RMOUSE, wParam & 0x02); - Input_Set(KEY_MMOUSE, wParam & 0x10); + Input_SetNonRepeatable(KEY_LMOUSE, wParam & 0x01); + Input_SetNonRepeatable(KEY_RMOUSE, wParam & 0x02); + Input_SetNonRepeatable(KEY_MMOUSE, wParam & 0x10); /* TODO: do we need to set XBUTTON1/XBUTTON2 here */ Pointer_SetPosition(0, LOWORD(lParam), HIWORD(lParam)); break; @@ -3168,7 +3168,7 @@ static EM_BOOL OnMouseButton(int type, const EmscriptenMouseEvent* ev, void* dat DeferredEnableRawMouse(); return true; } - + /* input coordinates are CSS pixels, remap to internal pixels */ static void RescaleXY(int srcX, int srcY, int* dstX, int* dstY) { double css_width, css_height; @@ -3187,9 +3187,9 @@ static void RescaleXY(int srcX, int srcY, int* dstX, int* dstY) { static EM_BOOL OnMouseMove(int type, const EmscriptenMouseEvent* ev, void* data) { int x, y, buttons = ev->buttons; /* Set before position change, in case mouse buttons changed when outside window */ - Input_Set(KEY_LMOUSE, buttons & 0x01); - Input_Set(KEY_RMOUSE, buttons & 0x02); - Input_Set(KEY_MMOUSE, buttons & 0x04); + Input_SetNonRepeatable(KEY_LMOUSE, buttons & 0x01); + Input_SetNonRepeatable(KEY_RMOUSE, buttons & 0x02); + Input_SetNonRepeatable(KEY_MMOUSE, buttons & 0x04); RescaleXY(ev->targetX, ev->targetY, &x, &y); Pointer_SetPosition(0, x, y);