]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/Canvas.hxx
canvas::Layout: clear parent/canvas after calling onRemove.
[simgear.git] / simgear / canvas / Canvas.hxx
index 08fbe40dc3a9f363596cf8fced67799f45fd45db..2c817f61bcbf98fe17805b505847204df1d41f7f 100644 (file)
@@ -1,4 +1,4 @@
-// The canvas for rendering with the 2d API
+///@file The canvas for rendering with the 2d API
 //
 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
 //
 #include "ODGauge.hxx"
 
 #include <simgear/canvas/elements/CanvasGroup.hxx>
+#include <simgear/canvas/layout/Layout.hxx>
 #include <simgear/math/SGRect.hxx>
+#include <simgear/nasal/cppbind/NasalObject.hxx>
 #include <simgear/props/PropertyBasedElement.hxx>
 #include <simgear/props/propertyObject.hxx>
+
 #include <osg/NodeCallback>
 #include <osg/observer_ptr>
 
 
 namespace simgear
 {
+/// Canvas 2D drawing API
 namespace canvas
 {
   class CanvasMgr;
   class MouseEvent;
 
   class Canvas:
-    public PropertyBasedElement
+    public PropertyBasedElement,
+    public nasal::Object
   {
     public:
 
       enum StatusFlags
       {
         STATUS_OK,
-        STATUS_DIRTY     = 1,
-        MISSING_SIZE_X = STATUS_DIRTY << 1,
+        STATUS_DIRTY   = 1,
+        LAYOUT_DIRTY   = STATUS_DIRTY << 1,
+        MISSING_SIZE_X = LAYOUT_DIRTY << 1,
         MISSING_SIZE_Y = MISSING_SIZE_X << 1,
+        MISSING_SIZE   = MISSING_SIZE_X | MISSING_SIZE_Y,
         CREATE_FAILED  = MISSING_SIZE_Y << 1
       };
 
@@ -71,11 +78,9 @@ namespace canvas
       typedef osg::ref_ptr<CullCallback> CullCallbackPtr;
 
       Canvas(SGPropertyNode* node);
+      virtual ~Canvas();
       virtual void onDestroy();
 
-      void setSystemAdapter(const SystemAdapterPtr& system_adapter);
-      SystemAdapterPtr getSystemAdapter() const;
-
       void setCanvasMgr(CanvasMgr* canvas_mgr);
       CanvasMgr* getCanvasMgr() const;
 
@@ -122,6 +127,12 @@ namespace canvas
        */
       GroupPtr getRootGroup();
 
+      /**
+       * Set the layout of the canvas (the layout will automatically update with
+       * the viewport size of the canvas)
+       */
+      void setLayout(const LayoutRef& layout);
+
       /**
        * Enable rendering for the next frame
        *
@@ -132,7 +143,8 @@ namespace canvas
 
       void update(double delta_time_sec);
 
-      naRef addEventListener(const nasal::CallContext& ctx);
+      bool addEventListener(const std::string& type, const EventListener& cb);
+      bool dispatchEvent(const EventPtr& event);
 
       void setSizeX(int sx);
       void setSizeY(int sy);
@@ -148,6 +160,8 @@ namespace canvas
       SGRect<int> getViewport() const;
 
       bool handleMouseEvent(const MouseEventPtr& event);
+      bool propagateEvent( EventPtr const& event,
+                           EventPropagationPath const& path );
 
       virtual void childAdded( SGPropertyNode * parent,
                                SGPropertyNode * child );
@@ -162,10 +176,20 @@ namespace canvas
       void reloadPlacements( const std::string& type = std::string() );
       static void addPlacementFactory( const std::string& type,
                                        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;
@@ -183,7 +207,9 @@ namespace canvas
            _visible;
 
       ODGauge _texture;
-      GroupPtr _root_group;
+
+      GroupPtr  _root_group;
+      LayoutRef _layout;
 
       CullCallbackPtr _cull_callback;
       bool _render_always; //<! Used to disable automatic lazy rendering (culling)
@@ -197,11 +223,12 @@ namespace canvas
       typedef std::map<std::string, PlacementFactory> PlacementFactoryMap;
       static PlacementFactoryMap _placement_factories;
 
-      virtual void setSelf(const PropertyBasedElementPtr& self);
       void setStatusFlags(unsigned int flags, bool set = true);
 
     private:
 
+      static SystemAdapterPtr _system_adapter;
+
       Canvas(const Canvas&); // = delete;
       Canvas& operator=(const Canvas&); // = delete;
   };