citra-emu
/
citra
Archived
1
0
Fork 0

citra-qt: Fix mouse events coordinates on high-DPI screens

This commit is contained in:
Pierre de La Morinerie 2015-09-10 23:42:45 +02:00
parent 2f4a1e0d59
commit ba5d0f594d
2 changed files with 21 additions and 12 deletions

View File

@ -181,16 +181,9 @@ void GRenderWindow::PollEvents() {
void GRenderWindow::OnFramebufferSizeChanged() void GRenderWindow::OnFramebufferSizeChanged()
{ {
// Screen changes potentially incur a change in screen DPI, hence we should update the framebuffer size // Screen changes potentially incur a change in screen DPI, hence we should update the framebuffer size
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) qreal pixelRatio = windowPixelRatio();
// windowHandle() might not be accessible until the window is displayed to screen. unsigned width = child->QPaintDevice::width() * pixelRatio;
auto pixel_ratio = windowHandle() ? (windowHandle()->screen()->devicePixelRatio()) : 1.0; unsigned height = child->QPaintDevice::height() * pixelRatio;
unsigned width = child->QPaintDevice::width() * pixel_ratio;
unsigned height = child->QPaintDevice::height() * pixel_ratio;
#else
unsigned width = child->QPaintDevice::width();
unsigned height = child->QPaintDevice::height();
#endif
NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height)); NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height));
} }
@ -223,6 +216,16 @@ QByteArray GRenderWindow::saveGeometry()
return geometry; return geometry;
} }
qreal GRenderWindow::windowPixelRatio()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
// windowHandle() might not be accessible until the window is displayed to screen.
return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f;
#else
return 1.0f;
#endif
}
void GRenderWindow::closeEvent(QCloseEvent* event) { void GRenderWindow::closeEvent(QCloseEvent* event) {
emit Closed(); emit Closed();
QWidget::closeEvent(event); QWidget::closeEvent(event);
@ -243,14 +246,18 @@ void GRenderWindow::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
{ {
auto pos = event->pos(); auto pos = event->pos();
this->TouchPressed(static_cast<unsigned>(pos.x()), static_cast<unsigned>(pos.y())); qreal pixelRatio = windowPixelRatio();
this->TouchPressed(static_cast<unsigned>(pos.x() * pixelRatio),
static_cast<unsigned>(pos.y() * pixelRatio));
} }
} }
void GRenderWindow::mouseMoveEvent(QMouseEvent *event) void GRenderWindow::mouseMoveEvent(QMouseEvent *event)
{ {
auto pos = event->pos(); auto pos = event->pos();
this->TouchMoved(static_cast<unsigned>(std::max(pos.x(), 0)), static_cast<unsigned>(std::max(pos.y(), 0))); qreal pixelRatio = windowPixelRatio();
this->TouchMoved(std::max(static_cast<unsigned>(pos.x() * pixelRatio), 0u),
std::max(static_cast<unsigned>(pos.y() * pixelRatio), 0u));
} }
void GRenderWindow::mouseReleaseEvent(QMouseEvent *event) void GRenderWindow::mouseReleaseEvent(QMouseEvent *event)

View File

@ -111,6 +111,8 @@ public:
void restoreGeometry(const QByteArray& geometry); // overridden void restoreGeometry(const QByteArray& geometry); // overridden
QByteArray saveGeometry(); // overridden QByteArray saveGeometry(); // overridden
qreal windowPixelRatio();
void closeEvent(QCloseEvent* event) override; void closeEvent(QCloseEvent* event) override;
void keyPressEvent(QKeyEvent* event) override; void keyPressEvent(QKeyEvent* event) override;