#include <boost/algorithm/string/predicate.hpp>
#include <boost/foreach.hpp>
-#include <iostream>
namespace simgear
{
}
//----------------------------------------------------------------------------
- Canvas::~Canvas()
+ void Canvas::onDestroy()
{
-
+ if( _root_group )
+ {
+ _root_group->clearEventListener();
+ _root_group->onDestroy();
+ }
}
//----------------------------------------------------------------------------
return _canvas_mgr;
}
+ //----------------------------------------------------------------------------
+ bool Canvas::isInit() const
+ {
+ return _texture.serviceable();
+ }
+
//----------------------------------------------------------------------------
void Canvas::addParentCanvas(const CanvasWeakPtr& canvas)
{
(
SG_GENERAL,
SG_WARN,
- "Canvas::addParentCanvas: got an expired parent: " << _node->getPath()
+ "Canvas::addParentCanvas(" << _node->getPath(true) << "): "
+ "got an expired parent!"
);
return;
}
(
SG_GENERAL,
SG_WARN,
- "Canvas::addChildCanvas: got an expired child: " << _node->getPath()
+ "Canvas::addChildCanvas(" << _node->getPath(true) << "): "
+ " got an expired child!"
);
return;
}
//----------------------------------------------------------------------------
GroupPtr Canvas::createGroup(const std::string& name)
{
- return boost::dynamic_pointer_cast<Group>
- (
- _root_group->createChild("group", name)
- );
+ return _root_group->createChild<Group>(name);
+ }
+
+ //----------------------------------------------------------------------------
+ GroupPtr Canvas::getGroup(const std::string& name)
+ {
+ return _root_group->getChild<Group>(name);
+ }
+
+ //----------------------------------------------------------------------------
+ GroupPtr Canvas::getOrCreateGroup(const std::string& name)
+ {
+ return _root_group->getOrCreateChild<Group>(name);
+ }
+
+ //----------------------------------------------------------------------------
+ GroupPtr Canvas::getRootGroup()
+ {
+ return _root_group;
}
//----------------------------------------------------------------------------
camera->addChild(_root_group->getMatrixTransform());
- // Ensure objects are drawn in order of traversal
- camera->getOrCreateStateSet()->setBinName("TraversalOrderBin");
-
if( _texture.serviceable() )
{
setStatusFlags(STATUS_OK);
return _texture.getViewSize().y();
}
+ //----------------------------------------------------------------------------
+ SGRect<int> Canvas::getViewport() const
+ {
+ return SGRect<int>(0, 0, getViewWidth(), getViewHeight());
+ }
+
//----------------------------------------------------------------------------
bool Canvas::handleMouseEvent(const MouseEventPtr& event)
{
EventVisitor visitor( EventVisitor::TRAVERSE_DOWN,
event->getClientPos(),
- event->getDelta() );
+ event->getDelta(),
+ _root_group );
if( !_root_group->accept(visitor) )
return false;
if( node->getParent()->getParent() == _node
&& node->getParent()->getNameString() == "placement" )
{
- bool placement_dirty = false;
- BOOST_FOREACH(Placements& placements, _placements)
+ size_t index = node->getIndex();
+ if( index < _placements.size() )
{
- BOOST_FOREACH(PlacementPtr& placement, placements)
+ Placements& placements = _placements[index];
+ if( !placements.empty() )
{
- // check if change can be directly handled by placement
- if( placement->getProps() == node->getParent()
- && !placement->childChanged(node) )
- placement_dirty = true;
+ bool placement_dirty = false;
+ BOOST_FOREACH(PlacementPtr& placement, placements)
+ {
+ // check if change can be directly handled by placement
+ if( placement->getProps() == node->getParent()
+ && !placement->childChanged(node) )
+ placement_dirty = true;
+ }
+
+ if( !placement_dirty )
+ return;
}
}
- if( !placement_dirty )
- return;
-
// prevent double updates...
for( size_t i = 0; i < _dirty_placements.size(); ++i )
{