From efcd60ce0f2228e0c16e42137a779b3b7e920288 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 26 Jun 2012 13:59:16 +0200 Subject: [PATCH] Add a method to sync internal button stages after mouse selection --- src/Gui/NavigationStyle.cpp | 68 +++++++++++++++++++++++++++++++++++++ src/Gui/NavigationStyle.h | 1 + 2 files changed, 69 insertions(+) diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 30f5ecf40..50dba3cf2 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -1118,11 +1118,13 @@ SbBool NavigationStyle::processEvent(const SoEvent * const ev) pcPolygon = mouseSelection->getPositions(); clipInner = mouseSelection->isInner(); delete mouseSelection; mouseSelection = 0; + syncWithEvent(ev); return NavigationStyle::processSoEvent(ev); } else if (hd==AbstractMouseSelection::Cancel) { pcPolygon.clear(); delete mouseSelection; mouseSelection = 0; + syncWithEvent(ev); return NavigationStyle::processSoEvent(ev); } } @@ -1150,6 +1152,72 @@ SbBool NavigationStyle::processSoEvent(const SoEvent * const ev) return viewer->processSoEventBase(ev); } +void NavigationStyle::syncWithEvent(const SoEvent * const ev) +{ + // Events when in "ready-to-seek" mode are ignored, except those + // which influence the seek mode itself -- these are handled further + // up the inheritance hierarchy. + if (this->isSeekMode()) { return; } + + const SoType type(ev->getTypeId()); + + // Mismatches in state of the modifier keys happens if the user + // presses or releases them outside the viewer window. + if (this->ctrldown != ev->wasCtrlDown()) { + this->ctrldown = ev->wasCtrlDown(); + } + if (this->shiftdown != ev->wasShiftDown()) { + this->shiftdown = ev->wasShiftDown(); + } + if (this->altdown != ev->wasAltDown()) { + this->altdown = ev->wasAltDown(); + } + + // Keyboard handling + if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { + const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev; + const SbBool press = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE; + switch (event->getKey()) { + case SoKeyboardEvent::LEFT_CONTROL: + case SoKeyboardEvent::RIGHT_CONTROL: + this->ctrldown = press; + break; + case SoKeyboardEvent::LEFT_SHIFT: + case SoKeyboardEvent::RIGHT_SHIFT: + this->shiftdown = press; + break; + case SoKeyboardEvent::LEFT_ALT: + case SoKeyboardEvent::RIGHT_ALT: + this->altdown = press; + break; + default: + break; + } + } + + // Mouse Button / Spaceball Button handling + if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) { + const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev; + const int button = event->getButton(); + const SbBool press = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE; + + // SoDebugError::postInfo("processSoEvent", "button = %d", button); + switch (button) { + case SoMouseButtonEvent::BUTTON1: + this->button1down = press; + break; + case SoMouseButtonEvent::BUTTON2: + this->button2down = press; + break; + case SoMouseButtonEvent::BUTTON3: + this->button3down = press; + break; + default: + break; + } + } +} + SbBool NavigationStyle::processMotionEvent(const SoMotion3Event * const ev) { SoCamera * const camera = viewer->getCamera(); diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index b6d4e20e6..cf7a1cdbc 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -175,6 +175,7 @@ protected: SbBool handleEventInForeground(const SoEvent* const e); virtual SbBool processSoEvent(const SoEvent * const ev); + void syncWithEvent(const SoEvent * const ev); virtual void openPopupMenu(const SbVec2s& position); void clearLog(void);