1
0
Fork 0

Canvas window: separate handling of content-size and overall size.

This commit is contained in:
Thomas Geymayer 2013-07-26 23:58:41 +02:00
parent e79e70062e
commit d2524d8fe6
2 changed files with 31 additions and 10 deletions

View file

@ -89,7 +89,8 @@ namespace canvas
_capture_events = node->getBoolValue(); _capture_events = node->getBoolValue();
else if( name == "decoration-border" ) else if( name == "decoration-border" )
parseDecorationBorder(node->getStringValue()); parseDecorationBorder(node->getStringValue());
else if( boost::starts_with(name, "shadow-") ) else if( boost::starts_with(name, "shadow-")
|| name == "content-size" )
_attributes_dirty |= DECORATION; _attributes_dirty |= DECORATION;
else else
handled = false; handled = false;
@ -205,21 +206,29 @@ namespace canvas
if( shadow_radius < 2 ) if( shadow_radius < 2 )
shadow_radius = 0; shadow_radius = 0;
sc::CanvasPtr content = _canvas_content.lock();
SGRect<int> content_view
(
0,
0,
get<int>("content-size[0]", content->getViewWidth()),
get<int>("content-size[1]", content->getViewHeight())
);
if( _decoration_border.isNone() && !shadow_radius ) if( _decoration_border.isNone() && !shadow_radius )
{ {
sc::CanvasPtr canvas_content = _canvas_content.lock(); setSrcCanvas(content);
setSrcCanvas(canvas_content); set<int>("size[0]", content_view.width());
set<int>("size[0]", canvas_content->getViewWidth()); set<int>("size[1]", content_view.height());
set<int>("size[1]", canvas_content->getViewHeight());
_image_content.reset(); _image_content.reset();
_image_shadow.reset(); _image_shadow.reset();
_canvas_decoration->destroy(); if( _canvas_decoration )
_canvas_decoration->destroy();
_canvas_decoration.reset(); _canvas_decoration.reset();
return; return;
} }
sc::CanvasPtr content = _canvas_content.lock();
if( !_canvas_decoration ) if( !_canvas_decoration )
{ {
CanvasMgr* mgr = CanvasMgr* mgr =
@ -252,11 +261,11 @@ namespace canvas
// the shadow? // the shadow?
simgear::CSSBorder::Offsets const border = simgear::CSSBorder::Offsets const border =
_decoration_border.getAbsOffsets(content->getViewport()); _decoration_border.getAbsOffsets(content_view);
int shad2 = 2 * shadow_radius, int shad2 = 2 * shadow_radius,
outer_width = border.l + content->getViewWidth() + border.r + shad2, outer_width = border.l + content_view.width() + border.r + shad2,
outer_height = border.t + content->getViewHeight() + border.b + shad2; outer_height = border.t + content_view.height() + border.b + shad2;
_canvas_decoration->setSizeX( outer_width ); _canvas_decoration->setSizeX( outer_width );
_canvas_decoration->setSizeY( outer_height ); _canvas_decoration->setSizeY( outer_height );
@ -270,6 +279,8 @@ namespace canvas
assert(_image_content); assert(_image_content);
_image_content->set<int>("x", shadow_radius + border.l); _image_content->set<int>("x", shadow_radius + border.l);
_image_content->set<int>("y", shadow_radius + border.t); _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 ) if( !shadow_radius )
{ {

View file

@ -48,6 +48,16 @@ namespace canvas
typedef simgear::canvas::Style Style; 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, Window( const simgear::canvas::CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node, const SGPropertyNode_ptr& node,
const Style& parent_style = Style(), const Style& parent_style = Style(),