From aa9ad6a780c923a863becc75c24376275af3a9d1 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 14 Jan 2018 13:16:56 +0000 Subject: [PATCH] Fix view right-drag interaction with PUI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When PUI doesn’t handle the right-mouse down, ensure it ignores the mouse-up event. --- src/Input/FGMouseInput.cxx | 9 +++++++++ src/Input/FGMouseInput.hxx | 13 +++++++++++-- src/Input/input.cxx | 2 +- src/Input/input.hxx | 8 ++------ src/Main/fg_init.cxx | 2 +- src/Viewer/PUICamera.cxx | 35 ++++++++++++++++++++++++----------- 6 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/Input/FGMouseInput.cxx b/src/Input/FGMouseInput.cxx index 5ee672e56..b102fcf86 100644 --- a/src/Input/FGMouseInput.cxx +++ b/src/Input/FGMouseInput.cxx @@ -714,5 +714,14 @@ void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea d->mouseYNode->setIntValue(y); } +bool FGMouseInput::isRightDragToLookEnabled() const +{ + if (!d->initialized) { + return false; + } + + return (d->rightClickModeCycle == false); +} + diff --git a/src/Input/FGMouseInput.hxx b/src/Input/FGMouseInput.hxx index 5ac542dd2..838d9aec4 100644 --- a/src/Input/FGMouseInput.hxx +++ b/src/Input/FGMouseInput.hxx @@ -43,11 +43,20 @@ public: FGMouseInput(); virtual ~FGMouseInput(); - virtual void init(); - virtual void update( double dt ); + void init() override; + void update( double dt ) override; + + static const char* subsystemName() { return "input-mouse"; } void doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea); void doMouseMotion (int x, int y, const osgGA::GUIEventAdapter*); + + /** + * @brief isRightDragToLookEnabled - test if we're in right-mouse-drag + * to adjust the view direction/position mode. + * @return + */ + bool isRightDragToLookEnabled() const; private: void processMotion(int x, int y, const osgGA::GUIEventAdapter* ea); diff --git a/src/Input/input.cxx b/src/Input/input.cxx index 8df7c8d8b..8992f260f 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -62,7 +62,7 @@ FGInput::FGInput () if( fgGetBool("/sim/input/no-mouse-input",false) ) { SG_LOG(SG_INPUT,SG_ALERT,"Mouse input disabled!"); } else { - set_subsystem( "input-mouse", new FGMouseInput() ); + set_subsystem( FGMouseInput::subsystemName(), new FGMouseInput() ); } if( fgGetBool("/sim/input/no-keyboard-input",false) ) { diff --git a/src/Input/input.hxx b/src/Input/input.hxx index f26f21a93..ce9a7aaee 100644 --- a/src/Input/input.hxx +++ b/src/Input/input.hxx @@ -26,15 +26,9 @@ #ifndef _INPUT_HXX #define _INPUT_HXX -#ifndef __cplusplus -# error This library requires C++ -#endif #include - - - //////////////////////////////////////////////////////////////////////// // General input mapping support. @@ -61,6 +55,8 @@ public: */ virtual ~FGInput(); + static const char* subsystemName() { return "input"; } + }; #endif // _INPUT_HXX diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index d4c0161f7..aed942bc0 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -919,7 +919,7 @@ void fgCreateSubsystems(bool duringReset) { // Initialize the input subsystem. //////////////////////////////////////////////////////////////////// - globals->add_subsystem("input", new FGInput, SGSubsystemMgr::GENERAL); + globals->add_new_subsystem(SGSubsystemMgr::GENERAL); //////////////////////////////////////////////////////////////////// diff --git a/src/Viewer/PUICamera.cxx b/src/Viewer/PUICamera.cxx index eac92179a..bf2a306d6 100644 --- a/src/Viewer/PUICamera.cxx +++ b/src/Viewer/PUICamera.cxx @@ -43,6 +43,9 @@ #include #include +#include +#include + // Old versions of PUI are missing these defines #ifndef PU_SCROLL_UP_BUTTON #define PU_SCROLL_UP_BUTTON 3 @@ -99,7 +102,9 @@ class PUIEventHandler : public osgGA::GUIEventHandler public: PUIEventHandler(PUICamera* cam) : _puiCamera(cam) - {} + { + _mouse0RightButtonNode = fgGetNode("/devices/status/mice/mouse[0]/button[2]", true); + } bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *, osg::NodeVisitor *nv) override { @@ -117,22 +122,29 @@ public: case(osgGA::GUIEventAdapter::MOVE): case(osgGA::GUIEventAdapter::DRAG): { + FGMouseInput* mouseSubsystem = globals->get_subsystem()->get_subsystem(); + if (mouseSubsystem && + mouseSubsystem->isRightDragToLookEnabled() && + _mouse0RightButtonNode->getBoolValue()) + { + return false; + } + bool handled = puMouse(scaledX, scaledY); return handled; } - // you might thnk the code below is a good idea, but apparently it's not - // PUI synthesises PU_DRAG internally, it doesn't want to see it delivered - // from the windowing system -#if 0 - case(osgGA::GUIEventAdapter::DRAG): - { - bool handled = puMouse(osgButtonToPUI(ea), PU_DRAG, scaledX, scaledY); - return handled; - } -#endif + case(osgGA::GUIEventAdapter::PUSH): case(osgGA::GUIEventAdapter::RELEASE): { + FGMouseInput* mouseSubsystem = globals->get_subsystem()->get_subsystem(); + if (mouseSubsystem && + mouseSubsystem->isRightDragToLookEnabled() && + _mouse0RightButtonNode->getBoolValue()) + { + return false; + } + bool upOrDown = (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE); bool handled = puMouse(osgButtonToPUI(ea), upOrDown, scaledX, scaledY); return handled; @@ -215,6 +227,7 @@ private: } PUICamera* _puiCamera; + SGPropertyNode_ptr _mouse0RightButtonNode; }; // The pu getWindow callback is supposed to return a window ID that