[gnome-games] Make Sudoku board less eye-straining



commit 4031753bcea3c3c25f64d3de9b1dc82c36d40672
Author: Robert Ancell <robert ancell gmail com>
Date:   Tue Apr 20 18:44:30 2010 +1000

    Make Sudoku board less eye-straining

 gnome-sudoku/src/lib/gsudoku.py    |   37 ++++++-----------------------------
 gnome-sudoku/src/lib/number_box.py |   24 +++-------------------
 2 files changed, 11 insertions(+), 50 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index 0a1233d..25c6922 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -26,11 +26,6 @@ def gtkcolor_to_rgb (color):
             color.green / float(2**16),
             color.blue  / float(2**16))
 
-SPACING_FACTOR = 40 # The size of a box compared (roughly) to the size
-                    # of padding -- the larger this is, the smaller
-                    # the spaces
-SMALL_TO_BIG_FACTOR = 3.5 # The number of times wider than a small line a big line is.
-
 class SudokuNumberGrid (gtk.AspectFrame):
 
     def __init__ (self, group_size = 9):
@@ -50,7 +45,13 @@ class SudokuNumberGrid (gtk.AspectFrame):
         self.eb = gtk.EventBox()
         self.eb.add(self.table)
         self.add(self.eb)
-        self.connect('size-allocate', self.allocate_cb)
+        self.table.set_row_spacings(1)
+        self.table.set_col_spacings(1)
+        box_side = int(math.sqrt(self.group_size))
+        for n in range(1, box_side):
+            self.table.set_row_spacing(box_side*n-1, 2)
+            self.table.set_col_spacing(box_side*n-1, 2)
+        self.table.set_border_width(2)
         self.show_all()
 
     def set_parent_for(self, parent):
@@ -61,30 +62,6 @@ class SudokuNumberGrid (gtk.AspectFrame):
         for entry in self.__entries__.values():
             entry.set_timer(timer)
 
-    def allocate_cb (self, w, rect):
-        if rect.width > rect.height:
-            side = rect.height
-        else: side = rect.width
-        # we want our small spacing to be 1/15th the size of a box
-        spacing = float(side) / (self.group_size * SPACING_FACTOR)
-        if spacing == 0:
-            spacing = 1
-        if hasattr(self, 'small_spacing') and spacing == self.small_spacing:
-            return
-        else:
-            self.change_spacing(spacing)
-
-    def change_spacing (self, small_spacing):
-        self.small_spacing = small_spacing
-        self.big_spacing = int(small_spacing*SMALL_TO_BIG_FACTOR)
-        self.table.set_row_spacings(int(small_spacing))
-        self.table.set_col_spacings(int(small_spacing))
-        box_side = int(math.sqrt(self.group_size))
-        for n in range(1, box_side):
-            self.table.set_row_spacing(box_side*n-1, self.big_spacing)
-            self.table.set_col_spacing(box_side*n-1, self.big_spacing)
-        self.table.set_border_width(self.big_spacing)
-
     def get_focused_entry (self):
         return self.table.focus_child
 
diff --git a/gnome-sudoku/src/lib/number_box.py b/gnome-sudoku/src/lib/number_box.py
index f6d86e1..f4534cb 100644
--- a/gnome-sudoku/src/lib/number_box.py
+++ b/gnome-sudoku/src/lib/number_box.py
@@ -17,7 +17,7 @@ NOTE_FONT_SIZE = pango.SCALE * 6
 
 BORDER_WIDTH = 9.0 # The size of space we leave for a box
 BORDER_LINE_WIDTH = 4 # The size of the line we draw around a selected box
-NORMAL_LINE_WIDTH = 1 # The size of the line we draw around a box
+NORMAL_LINE_WIDTH = 0 # The size of the line we draw around a box
 
 class NumberSelector (gtk.EventBox):
 
@@ -446,12 +446,12 @@ class NumberBox (gtk.Widget):
         # Create any resources in here.
         x, y, w, h = self.allocation
         cr = self.window.cairo_create()
+        self.draw_background_color(cr, w, h)
         if h < w:
             scale = h/float(BASE_SIZE)
         else:
             scale = w/float(BASE_SIZE)
         cr.scale(scale, scale)
-        self.draw_background_color(cr)
         if self.is_focus():
             self.draw_highlight_box(cr)
         self.draw_normal_box(cr)
@@ -460,7 +460,7 @@ class NumberBox (gtk.Widget):
             self.draw_note_area_highlight_box(cr)
 
 
-    def draw_background_color (self, cr):
+    def draw_background_color (self, cr, w, h):
         if self.read_only:
             if self.custom_background_color:
                 r, g, b = self.custom_background_color
@@ -478,7 +478,7 @@ class NumberBox (gtk.Widget):
                 self.style.base[self.state]
                 )
         cr.rectangle(
-            0, 0, BASE_SIZE, BASE_SIZE
+            0, 0, w, h,
             )
         cr.fill()
 
@@ -497,20 +497,6 @@ class NumberBox (gtk.Widget):
             BASE_SIZE-NORMAL_LINE_WIDTH,
             )
         cr.set_line_width(NORMAL_LINE_WIDTH)
-        cr.set_line_join(cairo.LINE_JOIN_ROUND)
-        cr.stroke()
-        # And now draw a thinner line around the very outside...
-        cr.set_source_color(
-            self.style.dark[state]
-            )
-        cr.rectangle(
-            NORMAL_LINE_WIDTH*0.25,
-            NORMAL_LINE_WIDTH*0.25,
-            BASE_SIZE-NORMAL_LINE_WIDTH*0.5,
-            BASE_SIZE-NORMAL_LINE_WIDTH*0.5,
-            )
-        cr.set_line_width(NORMAL_LINE_WIDTH*0.5)
-        cr.set_line_join(cairo.LINE_JOIN_MITER)
         cr.stroke()
 
     def draw_highlight_box (self, cr):
@@ -526,7 +512,6 @@ class NumberBox (gtk.Widget):
             BASE_SIZE-(BORDER_LINE_WIDTH),
             )
         cr.set_line_width(BORDER_LINE_WIDTH)
-        cr.set_line_join(cairo.LINE_JOIN_ROUND)
         cr.stroke()
 
     def draw_note_area_highlight_box (self, cr):
@@ -535,7 +520,6 @@ class NumberBox (gtk.Widget):
             self.style.mid[self.state]
             )
         cr.set_line_width(NORMAL_LINE_WIDTH)
-        cr.set_line_join(cairo.LINE_JOIN_ROUND)
         # top rectangle
         cr.rectangle(NORMAL_LINE_WIDTH*0.5,
                      NORMAL_LINE_WIDTH*0.5,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]