[gnome-games] gnomine: Stop using GamesPreimage



commit 1f20a8c3f1d1b0c1e46a1d4bb6e23c167c106ab6
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Aug 21 15:07:13 2012 +1200

    gnomine: Stop using GamesPreimage

 gnomine/src/Makefile.am         |    1 +
 gnomine/src/minefield-view.vala |   40 +++++++++++---------------------------
 2 files changed, 13 insertions(+), 28 deletions(-)
---
diff --git a/gnomine/src/Makefile.am b/gnomine/src/Makefile.am
index b09bc7d..ad96f54 100644
--- a/gnomine/src/Makefile.am
+++ b/gnomine/src/Makefile.am
@@ -18,6 +18,7 @@ gnomine_CFLAGS = \
 gnomine_VALAFLAGS = \
 	--pkg posix \
 	--pkg gtk+-3.0 \
+	--pkg librsvg-2.0 \
 	--pkg pango \
 	--pkg pangocairo \
 	--vapidir $(top_srcdir)/libgames-support \
diff --git a/gnomine/src/minefield-view.vala b/gnomine/src/minefield-view.vala
index b530ae3..5334756 100644
--- a/gnomine/src/minefield-view.vala
+++ b/gnomine/src/minefield-view.vala
@@ -13,13 +13,6 @@ public class MinefieldView : Gtk.DrawingArea
     private int selected_x = -1;
     private int selected_y = -1;
 
-    /* Images for flags and mines */
-    private GnomeGamesSupport.Preimage flag_preimage;
-    private GnomeGamesSupport.Preimage mine_preimage;
-    private GnomeGamesSupport.Preimage question_preimage;
-    private GnomeGamesSupport.Preimage bang_preimage;
-    private GnomeGamesSupport.Preimage warning_preimage;
-
     /* Pre-rendered images */
     private uint render_size = 0;
     private Cairo.Pattern? flag_pattern;
@@ -72,12 +65,6 @@ public class MinefieldView : Gtk.DrawingArea
     public MinefieldView ()
     {
         set_events (Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK);
-
-        flag_preimage = load_preimage (Path.build_filename (DATA_DIRECTORY, "flag.svg"));
-        mine_preimage = load_preimage (Path.build_filename (DATA_DIRECTORY, "mine.svg"));
-        question_preimage = load_preimage (Path.build_filename (DATA_DIRECTORY, "flag-question.svg"));
-        bang_preimage = load_preimage (Path.build_filename (DATA_DIRECTORY, "bang.svg"));
-        warning_preimage = load_preimage (Path.build_filename (DATA_DIRECTORY, "warning.svg"));
         number_patterns = new Cairo.Pattern[8];
     }
     
@@ -124,23 +111,20 @@ public class MinefieldView : Gtk.DrawingArea
                     redraw_sector_cb (x, y);
     }
 
-    private GnomeGamesSupport.Preimage? load_preimage (string filename)
+    private Cairo.Pattern render_svg_pattern (Cairo.Context cr, string filename)
     {
+        var surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) mine_size, (int) mine_size); 
+        var c = new Cairo.Context (surface);
+        Gdk.Pixbuf pixbuf;
+        var size = (int) mine_size - 2;
         try
         {
-            return new GnomeGamesSupport.Preimage.from_file (filename);
+            pixbuf = Rsvg.pixbuf_from_file_at_size (filename, size, size);
         }
         catch (Error e)
         {
-            return null;
+            pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.RGB, true, 8, size, size);
         }
-    }
-
-    private Cairo.Pattern render_preimage_pattern (Cairo.Context cr, GnomeGamesSupport.Preimage preimage)
-    {
-        var surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) mine_size, (int) mine_size); 
-        var c = new Cairo.Context (surface);
-        var pixbuf = preimage.render ((int) mine_size - 2, (int) mine_size - 2);
         Gdk.cairo_set_source_pixbuf (c, pixbuf, 1, 1);
         c.paint ();
 
@@ -285,7 +269,7 @@ public class MinefieldView : Gtk.DrawingArea
             if (minefield.has_mine (x, y))
             {
                 if (bang_pattern == null)
-                    bang_pattern = render_preimage_pattern (cr, bang_preimage);
+                    bang_pattern = render_svg_pattern (cr, Path.build_filename (DATA_DIRECTORY, "bang.svg"));
                 cr.set_source (bang_pattern);
                 cr.rectangle (0, 0, mine_size, mine_size);
                 cr.fill ();
@@ -297,7 +281,7 @@ public class MinefieldView : Gtk.DrawingArea
                 if (use_overmine_warning && minefield.has_flag_warning (x, y))
                 {
                     if (warning_pattern == null)
-                        warning_pattern = render_preimage_pattern (cr, warning_preimage);
+                        warning_pattern = render_svg_pattern (cr, Path.build_filename (DATA_DIRECTORY, "warning.svg"));
                     cr.set_source (warning_pattern);
                     cr.rectangle (0, 0, mine_size, mine_size);
                     cr.fill ();
@@ -330,7 +314,7 @@ public class MinefieldView : Gtk.DrawingArea
             if (minefield.get_flag (x, y) == FlagType.FLAG)
             {
                 if (flag_pattern == null)
-                    flag_pattern = render_preimage_pattern (cr, flag_preimage);                    
+                    flag_pattern = render_svg_pattern (cr, Path.build_filename (DATA_DIRECTORY, "flag.svg"));                    
                 cr.set_source (flag_pattern);
                 cr.rectangle (0, 0, mine_size, mine_size);
                 cr.fill ();
@@ -360,7 +344,7 @@ public class MinefieldView : Gtk.DrawingArea
             else if (minefield.exploded && minefield.has_mine (x, y))
             {
                 if (mine_pattern == null)
-                    mine_pattern = render_preimage_pattern (cr, mine_preimage);
+                    mine_pattern = render_svg_pattern (cr, Path.build_filename (DATA_DIRECTORY, "mine.svg"));
                 cr.set_source (mine_pattern);
                 cr.rectangle (0, 0, mine_size, mine_size);
                 cr.fill ();
@@ -368,7 +352,7 @@ public class MinefieldView : Gtk.DrawingArea
             else if (minefield.get_flag (x, y) == FlagType.MAYBE)
             {
                 if (question_pattern == null)
-                    question_pattern = render_preimage_pattern (cr, question_preimage);
+                    question_pattern = render_svg_pattern (cr, Path.build_filename (DATA_DIRECTORY, "flag-question.svg"));
                 cr.set_source (question_pattern);
                 cr.rectangle (0, 0, mine_size, mine_size);
                 cr.fill ();



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