//----------------------------------------------------------------------------
void Canvas::destroy()
{
+ if( _root_group )
+ _root_group->clearEventListener();
+
// TODO check if really not in use anymore
getProps()->getParent()
->removeChild( getProps()->getName(),
);
}
+ //----------------------------------------------------------------------------
+ GroupPtr Canvas::getOrCreateGroup(const std::string& name)
+ {
+ GroupPtr group = getGroup(name);
+ if( group )
+ return group;
+
+ return createGroup(name);
+ }
+
//----------------------------------------------------------------------------
GroupPtr Canvas::getRootGroup()
{
void removeParentCanvas(const CanvasWeakPtr& canvas);
void removeChildCanvas(const CanvasWeakPtr& canvas);
+ /**
+ * Create a new group
+ */
GroupPtr createGroup(const std::string& name = "");
+
+ /**
+ * Get an existing group with the given name
+ */
GroupPtr getGroup(const std::string& name);
+
+ /**
+ * Get an existing group with the given name or otherwise create a new
+ * group
+ */
+ GroupPtr getOrCreateGroup(const std::string& name);
+
+ /**
+ * Get the root group of the canvas
+ */
GroupPtr getRootGroup();
/**
// http://www.w3.org/TR/DOM-Level-3-Events/#event-flow
// Capturing phase
-// for( EventTargets::iterator it = _target_path.begin();
-// it != _target_path.end();
-// ++it )
+// for( EventPropagationPath::const_iterator it = path.begin();
+// it != path.end();
+// ++it )
// {
-// if( it->element )
-// std::cout << it->element->getProps()->getPath() << " "
-// << "(" << it->local_pos.x() << "|" << it->local_pos.y() << ")\n";
+// if( !it->element.expired() )
+// std::cout << it->element.lock()->getProps()->getPath() << std::endl;
// }
// Bubbling phase
// Don't check collision with root element (2nd element in _target_path)
// do event listeners attached to the canvas itself (its root group)
// always get called even if no element has been hit.
- if( _target_path.size() > 2 && !el.hitBound(pos, local_pos) )
+ if( _target_path.size() > 1 && !el.hitBound(pos, local_pos) )
return false;
const osg::Vec2f& delta = _target_path.back().local_delta;
return naNil();
}
+ //----------------------------------------------------------------------------
+ void Element::clearEventListener()
+ {
+ _listener.clear();
+ }
+
//----------------------------------------------------------------------------
bool Element::accept(EventVisitor& visitor)
{
// Drawables have a bounding box...
if( _drawable )
- {
- if( !_drawable->getBound().contains(osg::Vec3f(local_pos, 0)) )
- return false;
- }
+ return _drawable->getBound().contains(osg::Vec3f(local_pos, 0));
// ... for other elements, i.e. groups only a bounding sphere is available
- else if( !_transform->getBound().contains(osg::Vec3f(pos, 0)) )
- return false;
-
- return true;
+ else
+ return _transform->getBound().contains(osg::Vec3f(pos, 0));
}
//----------------------------------------------------------------------------
virtual void update(double dt);
naRef addEventListener(const nasal::CallContext& ctx);
+ virtual void clearEventListener();
virtual bool accept(EventVisitor& visitor);
virtual bool ascend(EventVisitor& visitor);
return ElementPtr();
}
+ //----------------------------------------------------------------------------
+ void Group::clearEventListener()
+ {
+ BOOST_FOREACH( ChildList::value_type child, _children )
+ child.second->clearEventListener();
+
+ Element::clearEventListener();
+ }
+
//----------------------------------------------------------------------------
void Group::update(double dt)
{
*/
ElementPtr getElementById(const std::string& id);
+ virtual void clearEventListener();
+
virtual void update(double dt);
virtual bool traverse(EventVisitor& visitor);