From 7a220921f0430a9c0e31efa70807e1480108d668 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Mon, 9 Dec 2013 23:05:31 +0100 Subject: [PATCH] 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). --- simgear/canvas/Canvas.cxx | 27 +++++++++++++------------ simgear/canvas/Canvas.hxx | 16 +++++++++++---- simgear/canvas/CanvasMgr.cxx | 7 ++----- simgear/canvas/CanvasMgr.hxx | 8 +------- simgear/canvas/ODGauge.cxx | 15 +++++--------- simgear/canvas/ODGauge.hxx | 4 ---- simgear/canvas/elements/CanvasImage.cxx | 2 +- simgear/canvas/elements/CanvasText.cxx | 2 +- 8 files changed, 36 insertions(+), 45 deletions(-) diff --git a/simgear/canvas/Canvas.cxx b/simgear/canvas/Canvas.cxx index 28fa521e..5a1e09cb 100644 --- a/simgear/canvas/Canvas.cxx +++ b/simgear/canvas/Canvas.cxx @@ -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 diff --git a/simgear/canvas/Canvas.hxx b/simgear/canvas/Canvas.hxx index 6857d61d..c350257c 100644 --- a/simgear/canvas/Canvas.hxx +++ b/simgear/canvas/Canvas.hxx @@ -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 _event_manager; @@ -204,6 +210,8 @@ namespace canvas private: + static SystemAdapterPtr _system_adapter; + Canvas(const Canvas&); // = delete; Canvas& operator=(const Canvas&); // = delete; }; diff --git a/simgear/canvas/CanvasMgr.cxx b/simgear/canvas/CanvasMgr.cxx index 55ab24a2..027d84ab 100644 --- a/simgear/canvas/CanvasMgr.cxx +++ b/simgear/canvas/CanvasMgr.cxx @@ -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(element); - canvas->setSystemAdapter(_system_adapter); canvas->setCanvasMgr(this); } diff --git a/simgear/canvas/CanvasMgr.hxx b/simgear/canvas/CanvasMgr.hxx index 238fcc76..084364e3 100644 --- a/simgear/canvas/CanvasMgr.hxx +++ b/simgear/canvas/CanvasMgr.hxx @@ -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); }; diff --git a/simgear/canvas/ODGauge.cxx b/simgear/canvas/ODGauge.cxx index 3f34f989..5c547eaf 100644 --- a/simgear/canvas/ODGauge.cxx +++ b/simgear/canvas/ODGauge.cxx @@ -29,6 +29,7 @@ #endif #include "ODGauge.hxx" +#include "Canvas.hxx" #include "CanvasSystemAdapter.hxx" #include @@ -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(); diff --git a/simgear/canvas/ODGauge.hxx b/simgear/canvas/ODGauge.hxx index 825b603b..413c9d57 100644 --- a/simgear/canvas/ODGauge.hxx +++ b/simgear/canvas/ODGauge.hxx @@ -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, diff --git a/simgear/canvas/elements/CanvasImage.cxx b/simgear/canvas/elements/CanvasImage.cxx index fee83c41..d86c7115 100644 --- a/simgear/canvas/elements/CanvasImage.cxx +++ b/simgear/canvas/elements/CanvasImage.cxx @@ -565,7 +565,7 @@ namespace canvas } else { - setImage( canvas->getSystemAdapter()->getImage(path) ); + setImage( Canvas::getSystemAdapter()->getImage(path) ); } } } diff --git a/simgear/canvas/elements/CanvasText.cxx b/simgear/canvas/elements/CanvasText.cxx index ef6f4393..f73a6ce8 100644 --- a/simgear/canvas/elements/CanvasText.cxx +++ b/simgear/canvas/elements/CanvasText.cxx @@ -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) ); } //---------------------------------------------------------------------------- -- 2.39.5