Canvas: one global SystemAdapter is enough.

This also fixes elements requiring a SystemAdapter without
being assigned to a Canvas (eg. because they are desktop
elements).
This commit is contained in:
Thomas Geymayer 2013-12-09 23:05:31 +01:00
parent 7ef9acda5d
commit 7a220921f0
8 changed files with 36 additions and 45 deletions

View File

@ -90,19 +90,6 @@ namespace canvas
} }
} }
//----------------------------------------------------------------------------
void Canvas::setSystemAdapter(const SystemAdapterPtr& system_adapter)
{
_system_adapter = system_adapter;
_texture.setSystemAdapter(system_adapter);
}
//----------------------------------------------------------------------------
SystemAdapterPtr Canvas::getSystemAdapter() const
{
return _system_adapter;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void Canvas::setCanvasMgr(CanvasMgr* canvas_mgr) void Canvas::setCanvasMgr(CanvasMgr* canvas_mgr)
{ {
@ -615,6 +602,19 @@ namespace canvas
_placement_factories.erase(it); _placement_factories.erase(it);
} }
//----------------------------------------------------------------------------
void Canvas::setSystemAdapter(const SystemAdapterPtr& system_adapter)
{
_system_adapter = system_adapter;
}
//----------------------------------------------------------------------------
SystemAdapterPtr Canvas::getSystemAdapter()
{
return _system_adapter;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void Canvas::setSelf(const PropertyBasedElementPtr& self) void Canvas::setSelf(const PropertyBasedElementPtr& self)
{ {
@ -656,6 +656,7 @@ namespace canvas
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
Canvas::PlacementFactoryMap Canvas::_placement_factories; Canvas::PlacementFactoryMap Canvas::_placement_factories;
SystemAdapterPtr Canvas::_system_adapter;
} // namespace canvas } // namespace canvas
} // namespace simgear } // namespace simgear

View File

@ -74,9 +74,6 @@ namespace canvas
virtual ~Canvas(); virtual ~Canvas();
virtual void onDestroy(); virtual void onDestroy();
void setSystemAdapter(const SystemAdapterPtr& system_adapter);
SystemAdapterPtr getSystemAdapter() const;
void setCanvasMgr(CanvasMgr* canvas_mgr); void setCanvasMgr(CanvasMgr* canvas_mgr);
CanvasMgr* getCanvasMgr() const; CanvasMgr* getCanvasMgr() const;
@ -165,9 +162,18 @@ namespace canvas
PlacementFactory factory ); PlacementFactory factory );
static void removePlacementFactory(const std::string& type); static void removePlacementFactory(const std::string& type);
/**
* Set global SystemAdapter for all Canvas/ODGauge instances.
*
* The SystemAdapter is responsible for application specific operations
* like loading images/fonts and adding/removing cameras to the scene
* graph.
*/
static void setSystemAdapter(const SystemAdapterPtr& system_adapter);
static SystemAdapterPtr getSystemAdapter();
protected: protected:
SystemAdapterPtr _system_adapter;
CanvasMgr *_canvas_mgr; CanvasMgr *_canvas_mgr;
boost::scoped_ptr<EventManager> _event_manager; boost::scoped_ptr<EventManager> _event_manager;
@ -204,6 +210,8 @@ namespace canvas
private: private:
static SystemAdapterPtr _system_adapter;
Canvas(const Canvas&); // = delete; Canvas(const Canvas&); // = delete;
Canvas& operator=(const Canvas&); // = delete; Canvas& operator=(const Canvas&); // = delete;
}; };

View File

@ -36,10 +36,8 @@ namespace canvas
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
CanvasMgr::CanvasMgr( SGPropertyNode_ptr node, CanvasMgr::CanvasMgr(SGPropertyNode_ptr node):
SystemAdapterPtr system_adapter ): PropertyBasedMgr(node, "texture", &canvasFactory)
PropertyBasedMgr(node, "texture", &canvasFactory),
_system_adapter(system_adapter)
{ {
} }
@ -66,7 +64,6 @@ namespace canvas
void CanvasMgr::elementCreated(PropertyBasedElementPtr element) void CanvasMgr::elementCreated(PropertyBasedElementPtr element)
{ {
CanvasPtr canvas = boost::static_pointer_cast<Canvas>(element); CanvasPtr canvas = boost::static_pointer_cast<Canvas>(element);
canvas->setSystemAdapter(_system_adapter);
canvas->setCanvasMgr(this); canvas->setCanvasMgr(this);
} }

View File

@ -34,12 +34,8 @@ namespace canvas
/** /**
* @param node Root node of branch used to control canvasses * @param node Root node of branch used to control canvasses
* @param system_adapter Adapter for connecting between canvas and
* application framework
*
*/ */
CanvasMgr( SGPropertyNode_ptr node, CanvasMgr(SGPropertyNode_ptr node);
SystemAdapterPtr system_adapter );
/** /**
* Create a new canvas * Create a new canvas
@ -65,8 +61,6 @@ namespace canvas
protected: protected:
SystemAdapterPtr _system_adapter;
virtual void elementCreated(PropertyBasedElementPtr element); virtual void elementCreated(PropertyBasedElementPtr element);
}; };

View File

@ -29,6 +29,7 @@
#endif #endif
#include "ODGauge.hxx" #include "ODGauge.hxx"
#include "Canvas.hxx"
#include "CanvasSystemAdapter.hxx" #include "CanvasSystemAdapter.hxx"
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
@ -123,12 +124,6 @@ namespace canvas
clear(); clear();
} }
//----------------------------------------------------------------------------
void ODGauge::setSystemAdapter(const SystemAdapterPtr& system_adapter)
{
_system_adapter = system_adapter;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void ODGauge::setSize(int size_x, int size_y) void ODGauge::setSize(int size_x, int size_y)
{ {
@ -262,8 +257,8 @@ namespace canvas
updateSampling(); updateSampling();
updateBlendMode(); updateBlendMode();
if( _system_adapter ) if( Canvas::getSystemAdapter() )
_system_adapter->addCamera(camera.get()); Canvas::getSystemAdapter()->addCamera(camera.get());
_flags |= AVAILABLE; _flags |= AVAILABLE;
} }
@ -279,8 +274,8 @@ namespace canvas
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void ODGauge::clear() void ODGauge::clear()
{ {
if( camera.valid() && _system_adapter ) if( camera.valid() && Canvas::getSystemAdapter() )
_system_adapter->removeCamera(camera.get()); Canvas::getSystemAdapter()->removeCamera(camera.get());
camera.release(); camera.release();
texture.release(); texture.release();

View File

@ -53,8 +53,6 @@ namespace canvas
ODGauge(); ODGauge();
virtual ~ODGauge(); virtual ~ODGauge();
void setSystemAdapter(const SystemAdapterPtr& system_adapter);
/** /**
* Set the size of the render target. * Set the size of the render target.
* *
@ -136,8 +134,6 @@ namespace canvas
protected: protected:
SystemAdapterPtr _system_adapter;
int _size_x, int _size_x,
_size_y, _size_y,
_view_width, _view_width,

View File

@ -565,7 +565,7 @@ namespace canvas
} }
else else
{ {
setImage( canvas->getSystemAdapter()->getImage(path) ); setImage( Canvas::getSystemAdapter()->getImage(path) );
} }
} }
} }

View File

@ -327,7 +327,7 @@ namespace canvas
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void Text::setFont(const char* name) void Text::setFont(const char* name)
{ {
_text->setFont( _canvas.lock()->getSystemAdapter()->getFont(name) ); _text->setFont( Canvas::getSystemAdapter()->getFont(name) );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------