+ return _canvas_content;
+ }
+
+ //----------------------------------------------------------------------------
+ sc::CanvasPtr Window::getCanvasDecoration()
+ {
+ return _canvas_decoration;
+ }
+
+ //----------------------------------------------------------------------------
+ bool Window::isResizable() const
+ {
+ return _resizable;
+ }
+
+ //----------------------------------------------------------------------------
+ bool Window::isCapturingEvents() const
+ {
+ return _capture_events;
+ }
+
+ //----------------------------------------------------------------------------
+ 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 )
+ {
+ _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 = getRegion().b() + offset.y();
+ else if( mode & TOP )
+ _resize_top = getRegion().t() + offset.y();
+
+ if( mode & canvas::Window::RIGHT )
+ _resize_right = getRegion().r() + offset.x();
+ else if( mode & canvas::Window::LEFT )
+ _resize_left = getRegion().l() + offset.x();
+ }
+
+ //----------------------------------------------------------------------------
+ void Window::parseDecorationBorder(const std::string& str)
+ {
+ _decoration_border = simgear::CSSBorder::parse(str);
+ _attributes_dirty |= DECORATION;
+ }
+
+ //----------------------------------------------------------------------------
+ void Window::updateDecoration()
+ {
+ int shadow_radius = get<float>("shadow-radius") + 0.5;
+ 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 )
+ {
+ setSrcCanvas(content);
+ set<int>("size[0]", content_view.width());
+ set<int>("size[1]", content_view.height());
+
+ _image_content.reset();
+ _image_shadow.reset();
+ if( _canvas_decoration )
+ _canvas_decoration->destroy();
+ _canvas_decoration.reset();
+ return;
+ }
+
+ if( !_canvas_decoration )
+ {
+ CanvasMgr* mgr =
+ dynamic_cast<CanvasMgr*>(globals->get_subsystem("Canvas"));
+
+ if( !mgr )
+ {
+ SG_LOG(SG_GENERAL, SG_WARN, "canvas::Window: no canvas manager!");
+ return;
+ }
+
+ _canvas_decoration = mgr->createCanvas("window-decoration");
+ _canvas_decoration->getProps()
+ ->setStringValue("background", "rgba(0,0,0,0)");
+ setSrcCanvas(_canvas_decoration);
+
+ _image_content = _canvas_decoration->getRootGroup()
+ ->createChild<sc::Image>("content");
+ _image_content->setSrcCanvas(content);
+
+ // Draw content on top of decoration
+ _image_content->set<int>("z-index", 1);
+ }
+
+ sc::GroupPtr group_decoration =
+ _canvas_decoration->getOrCreateGroup("decoration");
+ group_decoration->set<int>("tf/t[0]", shadow_radius);
+ group_decoration->set<int>("tf/t[1]", shadow_radius);
+ // TODO do we need clipping or shall we trust the decorator not to draw over
+ // the shadow?
+
+ simgear::CSSBorder::Offsets const border =
+ _decoration_border.getAbsOffsets(content_view);
+
+ int shad2 = 2 * shadow_radius,
+ 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 );
+ _canvas_decoration->setViewWidth( outer_width );
+ _canvas_decoration->setViewHeight( outer_height );
+
+ set<int>("size[0]", outer_width - shad2);
+ set<int>("size[1]", outer_height - shad2);
+ set<int>("outset", shadow_radius);
+
+ 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 )
+ {
+ if( _image_shadow )
+ {
+ _image_shadow->destroy();
+ _image_shadow.reset();
+ }
+ return;
+ }
+
+ int shadow_inset = std::max<int>(get<float>("shadow-inset") + 0.5, 0),
+ slice_width = shadow_radius + shadow_inset;
+
+ _image_shadow = _canvas_decoration->getRootGroup()
+ ->getOrCreateChild<sc::Image>("shadow");
+ _image_shadow->set<std::string>("file", "gui/images/shadow.png");
+ _image_shadow->set<float>("slice", 7);
+ _image_shadow->set<std::string>("fill", "#000000");
+ _image_shadow->set<float>("slice-width", slice_width);
+ _image_shadow->set<int>("size[0]", outer_width);
+ _image_shadow->set<int>("size[1]", outer_height);
+
+ // Draw shadow below decoration
+ _image_shadow->set<int>("z-index", -1);