[gnome-games] iagno: Stop using GamesPreimage
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] iagno: Stop using GamesPreimage
- Date: Tue, 21 Aug 2012 04:47:06 +0000 (UTC)
commit c20ba508d6d835ba395bfc84e7c4d24ff52c287f
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Aug 21 15:02:13 2012 +1200
iagno: Stop using GamesPreimage
iagno/src/Makefile.am | 1 +
iagno/src/game-view.vala | 30 +++++++++++++++++++++++++++---
iagno/src/iagno.vala | 30 ++----------------------------
3 files changed, 30 insertions(+), 31 deletions(-)
---
diff --git a/iagno/src/Makefile.am b/iagno/src/Makefile.am
index 689e98d..3034151 100644
--- a/iagno/src/Makefile.am
+++ b/iagno/src/Makefile.am
@@ -21,6 +21,7 @@ iagno_CFLAGS = \
iagno_VALAFLAGS = \
--pkg posix \
--pkg gtk+-3.0 \
+ --pkg librsvg-2.0 \
--pkg libcanberra \
--pkg libcanberra-gtk \
--vapidir $(top_srcdir)/libgames-support \
diff --git a/iagno/src/game-view.vala b/iagno/src/game-view.vala
index 9d45537..9bbb0e6 100644
--- a/iagno/src/game-view.vala
+++ b/iagno/src/game-view.vala
@@ -70,8 +70,8 @@ public class GameView : Gtk.DrawingArea
}
}
- private GnomeGamesSupport.Preimage? _theme = null;
- public GnomeGamesSupport.Preimage? theme
+ private string? _theme = null;
+ public string? theme
{
get { return _theme; }
set { _theme = value; tiles_pattern = null; queue_draw (); }
@@ -119,7 +119,7 @@ public class GameView : Gtk.DrawingArea
render_size = tile_size;
var surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, tile_size * 8, tile_size * 4);
var c = new Cairo.Context (surface);
- var pixbuf = theme.render (tile_size * 8, tile_size * 4);
+ var pixbuf = load_theme ();
Gdk.cairo_set_source_pixbuf (c, pixbuf, 0, 0);
c.paint ();
@@ -173,6 +173,30 @@ public class GameView : Gtk.DrawingArea
return false;
}
+ private Gdk.Pixbuf load_theme ()
+ {
+ var width = tile_size * 8;
+ var height = tile_size * 4;
+
+ try
+ {
+ return Rsvg.pixbuf_from_file_at_size (theme, width, height);
+ }
+ catch (Error e)
+ {
+ }
+
+ try
+ {
+ return new Gdk.Pixbuf.from_file_at_scale (theme, width, height, false);
+ }
+ catch (Error e)
+ {
+ }
+
+ return new Gdk.Pixbuf (Gdk.Colorspace.RGB, true, 8, width, height);
+ }
+
public void redraw ()
{
queue_draw ();
diff --git a/iagno/src/iagno.vala b/iagno/src/iagno.vala
index e914810..a2def8e 100644
--- a/iagno/src/iagno.vala
+++ b/iagno/src/iagno.vala
@@ -91,13 +91,7 @@ public class Iagno : Gtk.Application
view.show_grid = settings.get_boolean ("show-grid");
view.flip_final_result = settings.get_boolean ("flip-final-results");
var tile_set = settings.get_string ("tileset");
- var theme = load_theme_texture (tile_set);
- if (theme == null)
- {
- warning ("Unable to load theme %s, falling back to default", tile_set);
- theme = load_theme_texture ("black_and_white.svg", true);
- }
- view.theme = theme;
+ view.theme = Path.build_filename (DATA_DIRECTORY, "themes", tile_set);
view.show ();
top_grid.attach (view, 0, 3, 1, 1);
@@ -153,20 +147,6 @@ public class Iagno : Gtk.Application
window.show ();
}
- private GnomeGamesSupport.Preimage? load_theme_texture (string filename, bool fail_on_error = false)
- {
- var path = Path.build_filename (DATA_DIRECTORY, "themes", filename);
- try
- {
- return new GnomeGamesSupport.Preimage.from_file (path);
- }
- catch (Error e)
- {
- warning ("Failed to load theme %s: %s", filename, path);
- return null;
- }
- }
-
private void quit_cb ()
{
window.destroy ();
@@ -430,13 +410,7 @@ public class Iagno : Gtk.Application
string tile_set;
model.get (iter, 1, out tile_set);
settings.set_string ("tileset", tile_set);
-
- var theme = load_theme_texture (tile_set);
- if (theme == null)
- warning ("Unable to load theme %s", tile_set);
- else
- view.theme = theme;
-
+ view.theme = Path.build_filename (DATA_DIRECTORY, "themes", tile_set);
view.redraw ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]