mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-27 09:32:30 -06:00
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.
This commit is contained in:
parent
5b9bbc37d4
commit
b8328593fe
4 changed files with 23 additions and 8 deletions
|
@ -31,7 +31,7 @@ void EmuWindow_GLFW::OnMouseButtonEvent(GLFWwindow* win, int button, int action,
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuWindow_GLFW::OnCursorPosEvent(GLFWwindow* win, double x, double y) {
|
void EmuWindow_GLFW::OnCursorPosEvent(GLFWwindow* win, double x, double y) {
|
||||||
GetEmuWindow(win)->TouchMoved(static_cast<unsigned>(x), static_cast<unsigned>(y));
|
GetEmuWindow(win)->TouchMoved(static_cast<unsigned>(std::max(x, 0.0)), static_cast<unsigned>(std::max(y, 0.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called by GLFW when a key event occurs
|
/// Called by GLFW when a key event occurs
|
||||||
|
|
|
@ -288,7 +288,7 @@ void GRenderWindow::mousePressEvent(QMouseEvent *event)
|
||||||
void GRenderWindow::mouseMoveEvent(QMouseEvent *event)
|
void GRenderWindow::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
auto pos = event->pos();
|
auto pos = event->pos();
|
||||||
this->TouchMoved(static_cast<unsigned>(pos.x()), static_cast<unsigned>(pos.y()));
|
this->TouchMoved(static_cast<unsigned>(std::max(pos.x(), 0)), static_cast<unsigned>(std::max(pos.y(), 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::mouseReleaseEvent(QMouseEvent *event)
|
void GRenderWindow::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
|
|
@ -28,6 +28,17 @@ static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsi
|
||||||
framebuffer_x < layout.bottom_screen.right);
|
framebuffer_x < layout.bottom_screen.right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::tuple<unsigned,unsigned> 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) {
|
void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
|
||||||
if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
|
if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
|
||||||
return;
|
return;
|
||||||
|
@ -52,14 +63,13 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
|
||||||
if (!touch_pressed)
|
if (!touch_pressed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
|
if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
|
||||||
TouchPressed(framebuffer_x, framebuffer_y);
|
std::tie(framebuffer_x, framebuffer_y) = ClipToTouchScreen(framebuffer_x, framebuffer_y);
|
||||||
else
|
|
||||||
TouchReleased();
|
TouchPressed(framebuffer_x, framebuffer_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width,
|
EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, unsigned height) {
|
||||||
unsigned height) {
|
|
||||||
|
|
||||||
ASSERT(width > 0);
|
ASSERT(width > 0);
|
||||||
ASSERT(height > 0);
|
ASSERT(height > 0);
|
||||||
|
|
|
@ -206,5 +206,10 @@ private:
|
||||||
u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320)
|
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)
|
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<unsigned,unsigned> ClipToTouchScreen(unsigned new_x, unsigned new_y);
|
||||||
|
|
||||||
Service::HID::PadState pad_state;
|
Service::HID::PadState pad_state;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue