From c0173cf2b58d63a97bb3821e67e8c095b4cd91c2 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Thu, 7 Feb 2013 23:08:36 +0100 Subject: [PATCH] Improve mouse event capturing with Canvas windows. - 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 | 18 +++++++++++++++++- src/Canvas/gui_mgr.hxx | 5 ++++- src/Canvas/window.cxx | 9 +++++++++ src/Canvas/window.hxx | 4 +++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Canvas/gui_mgr.cxx b/src/Canvas/gui_mgr.cxx index 0c563ce6b..160671eff 100644 --- a/src/Canvas/gui_mgr.cxx +++ b/src/Canvas/gui_mgr.cxx @@ -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(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"); +} diff --git a/src/Canvas/gui_mgr.hxx b/src/Canvas/gui_mgr.hxx index 23888a52f..00319dd47 100644 --- a/src/Canvas/gui_mgr.hxx +++ b/src/Canvas/gui_mgr.hxx @@ -52,6 +52,8 @@ class GUIMgr: osg::ref_ptr _event_handler; osg::ref_ptr _transform; + SGPropertyChangeCallback _cb_mouse_mode; + bool _handle_events; simgear::PropertyObject _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_ */ diff --git a/src/Canvas/window.cxx b/src/Canvas/window.cxx index 8c0494b47..e47535bfc 100644 --- a/src/Canvas/window.cxx +++ b/src/Canvas/window.cxx @@ -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) { diff --git a/src/Canvas/window.hxx b/src/Canvas/window.hxx index 46fb48ee2..00eb58737 100644 --- a/src/Canvas/window.hxx +++ b/src/Canvas/window.hxx @@ -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 _resize_top, _resize_right,