diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9b30e03697..6fff0bf171 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1166,8 +1166,7 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { _seenMouseMove = true; } - _mouseX = event->x(); - _mouseY = event->y(); + setMousePosition(event, deviceID); } void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { @@ -1181,8 +1180,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - _mouseX = event->x(); - _mouseY = event->y(); + setMousePosition(event, deviceID); _mouseDragStartedX = _mouseX; _mouseDragStartedY = _mouseY; _mousePressed = true; @@ -1213,8 +1211,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - _mouseX = event->x(); - _mouseY = event->y(); + setMousePosition(event, deviceID); _mousePressed = false; checkBandwidthMeterClick(); if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { @@ -2328,6 +2325,18 @@ int Application::sendNackPackets() { return packetsSent; } +void Application::setMousePosition(QMouseEvent* event, unsigned int deviceID) { + if (deviceID > 0) { + // simulated events are in device coordinates + _mouseX = event->x(); + _mouseY = event->y(); + + } else { + _mouseX = _glWidget->getDeviceX(event->x()); + _mouseY = _glWidget->getDeviceY(event->y()); + } +} + void Application::queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions) { //qDebug() << ">>> inside... queryOctree()... _viewFrustum.getFieldOfView()=" << _viewFrustum.getFieldOfView(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 302c1bf2d3..73f8555dbb 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -435,6 +435,8 @@ private: int sendNackPackets(); + void setMousePosition(QMouseEvent* event, unsigned int deviceID); + MainWindow* _window; GLCanvas* _glWidget; // our GLCanvas has a couple extra features diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index 108b9ba829..e63e79f1f0 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -43,6 +43,14 @@ int GLCanvas::getDeviceHeight() const { return height() * (windowHandle() ? windowHandle()->devicePixelRatio() : 1.0f); } +int GLCanvas::getDeviceX(int x) const { + return x * getDeviceWidth() / width(); +} + +int GLCanvas::getDeviceY(int y) const { + return y * getDeviceHeight() / height(); +} + void GLCanvas::initializeGL() { Application::getInstance()->initializeGL(); setAttribute(Qt::WA_AcceptTouchEvents); diff --git a/interface/src/GLCanvas.h b/interface/src/GLCanvas.h index 0d381fa0bf..22cdaae75f 100644 --- a/interface/src/GLCanvas.h +++ b/interface/src/GLCanvas.h @@ -26,6 +26,9 @@ public: int getDeviceHeight() const; QSize getDeviceSize() const { return QSize(getDeviceWidth(), getDeviceHeight()); } + int getDeviceX(int x) const; + int getDeviceY(int y) const; + protected: QTimer _frameTimer;