| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- from geometry import Surface, RectangularSurface, CircularSurface
- from screen import screen_size
- class Window(Surface):
- """
- Abstract class that represents a 2D object on the screen to which gesture
- trackers can be added. Implementations of this class should define a method
- that can detect wether a touch point is located within the window.
- Because any type of window on the screen has (at least) an (x, y) position,
- it extends the Positionable object.
- Note: Dimensions used in implementations of this class should be in pixels.
- """
- def __init__(self, **kwargs):
- # All trackers that are currently bound to this window
- self.trackers = []
- # List of points that originated in this window
- self.points = []
- if 'server' in kwargs:
- kwargs['server'].add_window(self)
- def add_tracker(self, tracker):
- self.trackers.append(tracker)
- def remove_tracker(self, tracker):
- self.trackers.remove(tracker)
- def on_point_down(self, point):
- self.points.append(point)
- self.update_trackers('down', point)
- def on_point_move(self, point):
- self.update_trackers('move', point)
- def on_point_up(self, point):
- self.points.remove(point)
- self.update_trackers('up', point)
- def update_trackers(self, event_type, point):
- """
- Update all gesture trackers that are bound to this window with an
- added/moved/removed touch point.
- """
- handler_name = 'on_point_' + event_type
- for tracker in self.trackers:
- if hasattr(tracker, handler_name):
- getattr(tracker, handler_name)(point)
- class RectangularWindow(Window, RectangularSurface):
- """
- Rectangular window.
- """
- def __init__(self, x, y, width, height, **kwargs):
- Window.__init__(self, **kwargs)
- RectangularSurface.__init__(self, x, y, width, height)
- class CircularWindow(Window, CircularSurface):
- """
- Circular window.
- """
- def __init__(self, x, y, width, height, **kwargs):
- Window.__init__(self, **kwargs)
- CircularSurface.__init__(self, x, y, radius)
- class FullscreenWindow(RectangularWindow):
- """
- Window representation for the entire screen. This class provides an easy
- way to create a single rectangular window that catches all gestures.
- """
- def __init__(self, **kwargs):
- super(FullscreenWindow, self).__init__(0, 0, *screen_size, **kwargs)
- def __str__(self):
- return '<FullscreenWindow size=(%d, %d)>' % (self.width, self.height)
- def contains(self, point):
- return True
|