Fix pointer inputs not being properly intercepted by onscreen keyboard

Xbox: Fix being too sensitive to joystick input
This commit is contained in:
UnknownShadow200 2024-09-29 07:21:18 +10:00
parent a43ffbb54e
commit a004920785
7 changed files with 43 additions and 24 deletions

View file

@ -133,9 +133,9 @@ endif
ifeq ($(PLAT),dos)
CC = i586-pc-msdosdjgpp-gcc
LIBS =
BUILD_DIR = build-dos
LDFLAGS = -g
OEXT = .exe
BUILD_DIR = build-dos
endif

View file

@ -79,8 +79,8 @@ extern struct _InputState {
cc_bool RawMode;
/* Sources available for input (Mouse/Keyboard, Gamepad) */
cc_uint8 Sources;
/* Function that overrides all normal input handling (e.g. for virtual keyboard) */
void (*DownHook)(int btn, struct InputDevice* device);
/* Function that can override all normal input handling (e.g. for virtual keyboard) */
cc_bool (*DownHook)(int btn, struct InputDevice* device);
} Input;
/* Sets Input_Pressed[key] to true and raises InputEvents.Down */
@ -185,9 +185,9 @@ extern struct TouchPointer touches[INPUT_MAX_POINTERS];
struct Pointer {
int x, y;
/* Function that overrides all normal pointer input press handling */
void (*DownHook)(int index);
cc_bool (*DownHook)(int index);
/* Function that overrides all normal pointer input release handling */
void (*UpHook) (int index);
cc_bool (*UpHook) (int index);
};
CC_VAR extern struct Pointer Pointers[INPUT_MAX_POINTERS];

View file

@ -784,7 +784,7 @@ cc_bool KeyBind_IsPressed(InputBind binding) { return Bind_IsTriggered[binding];
static void OnPointerDown(void* obj, int idx) {
struct Screen* s;
int i, x, y, mask;
if (Pointers[idx].DownHook) { Pointers[idx].DownHook(idx); return; }
if (Pointers[0].DownHook && Pointers[0].DownHook(idx)) return;
/* Always set last click time, otherwise quickly tapping */
/* sometimes triggers a 'delete' in InputHandler_Tick, */
@ -822,7 +822,7 @@ static void OnPointerDown(void* obj, int idx) {
static void OnPointerUp(void* obj, int idx) {
struct Screen* s;
int i, x, y;
if (Pointers[idx].UpHook) { Pointers[idx].UpHook(idx); return; }
if (Pointers[0].UpHook && Pointers[0].UpHook(idx)) return;
#ifdef CC_BUILD_TOUCH
CheckBlockTap(idx);
@ -841,7 +841,7 @@ static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* dev
struct Screen* s;
cc_bool triggered;
int i;
if (Input.DownHook) { Input.DownHook(key, device); return; }
if (Input.DownHook && Input.DownHook(key, device)) return;
#ifndef CC_BUILD_WEB
if (key == device->escapeButton && (s = Gui_GetClosable())) {

View file

@ -190,7 +190,7 @@ static cc_bool IsShutdown(int key) {
}
static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* device) {
if (Input.DownHook) { Input.DownHook(key, device); return; }
if (Input.DownHook && Input.DownHook(key, device)) return;
if (IsShutdown(key)) Launcher_ShouldExit = true;
Launcher_Active->KeyDown(Launcher_Active, key, was, device);

View file

@ -1973,14 +1973,14 @@ static void KeyBindsScreen_Update(struct KeyBindsScreen* s, int i) {
s->dirty = true;
}
static void KeyBindsScreen_TriggerBinding(int key, struct InputDevice* device) {
static cc_bool KeyBindsScreen_TriggerBinding(int key, struct InputDevice* device) {
struct KeyBindsScreen* s = &KeyBindsScreen;
InputBind bind;
int idx;
if (device->type != bind_device->type) return;
if (device->type != bind_device->type) return false;
Input.DownHook = NULL;
if (s->curI == -1) return;
if (s->curI == -1) return false;
bind = s->binds[s->curI];
if (key == device->escapeButton) {
@ -1993,6 +1993,7 @@ static void KeyBindsScreen_TriggerBinding(int key, struct InputDevice* device) {
s->curI = -1;
s->closable = true;
KeyBindsScreen_Update(s, idx);
return true;
}
static void KeyBindsScreen_OnBindingClick(void* screen, void* widget) {

View file

@ -271,7 +271,7 @@ static void VirtualKeyboard_ClickSelected(void) {
}
}
static void VirtualKeyboard_ProcessDown(int key, struct InputDevice* device) {
static cc_bool VirtualKeyboard_OnInputDown(int key, struct InputDevice* device) {
int deltaX, deltaY;
Input_CalcDelta(key, device, &deltaX, &deltaY);
@ -290,6 +290,7 @@ static void VirtualKeyboard_ProcessDown(int key, struct InputDevice* device) {
} else if (key == CCPAD_R) {
VirtualKeyboard_AppendChar('/');
}
return true;
}
static void VirtualKeyboard_PadAxis(void* obj, int port, int axis, float x, float y) {
@ -302,21 +303,36 @@ static void VirtualKeyboard_PadAxis(void* obj, int port, int axis, float x, floa
if (ySteps) VirtualKeyboard_Scroll(0, ySteps > 0 ? 1 : -1);
}
static void VirtualKeyboard_PointerDown(void* obj, int idx) {
static cc_bool VirtualKeyboard_GetPointerPosition(int idx, int* kbX, int* kbY) {
int width = VirtualKeyboard_Width();
int height = VirtualKeyboard_Height();
int kbX, kbY;
VirtualKeyboard_CalcPosition(&kbX, &kbY, VirtualKeyboard_WindowWidth(), VirtualKeyboard_WindowHeight());
int originX, originY;
VirtualKeyboard_CalcPosition(&originX, &originY, VirtualKeyboard_WindowWidth(), VirtualKeyboard_WindowHeight());
int x = Pointers[idx].x, y = Pointers[idx].y;
if (x < kbX || y < kbY || x >= kbX + width || y >= kbY + height) return;
if (x < originX || y < originY || x >= originX + width || y >= originY + height) return false;
kb_curX = (x - kbX) / kb_tileWidth;
kb_curY = (y - kbY) / kb_tileHeight;
*kbX = x - originX;
*kbY = y - originY;
return true;
}
static cc_bool VirtualKeyboard_PointerDown(int idx) {
int kbX, kbY;
if (!VirtualKeyboard_GetPointerPosition(idx, &kbX, &kbY)) return false;
kb_curX = kbX / kb_tileWidth;
kb_curY = kbY / kb_tileHeight;
if (kb_curX >= kb->cellsPerRow) kb_curX = kb->cellsPerRow - 1;
VirtualKeyboard_Clamp();
VirtualKeyboard_ClickSelected();
return true;
}
static cc_bool VirtualKeyboard_PointerUp(int idx) {
int kbX, kbY;
return VirtualKeyboard_GetPointerPosition(idx, &kbX, &kbY);
}
@ -415,7 +431,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);
Event_Register_(&PointerEvents.Down, NULL, VirtualKeyboard_PointerDown);
Pointers[0].DownHook = VirtualKeyboard_PointerDown;
Pointers[0].UpHook = VirtualKeyboard_PointerUp;
}
static void VirtualKeyboard_Open(struct OpenKeyboardArgs* args, cc_bool launcher) {
@ -445,7 +462,7 @@ static void VirtualKeyboard_Open(struct OpenKeyboardArgs* args, cc_bool launcher
}
Window_Main.SoftKeyboardFocus = true;
Input.DownHook = VirtualKeyboard_ProcessDown;
Input.DownHook = VirtualKeyboard_OnInputDown;
LBackend_Hooks[0] = VirtualKeyboard_Display2D;
Game.Draw2DHooks[0] = VirtualKeyboard_Display3D;
}
@ -463,7 +480,8 @@ static void VirtualKeyboard_Close(void) {
VirtualKeyboard_Close3D();
Event_Unregister_(&ControllerEvents.AxisUpdate, NULL, VirtualKeyboard_PadAxis);
Event_Unregister_(&PointerEvents.Down, NULL, VirtualKeyboard_PointerDown);
Pointers[0].DownHook = NULL;
Pointers[0].UpHook = NULL;
Window_Main.SoftKeyboardFocus = false;
KB_MarkDirty = NULL;

View file

@ -171,8 +171,8 @@ static void HandleButtons(int port, xid_gamepad_in* gp) {
#define AXIS_SCALE 8192.0f
static void HandleJoystick(int port, int axis, int x, int y, float delta) {
if (Math_AbsI(x) <= 512) x = 0;
if (Math_AbsI(y) <= 512) y = 0;
if (Math_AbsI(x) <= 4096) x = 0;
if (Math_AbsI(y) <= 4096) y = 0;
Gamepad_SetAxis(port, axis, x / AXIS_SCALE, -y / AXIS_SCALE, delta);
}