[gnome-klotski] Use construct more.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-klotski] Use construct more.
- Date: Sat, 8 Feb 2020 20:48:47 +0000 (UTC)
commit 5e88f1677a2fd82fcac2624edadcce43c5b6b1f6
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Feb 8 20:58:24 2020 +0100
Use construct more.
src/klotski-window.vala | 2 +-
src/puzzle-view.vala | 15 ++++++++-------
src/puzzle.vala | 33 +++++++++++++++++----------------
3 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/src/klotski-window.vala b/src/klotski-window.vala
index 035692d..16673c3 100644
--- a/src/klotski-window.vala
+++ b/src/klotski-window.vala
@@ -513,7 +513,7 @@ private class KlotskiWindow : ApplicationWindow
category = score_categories[level];
}
- internal KlotskiWindow ()
+ construct
{
CssProvider css_provider = new CssProvider ();
css_provider.load_from_resource ("/org/gnome/Klotski/ui/klotski.css");
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index fd9e004..9fe5505 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -71,6 +71,14 @@ private class PuzzleView : Gtk.DrawingArea
construct
{
style_context = get_style_context ();
+
+ set_size_request (250, 250); // probably too small, but window requests 600x400 anyway
+ set_events (Gdk.EventMask.EXPOSURE_MASK |
+ Gdk.EventMask.BUTTON_PRESS_MASK |
+ Gdk.EventMask.POINTER_MOTION_MASK |
+ Gdk.EventMask.BUTTON_RELEASE_MASK );
+
+ load_image ();
}
private int tile_size
@@ -85,13 +93,6 @@ private class PuzzleView : Gtk.DrawingArea
}
}
- internal PuzzleView ()
- {
- set_size_request (250, 250); // TODO enough? Taquin is in 350^2
- set_events (Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK);
- load_image ();
- }
-
private void load_image ()
{
image_file = File.new_for_uri("resource:///org/gnome/Klotski/ui/assets.svg");
diff --git a/src/puzzle.vala b/src/puzzle.vala
index a57b11b..5077394 100644
--- a/src/puzzle.vala
+++ b/src/puzzle.vala
@@ -102,13 +102,14 @@ private class Puzzle : Object
-1, -1
};
- [CCode (notify = false)] internal uint8 width { internal get; private set; }
- [CCode (notify = false)] internal uint8 height { internal get; private set; }
+ [CCode (notify = false)] public uint8 width { internal get; protected construct; }
+ [CCode (notify = false)] public uint8 height { internal get; protected construct; }
+ [CCode (notify = false)] public string initial_map { private get; protected construct; }
// Type `char []' can not be used for a GLib.Object property
internal char [] map;
internal char [] move_map;
- internal char [] orig_map;
+ internal char [] orig_map; // TODO unduplicate with initial_map
internal char [] lastmove_map;
internal char [] undomove_map;
@@ -117,25 +118,25 @@ private class Puzzle : Object
internal signal void changed ();
internal signal void moved ();
- internal Puzzle (uint8 width, uint8 height, string? data)
+ internal Puzzle (uint8 width, uint8 height, string initial_map)
+ {
+ Object (width: width, height: height, initial_map: initial_map);
+ }
+
+ construct
{
- this.width = width;
- this.height = height;
map = new char[(width + 2) * (height + 2)];
move_map = map;
undomove_map = map;
- if (data != null)
- {
- uint16 i = 0;
- for (uint8 y = 0; y < height; y++)
+
+ uint16 i = 0;
+ for (uint8 y = 0; y < height; y++)
+ for (uint8 x = 0; x < width; x++)
{
- for (uint8 x = 0; x < width; x++)
- {
- set_piece_id (map, x, y, data [i]);
- i++;
- }
+ set_piece_id (map, x, y, initial_map [i]);
+ i++;
}
- }
+
orig_map = map;
lastmove_map = map;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]