[four-in-a-row] Clean method a bit.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row] Clean method a bit.
- Date: Sat, 21 Dec 2019 16:37:06 +0000 (UTC)
commit 0435cce03ed961084b6e4756b1f20efd5c852fc8
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Dec 21 11:09:49 2019 +0100
Clean method a bit.
src/game-board-view.vala | 85 +++++++++++++++++++++---------------------------
1 file changed, 37 insertions(+), 48 deletions(-)
---
diff --git a/src/game-board-view.vala b/src/game-board-view.vala
index b5c9b78..b68e9f1 100644
--- a/src/game-board-view.vala
+++ b/src/game-board-view.vala
@@ -177,56 +177,45 @@ private class GameBoardView : Gtk.DrawingArea {
pb_bground = (!) pb_bground_tmp;
}
- private void load_pixmaps() {
- string fname;
- Gdk.Pixbuf pb_tileset_tmp;
- Gdk.Pixbuf? pb_bground_tmp = null;
-
- fname = "/org/gnome/Four-in-a-row/images/" + theme[Prefs.instance.theme_id].fname_tileset;
- try {
- pb_tileset_tmp = new Gdk.Pixbuf.from_resource(fname);
- } catch (Error e) {
- critical(e.message);
- assert_not_reached ();
- }
-
- pb_tileset_raw = pb_tileset_tmp;
+ private void load_pixmaps ()
+ {
+ load_image (theme [Prefs.instance.theme_id].fname_tileset, out pb_tileset_raw);
- if (theme[Prefs.instance.theme_id].fname_bground != null) {
- fname = "/org/gnome/Four-in-a-row/images/" + ((!) theme[Prefs.instance.theme_id].fname_bground);
- try {
- pb_bground_tmp = new Gdk.Pixbuf.from_resource(fname);
- } catch (Error e) {
- critical(e.message);
- assert_not_reached ();
- }
+ if (theme [Prefs.instance.theme_id].fname_bground != null)
+ load_image ((!) theme [Prefs.instance.theme_id].fname_bground, out pb_bground_raw);
+ else
+ create_background ();
+ }
+ private static void load_image (string image_name, out Gdk.Pixbuf pixbuf)
+ {
+ string image_resource = "/org/gnome/Four-in-a-row/images/" + image_name;
+ try
+ {
+ pixbuf = new Gdk.Pixbuf.from_resource (image_resource);
}
-
- /* If a separate background image wasn't supplied,
- * derive the background image from the tile set
- */
- if (pb_bground_tmp != null) {
- pb_bground_raw = (!) pb_bground_tmp;
- } else {
- int raw_tile_size;
- int i, j;
-
- raw_tile_size = pb_tileset_raw.get_height();
-
- pb_bground_raw = new Gdk.Pixbuf(Gdk.Colorspace.RGB, true, 8,
- raw_tile_size * 7, raw_tile_size * 7);
- for (i = 0; i < 7; i++) {
- pb_tileset_raw.copy_area(raw_tile_size * 3, 0,
- raw_tile_size, raw_tile_size,
- pb_bground_raw, i * raw_tile_size, 0);
- for (j = 1; j < 7; j++) {
- pb_tileset_raw.copy_area(
- raw_tile_size * 2, 0,
- raw_tile_size, raw_tile_size,
- pb_bground_raw,
- i * raw_tile_size, j * raw_tile_size);
- }
- }
+ catch (Error e)
+ {
+ critical (e.message);
+ assert_not_reached ();
+ }
+ }
+ private inline void create_background ()
+ {
+ int raw_tile_size = pb_tileset_raw.get_height ();
+
+ pb_bground_raw = new Gdk.Pixbuf (Gdk.Colorspace.RGB, /* alpha */ true, /* bits per sample */ 8,
raw_tile_size * 7, raw_tile_size * 7);
+ for (int i = 0; i < 7; i++)
+ {
+ pb_tileset_raw.copy_area (raw_tile_size * 3, 0,
+ raw_tile_size, raw_tile_size,
+ pb_bground_raw,
+ i * raw_tile_size, 0);
+
+ for (int j = 1; j < 7; j++)
+ pb_tileset_raw.copy_area (raw_tile_size * 2, 0,
+ raw_tile_size, raw_tile_size,
+ pb_bground_raw,
+ i * raw_tile_size, j * raw_tile_size);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]