[gnome-mahjongg/arnaudb/wip/gtk4: 27/27] Remove deprecated method.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mahjongg/arnaudb/wip/gtk4: 27/27] Remove deprecated method.
- Date: Sat, 25 Apr 2020 11:54:12 +0000 (UTC)
commit 1e9081ae90064340a1c1b5befec854a16af3c10e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Apr 25 13:51:26 2020 +0200
Remove deprecated method.
src/game-view.vala | 54 ++++++++++++++++++++++++++++++------------------------
1 file changed, 30 insertions(+), 24 deletions(-)
---
diff --git a/src/game-view.vala b/src/game-view.vala
index 1d37b57..dcf1b74 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -29,6 +29,9 @@ public class GameView : Gtk.DrawingArea
private Rsvg.Handle? theme_handle = null;
private Cairo.Pattern? tile_pattern = null;
+ private bool needs_resize = false;
+ private Gdk.Pixbuf? fallback_pixbuf = null;
+
private uint theme_resize_timer;
private uint theme_timer_id;
@@ -54,7 +57,6 @@ public class GameView : Gtk.DrawingArea
set {
_theme = value;
- Gdk.Pixbuf? pixbuf = null;
theme_handle = null;
tile_pattern = null;
@@ -65,11 +67,12 @@ public class GameView : Gtk.DrawingArea
theme_width = dimensions.width;
theme_height = dimensions.height;
+ fallback_pixbuf = null;
} catch (Error e) {
try {
- pixbuf = new Gdk.Pixbuf.from_file (theme);
- theme_width = pixbuf.get_width ();
- theme_height = pixbuf.get_height ();
+ fallback_pixbuf = new Gdk.Pixbuf.from_file (theme);
+ theme_width = ((!) fallback_pixbuf).get_width ();
+ theme_height = ((!) fallback_pixbuf).get_height ();
} catch (Error e) {
warning ("Could not load theme %s: %s", value, e.message);
}
@@ -78,15 +81,6 @@ public class GameView : Gtk.DrawingArea
theme_aspect = ((double) theme_height / 2) / ((double) theme_width / 43);
update_dimensions ();
- if (pixbuf != null) {
- var cr = Gdk.cairo_create (get_window ());
- var theme_surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA,
theme_width, theme_height);
- var ctx = new Cairo.Context (theme_surface);
- Gdk.cairo_set_source_pixbuf (ctx, pixbuf, 0, 0);
- ctx.paint();
- tile_pattern = new Cairo.Pattern.for_surface (theme_surface);
- }
-
if (theme_handle != null) {
resize_theme ();
}
@@ -145,17 +139,7 @@ public class GameView : Gtk.DrawingArea
theme_height += theme_height;
}
- var cr = Gdk.cairo_create (get_window ());
- var theme_surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA,
theme_width, theme_height);
- var ctx = new Cairo.Context (theme_surface);
-
- try {
- theme_handle.render_document(ctx, {0,0,theme_width,theme_height});
- tile_pattern = new Cairo.Pattern.for_surface (theme_surface);
- queue_draw();
- } catch (Error e) {
- warning ("Could not upscale theme");
- }
+ needs_resize = true;
}
public void set_background (string? colour)
@@ -171,6 +155,28 @@ public class GameView : Gtk.DrawingArea
if (theme == null)
return;
+ if (fallback_pixbuf != null)
+ {
+ var theme_surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA,
theme_width, theme_height);
+ var ctx = new Cairo.Context (theme_surface);
+ Gdk.cairo_set_source_pixbuf (ctx, (!) fallback_pixbuf, 0.0, 0.0);
+ ctx.paint();
+ tile_pattern = new Cairo.Pattern.for_surface (theme_surface);
+ }
+ if (needs_resize)
+ {
+ var theme_surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA,
theme_width, theme_height);
+ var ctx = new Cairo.Context (theme_surface);
+
+ try {
+ theme_handle.render_document(ctx, {0,0,theme_width,theme_height});
+ tile_pattern = new Cairo.Pattern.for_surface (theme_surface);
+ } catch (Error e) {
+ warning ("Could not upscale theme");
+ }
+ needs_resize = false;
+ }
+
/* The images are bigger than the tile as they contain the isometric extension in the z-axis */
var image_width = tile_width + tile_layer_offset_x;
var image_height = tile_height + tile_layer_offset_y;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]