mirror of
https://github.com/azahar-emu/azahar.git
synced 2026-11-18 20:04:47 +01:00
mouse_tracker.cpp: Deduplicate code for mouse and touch input
This commit is contained in:
1 parent
5e7276c9d4
commit
8b6204bbfa
1 file changed
+2
-24
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user