[gnome-games] gnome-mahjongg: Stop using GamesPreimage
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] gnome-mahjongg: Stop using GamesPreimage
- Date: Tue, 21 Aug 2012 04:47:16 +0000 (UTC)
commit 41c52c0ef536dd27c02e039b39e0ed54a37518a4
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Aug 21 15:17:21 2012 +1200
gnome-mahjongg: Stop using GamesPreimage
gnome-mahjongg/src/Makefile.am | 1 +
gnome-mahjongg/src/game-view.vala | 49 +++++++++++++++++++++++++++++--
gnome-mahjongg/src/gnome-mahjongg.vala | 21 +-------------
3 files changed, 47 insertions(+), 24 deletions(-)
---
diff --git a/gnome-mahjongg/src/Makefile.am b/gnome-mahjongg/src/Makefile.am
index cbaa1b2..682abad 100644
--- a/gnome-mahjongg/src/Makefile.am
+++ b/gnome-mahjongg/src/Makefile.am
@@ -11,6 +11,7 @@ gnome_mahjongg_SOURCES = \
gnome_mahjongg_VALAFLAGS = \
--pkg posix \
--pkg gtk+-3.0 \
+ --pkg librsvg-2.0 \
--vapidir $(top_srcdir)/libgames-support \
--pkg GnomeGamesSupport-1.0
diff --git a/gnome-mahjongg/src/game-view.vala b/gnome-mahjongg/src/game-view.vala
index dac4322..ae20f07 100644
--- a/gnome-mahjongg/src/game-view.vala
+++ b/gnome-mahjongg/src/game-view.vala
@@ -25,8 +25,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; tile_pattern = null; queue_draw (); }
@@ -68,7 +68,7 @@ public class GameView : Gtk.DrawingArea
var surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, width, height);
var c = new Cairo.Context (surface);
- var pixbuf = theme.render (width, height);
+ var pixbuf = load_theme (width, height);
if (pixbuf == null)
return;
Gdk.cairo_set_source_pixbuf (c, pixbuf, 0, 0);
@@ -133,6 +133,27 @@ public class GameView : Gtk.DrawingArea
}
}
+ private Gdk.Pixbuf load_theme (int width, int height)
+ {
+ 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);
+ }
+
private void update_dimensions ()
{
var width = get_allocated_width ();
@@ -141,8 +162,12 @@ public class GameView : Gtk.DrawingArea
if (theme == null)
return;
+ int theme_width, theme_height;
+ if (!get_theme_dimensions (out theme_width, out theme_height))
+ return;
+
/* Get aspect ratio from theme - contains 43x2 tiles */
- var aspect = ((double) theme.get_height () / 2) / ((double) theme.get_width () / 43);
+ var aspect = ((double) theme_height / 2) / ((double) theme_width / 43);
/* Need enough space for the whole map and one unit border */
var map_width = game.map.width + 2.0;
@@ -164,6 +189,22 @@ public class GameView : Gtk.DrawingArea
x_offset = (int) (width - game.map.width * unit_width) / 2;
y_offset = (int) (height - game.map.height * unit_height) / 2;
}
+
+ private bool get_theme_dimensions (out int width, out int height)
+ {
+ try
+ {
+ var svg = new Rsvg.Handle.from_file (theme);
+ width = svg.width;
+ height = svg.height;
+ return true;
+ }
+ catch (Error e)
+ {
+ Gdk.Pixbuf.get_file_info (theme, out width, out height);
+ return true;
+ }
+ }
private void get_tile_position (Tile tile, out int x, out int y)
{
diff --git a/gnome-mahjongg/src/gnome-mahjongg.vala b/gnome-mahjongg/src/gnome-mahjongg.vala
index b6a02d2..6b6bd53 100644
--- a/gnome-mahjongg/src/gnome-mahjongg.vala
+++ b/gnome-mahjongg/src/gnome-mahjongg.vala
@@ -164,12 +164,7 @@ public class Mahjongg : Gtk.Application
if (key == "tileset")
{
var theme = settings.get_string ("tileset");
- game_view.theme = load_theme_texture (theme);
- if (game_view.theme == null)
- {
- warning ("Unable to load theme %s, falling back to default", theme);
- game_view.theme = load_theme_texture ("postmodern.svg", true);
- }
+ game_view.theme = Path.build_filename (DATA_DIRECTORY, "themes", theme);
}
else if (key == "bgcolour")
{
@@ -200,20 +195,6 @@ public class Mahjongg : Gtk.Application
}
}
- 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 bool view_button_press_event (Gtk.Widget widget, Gdk.EventButton event)
{
/* Cancel pause on click */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]