From b8328593fe3d60ecb066ad0959d8c1e8dfb4d3c5 Mon Sep 17 00:00:00 2001 From: Zaneo Date: Tue, 14 Apr 2015 00:06:44 -0400 Subject: EmuWindow: Clip mouse input coordinates to emulated screen dimensions. If the mouse position for a mouse move/drag would take it outside the emulated screen dimensions, clip the coordinates to the emulated screen dimensions. Qt and GLFW will report negative coordinates for mouse positions to the left, or above citra window. Added restriction to mouse coordinates passed to touchmoved by Qt/GLFW to be greater or equal to zero. --- src/common/emu_window.cpp | 22 ++++++++++++++++------ src/common/emu_window.h | 5 +++++ 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src/common') diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp index 6516fc63..f5b6c730 100644 --- a/src/common/emu_window.cpp +++ b/src/common/emu_window.cpp @@ -28,6 +28,17 @@ static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsi framebuffer_x < layout.bottom_screen.right); } +std::tuple EmuWindow::ClipToTouchScreen(unsigned new_x, unsigned new_y) { + + new_x = std::max(new_x, framebuffer_layout.bottom_screen.left); + new_x = std::min(new_x, framebuffer_layout.bottom_screen.right-1); + + new_y = std::max(new_y, framebuffer_layout.bottom_screen.top); + new_y = std::min(new_y, framebuffer_layout.bottom_screen.bottom-1); + + return std::make_tuple(new_x, new_y); +} + void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) { if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) return; @@ -52,14 +63,13 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { if (!touch_pressed) return; - if (IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) - TouchPressed(framebuffer_x, framebuffer_y); - else - TouchReleased(); + if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) + std::tie(framebuffer_x, framebuffer_y) = ClipToTouchScreen(framebuffer_x, framebuffer_y); + + TouchPressed(framebuffer_x, framebuffer_y); } -EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, - unsigned height) { +EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, unsigned height) { ASSERT(width > 0); ASSERT(height > 0); diff --git a/src/common/emu_window.h b/src/common/emu_window.h index c8e2de04..e0fc12a4 100644 --- a/src/common/emu_window.h +++ b/src/common/emu_window.h @@ -206,5 +206,10 @@ private: u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320) u16 touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240) + /** + * Clip the provided coordinates to be inside the touchscreen area. + */ + std::tuple ClipToTouchScreen(unsigned new_x, unsigned new_y); + Service::HID::PadState pad_state; }; -- cgit v1.2.3