[gnome-mines] Adds a number border option to increase number visibility.



commit 1cbaffcac1df1dda4420eca6d63050ad8ae51888
Author: Isaac Lenton <isaac isuniversal com>
Date:   Fri Feb 15 12:15:02 2013 +1000

    Adds a number border option to increase number visibility.

 data/org.gnome.mines.gschema.xml.in |    5 +++++
 src/gnome-mines.vala                |   15 +++++++++++++++
 src/minefield-view.vala             |   32 ++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.mines.gschema.xml.in b/data/org.gnome.mines.gschema.xml.in
index 201315e..379e520 100644
--- a/data/org.gnome.mines.gschema.xml.in
+++ b/data/org.gnome.mines.gschema.xml.in
@@ -10,6 +10,11 @@
       <_summary>Warning about too many flags</_summary>
       <_description>Set to true to enable warning icons when too many flags are placed.</_description>
     </key>
+    <key name="use-number-border" type="b">
+      <default>false</default>
+      <_summary>Display border around numbers</_summary>
+      <_description>Set to true to display a border around mine indication numbers.</_description>
+    </key>
     <key type="b" name="use-newgame-confirm">
       <default>false</default>
       <summary>Confirm before a new game</summary>
diff --git a/src/gnome-mines.vala b/src/gnome-mines.vala
index 62bd462..e7895d8 100644
--- a/src/gnome-mines.vala
+++ b/src/gnome-mines.vala
@@ -23,6 +23,7 @@ public class Mines : Gtk.Application
     private const string KEY_USE_QUESTION_MARKS = "use-question-marks";
     private const string KEY_USE_OVERMINE_WARNING = "use-overmine-warning";
     private const string KEY_USE_AUTOFLAG = "use-autoflag";
+    private const string KEY_USE_NUMBER_BORDER = "use-number-border";
 
     /* Faces for new game button */
     private Gtk.ToolButton face_button;
@@ -225,6 +226,7 @@ public class Mines : Gtk.Application
         minefield_view.set_use_question_marks (settings.get_boolean (KEY_USE_QUESTION_MARKS));
         minefield_view.set_use_overmine_warning (settings.get_boolean (KEY_USE_OVERMINE_WARNING));
         minefield_view.set_use_autoflag (settings.get_boolean (KEY_USE_AUTOFLAG));
+        minefield_view.set_use_number_border (settings.get_boolean (KEY_USE_NUMBER_BORDER));
         minefield_view.button_press_event.connect (view_button_press_event);
         minefield_view.look.connect (look_cb);
         minefield_view.unlook.connect (unlook_cb);
@@ -805,6 +807,13 @@ public class Mines : Gtk.Application
         minefield_view.set_use_overmine_warning (use_overmine_warning);
     }
 
+    private void use_number_border_toggle_cb (Gtk.ToggleButton button)
+    {
+        var use_number_border = button.get_active ();
+        settings.set_boolean (KEY_USE_NUMBER_BORDER, use_number_border);
+        minefield_view.set_use_number_border (use_number_border);
+    }
+
     private Gtk.Dialog create_preferences ()
     {
         var dialog = new Gtk.Dialog.with_buttons (_("Mines Preferences"),
@@ -837,6 +846,12 @@ public class Mines : Gtk.Application
         overmine_toggle.set_active (settings.get_boolean (KEY_USE_OVERMINE_WARNING));
         grid.attach (overmine_toggle, 0, 1, 1, 1);
 
+        var border_toggle = new Gtk.CheckButton.with_mnemonic (_("_Display numbers with border"));
+        border_toggle.show ();
+        border_toggle.toggled.connect (use_number_border_toggle_cb);
+        border_toggle.set_active (settings.get_boolean (KEY_USE_NUMBER_BORDER));
+        grid.attach (border_toggle, 0, 2, 1, 1);
+
         return dialog;
     }
     
diff --git a/src/minefield-view.vala b/src/minefield-view.vala
index 6d15a56..e21c19a 100644
--- a/src/minefield-view.vala
+++ b/src/minefield-view.vala
@@ -105,6 +105,9 @@ public class MinefieldView : Gtk.DrawingArea
     private Position keyboard_cursor;
     private Position selected;
 
+    /* true if numbers should be drawn with border */
+    private bool use_number_border;
+
     /* Pre-rendered images */
     private uint render_size = 0;
     private Cairo.Pattern? flag_pattern;
@@ -211,6 +214,14 @@ public class MinefieldView : Gtk.DrawingArea
         this.use_autoflag = use_autoflag;
     }
 
+    public void set_use_number_border (bool use_number_border)
+    {
+        if (this.use_number_border != use_number_border)
+            render_size = 0;
+
+        this.use_number_border = use_number_border;
+    }
+
     private void explode_cb (Minefield minefield)
     {
         /* Show the mines that we missed or the flags that were wrong */
@@ -252,32 +263,41 @@ public class MinefieldView : Gtk.DrawingArea
 
         /* Color */
         Pango.Attribute color_attribute;
+        double color_outline[3];
         switch (n)
         {
         case 1:
             color_attribute = Pango.attr_foreground_new (0x0000, 0x0000, 0xffff); /* Blue */
+            color_outline = {0.0, 0.0, 0.5};
             break;
         case 2:
             color_attribute = Pango.attr_foreground_new (0x0000, 0xa0a0, 0x0000); /* Green */
+            color_outline = {0.0, 0.5*0.62745098039, 0.0};
             break;
         case 3:
             color_attribute = Pango.attr_foreground_new (0xffff, 0x0000, 0x0000); /* Red */
+            color_outline = {0.5, 0.0, 0.0};
             break;
         case 4:
             color_attribute = Pango.attr_foreground_new (0x0000, 0x0000, 0x7fff); /* Dark Blue */
+            color_outline = {0.0, 0.0, 0.5*0.49999237048};
             break;
         case 5:
             color_attribute = Pango.attr_foreground_new (0xa0a0, 0x0000, 0x0000); /* Dark Red */
+            color_outline = {0.5*0.62745098039, 0.0, 0.0};
             break;
         case 6:
             color_attribute = Pango.attr_foreground_new (0x0000, 0xffff, 0xffff); /* Cyan */
+            color_outline = {0.0, 0.5, 0.5};
             break;
         case 7:
             color_attribute = Pango.attr_foreground_new (0xa0a0, 0x0000, 0xa0a0); /* Dark Violet */
+            color_outline = {0.5*0.62745098039, 0.0, 0.5*0.62745098039};
             break;
         default:
         case 8:
             color_attribute = Pango.attr_foreground_new (0x0000, 0x0000, 0x0000); /* Black */
+            color_outline = {0.0, 0.0, 0.0};
             break;
         }
         color_attribute.start_index = 0;
@@ -305,6 +325,18 @@ public class MinefieldView : Gtk.DrawingArea
         c.move_to (dx, dy);
         Pango.cairo_show_layout (c, layout);
 
+        if (use_number_border)
+        {
+            c.save ();
+            c.set_line_width(1.0);
+            c.set_source_rgb(color_outline[0],
+                             color_outline[1],
+                             color_outline[2]);
+            Pango.cairo_layout_path(c, layout);
+            c.stroke_preserve();
+            c.restore ();
+        }
+
         var pattern = new Cairo.Pattern.for_surface (surface);
         pattern.set_extend (Cairo.Extend.REPEAT);
         return pattern;


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