// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "canvas_mgr.hxx"
-#include "canvas.hxx"
+#include <Canvas/FGCanvasSystemAdapter.hxx>
+#include <Cockpit/od_gauge.hxx>
#include <Main/fg_props.hxx>
+#include <Viewer/CameraGroup.hxx>
-#include <osg/Camera>
-#include <osg/Texture2D>
-
-#include <stdexcept>
-#include <string>
+#include <simgear/canvas/Canvas.hxx>
//------------------------------------------------------------------------------
CanvasMgr::CanvasMgr():
- _props( fgGetNode("/canvas", true) )
-{
-
-}
-
-//------------------------------------------------------------------------------
-CanvasMgr::~CanvasMgr()
-{
-
-}
-
-//------------------------------------------------------------------------------
-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)
+ simgear::canvas::CanvasMgr
+ (
+ fgGetNode("/canvas/by-index", true),
+ simgear::canvas::SystemAdapterPtr( new canvas::FGCanvasSystemAdapter )
+ )
{
- for( size_t i = 0; i < _canvases.size(); ++i )
- if( _canvases[i] )
- _canvases[i]->update(delta_time_sec);
+ using simgear::canvas::Canvas;
+ Canvas::addPlacementFactory
+ (
+ "object",
+ boost::bind
+ (
+ &FGODGauge::set_texture,
+ _1,
+ boost::bind(&Canvas::getTexture, _2),
+ boost::bind(&Canvas::getCullCallback, _2)
+ )
+ );
}
//------------------------------------------------------------------------------
-void CanvasMgr::childAdded( SGPropertyNode * parent,
- SGPropertyNode * child )
+unsigned int CanvasMgr::getCanvasTexId(size_t index) const
{
- if( parent != _props )
- return;
+ simgear::canvas::CanvasPtr canvas = getCanvas(index);
- if( child->getNameString() == "texture" )
- textureAdded(child);
-}
+ if( !canvas )
+ return 0;
-//------------------------------------------------------------------------------
-void CanvasMgr::childRemoved( SGPropertyNode * parent,
- SGPropertyNode * child )
-{
- if( parent != _props )
- return;
+ osg::Texture2D* tex = canvas->getTexture();
+ if( !tex )
+ return 0;
- if( child->getNameString() == "texture" )
- {
- size_t index = child->getIndex();
-
- if( index >= _canvases.size() )
- SG_LOG(SG_GL, SG_WARN, "can't removed unknown texture[" << index << "]!");
- else
- // remove the canvas...
- _canvases[index].reset();
- }
-}
-
-//------------------------------------------------------------------------------
-void CanvasMgr::textureAdded(SGPropertyNode* node)
-{
- size_t index = node->getIndex();
-
- if( index >= _canvases.size() )
- {
- if( index > _canvases.size() )
- SG_LOG(SG_GL, SG_WARN, "Skipping unused texture slot(s)!");
-
- _canvases.resize(index + 1);
- }
- else
- {
- SG_LOG(SG_GL, SG_WARN, "texture[" << index << "] already exists!");
- }
+// osgViewer::Viewer::Contexts contexts;
+// globals->get_renderer()->getViewer()->getContexts(contexts);
+//
+// if( contexts.empty() )
+// return 0;
- _canvases[index].reset( new Canvas() );
- _canvases[index]->reset(node);
-}
+ osg::Camera* guiCamera =
+ flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
-//------------------------------------------------------------------------------
-void CanvasMgr::triggerChangeRecursive(SGPropertyNode* node)
-{
- node->getParent()->fireChildAdded(node);
+ osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState();
+ if( !state )
+ return 0;
- if( node->nChildren() == 0 && node->getType() != simgear::props::NONE )
- return node->fireValueChanged();
+ osg::Texture::TextureObject* tobj =
+ tex->getTextureObject( state->getContextID() );
+ if( !tobj )
+ return 0;
- for( int i = 0; i < node->nChildren(); ++i )
- triggerChangeRecursive( node->getChild(i) );
+ return tobj->_id;
}