1 // Window for placing a Canvas onto it (for dialogs, menus, etc.)
3 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <Canvas/canvas.hxx>
22 #include <osgGA/GUIEventHandler>
24 #include <boost/foreach.hpp>
28 //----------------------------------------------------------------------------
29 Window::Window(SGPropertyNode* node):
30 PropertyBasedElement(node),
33 // TODO probably better remove default position and size
34 node->setFloatValue("x", 50);
35 node->setFloatValue("y", 100);
36 node->setFloatValue("size[0]", 400);
37 node->setFloatValue("size[1]", 300);
39 node->setFloatValue("source/right", 1);
40 node->setFloatValue("source/bottom", 1);
41 node->setBoolValue("source/normalized", true);
44 //----------------------------------------------------------------------------
47 BOOST_FOREACH(osg::Group* parent, getGroup()->getParents())
49 parent->removeChild(getGroup());
53 //----------------------------------------------------------------------------
54 void Window::update(double delta_time_sec)
56 _image.update(delta_time_sec);
59 //----------------------------------------------------------------------------
60 void Window::valueChanged(SGPropertyNode * node)
62 _image.valueChanged(node);
65 //----------------------------------------------------------------------------
66 osg::Group* Window::getGroup()
68 return _image.getMatrixTransform();
71 //----------------------------------------------------------------------------
72 const Rect<float>& Window::getRegion() const
74 return _image.getRegion();
77 //----------------------------------------------------------------------------
78 void Window::setCanvas(CanvasPtr canvas)
80 _image.setCanvas(canvas);
83 //----------------------------------------------------------------------------
84 CanvasWeakPtr Window::getCanvas() const
86 return _image.getCanvas();
89 //----------------------------------------------------------------------------
90 bool Window::handleMouseEvent(const MouseEvent& event)
92 if( !getCanvas().expired() )
93 return getCanvas().lock()->handleMouseEvent(event);