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)
{
@ -615,6 +602,19 @@ namespace canvas
_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)
{
@ -656,6 +656,7 @@ namespace canvas
//----------------------------------------------------------------------------
Canvas::PlacementFactoryMap Canvas::_placement_factories;
SystemAdapterPtr Canvas::_system_adapter;
} // namespace canvas
} // namespace simgear

View File

@ -74,9 +74,6 @@ namespace canvas
virtual ~Canvas();
virtual void onDestroy();
void setSystemAdapter(const SystemAdapterPtr& system_adapter);
SystemAdapterPtr getSystemAdapter() const;
void setCanvasMgr(CanvasMgr* canvas_mgr);
CanvasMgr* getCanvasMgr() const;
@ -165,9 +162,18 @@ namespace canvas
PlacementFactory factory );
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:
SystemAdapterPtr _system_adapter;
CanvasMgr *_canvas_mgr;
boost::scoped_ptr<EventManager> _event_manager;
@ -204,6 +210,8 @@ namespace canvas
private:
static SystemAdapterPtr _system_adapter;
Canvas(const Canvas&); // = delete;
Canvas& operator=(const Canvas&); // = delete;
};

View File

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

View File

@ -34,12 +34,8 @@ namespace canvas
/**
* @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,
SystemAdapterPtr system_adapter );
CanvasMgr(SGPropertyNode_ptr node);
/**
* Create a new canvas
@ -65,8 +61,6 @@ namespace canvas
protected:
SystemAdapterPtr _system_adapter;
virtual void elementCreated(PropertyBasedElementPtr element);
};

View File

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

View File

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

View File

@ -565,7 +565,7 @@ namespace canvas
}
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)
{
_text->setFont( _canvas.lock()->getSystemAdapter()->getFont(name) );
_text->setFont( Canvas::getSystemAdapter()->getFont(name) );
}
//----------------------------------------------------------------------------