[gnome-klotski] Use cairo instead of pixbuf to render svg



commit 3d535781227f6a078c67eefbbe6a8b51e97d5bf1
Author: John Cheetham <developer johncheetham com>
Date:   Thu Nov 15 20:14:38 2012 +0000

    Use cairo instead of pixbuf to render svg
    
    This has got rid of the deprecation warnings

 src/puzzle-view.vala |   46 +++++++++++++++++++++++-----------------------
 1 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index c720d35..e861cea 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -7,10 +7,7 @@ public class PuzzleView : Gtk.DrawingArea
     private const int THEME_TILE_CENTER = 14;
     private const int THEME_TILE_SIZE = 34;
 
-    private int render_size = 0;
-
-    private Gdk.Pixbuf tiles_pixbuf = null;
-    private Gdk.Pixbuf tiles_image = null;
+    private int render_size = 0;    
 
     private int piece_x = 0;
     private int piece_y = 0;
@@ -21,7 +18,9 @@ public class PuzzleView : Gtk.DrawingArea
     private double kx = 0;
     private double ky = 0;
 
+    private Rsvg.Handle tiles_handle = null;
     private string image_filepath = "";
+    private Cairo.Surface surface = null;
 
     private Puzzle? _puzzle = null;
     public Puzzle? puzzle
@@ -63,8 +62,8 @@ public class PuzzleView : Gtk.DrawingArea
         image_filepath = Path.build_filename (DATA_DIRECTORY, "gnome-klotski.svg", null);
 
         try
-        {
-            tiles_image = Rsvg.pixbuf_from_file (image_filepath);
+        {            
+            tiles_handle = new Rsvg.Handle.from_file (image_filepath);           
         }
         catch (Error e)
         {
@@ -85,25 +84,26 @@ public class PuzzleView : Gtk.DrawingArea
     {
 
         if (tile_size != render_size)
-        {
-            render_size = tile_size;
+        {          
 
-            tiles_pixbuf = null;
-
-            if (tiles_image != null)
+            if (tiles_handle != null)
             {                
                 int height = tile_size * 2;
                 int width = tile_size * THEME_TILE_SEGMENTS;
 
-                try
-                { 
-                    tiles_pixbuf = Rsvg.pixbuf_from_file_at_size (image_filepath, width, height);
-                }
-                catch (Error e)
-                {
-                    stderr.printf ("%s %s\n", "Error in puzzle-view.vala draw function:", e.message);
-                }
+                surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, width, height); 
+                var c = new Cairo.Context (surface);
+
+                /* calc scale factor */
+                double sfw = (double) width / 918;
+                double sfh = (double) height / 68; 
+               
+                c.scale (sfw, sfh);
+
+                tiles_handle.render_cairo (c);
+
             }
+            render_size = tile_size;
 
         }
 
@@ -153,8 +153,8 @@ public class PuzzleView : Gtk.DrawingArea
 
         if (puzzle.get_piece_id (puzzle.map, x, y) != ' ')
         {
-            Gdk.cairo_rectangle (cr, rect);
-            Gdk.cairo_set_source_pixbuf (cr, tiles_pixbuf, rect.x - puzzle.get_piece_nr (x, y) * tile_size, rect.y - tile_size / 2);
+            Gdk.cairo_rectangle (cr, rect);            
+            cr.set_source_surface (surface, rect.x - puzzle.get_piece_nr (x, y) * tile_size, rect.y - tile_size / 2);
             cr.fill ();
         }
 
@@ -169,8 +169,8 @@ public class PuzzleView : Gtk.DrawingArea
 
             cr.rectangle (rect.x + overlay_offset, rect.y + overlay_offset,
                           overlay_size, overlay_size);
-
-            Gdk.cairo_set_source_pixbuf (cr, tiles_pixbuf, rect.x - value * tile_size, rect.y - tile_size / 2);
+            
+            cr.set_source_surface (surface, rect.x - value * tile_size, rect.y - tile_size / 2);
             cr.fill ();
         }
     }



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