]> git.mxchange.org Git - simgear.git/commitdiff
Canvas: Fix handling drag events and some cleanup.
authorThomas Geymayer <tomgey@gmail.com>
Fri, 7 Dec 2012 17:34:43 +0000 (18:34 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Fri, 7 Dec 2012 17:35:20 +0000 (18:35 +0100)
simgear/canvas/CanvasEventManager.cxx
simgear/canvas/CanvasEventManager.hxx

index da10ba5f542fc76b3bf002df3e737c29d94325fe..d7135f802746d1a806fb237dbb86aab7997e7c53 100644 (file)
@@ -28,6 +28,38 @@ namespace canvas
   const unsigned int drag_threshold = 8;
   const double multi_click_timeout = 0.4;
 
+  //----------------------------------------------------------------------------
+  EventManager::StampedPropagationPath::StampedPropagationPath():
+    time(0)
+  {
+
+  }
+
+  //----------------------------------------------------------------------------
+
+  EventManager::StampedPropagationPath::StampedPropagationPath(
+    const EventPropagationPath& path,
+    double time
+  ):
+    path(path),
+    time(time)
+  {
+
+  }
+
+  //----------------------------------------------------------------------------
+  void EventManager::StampedPropagationPath::clear()
+  {
+    path.clear();
+    time = 0;
+  }
+
+  //----------------------------------------------------------------------------
+  bool EventManager::StampedPropagationPath::valid() const
+  {
+    return !path.empty() && time > 0;
+  }
+
   //----------------------------------------------------------------------------
   EventManager::EventManager():
     _current_click_count(0)
@@ -39,7 +71,6 @@ namespace canvas
   bool EventManager::handleEvent( const MouseEventPtr& event,
                                   const EventPropagationPath& path )
   {
-    propagateEvent(event, path);
     switch( event->type )
     {
       case Event::MOUSE_DOWN:
@@ -51,16 +82,30 @@ namespace canvas
           // Ignore mouse up without any previous mouse down
           return false;
 
+        // normal mouseup
+        propagateEvent(event, path);
+
+        // now handle click/dblclick
         if( checkClickDistance(path, _last_mouse_down.path) )
           handleClick(event, getCommonAncestor(_last_mouse_down.path, path));
 
-        break;
+        _last_mouse_down.clear();
+
+        return true;
       }
+      case Event::DRAG:
+        if( !_last_mouse_down.valid() )
+          return false;
+        else
+          return propagateEvent(event, _last_mouse_down.path);
+      case Event::WHEEL:
+      case Event::MOUSE_MOVE:
+        break;
       default:
         return false;
     }
 
-    return true;
+    return propagateEvent(event, path);
   }
 
   //----------------------------------------------------------------------------
@@ -135,8 +180,12 @@ namespace canvas
         // (eg. removed by another event handler)
         continue;
 
-      if( mouse_event )
+      if( mouse_event && event->type != Event::DRAG )
       {
+        // TODO transform pos and delta for drag events. Maybe we should just
+        //      store the global coordinates and convert to local coordinates
+        //      on demand.
+
         // Position and delta are specified in local coordinate system of
         // current element
         mouse_event->pos = it->local_pos;
index f8e80571f405264ff2be2c6a653fb55eb30bac0f..8ec3cf7e702583f8d5282ec67c58836c7ff13588 100644 (file)
@@ -46,14 +46,11 @@ namespace canvas
     protected:
       struct StampedPropagationPath
       {
-        StampedPropagationPath():
-          time(0)
-        {}
+        StampedPropagationPath();
+        StampedPropagationPath(const EventPropagationPath& path, double time);
 
-        StampedPropagationPath(const EventPropagationPath& path, double time):
-          path(path),
-          time(time)
-        {}
+        void clear();
+        bool valid() const;
 
         EventPropagationPath path;
         double time;