[gnome-games/sudoku-css-theming: 3/4] move fonts to css



commit b57c51ae1d635ea1cc76d267a79650e52d261acd
Author: John Stowers <john stowers gmail com>
Date:   Fri May 13 12:39:39 2011 +1200

    move fonts to css

 gnome-sudoku/src/lib/number_box.py |   36 +++++++++++++-----------------------
 1 files changed, 13 insertions(+), 23 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/number_box.py b/gnome-sudoku/src/lib/number_box.py
index 1029a70..d0447b3 100644
--- a/gnome-sudoku/src/lib/number_box.py
+++ b/gnome-sudoku/src/lib/number_box.py
@@ -13,11 +13,6 @@ ERROR_HIGHLIGHT_COLOR = (1.0, 0, 0)
 
 BASE_SIZE = 35 # The "normal" size of a box (in pixels)
 
-# And the standard font-sizes -- these should fit nicely with the
-# BASE_SIZE
-BASE_FONT_SIZE = Pango.SCALE * 13
-NOTE_FONT_SIZE = Pango.SCALE * 6
-
 BORDER_WIDTH = 9.0 # The size of space we leave for a box
 NORMAL_LINE_WIDTH = 1 # The size of the line we draw around a box
 
@@ -85,6 +80,8 @@ class NumberBox (Gtk.DrawingArea):
     shadow_color = None
     border_color = None
 
+    NOTE_STYLE_CLASS = Gtk.STYLE_CLASS_ENTRY
+
     __gtype_name__ = 'NumberBox'
     __gsignals__ = {
         'value-about-to-change':(GObject.SignalFlags.RUN_LAST, None, ()),
@@ -130,10 +127,14 @@ class NumberBox (Gtk.DrawingArea):
         p.load_from_data("""
 NumberBox {
     background-color: rgb(255, 0, 0);
+    color: rgb(0, 0, 255);
+    font: monospace 13;
 }
 
 NumberBox.entry {
     background-color: rgb(0, 255, 0);
+    color: rgb(0, 127, 127);
+    font: monospace 5;
 }
 """, -1)
         style_ctx.add_provider(p, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
@@ -507,19 +508,13 @@ NumberBox.entry {
 
         print self.get_state_flags()
 
-        #CSS should be NumberBox {}
-        #use .entry class for the hints
-        #use :prelight etc for colors
-
-        print self.class_path()
-        print self.path()
-
         Gtk.render_background(style_ctx, cr, 0, 0, w, h)
 
         if self.is_focus():
             Gtk.render_focus(style_ctx, cr, 0, 0, w, h)
 
         if self.border_color is not None:
+            assert False
             print "border"
             border_width = 3.0
             cr.set_source_rgb(*self.border_color)
@@ -539,7 +534,7 @@ NumberBox.entry {
 
     def draw_note_area_highlight_box (self, cr, style_ctx):
         style_ctx.save()
-        style_ctx.add_class(Gtk.STYLE_CLASS_ENTRY)    
+        style_ctx.add_class(self.NOTE_STYLE_CLASS)
         # top rectangle
         #Gtk.render_focus(style_ctx, cr,
         #            NORMAL_LINE_WIDTH*0.5,
@@ -565,18 +560,17 @@ NumberBox.entry {
         style_ctx.restore()
 
     def draw_text (self, cr, style_ctx):
-        font = style_ctx.get_font(self.get_state_flags())
-        font.set_size(BASE_FONT_SIZE)
-        self._layout.set_font_description(font)
         fontw, fonth = self._layout.get_pixel_size()
         # Draw a shadow for tracked conflicts.  This is done to
         # differentiate between tracked and untracked conflicts.
         if self.shadow_color:
+            assert False
             cr.set_source_rgb(*self.shadow_color)
             for xoff, yoff in [(1,1),(2,2)]:
                 cr.move_to((BASE_SIZE/2)-(fontw/2) + xoff, (BASE_SIZE/2) - (fonth/2) + yoff)
                 PangoCairo.show_layout(cr, self._layout)
         if self.text_color:
+            assert False
             cr.set_source_rgb(*self.text_color)
 
         # And draw the text in the middle of the allocated space
@@ -586,25 +580,21 @@ NumberBox.entry {
                 (BASE_SIZE/2) - (fonth/2),
                 self._layout)
 
-        # And draw any note text...
-        if self._top_note_layout or self._bottom_note_layout:
-            note_font = font.copy()
-            note_font.set_size(NOTE_FONT_SIZE)
-
+        style_ctx.save()
+        style_ctx.add_class(self.NOTE_STYLE_CLASS)
         if self._top_note_layout:
-            self._top_note_layout.set_font_description(note_font)
             fontw, fonth = self._top_note_layout.get_pixel_size()
             Gtk.render_layout(style_ctx, cr,
                 NORMAL_LINE_WIDTH,
                 0,
                 self._top_note_layout)
         if self._bottom_note_layout:
-            self._bottom_note_layout.set_font_description(note_font)
             fontw, fonth = self._bottom_note_layout.get_pixel_size()
             Gtk.render_layout(style_ctx, cr,
                 NORMAL_LINE_WIDTH,
                 BASE_SIZE-fonth,
                 self._bottom_note_layout)
+        style_ctx.restore()
 
     def set_text_color (self, color, shadow = None):
         self.shadow_color = shadow



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