Mouse coordinate fix.

This commit is contained in:
Andrzej Kapolka 2014-09-05 17:07:37 -07:00
parent 5bdad18ade
commit c2cd23a54c
4 changed files with 28 additions and 6 deletions

View file

@ -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();

View file

@ -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

View file

@ -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);

View file

@ -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;