From b200801ebcb0d8b9d7a0cd5862de383d9c58b7e7 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Fri, 21 Aug 2020 03:58:18 +0300 Subject: [PATCH] Gui: use SoMouseWheelEvent in navigation styles --- src/Gui/BlenderNavigationStyle.cpp | 8 ------- src/Gui/CADNavigationStyle.cpp | 8 ------- src/Gui/GestureNavigationStyle.cpp | 10 --------- src/Gui/InventorNavigationStyle.cpp | 13 ++++------- src/Gui/MayaGestureNavigationStyle.cpp | 8 ------- src/Gui/NavigationStyle.cpp | 30 +++++++++++++++++++++++++- src/Gui/NavigationStyle.h | 1 + src/Gui/OpenCascadeNavigationStyle.cpp | 5 ----- src/Gui/RevitNavigationStyle.cpp | 8 ------- src/Gui/TouchpadNavigationStyle.cpp | 8 ------- 10 files changed, 34 insertions(+), 65 deletions(-) diff --git a/src/Gui/BlenderNavigationStyle.cpp b/src/Gui/BlenderNavigationStyle.cpp index 2c2b6f9673..870dd54d43 100644 --- a/src/Gui/BlenderNavigationStyle.cpp +++ b/src/Gui/BlenderNavigationStyle.cpp @@ -266,14 +266,6 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) } this->button3down = press; break; - case SoMouseButtonEvent::BUTTON4: - doZoom(viewer->getSoRenderManager()->getCamera(), true, posn); - processed = true; - break; - case SoMouseButtonEvent::BUTTON5: - doZoom(viewer->getSoRenderManager()->getCamera(), false, posn); - processed = true; - break; default: break; } diff --git a/src/Gui/CADNavigationStyle.cpp b/src/Gui/CADNavigationStyle.cpp index ef82b26631..2ff7e88863 100644 --- a/src/Gui/CADNavigationStyle.cpp +++ b/src/Gui/CADNavigationStyle.cpp @@ -310,14 +310,6 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev) } this->button3down = press; break; - case SoMouseButtonEvent::BUTTON4: - doZoom(viewer->getSoRenderManager()->getCamera(), true, posn); - processed = true; - break; - case SoMouseButtonEvent::BUTTON5: - doZoom(viewer->getSoRenderManager()->getCamera(), false, posn); - processed = true; - break; default: break; } diff --git a/src/Gui/GestureNavigationStyle.cpp b/src/Gui/GestureNavigationStyle.cpp index 5877512b0f..58ba083877 100644 --- a/src/Gui/GestureNavigationStyle.cpp +++ b/src/Gui/GestureNavigationStyle.cpp @@ -301,16 +301,6 @@ public: return transit(); } - //wheel events - if(ev.isMouseButtonEvent() && ev.asMouseButtonEvent()->getButton() == SoMouseButtonEvent::BUTTON4){ - ns.doZoom(ns.viewer->getSoRenderManager()->getCamera(), true, posn); - ev.flags->processed = true; - } - if(ev.isMouseButtonEvent() && ev.asMouseButtonEvent()->getButton() == SoMouseButtonEvent::BUTTON5){ - ns.doZoom(ns.viewer->getSoRenderManager()->getCamera(), false, posn); - ev.flags->processed = true; - } - //touchscreen gestures if(ev.isGestureActive()){ ev.flags->processed = true; diff --git a/src/Gui/InventorNavigationStyle.cpp b/src/Gui/InventorNavigationStyle.cpp index b0ad78ab60..e386d15e82 100644 --- a/src/Gui/InventorNavigationStyle.cpp +++ b/src/Gui/InventorNavigationStyle.cpp @@ -37,6 +37,7 @@ #endif #include +#include "SoMouseWheelEvent.h" #include #include "NavigationStyle.h" @@ -284,14 +285,6 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) } this->button3down = press; break; - case SoMouseButtonEvent::BUTTON4: - doZoom(viewer->getSoRenderManager()->getCamera(), true, posn); - processed = true; - break; - case SoMouseButtonEvent::BUTTON5: - doZoom(viewer->getSoRenderManager()->getCamera(), false, posn); - processed = true; - break; default: break; } @@ -396,7 +389,9 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) // If not handled in this class, pass on upwards in the inheritance // hierarchy. - if ((curmode == NavigationStyle::SELECTION || + if (ev->isOfType(SoMouseWheelEvent::getClassTypeId())) + processed = inherited::processSoEvent(ev); + else if ((curmode == NavigationStyle::SELECTION || newmode == NavigationStyle::SELECTION || viewer->isEditing()) && !processed) processed = inherited::processSoEvent(ev); diff --git a/src/Gui/MayaGestureNavigationStyle.cpp b/src/Gui/MayaGestureNavigationStyle.cpp index 9ec8a73e01..2be4f54707 100644 --- a/src/Gui/MayaGestureNavigationStyle.cpp +++ b/src/Gui/MayaGestureNavigationStyle.cpp @@ -423,14 +423,6 @@ SbBool MayaGestureNavigationStyle::processSoEvent(const SoEvent * const ev) } processed = true; break; - case SoMouseButtonEvent::BUTTON4: //(wheel?) - doZoom(viewer->getSoRenderManager()->getCamera(), true, posn); - processed = true; - break; - case SoMouseButtonEvent::BUTTON5: //(wheel?) - doZoom(viewer->getSoRenderManager()->getCamera(), false, posn); - processed = true; - break; } } diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index bd46c209dc..c98d268b29 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -45,6 +45,7 @@ #include "Application.h" #include "MenuManager.h" #include "MouseSelection.h" +#include "SoMouseWheelEvent.h" using namespace Gui; @@ -797,6 +798,13 @@ void NavigationStyle::doZoom(SoCamera* camera, SbBool forward, const SbVec2f& po // } } +void NavigationStyle::doZoom_wheel(SoCamera* camera, int wheeldelta, const SbVec2f& pos) +{ + float value =this->zoomStep * wheeldelta / float(120.0); + if (this->invertZoom) + value = -value; + doZoom(camera, value, pos); +} /*! *\brief NavigationStyle::doZoom Zooms in or out by specified factor, keeping the point on screen specified by parameter pos fixed @@ -1466,7 +1474,27 @@ SbBool NavigationStyle::processEvent(const SoEvent * const ev) SbBool NavigationStyle::processSoEvent(const SoEvent * const ev) { - return viewer->processSoEventBase(ev); + const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion(); + const SbVec2s size(vp.getViewportSizePixels()); + const SbVec2s pos(ev->getPosition()); + const SbVec2f posn((float) pos[0] / (float) std::max((int)(size[0] - 1), 1), + (float) pos[1] / (float) std::max((int)(size[1] - 1), 1)); + bool processed = false; + + //handle mouse wheel zoom + if(ev->isOfType(SoMouseWheelEvent::getClassTypeId())){ + doZoom_wheel( + viewer->getSoRenderManager()->getCamera(), + static_cast(ev)->getDelta(), + posn + ); + processed = true; + } + + if (! processed) + return viewer->processSoEventBase(ev); + else + return processed; } void NavigationStyle::syncWithEvent(const SoEvent * const ev) diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 5fe13b70b8..e542ce762a 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -191,6 +191,7 @@ protected: void zoom(SoCamera * camera, float diffvalue); void zoomByCursor(const SbVec2f & thispos, const SbVec2f & prevpos); void doZoom(SoCamera * camera, SbBool forward, const SbVec2f& pos); + void doZoom_wheel(SoCamera * camera, int wheeldelta, const SbVec2f& pos); void doZoom(SoCamera * camera, float logzoomfactor, const SbVec2f& pos); void doRotate(SoCamera * camera, float angle, const SbVec2f& pos); void spin(const SbVec2f & pointerpos); diff --git a/src/Gui/OpenCascadeNavigationStyle.cpp b/src/Gui/OpenCascadeNavigationStyle.cpp index 1469f12ff5..3326fd7000 100644 --- a/src/Gui/OpenCascadeNavigationStyle.cpp +++ b/src/Gui/OpenCascadeNavigationStyle.cpp @@ -258,11 +258,6 @@ SbBool OpenCascadeNavigationStyle::processSoEvent(const SoEvent * const ev) } this->button3down = press; break; - case SoMouseButtonEvent::BUTTON4: - case SoMouseButtonEvent::BUTTON5: - doZoom(viewer->getSoRenderManager()->getCamera(), button == SoMouseButtonEvent::BUTTON4, posn); - processed = true; - break; default: break; } diff --git a/src/Gui/RevitNavigationStyle.cpp b/src/Gui/RevitNavigationStyle.cpp index 127a4b6375..6c38346c88 100644 --- a/src/Gui/RevitNavigationStyle.cpp +++ b/src/Gui/RevitNavigationStyle.cpp @@ -266,14 +266,6 @@ SbBool RevitNavigationStyle::processSoEvent(const SoEvent * const ev) } this->button3down = press; break; - case SoMouseButtonEvent::BUTTON4: - doZoom(viewer->getSoRenderManager()->getCamera(), true, posn); - processed = true; - break; - case SoMouseButtonEvent::BUTTON5: - doZoom(viewer->getSoRenderManager()->getCamera(), false, posn); - processed = true; - break; default: break; } diff --git a/src/Gui/TouchpadNavigationStyle.cpp b/src/Gui/TouchpadNavigationStyle.cpp index 20f2b35570..d9f2802098 100644 --- a/src/Gui/TouchpadNavigationStyle.cpp +++ b/src/Gui/TouchpadNavigationStyle.cpp @@ -248,14 +248,6 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) } this->button2down = press; break; - case SoMouseButtonEvent::BUTTON4: - doZoom(viewer->getSoRenderManager()->getCamera(), true, posn); - processed = true; - break; - case SoMouseButtonEvent::BUTTON5: - doZoom(viewer->getSoRenderManager()->getCamera(), false, posn); - processed = true; - break; default: break; }