summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2007-07-24 05:25:35 +0200
committerGuillaume Seguin <guillaume@segu.in>2007-07-24 05:25:35 +0200
commitcde1100fb36efa4d11cc84e5b2c23041258be2f5 (patch)
treecc0b14792fbe250735a2fd68a017b3f2fe6059ce
parent4046d3532ba8eafb54c2b3a52cbda5639e0ff07f (diff)
downloadtictactoe-cde1100fb36efa4d11cc84e5b2c23041258be2f5.tar.gz
tictactoe-cde1100fb36efa4d11cc84e5b2c23041258be2f5.tar.bz2
* Beautify
-rwxr-xr-xtictactoe.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/tictactoe.py b/tictactoe.py
index 9432fae..12e6c25 100755
--- a/tictactoe.py
+++ b/tictactoe.py
@@ -32,6 +32,7 @@ import gtk.glade
import random
import cairo
+import pangocairo
from math import pi
def autoconnect (ob):
@@ -41,6 +42,28 @@ def autoconnect (ob):
handlers[i] = getattr (ob, i)
ob.glade.signal_autoconnect (handlers);
+def draw_rounded_rectangle (cr, x, y, width, height):
+ radius = 30
+ x0 = x + 10
+ y0 = y + 10
+ x1 = x + width - 10
+ y1 = y + height - 10
+ cr.new_path ()
+ cr.arc (x0 + radius, y1 - radius, radius, pi / 2, pi)
+ cr.line_to (x0, y0 + radius)
+ cr.arc (x0 + radius, y0 + radius, radius, pi, 3 * pi / 2)
+ cr.line_to (x1 - radius, y0)
+ cr.arc (x1 - radius, y0 + radius, radius, 3 * pi / 2, 2 * pi)
+ cr.line_to (x1, y1 - radius)
+ cr.arc (x1 - radius, y1 - radius, radius, 0, pi / 2)
+ cr.close_path ()
+
+def prepare_text (cr, text):
+ pcr = pangocairo.CairoContext (cr)
+ layout = pcr.create_layout ()
+ layout.set_markup (text)
+ return pcr, layout
+
NO_WINNER = -1
PLAYER_ID = 1
COMPUTER_ID = 2
@@ -188,7 +211,7 @@ class gtkTicTacToe (gtk.DrawingArea):
def button_press (self, widget, event):
'''Check if the cursor clicked an interesting area'''
if self._finished:
- return
+ self.new_game ()
alloc = self.get_allocation ()
side = min (alloc.width, alloc.height)
cell_side = int (float (side) / 3)
@@ -265,6 +288,15 @@ class gtkTicTacToe (gtk.DrawingArea):
if self._finished:
cr.set_source_rgba (0.8, 0.8, 0.8, 0.5)
cr.paint ()
+ cr.set_source_rgba (0.2, 0.2, 0.2, 0.6)
+ draw_rounded_rectangle (cr, side * 0.1, side * 0.25,
+ side * 0.8, side * 0.5)
+ cr.fill ()
+ cr.set_source_rgb (1, 1, 1)
+ cr.move_to (side * 0.25, side * 0.43)
+ text = '<span font_desc="Sans 25"><b>Replay ?</b></span>'
+ pcr, layout = prepare_text (cr, text)
+ pcr.show_layout (layout)
if queue:
self.queue_draw ()