]> git.mxchange.org Git - flightgear.git/blobdiff - src/Canvas/window.cxx
Canvas window: Update for SimGear MouseEvent changes.
[flightgear.git] / src / Canvas / window.cxx
index 43c9a1654b764942c445792c64d619375831c43f..cdebb5d0e12df21c0bbf206e1b96f2855d696202 100644 (file)
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #include "window.hxx"
-#include <Canvas/canvas.hxx>
+#include <simgear/canvas/Canvas.hxx>
 
 #include <osgGA/GUIEventHandler>
 
@@ -28,8 +28,19 @@ namespace canvas
   //----------------------------------------------------------------------------
   Window::Window(SGPropertyNode* node):
     PropertyBasedElement(node),
-    _image(node)
+    _image( simgear::canvas::CanvasPtr(),
+            node,
+            simgear::canvas::Style() ),
+    _resizable(false),
+    _capture_events(true),
+    _resize_top(node, "resize-top"),
+    _resize_right(node, "resize-right"),
+    _resize_bottom(node, "resize-bottom"),
+    _resize_left(node, "resize-left"),
+    _resize_status(node, "resize-status")
   {
+    _image.removeListener();
+
     // TODO probably better remove default position and size
     node->setFloatValue("x", 50);
     node->setFloatValue("y", 100);
@@ -44,10 +55,7 @@ namespace canvas
   //----------------------------------------------------------------------------
   Window::~Window()
   {
-    BOOST_FOREACH(osg::Group* parent, getGroup()->getParents())
-    {
-      parent->removeChild(getGroup());
-    }
+
   }
 
   //----------------------------------------------------------------------------
@@ -59,7 +67,22 @@ namespace canvas
   //----------------------------------------------------------------------------
   void Window::valueChanged(SGPropertyNode * node)
   {
-    _image.valueChanged(node);
+    bool handled = false;
+    if( node->getParent() == _node )
+    {
+      handled = true;
+      if( node->getNameString() == "raise-top" )
+        doRaise(node);
+      else if( node->getNameString()  == "resize" )
+        _resizable = node->getBoolValue();
+      else if( node->getNameString() == "capture-events" )
+        _capture_events = node->getBoolValue();
+      else
+        handled = false;
+    }
+
+    if( !handled )
+      _image.valueChanged(node);
   }
 
   //----------------------------------------------------------------------------
@@ -69,30 +92,92 @@ namespace canvas
   }
 
   //----------------------------------------------------------------------------
-  const Rect<float>& Window::getRegion() const
+  const SGRect<float>& Window::getRegion() const
   {
     return _image.getRegion();
   }
 
   //----------------------------------------------------------------------------
-  void Window::setCanvas(CanvasPtr canvas)
+  void Window::setCanvas(simgear::canvas::CanvasPtr canvas)
+  {
+    _image.setSrcCanvas(canvas);
+  }
+
+  //----------------------------------------------------------------------------
+  simgear::canvas::CanvasWeakPtr Window::getCanvas() const
+  {
+    return _image.getSrcCanvas();
+  }
+
+  //----------------------------------------------------------------------------
+  bool Window::isVisible() const
+  {
+    return _image.isVisible();
+  }
+
+  //----------------------------------------------------------------------------
+  bool Window::isResizable() const
   {
-    _image.setCanvas(canvas);
+    return _resizable;
   }
 
   //----------------------------------------------------------------------------
-  CanvasWeakPtr Window::getCanvas() const
+  bool Window::isCapturingEvents() const
   {
-    return _image.getCanvas();
+    return _capture_events;
   }
 
   //----------------------------------------------------------------------------
-  bool Window::handleMouseEvent(const MouseEvent& event)
+  bool Window::handleMouseEvent(const simgear::canvas::MouseEventPtr& event)
   {
-    if( !getCanvas().expired() )
-      return getCanvas().lock()->handleMouseEvent(event);
-    else
-      return false;
+    return _image.handleEvent(event);
+  }
+
+  //----------------------------------------------------------------------------
+  void Window::handleResize(uint8_t mode, const osg::Vec2f& delta)
+  {
+    if( mode == NONE )
+    {
+      _resize_status = 0;
+      return;
+    }
+    else if( mode & INIT )
+    {
+      _resize_top    = getRegion().t();
+      _resize_right  = getRegion().r();
+      _resize_bottom = getRegion().b();
+      _resize_left   = getRegion().l();
+      _resize_status = 1;
+    }
+
+    if( mode & BOTTOM )
+      _resize_bottom += delta.y();
+    else if( mode & TOP )
+      _resize_top += delta.y();
+
+    if( mode & canvas::Window::RIGHT )
+      _resize_right += delta.x();
+    else if( mode & canvas::Window::LEFT )
+      _resize_left += delta.x();
+  }
+
+  //----------------------------------------------------------------------------
+  void Window::doRaise(SGPropertyNode* node_raise)
+  {
+    if( node_raise && !node_raise->getBoolValue() )
+      return;
+
+    BOOST_FOREACH(osg::Group* parent, getGroup()->getParents())
+    {
+      // Remove window...
+      parent->removeChild(getGroup());
+
+      // ...and add again as topmost window
+      parent->addChild(getGroup());
+    }
+
+    if( node_raise )
+      node_raise->setBoolValue(false);
   }
 
 } // namespace canvas