Эх сурвалжийг харах

Added simple pan detection.

Taddeus Kroes 13 жил өмнө
parent
commit
2f572483dd
2 өөрчлөгдсөн 44 нэмэгдсэн , 28 устгасан
  1. 2 2
      src/events.py
  2. 42 26
      src/touch.py

+ 2 - 2
src/events.py

@@ -107,6 +107,6 @@ class Pan(Gesture):
         self.n = n
 
     def __str__(self):
-        return '<%s (%s, %s) to (%s, %s) n=%d>' % \
+        return '<%s (%s, %s) direction=(%s, %s) n=%d>' % \
                (self.__class__.__name__, self.x, self.y, self.dx, self.dy,
-                self.amount, self.n)
+                self.n)

+ 42 - 26
src/touch.py

@@ -273,36 +273,47 @@ class MultiTouchListener(Logger):
 
         return cx - ocx, cy - ocy
 
-    def detect_pan(self):
-        """
-        Look for multi-finger drag events. Multi-drag is defined as all the
-        fingers moving close-ish together in the same direction.
-        """
-        l = len(self.points)
+    #def detect_pan(self):
+    #    """
+    #    Look for multi-finger drag events. Multi-drag is defined as all the
+    #    fingers moving close-ish together in the same direction.
+    #    """
+    #    l = len(self.points)
 
-        if not l:
-            return False
+    #    if not l:
+    #        return False
 
-        m = MAX_MULTI_DRAG_DISTANCE
-        clustered = l == 1 or all([p.distance(*self.centroid) <= m \
-                                   for p in self.points])
-        directions = [(cmp(p.dx(), 0), cmp(p.dy(), 0))
-                      for p in self.points]
+    #    m = MAX_MULTI_DRAG_DISTANCE
+    #    clustered = l == 1 or all([p.distance(*self.centroid) <= m \
+    #                               for p in self.points])
+    #    directions = [(cmp(p.dx(), 0), cmp(p.dy(), 0))
+    #                  for p in self.points]
 
-        if not clustered or not any(map(all, zip(*directions))):
-            return False
+    #    if not clustered or not any(map(all, zip(*directions))):
+    #        return False
 
-        if l == 1:
-            p = self.points[0]
-            cx, cy, dx, dy = p.x, p.y, p.dx(), p.dy()
-        else:
-            cx, cy = self.centroid
-            old_cx, old_cy = self.old_centroid
-            dx, dy = cx - old_cx, cy - old_cy
+    #    if l == 1:
+    #        p = self.points[0]
+    #        cx, cy, dx, dy = p.x, p.y, p.dx(), p.dy()
+    #    else:
+    #        cx, cy = self.centroid
+    #        old_cx, old_cy = self.old_centroid
+    #        dx, dy = cx - old_cx, cy - old_cy
+
+    #    self.trigger(Pan(cx, cy, dx, dy, l))
 
-        self.trigger(Pan(cx, cy, dx, dy, l))
+    #    return True
 
-        return True
+    def detect_pan(self):
+        l = len(self.points)
+
+        if not l:
+            return
+
+        if distance(self.centroid, self.old_centroid) > DIST_THRESHOLD:
+            cx, cy = self.centroid
+            dx, dy = self.centroid_movement()
+            self.trigger(Pan(cx, cy, dx, dy, l))
 
     def find_point(self, sid, index=False):
         for i, p in enumerate(self.points):
@@ -340,8 +351,10 @@ class MultiTouchListener(Logger):
 
             # If a pan event is detected, ignore any rotate or pinch movement
             # (they are considered noise)
-            if not self.detect_pan():
-                self.detect_rotation_and_pinch()
+            self.detect_pan()
+            self.detect_rotation_and_pinch()
+            #if not self.detect_pan():
+            #    self.detect_rotation_and_pinch()
 
             self.points_changed = False
 
@@ -427,8 +440,11 @@ if __name__ == '__main__':
     listener.bind('tap', tap, 0)
     listener.bind('single_tap', tap, 1)
     listener.bind('double_tap', tap, 2)
+
+    # Add empty handlers sp that the events are actually triggered
     listener.bind('rotate', lambda e: 0)
     listener.bind('pinch', lambda e: 0)
+    listener.bind('pan', lambda e: 0)
 
     try:
         listener.start()