diff options
author | Cristhofer Travieso <cristhofert97@gmail.com> | 2013-04-04 21:56:50 (GMT) |
---|---|---|
committer | Cristhofer Travieso <cristhofert97@gmail.com> | 2013-04-04 21:56:50 (GMT) |
commit | c0293bc75b3cf60416c1e29cc17c5537bb8b99a7 (patch) | |
tree | 9edfdab26ab19ba54bf49eaa1a6a0ae1c4272fde | |
parent | d025c0cdb044d6f789254766f689e1f0e816528f (diff) |
Add backgroud and window
Signed-off-by: Cristhofer Travieso <cristhofert97@gmail.com>
-rw-r--r-- | game.py | 64 |
1 files changed, 63 insertions, 1 deletions
@@ -1,8 +1,10 @@ +#!/usr/bin/env python + # 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 3 of the License, or +# 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, @@ -14,4 +16,64 @@ # 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 gi.repository import Gdk +from gi.repository import GObject + +try: + from sugar3.graphics import style + + SIZE = style.zoom(150) + BETWEEN_LINE_SPACE = style.zoom(200) +except: + pass + +LINE_WIDTH = 12 + +MODE_CIRCLE = 0 +MODE_CROSS = 1 + +TICTACTOE_COLOR = (1, 1, 1) +CROSS_COLOR = (0, 0.921568, 0.0627450) +CIRCLE_COLOR = (1, 0.556862, 0) +BACKGROUND_COLOR = (0.50, 0.20, 0) + + +class Game(Gtk.DrawingArea): + + def __init__(self): + GObject.GObject.__init__(self) + + 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() + + def _draw_cb(self, widget, context): + alloc = self.get_allocation() + + # Background + context.rectangle(0, 0, alloc.width, alloc.height) + context.set_source_rgb(*BACKGROUND_COLOR) + context.fill() + + def _motion_notify_cb(self, widget, event): + x_cursor = event.x + y_cursor = event.y + + def _click_cb(self, widget, event): + x_click = event.x + y_click = event.y + +if __name__ == "__main__": + window = Gtk.Window() + window.connect('destroy', lambda w: Gtk.main_quit()) + window.add(Game()) + window.maximize() + window.show_all() + Gtk.main() |