#include "canvas_mgr.hxx"
#include "canvas.hxx"
-#include <Main/fg_props.hxx>
+#include <boost/bind.hpp>
-#include <osg/Camera>
-#include <osg/Texture2D>
-
-#include <stdexcept>
-#include <string>
-
-//------------------------------------------------------------------------------
-CanvasMgr::CanvasMgr():
- _props( fgGetNode("/canvas", true) )
-{
-
-}
-
-//------------------------------------------------------------------------------
-CanvasMgr::~CanvasMgr()
+typedef boost::shared_ptr<Canvas> CanvasPtr;
+CanvasPtr canvasFactory(SGPropertyNode* node)
{
-
+ return CanvasPtr(new Canvas(node));
}
-//------------------------------------------------------------------------------
-void CanvasMgr::init()
-{
- _props->addChangeListener(this);
- triggerChangeRecursive(_props);
-}
//------------------------------------------------------------------------------
-void CanvasMgr::reinit()
-{
-
-}
-
-//------------------------------------------------------------------------------
-void CanvasMgr::shutdown()
-{
- _props->removeChangeListener(this);
-}
-
-//------------------------------------------------------------------------------
-void CanvasMgr::bind()
-{
-}
-
-//------------------------------------------------------------------------------
-void CanvasMgr::unbind()
-{
-}
-
-//------------------------------------------------------------------------------
-void CanvasMgr::update(double delta_time_sec)
-{
- for( size_t i = 0; i < _canvases.size(); ++i )
- _canvases[i].update(delta_time_sec);
-}
-
-//------------------------------------------------------------------------------
-void CanvasMgr::childAdded( SGPropertyNode * parent,
- SGPropertyNode * child )
-{
- if( parent != _props )
- return;
-
- if( child->getNameString() == "texture" )
- textureAdded(child);
- else
- std::cout << "CanvasMgr::childAdded: " << child->getPath() << std::endl;
-}
-
-//------------------------------------------------------------------------------
-void CanvasMgr::childRemoved( SGPropertyNode * parent,
- SGPropertyNode * child )
-{
- if( parent != _props )
- return;
-
- std::cout << "CanvasMgr::childRemoved: " << child->getPath() << std::endl;
-}
-
-//------------------------------------------------------------------------------
-void CanvasMgr::textureAdded(SGPropertyNode* node)
+CanvasMgr::CanvasMgr():
+ PropertyBasedMgr("/canvas", "texture", &canvasFactory)
{
- size_t index = node->getIndex();
-
- if( index >= _canvases.size() )
- {
- if( index > _canvases.size() )
- SG_LOG(SG_GL, SG_WARN, "Skipping unused texture slot(s)!");
- SG_LOG(SG_GL, SG_INFO, "Add new texture[" << index << "]");
-
- _canvases.resize(index + 1);
- _canvases[index];
- }
- else
- {
- SG_LOG(SG_GL, SG_WARN, "texture[" << index << "] already exists!");
- }
-
- _canvases[index].reset(node);
+ Canvas::addPlacementFactory
+ (
+ "object",
+ boost::bind
+ (
+ &FGODGauge::set_texture,
+ _1,
+ boost::bind(&Canvas::getTexture, _2),
+ boost::bind(&Canvas::getCullCallback, _2)
+ )
+ );
}
//------------------------------------------------------------------------------
-void CanvasMgr::triggerChangeRecursive(SGPropertyNode* node)
+unsigned int CanvasMgr::getCanvasTexId(size_t index) const
{
- node->getParent()->fireChildAdded(node);
-
- if( node->nChildren() == 0 && node->getType() != simgear::props::NONE )
- return node->fireValueChanged();
-
- for( int i = 0; i < node->nChildren(); ++i )
- triggerChangeRecursive( node->getChild(i) );
-}
+ if( index >= _elements.size()
+ || !_elements[index] )
+ return 0;
-//------------------------------------------------------------------------------
-template<class T>
-T CanvasMgr::getParam(const SGPropertyNode* node, const char* prop)
-{
- const SGPropertyNode* child = node->getChild(prop);
- if( !child )
- throw std::runtime_error(std::string("Missing property ") + prop);
- return getValue<T>(child);
+ return static_cast<Canvas*>(_elements[index].get())->getTexId();
}