From 038765b2b081b43b815c879d59fa15202ca29356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Mon, 25 Oct 2021 10:20:15 +0700 Subject: [PATCH] Mouse support (#469) --- input/input.go | 23 +++++++++++++++++++++++ libretro/libretro.go | 17 ++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/input/input.go b/input/input.go index 5e221b9f..22ce36cf 100644 --- a/input/input.go +++ b/input/input.go @@ -32,6 +32,9 @@ var ( NewAnalogState AnalogStates // analog input state for the current frame ) +var oldMouseX float64 +var oldMouseY float64 + // Hot keys const ( // ActionMenuToggle toggles the menu UI @@ -190,5 +193,25 @@ func State(port uint, device uint32, index uint, id uint) int16 { return NewAnalogState[port][index][id] } + if device == lr.DeviceMouse { + x, y := vid.Window.GetCursorPos() + if id == uint(lr.DeviceIDMouseX) { + d := x - oldMouseX + oldMouseX = x + return int16(d) + } + if id == uint(lr.DeviceIDMouseY) { + d := y - oldMouseY + oldMouseY = y + return int16(d) + } + if id == uint(lr.DeviceIDMouseLeft) && vid.Window.GetMouseButton(glfw.MouseButton1) == glfw.Press { + return 1 + } + if id == uint(lr.DeviceIDMouseRight) && vid.Window.GetMouseButton(glfw.MouseButton2) == glfw.Press { + return 1 + } + } + return 0 } diff --git a/libretro/libretro.go b/libretro/libretro.go index 32f15248..381ce7f5 100644 --- a/libretro/libretro.go +++ b/libretro/libretro.go @@ -295,7 +295,7 @@ const ( DeviceIDJoypadMask = uint32(C.RETRO_DEVICE_ID_JOYPAD_MASK) ) -// Index / Id values for ANALOG device. +// Index / Id values for analog device const ( DeviceIndexAnalogLeft = uint32(C.RETRO_DEVICE_INDEX_ANALOG_LEFT) DeviceIndexAnalogRight = uint32(C.RETRO_DEVICE_INDEX_ANALOG_RIGHT) @@ -304,6 +304,21 @@ const ( DeviceIDAnalogY = uint32(C.RETRO_DEVICE_ID_ANALOG_Y) ) +// ID values for the mouse device +const ( + DeviceIDMouseX = uint32(C.RETRO_DEVICE_ID_MOUSE_X) + DeviceIDMouseY = uint32(C.RETRO_DEVICE_ID_MOUSE_Y) + DeviceIDMouseLeft = uint32(C.RETRO_DEVICE_ID_MOUSE_LEFT) + DeviceIDMouseRight = uint32(C.RETRO_DEVICE_ID_MOUSE_RIGHT) + DeviceIDMouseWheelUp = uint32(C.RETRO_DEVICE_ID_MOUSE_WHEELUP) + DeviceIDMouseWheelDown = uint32(C.RETRO_DEVICE_ID_MOUSE_WHEELDOWN) + DeviceIDMouseMiddle = uint32(C.RETRO_DEVICE_ID_MOUSE_MIDDLE) + DeviceIDMouseHorizWheelUp = uint32(C.RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP) + DeviceIDMouseHorizWheelDown = uint32(C.RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN) + DeviceIDMouseButton4 = uint32(C.RETRO_DEVICE_ID_MOUSE_BUTTON_4) + DeviceIDMouseButton5 = uint32(C.RETRO_DEVICE_ID_MOUSE_BUTTON_5) +) + // Environment callback API. See libretro.h for details const ( EnvironmentSetRotation = uint32(C.RETRO_ENVIRONMENT_SET_ROTATION)