2012-07-27 13:17:42 +02:00
|
|
|
// Window for placing a Canvas onto it (for dialogs, menus, etc.)
|
|
|
|
//
|
|
|
|
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#include "window.hxx"
|
|
|
|
#include <Canvas/canvas.hxx>
|
|
|
|
|
|
|
|
#include <osgGA/GUIEventHandler>
|
|
|
|
|
2012-08-05 18:06:56 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2012-07-27 13:17:42 +02:00
|
|
|
namespace canvas
|
|
|
|
{
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
Window::Window(SGPropertyNode* node):
|
|
|
|
PropertyBasedElement(node),
|
2012-08-09 14:50:20 +02:00
|
|
|
_image(node)
|
2012-07-27 13:17:42 +02:00
|
|
|
{
|
2012-08-09 14:50:20 +02:00
|
|
|
// TODO probably better remove default position and size
|
|
|
|
node->setFloatValue("x", 50);
|
|
|
|
node->setFloatValue("y", 100);
|
|
|
|
node->setFloatValue("size[0]", 400);
|
|
|
|
node->setFloatValue("size[1]", 300);
|
|
|
|
|
|
|
|
node->setFloatValue("source/right", 1);
|
|
|
|
node->setFloatValue("source/bottom", 1);
|
|
|
|
node->setBoolValue("source/normalized", true);
|
2012-07-27 13:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
Window::~Window()
|
|
|
|
{
|
2012-08-09 14:50:20 +02:00
|
|
|
BOOST_FOREACH(osg::Group* parent, getGroup()->getParents())
|
2012-08-05 18:06:56 +02:00
|
|
|
{
|
2012-08-09 14:50:20 +02:00
|
|
|
parent->removeChild(getGroup());
|
2012-08-05 18:06:56 +02:00
|
|
|
}
|
2012-07-27 13:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void Window::update(double delta_time_sec)
|
|
|
|
{
|
2012-08-09 14:50:20 +02:00
|
|
|
_image.update(delta_time_sec);
|
|
|
|
}
|
2012-07-27 13:17:42 +02:00
|
|
|
|
2012-08-09 14:50:20 +02:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void Window::valueChanged(SGPropertyNode * node)
|
|
|
|
{
|
2012-08-11 23:35:33 +02:00
|
|
|
if( node->getParent() == _node && node->getNameString() == "raise-top" )
|
|
|
|
doRaise(node);
|
|
|
|
else
|
|
|
|
_image.valueChanged(node);
|
2012-07-27 13:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-08-09 14:50:20 +02:00
|
|
|
osg::Group* Window::getGroup()
|
2012-07-27 13:17:42 +02:00
|
|
|
{
|
2012-08-09 14:50:20 +02:00
|
|
|
return _image.getMatrixTransform();
|
|
|
|
}
|
2012-07-27 13:17:42 +02:00
|
|
|
|
2012-08-09 14:50:20 +02:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
const Rect<float>& Window::getRegion() const
|
|
|
|
{
|
|
|
|
return _image.getRegion();
|
2012-07-27 13:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void Window::setCanvas(CanvasPtr canvas)
|
|
|
|
{
|
2012-08-09 14:50:20 +02:00
|
|
|
_image.setCanvas(canvas);
|
2012-07-27 13:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
CanvasWeakPtr Window::getCanvas() const
|
|
|
|
{
|
2012-08-09 14:50:20 +02:00
|
|
|
return _image.getCanvas();
|
2012-07-27 13:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool Window::handleMouseEvent(const MouseEvent& event)
|
|
|
|
{
|
2012-08-09 14:50:20 +02:00
|
|
|
if( !getCanvas().expired() )
|
|
|
|
return getCanvas().lock()->handleMouseEvent(event);
|
2012-07-27 13:17:42 +02:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-11 23:35:33 +02:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void Window::doRaise(SGPropertyNode* node_raise)
|
|
|
|
{
|
|
|
|
if( !node_raise->getBoolValue() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
BOOST_FOREACH(osg::Group* parent, getGroup()->getParents())
|
|
|
|
{
|
|
|
|
// Remove window...
|
|
|
|
parent->removeChild(getGroup());
|
|
|
|
|
|
|
|
// ...and add again as topmost window
|
|
|
|
parent->addChild(getGroup());
|
|
|
|
}
|
|
|
|
|
|
|
|
node_raise->setBoolValue(false);
|
|
|
|
}
|
|
|
|
|
2012-07-27 13:17:42 +02:00
|
|
|
} // namespace canvas
|