diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 20 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.h | 2 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 17acd3933..4c7bf28d8 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -401,6 +401,12 @@ qreal GRenderWindow::windowPixelRatio() const { | |||
| 401 | return devicePixelRatioF(); | 401 | return devicePixelRatioF(); |
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | std::pair<u32, u32> GRenderWindow::ScaleTouch(const QPointF& pos) const { | ||
| 405 | const qreal pixel_ratio = windowPixelRatio(); | ||
| 406 | return {static_cast<u32>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})), | ||
| 407 | static_cast<u32>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))}; | ||
| 408 | } | ||
| 409 | |||
| 404 | void GRenderWindow::closeEvent(QCloseEvent* event) { | 410 | void GRenderWindow::closeEvent(QCloseEvent* event) { |
| 405 | emit Closed(); | 411 | emit Closed(); |
| 406 | QWidget::closeEvent(event); | 412 | QWidget::closeEvent(event); |
| @@ -643,7 +649,8 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) { | |||
| 643 | // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse | 649 | // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse |
| 644 | // coordinates and map them to the current render area | 650 | // coordinates and map them to the current render area |
| 645 | const auto pos = mapFromGlobal(QCursor::pos()); | 651 | const auto pos = mapFromGlobal(QCursor::pos()); |
| 646 | const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); | 652 | const auto [x, y] = ScaleTouch(pos); |
| 653 | const auto [touch_x, touch_y] = MapToTouchScreen(x, y); | ||
| 647 | const auto button = QtButtonToMouseButton(event->button()); | 654 | const auto button = QtButtonToMouseButton(event->button()); |
| 648 | 655 | ||
| 649 | input_subsystem->GetMouse()->PressMouseButton(button); | 656 | input_subsystem->GetMouse()->PressMouseButton(button); |
| @@ -661,7 +668,8 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) { | |||
| 661 | // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse | 668 | // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse |
| 662 | // coordinates and map them to the current render area | 669 | // coordinates and map them to the current render area |
| 663 | const auto pos = mapFromGlobal(QCursor::pos()); | 670 | const auto pos = mapFromGlobal(QCursor::pos()); |
| 664 | const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); | 671 | const auto [x, y] = ScaleTouch(pos); |
| 672 | const auto [touch_x, touch_y] = MapToTouchScreen(x, y); | ||
| 665 | const int center_x = width() / 2; | 673 | const int center_x = width() / 2; |
| 666 | const int center_y = height() / 2; | 674 | const int center_y = height() / 2; |
| 667 | 675 | ||
| @@ -695,8 +703,8 @@ void GRenderWindow::wheelEvent(QWheelEvent* event) { | |||
| 695 | void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) { | 703 | void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) { |
| 696 | QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints(); | 704 | QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints(); |
| 697 | for (const auto& touch_point : touch_points) { | 705 | for (const auto& touch_point : touch_points) { |
| 698 | const auto pos = touch_point.pos(); | 706 | const auto [x, y] = ScaleTouch(touch_point.pos()); |
| 699 | const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); | 707 | const auto [touch_x, touch_y] = MapToTouchScreen(x, y); |
| 700 | input_subsystem->GetTouchScreen()->TouchPressed(touch_x, touch_y, touch_point.id()); | 708 | input_subsystem->GetTouchScreen()->TouchPressed(touch_x, touch_y, touch_point.id()); |
| 701 | } | 709 | } |
| 702 | } | 710 | } |
| @@ -705,8 +713,8 @@ void GRenderWindow::TouchUpdateEvent(const QTouchEvent* event) { | |||
| 705 | QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints(); | 713 | QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints(); |
| 706 | input_subsystem->GetTouchScreen()->ClearActiveFlag(); | 714 | input_subsystem->GetTouchScreen()->ClearActiveFlag(); |
| 707 | for (const auto& touch_point : touch_points) { | 715 | for (const auto& touch_point : touch_points) { |
| 708 | const auto pos = touch_point.pos(); | 716 | const auto [x, y] = ScaleTouch(touch_point.pos()); |
| 709 | const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); | 717 | const auto [touch_x, touch_y] = MapToTouchScreen(x, y); |
| 710 | input_subsystem->GetTouchScreen()->TouchMoved(touch_x, touch_y, touch_point.id()); | 718 | input_subsystem->GetTouchScreen()->TouchMoved(touch_x, touch_y, touch_point.id()); |
| 711 | } | 719 | } |
| 712 | input_subsystem->GetTouchScreen()->ReleaseInactiveTouch(); | 720 | input_subsystem->GetTouchScreen()->ReleaseInactiveTouch(); |
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 627e19f42..bb4eca07f 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h | |||
| @@ -147,6 +147,8 @@ public: | |||
| 147 | 147 | ||
| 148 | qreal windowPixelRatio() const; | 148 | qreal windowPixelRatio() const; |
| 149 | 149 | ||
| 150 | std::pair<u32, u32> ScaleTouch(const QPointF& pos) const; | ||
| 151 | |||
| 150 | void closeEvent(QCloseEvent* event) override; | 152 | void closeEvent(QCloseEvent* event) override; |
| 151 | 153 | ||
| 152 | void resizeEvent(QResizeEvent* event) override; | 154 | void resizeEvent(QResizeEvent* event) override; |