summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wasp/widgets.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/wasp/widgets.py b/wasp/widgets.py
index 4d17c02..970ab74 100644
--- a/wasp/widgets.py
+++ b/wasp/widgets.py
@@ -302,6 +302,34 @@ class Checkbox():
return True
return False
+class GfxButton():
+ """A button with a graphical icon."""
+ def __init__(self, x, y, gfx):
+ self._im = (x, y)
+ self.gfx = gfx
+
+ def draw(self):
+ """Draw the button."""
+ im = self._im
+ wasp.watch.drawable.blit(self.gfx, im[0], im[1])
+
+ def touch(self, event):
+ x = event[1]
+ y = event[2]
+
+ # Adopt a slightly oversized hit box
+ im = self._im
+ gfx = self.gfx
+ x1 = im[0] - 10
+ x2 = x1 + gfx[1] + 20
+ y1 = im[1] - 10
+ y2 = y1 + gfx[2] + 20
+
+ if x >= x1 and x < x2 and y >= y1 and y < y2:
+ return True
+
+ return False
+
_SLIDER_KNOB_DIAMETER = const(40)
_SLIDER_KNOB_RADIUS = const(_SLIDER_KNOB_DIAMETER // 2)
_SLIDER_WIDTH = const(220)