diff --git a/include/vsgQt/ViewerWindow.h b/include/vsgQt/ViewerWindow.h index 4c3987a..498063e 100644 --- a/include/vsgQt/ViewerWindow.h +++ b/include/vsgQt/ViewerWindow.h @@ -67,15 +67,14 @@ namespace vsgQt void mousePressEvent(QMouseEvent*) override; void mouseReleaseEvent(QMouseEvent*) override; void resizeEvent(QResizeEvent*) override; - void moveEvent(QMoveEvent*) override; void wheelEvent(QWheelEvent*) override; /// convert Qt's window coordinate into Vulkan/VSG ones by scaling by the devicePixelRatio() - int32_t convert_coord(int c) const { return static_cast(std::round(static_cast(c) * devicePixelRatio())); } - int32_t convert_coord(unsigned int c) const { return static_cast(std::round(static_cast(c) * devicePixelRatio())); } - int32_t convert_coord(float c) const { return static_cast(std::round(c * devicePixelRatio())); } + template + int32_t convert_coord(T c) const { return static_cast(std::round(static_cast(c) * devicePixelRatio())); } std::pair convertMouseButtons(QMouseEvent* e) const; + std::pair convertMousePosition(QMouseEvent* e) const; private: bool _initialized = false; diff --git a/src/vsgQt/ViewerWindow.cpp b/src/vsgQt/ViewerWindow.cpp index 45a6128..1c05716 100644 --- a/src/vsgQt/ViewerWindow.cpp +++ b/src/vsgQt/ViewerWindow.cpp @@ -11,9 +11,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include -#ifdef vsgXchange_FOUND -# include -#endif #include #include @@ -30,6 +27,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI # include #endif +#include + + using namespace vsgQt; const char* instanceExtensionSurfaceName() @@ -296,8 +296,9 @@ void ViewerWindow::mouseMoveEvent(QMouseEvent* e) vsg::clock::time_point event_time = vsg::clock::now(); auto [mask, button] = convertMouseButtons(e); + auto [x, y] = convertMousePosition(e); - windowAdapter->bufferedEvents.push_back(vsg::MoveEvent::create(windowAdapter, event_time, convert_coord(e->x()), convert_coord(e->y()), mask)); + windowAdapter->bufferedEvents.push_back(vsg::MoveEvent::create(windowAdapter, event_time, x, y, mask)); } void ViewerWindow::mousePressEvent(QMouseEvent* e) @@ -307,10 +308,12 @@ void ViewerWindow::mousePressEvent(QMouseEvent* e) vsg::clock::time_point event_time = vsg::clock::now(); auto [mask, button] = convertMouseButtons(e); + auto [x, y] = convertMousePosition(e); - windowAdapter->bufferedEvents.push_back(vsg::ButtonPressEvent::create(windowAdapter, event_time, convert_coord(e->x()), convert_coord(e->y()), mask, button)); + windowAdapter->bufferedEvents.push_back(vsg::ButtonPressEvent::create(windowAdapter, event_time, x, y, mask, button)); } + void ViewerWindow::mouseReleaseEvent(QMouseEvent* e) { if (!windowAdapter) return; @@ -318,16 +321,9 @@ void ViewerWindow::mouseReleaseEvent(QMouseEvent* e) vsg::clock::time_point event_time = vsg::clock::now(); auto [mask, button] = convertMouseButtons(e); + auto [x, y] = convertMousePosition(e); - windowAdapter->bufferedEvents.push_back(vsg::ButtonReleaseEvent::create(windowAdapter, event_time, convert_coord(e->x()), convert_coord(e->y()), mask, button)); -} - -void ViewerWindow::moveEvent(QMoveEvent*) -{ - if (!windowAdapter) return; - - vsg::clock::time_point event_time = vsg::clock::now(); - windowAdapter->bufferedEvents.push_back(vsg::ConfigureWindowEvent::create(windowAdapter, event_time, convert_coord(x()), convert_coord(y()), convert_coord(width()), convert_coord(height()))); + windowAdapter->bufferedEvents.push_back(vsg::ButtonReleaseEvent::create(windowAdapter, event_time, x, y, mask, button)); } void ViewerWindow::wheelEvent(QWheelEvent* e) @@ -356,4 +352,13 @@ std::pair ViewerWindow::convertMouseButtons(QMouseEve } return {static_cast(mask), button}; - } +} + +std::pair ViewerWindow::convertMousePosition(QMouseEvent* e) const +{ +#if QT_VERSION_MAJOR == 6 + return {convert_coord(e->position().x()), convert_coord(e->position().y())}; +#else + return {convert_coord(e->x()), convert_coord(e->y())}; +#endif +}