]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/Canvas.hxx
Fix #1783: repeated error message on console
[simgear.git] / simgear / canvas / Canvas.hxx
index 335b297d99f283b47f398b67ccd435bffe273ada..efcb0a473f38cf53b139baf488e84f2b57a274b2 100644 (file)
@@ -1,4 +1,5 @@
-///@file 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>
 
@@ -40,17 +44,22 @@ namespace canvas
   class CanvasMgr;
   class MouseEvent;
 
+  /**
+   * Canvas to draw onto (to an off-screen render target).
+   */
   class Canvas:
-    public PropertyBasedElement
+    public PropertyBasedElement,
+    public nasal::Object
   {
     public:
 
       enum StatusFlags
       {
         STATUS_OK,
-        STATUS_DIRTY     = 1,
+        STATUS_DIRTY   = 1,
         MISSING_SIZE_X = STATUS_DIRTY << 1,
         MISSING_SIZE_Y = MISSING_SIZE_X << 1,
+        MISSING_SIZE   = MISSING_SIZE_X | MISSING_SIZE_Y,
         CREATE_FAILED  = MISSING_SIZE_Y << 1
       };
 
@@ -121,6 +130,28 @@ 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);
+
+      /**
+       * Set the focus to the given element.
+       *
+       * The focus element will receive all keyboard events propagated to this
+       * canvas. If there is no valid focus element the root group will receive
+       * the events instead.
+       */
+      void setFocusElement(const ElementPtr& el);
+
+      /**
+       * Clear the focus element.
+       *
+       * @see setFocusElement()
+       */
+      void clearFocusElement();
+
       /**
        * Enable rendering for the next frame
        *
@@ -132,6 +163,7 @@ namespace canvas
       void update(double delta_time_sec);
 
       bool addEventListener(const std::string& type, const EventListener& cb);
+      bool dispatchEvent(const EventPtr& event);
 
       void setSizeX(int sx);
       void setSizeY(int sy);
@@ -147,6 +179,8 @@ namespace canvas
       SGRect<int> getViewport() const;
 
       bool handleMouseEvent(const MouseEventPtr& event);
+      bool handleKeyboardEvent(const KeyboardEventPtr& event);
+
       bool propagateEvent( EventPtr const& event,
                            EventPropagationPath const& path );
 
@@ -194,15 +228,19 @@ namespace canvas
            _visible;
 
       ODGauge _texture;
-      GroupPtr _root_group;
+
+      GroupPtr  _root_group;
+      LayoutRef _layout;
+
+      ElementWeakPtr _focus_element;
 
       CullCallbackPtr _cull_callback;
-      bool _render_always; //<! Used to disable automatic lazy rendering (culling)
+      bool _render_always; //!< Used to disable automatic lazy rendering (culling)
 
       std::vector<SGPropertyNode*> _dirty_placements;
       std::vector<Placements> _placements;
-      std::set<CanvasWeakPtr> _parent_canvases, //<! Canvases showing this canvas
-                              _child_canvases;  //<! Canvases displayed within
+      std::set<CanvasWeakPtr> _parent_canvases, //!< Canvases showing this canvas
+                              _child_canvases;  //!< Canvases displayed within
                                                 //   this canvas
 
       typedef std::map<std::string, PlacementFactory> PlacementFactoryMap;