mouse_tracker.cpp: Deduplicate code for mouse and touch input

This commit is contained in:
OpenSauce04 authored and OpenSauce committed 2026-09-16 05:15:17 -07:00
1 parent 5e7276c9d4
commit 8b6204bbfa
1 file changed
+2 -24
+2 -24
View File
@@ -103,36 +103,14 @@ void MouseTracker::Update(int bufferWidth, int bufferHeight,
bool wasMoved = false;
if (LibRetro::settings.enable_mouse_touchscreen) {
// Check mouse input
state |= LibRetro::CheckInput(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT);
// Read in and convert pointer values to absolute values on the canvas
auto pointerX = LibRetro::CheckInput(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X);
auto pointerY = LibRetro::CheckInput(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y);
auto newX = static_cast<int>((pointerX + 0x7fff) / (float)(0x7fff * 2) * bufferWidth);
auto newY = static_cast<int>((pointerY + 0x7fff) / (float)(0x7fff * 2) * bufferHeight);
// Use mouse pointer movement
if ((pointerX != 0 || pointerY != 0) && (newX != lastMouseX || newY != lastMouseY)) {
lastMouseX = newX;
lastMouseY = newY;
// Use layout system to validate and map coordinates
if (layout.IsWithinTouchscreen(newX, newY)) {
x = std::clamp(newX, static_cast<int>(layout.bottom_screen.left),
static_cast<int>(layout.bottom_screen.right)) -
layout.bottom_screen.left;
y = std::clamp(newY, static_cast<int>(layout.bottom_screen.top),
static_cast<int>(layout.bottom_screen.bottom)) -
layout.bottom_screen.top;
}
}
}
if (LibRetro::settings.enable_touch_touchscreen) {
// Check touchscreen input
state |= LibRetro::CheckInput(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);
}
if (state == true) {
// Read in and convert pointer values to absolute values on the canvas
auto pointerX = LibRetro::CheckInput(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X);
auto pointerY = LibRetro::CheckInput(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y);