From 561010d89719b5236fb8555d10116f727869a45c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 16 Jul 2024 19:22:56 +1000 Subject: [PATCH] N64: Untested mouse support --- src/Window_N64.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Window_N64.c b/src/Window_N64.c index d5efdd693..4dbb56624 100644 --- a/src/Window_N64.c +++ b/src/Window_N64.c @@ -14,6 +14,7 @@ #include static cc_bool launcherMode; +#include "VirtualCursor.h" struct _DisplayData DisplayInfo; struct cc_window WindowInfo; @@ -76,6 +77,22 @@ void Window_EnableRawMouse(void) { Input.RawMode = true; } void Window_DisableRawMouse(void) { Input.RawMode = false; } void Window_UpdateRawMouse(void) { } +static void ProcessMouse(joypad_inputs_t* inputs, float delta) { + Input_SetNonRepeatable(CCMOUSE_L, inputs->btn.a); + Input_SetNonRepeatable(CCMOUSE_R, inputs->btn.b); + + // TODO check stick_x/y is right + if (!vc_hooked) { + Pointer_SetPosition(0, Window_Main.Width / 2, Window_Main.Height / 2); + } + VirtualCursor_SetPosition(Pointers[0].x + inputs->stick_x, Pointers[0].y + inputs->stick_y); + + if (!Input.RawMode) return; + float scale = (delta * 60.0) / 2.0f; + Event_RaiseRawMove(&PointerEvents.RawMoved, + inputs->stick_x * scale, inputs->stick_y * scale); +} + /*########################################################################################################################* *-------------------------------------------------------Gamepads----------------------------------------------------------* @@ -143,9 +160,13 @@ void Gamepads_Process(float delta) { for (int i = 0; i < INPUT_MAX_GAMEPADS; i++) { if (!joypad_is_connected(i)) continue; - int port = Gamepad_Connect(0x64 + i, default_n64); - joypad_inputs_t inputs = joypad_get_inputs(i); + + if (joypad_get_style(i) == JOYPAD_STYLE_MOUSE) { + ProcessMouse(&inputs, delta); continue; + } + + int port = Gamepad_Connect(0x64 + i, default_n64); HandleButtons(port, inputs.btn); ProcessAnalogInput(port, &inputs, delta); }