]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/CanvasEventVisitor.cxx
canvas::Layout: support for contents margins.
[simgear.git] / simgear / canvas / CanvasEventVisitor.cxx
index 6ba90a9f363a41c4f5c738545f584e5774ab2dea..efb12dbb49ad0073c0558d869765f75021dd17b6 100644 (file)
@@ -20,7 +20,6 @@
 #include "CanvasEvent.hxx"
 #include "CanvasEventVisitor.hxx"
 #include <simgear/canvas/elements/CanvasElement.hxx>
-#include <iostream>
 
 namespace simgear
 {
@@ -30,16 +29,12 @@ namespace canvas
   //----------------------------------------------------------------------------
   EventVisitor::EventVisitor( TraverseMode mode,
                               const osg::Vec2f& pos,
-                              const osg::Vec2f& delta,
                               const ElementPtr& root ):
     _traverse_mode( mode ),
     _root(root)
   {
     if( mode == TRAVERSE_DOWN )
-    {
-      EventTarget target = {ElementWeakPtr(), pos, delta};
-      _target_path.push_back(target);
-    }
+      _target_path.push_back( EventTarget(NULL, pos) );
   }
 
   //----------------------------------------------------------------------------
@@ -63,31 +58,18 @@ namespace canvas
     // We only need to check for hits while traversing down
     if( _traverse_mode == TRAVERSE_DOWN )
     {
-      // Transform event to local coordinates
-      const osg::Matrix& m = el.getMatrixTransform()->getInverseMatrix();
       const osg::Vec2f& pos = _target_path.back().local_pos;
-      const osg::Vec2f local_pos
-      (
-        m(0, 0) * pos[0] + m(1, 0) * pos[1] + m(3, 0),
-        m(0, 1) * pos[0] + m(1, 1) * pos[1] + m(3, 1)
-      );
+      const osg::Vec2f local_pos = el.posToLocal(pos);
 
       // Don't check specified root element for collision, as its purpose is to
       // catch all events which have no target. This allows for example calling
       // event listeners attached to the canvas itself (its root group) even if
       // no element has been hit.
-      if( _root.get() != &el && !el.hitBound(pos, local_pos) )
+      if(    _root.get() != &el
+          && !el.hitBound(_target_path.front().local_pos, pos, local_pos) )
         return false;
 
-      const osg::Vec2f& delta = _target_path.back().local_delta;
-      const osg::Vec2f local_delta
-      (
-        m(0, 0) * delta[0] + m(1, 0) * delta[1],
-        m(0, 1) * delta[0] + m(1, 1) * delta[1]
-      );
-
-      EventTarget target = {el.getWeakPtr(), local_pos, local_delta};
-      _target_path.push_back(target);
+      _target_path.push_back( EventTarget(&el, local_pos) );
 
       if( el.traverse(*this) || &el == _root.get() )
         return true;