Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgustin Zubiaga <aguz@sugarlabs.org>2012-09-03 01:50:36 (GMT)
committer Agustin Zubiaga <aguz@sugarlabs.org>2012-09-03 01:50:36 (GMT)
commit3ea9371c70fea3f76c59a2b74e38f045995d3d59 (patch)
tree55d7e3eb9b21b128633a33060f8bf3b7a17b7274
parent5dc65f60360173bb729e58cb95a469fa9a771844 (diff)
Draw a cursor dot
-rwxr-xr-xgame.py38
1 files changed, 25 insertions, 13 deletions
diff --git a/game.py b/game.py
index 79d482b..0b18676 100755
--- a/game.py
+++ b/game.py
@@ -42,11 +42,14 @@ class Canvas(Gtk.DrawingArea):
self.circles = []
self.crosses = []
self.squares = []
+ self.cursor = None
- self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
+ Gdk.EventMask.POINTER_MOTION_MASK)
self.connect('draw', self._draw_cb)
self.connect('button-press-event', self._click_cb)
+ self.connect('motion-notify-event', self._motion_notify_cb)
self.show_all()
@@ -55,7 +58,7 @@ class Canvas(Gtk.DrawingArea):
def _draw_cb(self, widget, context):
alloc = self.get_allocation()
-
+
# White Background
context.rectangle(0, 0, alloc.width, alloc.height)
context.set_source_rgb(255, 255, 255)
@@ -77,7 +80,6 @@ class Canvas(Gtk.DrawingArea):
lx = BETWEEN_LINE_SPACE * SIZE_FACTOR
context.move_to(x, y)
context.line_to(lx, y)
- context.stroke()
size = SIZE / 2 + style.zoom(25)
@@ -90,7 +92,6 @@ class Canvas(Gtk.DrawingArea):
ly = BETWEEN_LINE_SPACE * SIZE_FACTOR_2
context.move_to(x, y)
context.line_to(x, ly)
- context.stroke()
cy1 = y + size
cy2 = y + BETWEEN_LINE_SPACE + size
@@ -100,7 +101,6 @@ class Canvas(Gtk.DrawingArea):
x -= BETWEEN_LINE_SPACE
context.move_to(x, y)
context.line_to(lx, y)
- context.stroke()
x += BETWEEN_LINE_SPACE * 2
y -= BETWEEN_LINE_SPACE * 2
@@ -131,8 +131,22 @@ class Canvas(Gtk.DrawingArea):
context.line_to(x - a, y + a)
context.stroke()
- def _click_cb(self, widget, event):
- pos = self.get_pos(event.x, event.y)
+ # Draw cursor dot
+ if self.cursor:
+ cx, cy = self.cursor
+ context.arc(cx, cy, 9, 0, 360)
+ context.fill_preserve()
+ context.stroke()
+
+ def _motion_notify_cb(self, widget, event):
+ self.cursor = self.get_pos(event.x, event.y)
+ self.queue_draw()
+
+ def _click_cb(self, widget, event):
+ try:
+ pos = self.get_pos(event.x, event.y)
+ except IndexError:
+ pos = None
if self._mode == MODE_CIRCLE and pos:
self.circles.append(pos)
@@ -149,15 +163,15 @@ class Canvas(Gtk.DrawingArea):
all_x = [s[0] for s in self.squares]
all_y = [s[1] for s in self.squares]
+ size = SIZE / 2 + style.zoom(25)
+
if mx > all_x[0] and not mx > all_x[-1]:
count = 0
for x in all_x:
if not xpos:
count += 1
next_x = all_x[count]
- if mx > x and mx < next_x or \
- mx > x - BETWEEN_LINE_SPACE and \
- mx < next_x - BETWEEN_LINE_SPACE:
+ if mx >= (x - size) and mx <= (next_x - size):
xpos = x
elif mx < all_x[0]:
@@ -172,9 +186,7 @@ class Canvas(Gtk.DrawingArea):
if not ypos:
count += 1
next_y = all_y[count]
- if my > y and my < next_y or \
- my > y - BETWEEN_LINE_SPACE and \
- my < next_y - BETWEEN_LINE_SPACE:
+ if my >= (y - size) and my <= (next_y - size):
ypos = y
elif my < all_y[0]: