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-01 02:33:07 (GMT)
committer Agustin Zubiaga <aguz@sugarlabs.org>2012-09-01 02:33:07 (GMT)
commitb54f1378dcfe728ebe6584dba93b0672c7ddb1d6 (patch)
tree891c3c0ffa9ae2cafedef2ccad3dce9caa5cbd94
parentf39842cb723ef7d8db4e962e8c2d0fd3d5adc6be (diff)
Draw circles at mouse position
-rwxr-xr-xgame.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/game.py b/game.py
index 4f59198..199bb6e 100755
--- a/game.py
+++ b/game.py
@@ -19,6 +19,7 @@
import cairo
from gi.repository import Gtk
+from gi.repository import Gdk
from sugar3.graphics import style
from sugar3 import profile
@@ -41,6 +42,8 @@ class Canvas(Gtk.DrawingArea):
self._crosses = []
self._center = ()
+ self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
+
self.connect('draw', self._draw_cb)
self.connect('button-press-event', self._click_cb)
@@ -58,7 +61,8 @@ class Canvas(Gtk.DrawingArea):
context.fill()
# Colors
- stroke, fill = (0, 0, 255), (0, 0, 255)
+ # FIXME: Use the sugar profile colors
+ stroke, fill = (0, 0, 255), (0, 255, 0)
# Tic-Tac-Toe
context.set_source_rgb(*stroke)
@@ -91,29 +95,33 @@ class Canvas(Gtk.DrawingArea):
context.line_to(x, BETWEEN_LINE_SPACE * SIZE_FACTOR_2)
context.stroke()
+ context.set_source_rgb(*fill)
for circle in self._circles:
x, y = circle
context.arc(x, y, SIZE / 2, 0, 360)
- context.stroke()
+ context.stroke()
+
+ # TODO: Create a function for draw crosses
def _click_cb(self, widget, event):
- x, y = (event.x, event.y)
+ pos = self.get_pos(event.x, event.y)
- if self._mode == MODE_CIRCLE:
- self._circles.append(self.get_pos(x, y))
+ if self._mode == MODE_CIRCLE and pos:
+ self._circles.append(pos)
- elif self._mode == MODE_CROSS:
- self._crosses.append(self.get_pos(x, y))
+ elif self._mode == MODE_CROSS and pos:
+ self._crosses.append(pos)
self.queue_draw()
def get_pos(self, x, y):
+ # TODO: Return the specific square coords
return x, y
if __name__ == "__main__":
window = Gtk.Window()
- window.connect('destroy', lambda w: exit())
+ window.connect('destroy', lambda w: Gtk.main_quit())
window.add(Canvas())
window.maximize()
window.show_all()