from widget import Widget from screen import screen_size class RectangularWidget(Widget): """ Rectangular widget, has a position and a size. """ def __init__(self, x, y, width, height): super(RectangularWidget, self).__init__(x, y) self.set_size(width, height) def __str__(self): return '<%s at (%s, %s) size=(%s, %s)>' \ % (self.__class__.__name__, self.x, self.y, self.width, self.height) def set_size(self, width, height): self.width = width self.height = height def get_size(self): return self.width, self.height def contains_event(self, event): x, y = event.get_position() return self.x <= x <= self.x + self.width \ and self.y <= y <= self.y + self.height class CircularWidget(Widget): """ Circular widget, has a position and a radius. """ def __init__(self, x, y, radius): super(CircularWidget, self).__init__(x, y) self.set_radius(radius) def __str__(self): return '<%s at (%s, %s) size=(%s, %s)>' \ % (self.__class__.__name__, self.x, self.y, self.width, self.height) def set_radius(self, radius): self.radius = radius def get_radius(self): return self.radius def contains_event(self, event): return self.distance_to(event.get_touch_object()) <= self.radius class FullscreenWidget(RectangularWidget): """ Widget representation for the entire screen. This class provides an easy way to create a single rectangular widget that catches all gestures. """ def __init__(self): super(FullscreenWidget, self).__init__(0, 0, *screen_size) def __str__(self): return '' % self.get_size() def contains_event(self, event): return True