]> git.mxchange.org Git - flightgear.git/commitdiff
Improve mouse event capturing with Canvas windows.
authorThomas Geymayer <tomgey@gmail.com>
Thu, 7 Feb 2013 22:08:36 +0000 (23:08 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Thu, 7 Feb 2013 22:08:53 +0000 (23:08 +0100)
 - Don't capture mouse events if mouse mode has
   pass-through disabled. This behaviour is
   consistent with the PUI dialogs and allows
   changing moving view and controls while above
   any GUI dialog.
 - Add option to canvas windows to ignore all
   events and let them pass through
   ("capture-events").

src/Canvas/gui_mgr.cxx
src/Canvas/gui_mgr.hxx
src/Canvas/window.cxx
src/Canvas/window.hxx

index 0c563ce6bc9b6028d16c42f81891637da3f3dfdc..160671eff0f7abad68662ed68d477c1b102aac1e 100644 (file)
@@ -118,6 +118,10 @@ GUIMgr::GUIMgr():
                     &windowFactory ),
   _event_handler( new GUIEventHandler(this) ),
   _transform( new osg::MatrixTransform ),
+  _cb_mouse_mode( this,
+                  &GUIMgr::handleMouseMode,
+                  fgGetNode("/devices/status/mice/mouse[0]/mode") ),
+  _handle_events(true),
   _width(_props, "size[0]"),
   _height(_props, "size[1]"),
   _resize(canvas::Window::NONE),
@@ -286,7 +290,7 @@ const float resize_corner = 20;
 //------------------------------------------------------------------------------
 bool GUIMgr::handleMouse(const osgGA::GUIEventAdapter& ea)
 {
-  if( !_transform->getNumChildren() )
+  if( !_transform->getNumChildren() || !_handle_events )
     return false;
 
   namespace sc = simgear::canvas;
@@ -340,6 +344,10 @@ bool GUIMgr::handleMouse(const osgGA::GUIEventAdapter& ea)
       canvas::WindowPtr window =
         static_cast<WindowUserData*>(layer->getChild(j)->getUserData())
           ->window.lock();
+
+      if( !window->isCapturingEvents() )
+        continue;
+
       float margin = window->isResizable() ? resize_margin_pos : 0;
       if( window->getRegion().contains( event->getScreenX(),
                                         event->getScreenY(),
@@ -505,3 +513,11 @@ void GUIMgr::handleResize(int x, int y, int width, int height)
     0, _height, 0, 1
   ));
 }
+
+//------------------------------------------------------------------------------
+void GUIMgr::handleMouseMode(SGPropertyNode* node)
+{
+  // pass-through indicates events should pass through to the UI
+  _handle_events = fgGetNode("/input/mice/mouse[0]/mode", node->getIntValue())
+                     ->getBoolValue("pass-through");
+}
index 23888a52f17658b8b4efbd6cb8b4e3cb8d6bdaa1..00319dd47bdcd3c77aed4dfe4e0bec0cdd35720f 100644 (file)
@@ -52,6 +52,8 @@ class GUIMgr:
 
     osg::ref_ptr<GUIEventHandler>       _event_handler;
     osg::ref_ptr<osg::MatrixTransform>  _transform;
+    SGPropertyChangeCallback<GUIMgr>    _cb_mouse_mode;
+    bool                                _handle_events;
 
     simgear::PropertyObject<int>        _width,
                                         _height;
@@ -68,10 +70,11 @@ class GUIMgr:
 
     canvas::WindowPtr getWindow(size_t i);
     simgear::canvas::Placements
-    addPlacement(SGPropertyNode*, simgear::canvas::CanvasPtr canvas );
+    addPlacement(SGPropertyNode*, simgear::canvas::CanvasPtr canvas);
 
     bool handleMouse(const osgGA::GUIEventAdapter& ea);
     void handleResize(int x, int y, int width, int height);
+    void handleMouseMode(SGPropertyNode* node);
 };
 
 #endif /* CANVAS_GUI_MGR_HXX_ */
index 8c0494b4729a680183afe26ed3a86bfd7172178c..e47535bfcb81b870abb420f1ceb0d9bd17e13cd9 100644 (file)
@@ -32,6 +32,7 @@ namespace canvas
             node,
             simgear::canvas::Style() ),
     _resizable(false),
+    _capture_events(true),
     _resize_top(node, "resize-top"),
     _resize_right(node, "resize-right"),
     _resize_bottom(node, "resize-bottom"),
@@ -74,6 +75,8 @@ namespace canvas
         doRaise(node);
       else if( node->getNameString()  == "resize" )
         _resizable = node->getBoolValue();
+      else if( node->getNameString() == "capture-events" )
+        _capture_events = node->getBoolValue();
       else
         handled = false;
     }
@@ -112,6 +115,12 @@ namespace canvas
     return _resizable;
   }
 
+  //----------------------------------------------------------------------------
+  bool Window::isCapturingEvents() const
+  {
+    return _capture_events;
+  }
+
   //----------------------------------------------------------------------------
   bool Window::handleMouseEvent(const simgear::canvas::MouseEventPtr& event)
   {
index 46fb48ee2c43a2f1b2cf88202e73613f2e3ae3f5..00eb58737e7f7da4732f0a0fb02741425e0f0b08 100644 (file)
@@ -57,6 +57,7 @@ namespace canvas
       simgear::canvas::CanvasWeakPtr getCanvas() const;
 
       bool isResizable() const;
+      bool isCapturingEvents() const;
 
       bool handleMouseEvent(const simgear::canvas::MouseEventPtr& event);
 
@@ -67,7 +68,8 @@ namespace canvas
     protected:
 
       simgear::canvas::Image _image;
-      bool _resizable;
+      bool _resizable,
+           _capture_events;
 
       simgear::PropertyObject<int> _resize_top,
                                    _resize_right,