]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/Canvas.cxx
Fix #1783: repeated error message on console
[simgear.git] / simgear / canvas / Canvas.cxx
index c7898b4535df604b07de4b0ccda9fa545af708af..025b6f7f4b2508cfe07431748b77f1a1ed55721c 100644 (file)
@@ -20,6 +20,7 @@
 #include "CanvasEventManager.hxx"
 #include "CanvasEventVisitor.hxx"
 #include "CanvasPlacement.hxx"
+#include <simgear/canvas/events/KeyboardEvent.hxx>
 #include <simgear/canvas/events/MouseEvent.hxx>
 #include <simgear/scene/util/parse_color.hxx>
 #include <simgear/scene/util/RenderConstants.hxx>
@@ -196,7 +197,25 @@ namespace canvas
   {
     _layout = layout;
     _layout->setCanvas(this);
-    _status |= LAYOUT_DIRTY;
+  }
+
+  //----------------------------------------------------------------------------
+  void Canvas::setFocusElement(const ElementPtr& el)
+  {
+    if( el && el->getCanvas().lock() != this )
+    {
+      SG_LOG(SG_GUI, SG_WARN, "setFocusElement: element not from this canvas");
+      return;
+    }
+
+    // TODO focus out/in events
+    _focus_element = el;
+  }
+
+  //----------------------------------------------------------------------------
+  void Canvas::clearFocusElement()
+  {
+    _focus_element.reset();
   }
 
   //----------------------------------------------------------------------------
@@ -256,15 +275,7 @@ namespace canvas
     }
 
     if( _layout )
-    {
-      if( (_status & LAYOUT_DIRTY) )
-      {
-        _layout->setGeometry(SGRecti(0, 0, _view_width, _view_height));
-        _status &= ~LAYOUT_DIRTY;
-      }
-      else
-        _layout->update();
-    }
+      _layout->setGeometry(SGRecti(0, 0, _view_width, _view_height));
 
     if( _visible || _render_always )
     {
@@ -410,7 +421,6 @@ namespace canvas
     if( _view_width == w )
       return;
     _view_width = w;
-    _status |= LAYOUT_DIRTY;
 
     _texture.setViewSize(_view_width, _view_height);
   }
@@ -421,7 +431,6 @@ namespace canvas
     if( _view_height == h )
       return;
     _view_height = h;
-    _status |= LAYOUT_DIRTY;
 
     _texture.setViewSize(_view_width, _view_height);
   }
@@ -459,6 +468,18 @@ namespace canvas
     return _event_manager->handleEvent(event, visitor.getPropagationPath());
   }
 
+  //----------------------------------------------------------------------------
+  bool Canvas::handleKeyboardEvent(const KeyboardEventPtr& event)
+  {
+    ElementPtr target = _focus_element.lock();
+    if( !target )
+      target = _root_group;
+    if( !target )
+      return false;
+
+    return target->dispatchEvent(event);
+  }
+
   //----------------------------------------------------------------------------
   bool Canvas::propagateEvent( EventPtr const& event,
                                EventPropagationPath const& path )