]> git.mxchange.org Git - simgear.git/commitdiff
Canvas: one global SystemAdapter is enough.
authorThomas Geymayer <tomgey@gmail.com>
Mon, 9 Dec 2013 22:05:31 +0000 (23:05 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 9 Dec 2013 22:07:17 +0000 (23:07 +0100)
This also fixes elements requiring a SystemAdapter without
being assigned to a Canvas (eg. because they are desktop
elements).

simgear/canvas/Canvas.cxx
simgear/canvas/Canvas.hxx
simgear/canvas/CanvasMgr.cxx
simgear/canvas/CanvasMgr.hxx
simgear/canvas/ODGauge.cxx
simgear/canvas/ODGauge.hxx
simgear/canvas/elements/CanvasImage.cxx
simgear/canvas/elements/CanvasText.cxx

index 28fa521e026a03b5eecdf3c22a02164b4c80638b..5a1e09cb02471e7d42a140d591ddeed6844a5881 100644 (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
index 6857d61ddb9485fd5bf3ec6966d9248ec3807f12..c350257c0b26833df58f077ea50a5213b6d45baf 100644 (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;
   };
index 55ab24a2ecc13e43de0363c848b9fe30389d43f4..027d84abe43e5258b3a821dc4d95fda05e8aee33 100644 (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);
   }
 
index 238fcc76118380bbedf5c8289f1e8ff854c2f5d9..084364e392cf38598910d6d0ad2c7b2e61197b11 100644 (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);
   };
 
index 3f34f989a8635c27d26fc88e32066e83e2d83cad..5c547eafa1af784ddc0cfffb46f278bad1cae190 100644 (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();
 
index 825b603bca7e4b959400af9b1a33fa755a6bcbba..413c9d57f07bbe210e215d6fa8089594996ef1ce 100644 (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,
index fee83c417c3b6bd0fa47b9967d545cb8300f7223..d86c7115337350d62062104e5c4c7abda1c8ea42 100644 (file)
@@ -565,7 +565,7 @@ namespace canvas
       }
       else
       {
-        setImage( canvas->getSystemAdapter()->getImage(path) );
+        setImage( Canvas::getSystemAdapter()->getImage(path) );
       }
     }
   }
index ef6f439337fa2cbdd0ca109cbd11adca6f89697c..f73a6ce8ccc2d7d14f352fad1294e061e00dbcd5 100644 (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) );
   }
 
   //----------------------------------------------------------------------------