]> git.mxchange.org Git - flightgear.git/blobdiff - src/Canvas/window.cxx
Fix starting on carrier.
[flightgear.git] / src / Canvas / window.cxx
index 3b5556a19a6cd129a74df9511438ac604cda61bd..012915faf80bbee9d5917093b3ee212b53d3b18f 100644 (file)
@@ -32,8 +32,14 @@ namespace canvas
   namespace sc = simgear::canvas;
 
   //----------------------------------------------------------------------------
-  Window::Window(SGPropertyNode* node):
-    Image(sc::CanvasPtr(), node),
+  const std::string Window::TYPE_NAME = "window";
+
+  //----------------------------------------------------------------------------
+  Window::Window( const simgear::canvas::CanvasWeakPtr& canvas,
+                  const SGPropertyNode_ptr& node,
+                  const Style& parent_style,
+                  Element* parent ):
+    Image(canvas, node, parent_style, parent),
     _attributes_dirty(0),
     _resizable(false),
     _capture_events(true),
@@ -75,9 +81,7 @@ namespace canvas
     {
       handled = true;
       const std::string& name = node->getNameString();
-      if( name == "raise-top" )
-        doRaise(node);
-      else if( name  == "resize" )
+      if( name  == "resize" )
         _resizable = node->getBoolValue();
       else if( name == "update" )
         update(0);
@@ -85,7 +89,8 @@ namespace canvas
         _capture_events = node->getBoolValue();
       else if( name == "decoration-border" )
         parseDecorationBorder(node->getStringValue());
-      else if( boost::starts_with(name, "shadow-") )
+      else if(    boost::starts_with(name, "shadow-")
+               || name == "content-size" )
         _attributes_dirty |= DECORATION;
       else
         handled = false;
@@ -115,16 +120,21 @@ namespace canvas
   }
 
   //----------------------------------------------------------------------------
-  void Window::setCanvas(sc::CanvasPtr canvas)
+  void Window::setCanvasContent(sc::CanvasPtr canvas)
   {
     _canvas_content = canvas;
-    setSrcCanvas(canvas);
+
+    if( _image_content )
+      // Placement within decoration canvas
+      _image_content->setSrcCanvas(canvas);
+    else
+      setSrcCanvas(canvas);
   }
 
   //----------------------------------------------------------------------------
-  sc::CanvasWeakPtr Window::getCanvas() const
+  sc::CanvasWeakPtr Window::getCanvasContent() const
   {
-    return getSrcCanvas();
+    return _canvas_content;
   }
 
   //----------------------------------------------------------------------------
@@ -146,7 +156,16 @@ namespace canvas
   }
 
   //----------------------------------------------------------------------------
-  void Window::handleResize(uint8_t mode, const osg::Vec2f& delta)
+  void Window::raise()
+  {
+    // on writing the z-index the window always is moved to the top of all other
+    // windows with the same z-index.
+    set<int>("z-index", get<int>("z-index", 0));
+  }
+
+  //----------------------------------------------------------------------------
+  void Window::handleResize( uint8_t mode,
+                             const osg::Vec2f& offset )
   {
     if( mode == NONE )
     {
@@ -163,37 +182,14 @@ namespace canvas
     }
 
     if( mode & BOTTOM )
-      _resize_bottom += delta.y();
+      _resize_bottom = getRegion().b() + offset.y();
     else if( mode & TOP )
-      _resize_top += delta.y();
+      _resize_top = getRegion().t() + offset.y();
 
     if( mode & canvas::Window::RIGHT )
-      _resize_right += delta.x();
+      _resize_right = getRegion().r() + offset.x();
     else if( mode & canvas::Window::LEFT )
-      _resize_left += delta.x();
-  }
-
-  //----------------------------------------------------------------------------
-  void Window::doRaise(SGPropertyNode* node_raise)
-  {
-    if( node_raise && !node_raise->getBoolValue() )
-      return;
-
-    // Keep a reference to ensure the window is not deleted between removing and
-    // adding it back to the scenegraph
-    osg::ref_ptr<osg::Group> window = getGroup();
-
-    BOOST_FOREACH(osg::Group* parent, getGroup()->getParents())
-    {
-      // Remove window...
-      parent->removeChild(window);
-
-      // ...and add again as topmost window
-      parent->addChild(window);
-    }
-
-    if( node_raise )
-      node_raise->setBoolValue(false);
+      _resize_left = getRegion().l() + offset.x();
   }
 
   //----------------------------------------------------------------------------
@@ -210,21 +206,29 @@ namespace canvas
     if( shadow_radius < 2 )
       shadow_radius = 0;
 
+    sc::CanvasPtr content = _canvas_content.lock();
+    SGRect<int> content_view
+    (
+      0,
+      0,
+      get<int>("content-size[0]", content ? content->getViewWidth()  : 400),
+      get<int>("content-size[1]", content ? content->getViewHeight() : 300)
+    );
+
     if( _decoration_border.isNone() && !shadow_radius )
     {
-      sc::CanvasPtr canvas_content = _canvas_content.lock();
-      setSrcCanvas(canvas_content);
-      set<int>("size[0]", canvas_content->getViewWidth());
-      set<int>("size[1]", canvas_content->getViewHeight());
+      setSrcCanvas(content);
+      set<int>("size[0]", content_view.width());
+      set<int>("size[1]", content_view.height());
 
       _image_content.reset();
       _image_shadow.reset();
-      _canvas_decoration->destroy();
+      if( _canvas_decoration )
+        _canvas_decoration->destroy();
       _canvas_decoration.reset();
       return;
     }
 
-    sc::CanvasPtr content = _canvas_content.lock();
     if( !_canvas_decoration )
     {
       CanvasMgr* mgr =
@@ -257,11 +261,11 @@ namespace canvas
     //      the shadow?
 
     simgear::CSSBorder::Offsets const border =
-      _decoration_border.getAbsOffsets(content->getViewport());
+      _decoration_border.getAbsOffsets(content_view);
 
     int shad2 = 2 * shadow_radius,
-        outer_width  = border.l + content->getViewWidth()  + border.r + shad2,
-        outer_height = border.t + content->getViewHeight() + border.b + shad2;
+        outer_width  = border.l + content_view.width()  + border.r + shad2,
+        outer_height = border.t + content_view.height() + border.b + shad2;
 
     _canvas_decoration->setSizeX( outer_width );
     _canvas_decoration->setSizeY( outer_height );
@@ -275,6 +279,8 @@ namespace canvas
     assert(_image_content);
     _image_content->set<int>("x", shadow_radius + border.l);
     _image_content->set<int>("y", shadow_radius + border.t);
+    _image_content->set<int>("size[0]", content_view.width());
+    _image_content->set<int>("size[1]", content_view.height());
 
     if( !shadow_radius )
     {