void Canvas::CullCallback::operator()( osg::Node* node,
osg::NodeVisitor* nv )
{
- if( (nv->getTraversalMask() & simgear::MODEL_BIT) && !_canvas.expired() )
- _canvas.lock()->enableRendering();
+ if( (nv->getTraversalMask() & simgear::MODEL_BIT) )
+ {
+ CanvasPtr canvas = _canvas.lock();
+ if( canvas )
+ canvas->enableRendering();
+ }
traverse(node, nv);
}
{
_status = 0;
setStatusFlags(MISSING_SIZE_X | MISSING_SIZE_Y);
+
+ _root_group.reset( new Group(this, _node) );
+
+ // Remove automatically created property listener as we forward them on our
+ // own
+ _root_group->removeListener();
+ _cull_callback = new CullCallback(this);
}
//----------------------------------------------------------------------------
if( _visible || _render_always )
{
- BOOST_FOREACH(CanvasWeakPtr canvas, _child_canvases)
+ BOOST_FOREACH(CanvasWeakPtr canvas_weak, _child_canvases)
{
// TODO should we check if the image the child canvas is displayed
// within is really visible?
- if( !canvas.expired() )
- canvas.lock()->_visible = true;
+ CanvasPtr canvas = canvas_weak.lock();
+ if( canvas )
+ canvas->_visible = true;
}
if( _render_dirty )
{
// Also mark all canvases this canvas is displayed within as dirty
- BOOST_FOREACH(CanvasWeakPtr canvas, _parent_canvases)
+ BOOST_FOREACH(CanvasWeakPtr canvas_weak, _parent_canvases)
{
- if( !canvas.expired() )
- canvas.lock()->_render_dirty = true;
+ CanvasPtr canvas = canvas_weak.lock();
+ if( canvas )
+ canvas->_render_dirty = true;
}
}
if( placement_factory != _placement_factories.end() )
{
Placements& placements = _placements[ node->getIndex() ] =
- placement_factory->second
- (
- node,
- boost::static_pointer_cast<Canvas>(_self.lock())
- );
+ placement_factory->second(node, this);
node->setStringValue
(
"status-msg",
return _system_adapter;
}
- //----------------------------------------------------------------------------
- void Canvas::setSelf(const PropertyBasedElementPtr& self)
- {
- PropertyBasedElement::setSelf(self);
-
- CanvasPtr canvas = boost::static_pointer_cast<Canvas>(self);
-
- _root_group.reset( new Group(canvas, _node) );
- _root_group->setSelf(_root_group);
-
- // Remove automatically created property listener as we forward them on our
- // own
- _root_group->removeListener();
-
- _cull_callback = new CullCallback(canvas);
- }
-
//----------------------------------------------------------------------------
void Canvas::setStatusFlags(unsigned int flags, bool set)
{
typedef std::map<std::string, PlacementFactory> PlacementFactoryMap;
static PlacementFactoryMap _placement_factories;
- virtual void setSelf(const PropertyBasedElementPtr& self);
void setStatusFlags(unsigned int flags, bool set = true);
private:
#include "CanvasEvent.hxx"
#include "CanvasEventVisitor.hxx"
#include <simgear/canvas/elements/CanvasElement.hxx>
-#include <iostream>
namespace simgear
{
&& !el.hitBound(_target_path.front().local_pos, pos, local_pos) )
return false;
- EventTarget target = {el.getWeakPtr(), local_pos};
+ EventTarget target = {ElementPtr(&el), local_pos};
_target_path.push_back(target);
if( el.traverse(*this) || &el == _root.get() )
//----------------------------------------------------------------------------
CanvasPtr CanvasMgr::createCanvas(const std::string& name)
{
- return boost::static_pointer_cast<Canvas>( createElement(name) );
+ return static_cast<Canvas*>( createElement(name).get() );
}
//----------------------------------------------------------------------------
CanvasPtr CanvasMgr::getCanvas(size_t index) const
{
- return boost::static_pointer_cast<Canvas>( getElement(index) );
+ return static_cast<Canvas*>( getElement(index).get() );
}
//----------------------------------------------------------------------------
CanvasPtr CanvasMgr::getCanvas(const std::string& name) const
{
- return boost::static_pointer_cast<Canvas>( getElement(name) );
+ return static_cast<Canvas*>( getElement(name).get() );
}
//----------------------------------------------------------------------------
void CanvasMgr::elementCreated(PropertyBasedElementPtr element)
{
- CanvasPtr canvas = boost::static_pointer_cast<Canvas>(element);
+ CanvasPtr canvas = static_cast<Canvas*>(element.get());
canvas->setCanvasMgr(this);
}
#define SG_FWD_DECL(name)\
class name;\
- typedef boost::shared_ptr<name> name##Ptr;\
- typedef boost::weak_ptr<name> name##WeakPtr;
+ typedef SGSharedPtr<name> name##Ptr;\
+ typedef SGWeakPtr<name> name##WeakPtr;
SG_FWD_DECL(Canvas)
SG_FWD_DECL(Element)
SG_FWD_DECL(Path)
SG_FWD_DECL(Text)
+#undef SG_FWD_DECL
+
+#define SG_FWD_DECL(name)\
+ class name;\
+ typedef boost::shared_ptr<name> name##Ptr;\
+ typedef boost::weak_ptr<name> name##WeakPtr;
+
SG_FWD_DECL(Event)
SG_FWD_DECL(MouseEvent)
SG_FWD_DECL(Placement)
}
}
- //----------------------------------------------------------------------------
- void Element::setSelf(const PropertyBasedElementPtr& self)
- {
- PropertyBasedElement::setSelf(self);
-
- _transform->setUserData
- (
- new OSGUserData(boost::static_pointer_cast<Element>(self))
- );
- }
-
//----------------------------------------------------------------------------
void Element::onDestroy()
{
}
}
- //----------------------------------------------------------------------------
- ElementWeakPtr Element::getWeakPtr() const
- {
- return boost::static_pointer_cast<Element>(_self.lock());
- }
-
//----------------------------------------------------------------------------
ElementPtr Element::getParent()
{
- return _parent ? _parent->getWeakPtr().lock() : ElementPtr();
+ return _parent;
}
//----------------------------------------------------------------------------
"PreOrderBin",
osg::StateSet::OVERRIDE_RENDERBIN_DETAILS
);
+
+ _transform->setUserData( new OSGUserData(this) );
}
//----------------------------------------------------------------------------
*
*/
virtual ~Element() = 0;
-
- virtual void setSelf(const PropertyBasedElementPtr& self);
virtual void onDestroy();
- ElementWeakPtr getWeakPtr() const;
ElementPtr getParent();
/**
const Style& style,
Element* parent )
{
- ElementPtr el( new Derived(canvas, node, style, parent) );
- el->setSelf(el);
- return el;
+ return ElementPtr( new Derived(canvas, node, style, parent) );
}
protected:
if( el->get<std::string>("id") == id )
return el;
- GroupPtr group = boost::dynamic_pointer_cast<Group>(el);
+ Group* group = dynamic_cast<Group*>(el.get());
if( group )
groups.push_back(group);
}
const std::string& id );
template<class T>
- boost::shared_ptr<T> createChild(const std::string& id = "")
+ SGSharedPtr<T> createChild(const std::string& id = "")
{
- return boost::dynamic_pointer_cast<T>( createChild(T::TYPE_NAME, id) );
+ return dynamic_cast<T*>( createChild(T::TYPE_NAME, id).get() );
}
template<class T>
- boost::shared_ptr<T> getChild(const SGPropertyNode* node)
+ SGSharedPtr<T> getChild(const SGPropertyNode* node)
{
- return boost::dynamic_pointer_cast<T>( getChild(node) );
+ return dynamic_cast<T*>( getChild(node).get() );
}
template<class T>
- boost::shared_ptr<T> getChild(const std::string& id)
+ SGSharedPtr<T> getChild(const std::string& id)
{
- return boost::dynamic_pointer_cast<T>( getChild(id) );
+ return dynamic_cast<T*>( getChild(id).get() );
}
template<class T>
- boost::shared_ptr<T> getOrCreateChild(const std::string& id)
+ SGSharedPtr<T> getOrCreateChild(const std::string& id)
{
- return
- boost::dynamic_pointer_cast<T>( getOrCreateChild(T::TYPE_NAME, id) );
+ return dynamic_cast<T*>( getOrCreateChild(T::TYPE_NAME, id).get() );
}
/**
osg::Drawable* drawable,
osg::RenderInfo* renderInfo ) const
{
- if( !_canvas.expired() )
- _canvas.lock()->enableRendering();
+ CanvasPtr canvas = _canvas.lock();
+ if( canvas )
+ canvas->enableRendering();
if( !_cull_next_frame )
// TODO check if window/image should be culled
return _node;
}
- //----------------------------------------------------------------------------
- void PropertyBasedElement::setSelf(const PropertyBasedElementPtr& self)
- {
- _self = self;
- }
-
} // namespace simgear
#define SG_PROPERTY_BASED_ELEMENT_HXX_
#include <simgear/props/props.hxx>
+#include <simgear/structure/SGWeakReferenced.hxx>
#include <boost/call_traits.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/weak_ptr.hpp>
-
namespace simgear
{
- class PropertyBasedElement;
- typedef boost::shared_ptr<PropertyBasedElement> PropertyBasedElementPtr;
- typedef boost::weak_ptr<PropertyBasedElement> PropertyBasedElementWeakPtr;
-
/**
* Base class for a property controlled element
*/
class PropertyBasedElement:
- public SGPropertyChangeListener
+ public SGPropertyChangeListener,
+ public SGWeakReferenced
{
public:
PropertyBasedElement(SGPropertyNode* node);
return getValue<T>(child);
}
- virtual void setSelf(const PropertyBasedElementPtr& self);
+ // Unshadow what we have just hidden...
+ using SGWeakReferenced::get;
+
virtual void onDestroy() {};
protected:
SGPropertyNode_ptr _node;
- PropertyBasedElementWeakPtr _self;
+
};
+ typedef SGSharedPtr<PropertyBasedElement> PropertyBasedElementPtr;
+ typedef SGWeakPtr<PropertyBasedElement> PropertyBasedElementWeakPtr;
+
} // namespace simgear
#endif /* SG_PROPERTY_BASED_ELEMENT_HXX_ */
}
PropertyBasedElementPtr el = _element_factory(child);
- el->setSelf( el );
_elements[index] = el;
elementCreated( el );
}
#include "PropertyBasedElement.hxx"
#include <simgear/structure/subsystem_mgr.hxx>
-#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <vector>