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-08-28 00:29:05 (GMT)
committer Agustin Zubiaga <aguz@sugarlabs.org>2012-08-28 15:22:14 (GMT)
commit179d52434945fdf43e7470c5f85de455f624f1e7 (patch)
treebbb3dc57a01d58f3cb13ca32f0a586e90aad8708
parenta81918f8bdafc9b67399aa7316ee892efaf08d48 (diff)
File canvas.py
Draw the tic-tac-toe using cairo Signed-off-by: Agustin Zubiaga <aguz@sugarlabs.org>
-rw-r--r--activity.py6
-rw-r--r--canvas.py75
2 files changed, 79 insertions, 2 deletions
diff --git a/activity.py b/activity.py
index 56a3c8d..5006b73 100644
--- a/activity.py
+++ b/activity.py
@@ -24,6 +24,8 @@ from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.graphics.radiotoolbutton import RadioToolButton
from sugar3.graphics.toolbutton import ToolButton
+from canvas import GameCanvas
+
class Activity(activity.Activity):
def __init__(self, handle):
@@ -85,8 +87,8 @@ class Activity(activity.Activity):
toolbarbox.toolbar.insert(stopbtn, -1)
# Canvas
- drawingarea = Gtk.DrawingArea()
- self.set_canvas(drawingarea)
+ canvas = GameCanvas()
+ self.set_canvas(canvas)
self.set_toolbar_box(toolbarbox)
self.show_all()
diff --git a/canvas.py b/canvas.py
new file mode 100644
index 0000000..f9c242e
--- /dev/null
+++ b/canvas.py
@@ -0,0 +1,75 @@
+# Copyright (C) 2012 Agustin Zubiaga <aguz@sugarlabs.org>
+# Copyright (C) 2012 Cristhofer Travieso <cristhofert97@gmail.com>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import cairo
+from gi.repository import Gtk
+from sugar3.graphics import style
+from sugar3 import profile
+
+BETWEEN_LINE_SPACE = style.zoom(200)
+
+
+class GameCanvas(Gtk.DrawingArea):
+
+ def __init__(self):
+ Gtk.DrawingArea.__init__(self)
+
+ self.connect('draw', self._draw_cb)
+
+ self.show_all()
+
+ 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)
+ context.fill()
+
+ # Colors
+ stroke, fill = (0, 0, 255), (0, 0, 255)
+
+ # Tic-Tac-Toe
+ context.set_line_width(10)
+ context.set_line_cap(cairo.LINE_CAP_ROUND)
+
+ ttt_size = BETWEEN_LINE_SPACE * 4
+ x = alloc.width - ttt_size
+ y = alloc.height - ttt_size
+
+ context.move_to(x, y)
+ context.line_to(x, ttt_size - BETWEEN_LINE_SPACE)
+ context.set_source_rgb(*stroke)
+ context.stroke()
+
+ x += BETWEEN_LINE_SPACE
+ context.move_to(x, y)
+ context.line_to(x, ttt_size - BETWEEN_LINE_SPACE)
+ context.stroke()
+
+ x -= BETWEEN_LINE_SPACE * 2
+ y += BETWEEN_LINE_SPACE
+
+ context.move_to(x, y)
+ context.line_to(ttt_size, y)
+ context.stroke()
+
+ y += BETWEEN_LINE_SPACE
+ context.move_to(x, y)
+ context.line_to(ttt_size, y)
+ context.stroke()
+