From d2524d8fe6e1624808bb88d6cb298ab583230337 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Fri, 26 Jul 2013 23:58:41 +0200 Subject: [PATCH] Canvas window: separate handling of content-size and overall size. --- src/Canvas/window.cxx | 31 +++++++++++++++++++++---------- src/Canvas/window.hxx | 10 ++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Canvas/window.cxx b/src/Canvas/window.cxx index ab02db9ad..d1bbe90eb 100644 --- a/src/Canvas/window.cxx +++ b/src/Canvas/window.cxx @@ -89,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; @@ -205,21 +206,29 @@ namespace canvas if( shadow_radius < 2 ) shadow_radius = 0; + sc::CanvasPtr content = _canvas_content.lock(); + SGRect content_view + ( + 0, + 0, + get("content-size[0]", content->getViewWidth()), + get("content-size[1]", content->getViewHeight()) + ); + if( _decoration_border.isNone() && !shadow_radius ) { - sc::CanvasPtr canvas_content = _canvas_content.lock(); - setSrcCanvas(canvas_content); - set("size[0]", canvas_content->getViewWidth()); - set("size[1]", canvas_content->getViewHeight()); + setSrcCanvas(content); + set("size[0]", content_view.width()); + set("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 = @@ -252,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 ); @@ -270,6 +279,8 @@ namespace canvas assert(_image_content); _image_content->set("x", shadow_radius + border.l); _image_content->set("y", shadow_radius + border.t); + _image_content->set("size[0]", content_view.width()); + _image_content->set("size[1]", content_view.height()); if( !shadow_radius ) { diff --git a/src/Canvas/window.hxx b/src/Canvas/window.hxx index ece277281..da99b6070 100644 --- a/src/Canvas/window.hxx +++ b/src/Canvas/window.hxx @@ -48,6 +48,16 @@ namespace canvas typedef simgear::canvas::Style Style; + /** + * @param node Property node containing settings for this window: + * capture-events Disable/Enable event capturing + * content-size[0-1] Size of content area (excluding + * decoration border) + * decoration-border Size of decoration border + * resize Enable resize cursor and properties + * shadow-inset Inset of shadow image + * shadow-radius Radius/outset of shadow image + */ Window( const simgear::canvas::CanvasWeakPtr& canvas, const SGPropertyNode_ptr& node, const Style& parent_style = Style(),