[gnome-tetravex] Use internal and protected.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tetravex] Use internal and protected.
- Date: Wed, 18 Sep 2019 00:45:46 +0000 (UTC)
commit ad532265b4aa80cf1029e89341f06cedef32da3b
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Sep 17 04:21:31 2019 +0200
Use internal and protected.
src/gnome-tetravex.vala | 32 ++----
src/history.vala | 73 ++++++------
src/puzzle-view.vala | 118 ++++++++++----------
src/puzzle.vala | 287 ++++++++++++++++++++++++------------------------
src/score-dialog.vala | 4 +-
src/theme.vala | 94 ++++++++--------
6 files changed, 294 insertions(+), 314 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index e98a925..dc5953d 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -53,10 +53,10 @@ private class Tetravex : Gtk.Application
{ "solve", solve_cb },
{ "scores", scores_cb },
{ "quit", quit },
- { "move-up", move_up_cb },
- { "move-down", move_down_cb },
- { "move-left", move_left_cb },
- { "move-right", move_right_cb },
+ { "move-up", move_up },
+ { "move-down", move_down },
+ { "move-left", move_left },
+ { "move-right", move_right },
{ "size", radio_cb, "s", "'2'", size_changed },
{ "help", help_cb },
{ "about", about_cb }
@@ -104,7 +104,6 @@ private class Tetravex : Gtk.Application
settings = new GLib.Settings ("org.gnome.Tetravex");
history = new History (Path.build_filename (Environment.get_user_data_dir (), "gnome-tetravex",
"history"));
- history.load ();
window = (ApplicationWindow) builder.get_object ("gnome-tetravex-window");
this.add_window (window);
@@ -466,25 +465,10 @@ private class Tetravex : Gtk.Application
new_game ();
}
- private void move_up_cb ()
- {
- puzzle.move_up ();
- }
-
- private void move_left_cb ()
- {
- puzzle.move_left ();
- }
-
- private void move_right_cb ()
- {
- puzzle.move_right ();
- }
-
- private void move_down_cb ()
- {
- puzzle.move_down ();
- }
+ private void move_up () { puzzle.move_up (); }
+ private void move_down () { puzzle.move_down (); }
+ private void move_left () { puzzle.move_left (); }
+ private void move_right () { puzzle.move_right (); }
private void pause_cb (SimpleAction action, Variant? parameter)
{
diff --git a/src/history.vala b/src/history.vala
index 51862f3..88f95d8 100644
--- a/src/history.vala
+++ b/src/history.vala
@@ -9,30 +9,28 @@
* license.
*/
-public class History : Object
+private class History : Object
{
- public string filename;
- public List<HistoryEntry> entries;
+ [CCode (notify = false)] public string filename { private get; protected construct; }
+ internal List<HistoryEntry> entries = new List<HistoryEntry> ();
- public signal void entry_added (HistoryEntry entry);
+ internal signal void entry_added (HistoryEntry entry);
- public History (string filename)
+ internal History (string filename)
{
- this.filename = filename;
- entries = new List<HistoryEntry> ();
+ Object (filename: filename);
+ load ();
}
- public void add (HistoryEntry entry)
+ internal void add (HistoryEntry entry)
{
entries.append (entry);
entry_added (entry);
}
- public void load ()
+ internal void load ()
{
- entries = new List<HistoryEntry> ();
-
- var contents = "";
+ string contents = "";
try
{
FileUtils.get_contents (filename, out contents);
@@ -44,29 +42,32 @@ public class History : Object
return;
}
- foreach (var line in contents.split ("\n"))
+ foreach (string line in contents.split ("\n"))
{
- var tokens = line.split (" ");
+ string [] tokens = line.split (" ");
if (tokens.length != 3)
continue;
- var date = parse_date (tokens[0]);
+ DateTime? date = parse_date (tokens[0]);
if (date == null)
continue;
- var size = int.parse (tokens[1]);
- var duration = int.parse (tokens[2]);
+
+ int size = int.parse (tokens[1]);
+ int duration = int.parse (tokens[2]);
+
+ // FIXME use try_parse
add (new HistoryEntry (date, size, duration));
}
}
- public void save ()
+ internal void save ()
{
- var contents = "";
+ string contents = "";
- foreach (var entry in entries)
+ foreach (HistoryEntry entry in entries)
{
- var line = "%s %u %u\n".printf (entry.date.to_string (), entry.size, entry.duration);
+ string line = "%s %u %u\n".printf (entry.date.to_string (), entry.size, entry.duration);
contents += line;
}
@@ -86,28 +87,28 @@ public class History : Object
if (date.length < 19 || date[4] != '-' || date[7] != '-' || date[10] != 'T' || date[13] != ':' ||
date[16] != ':')
return null;
- var year = int.parse (date.substring (0, 4));
- var month = int.parse (date.substring (5, 2));
- var day = int.parse (date.substring (8, 2));
- var hour = int.parse (date.substring (11, 2));
- var minute = int.parse (date.substring (14, 2));
- var seconds = int.parse (date.substring (17, 2));
- var timezone = date.substring (19);
+ // FIXME use try_parse
+
+ int year = int.parse (date.substring (0, 4));
+ int month = int.parse (date.substring (5, 2));
+ int day = int.parse (date.substring (8, 2));
+ int hour = int.parse (date.substring (11, 2));
+ int minute = int.parse (date.substring (14, 2));
+ int seconds = int.parse (date.substring (17, 2));
+ string timezone = date.substring (19);
return new DateTime (new TimeZone (timezone), year, month, day, hour, minute, seconds);
}
}
-public class HistoryEntry : Object
+private class HistoryEntry : Object // TODO make struct? needs using HistoryEntry? for the List...
{
- public DateTime date;
- public uint size;
- public uint duration;
+ [CCode (notify = false)] public DateTime date { internal get; protected construct; }
+ [CCode (notify = false)] public uint size { internal get; protected construct; }
+ [CCode (notify = false)] public uint duration { internal get; protected construct; }
- public HistoryEntry (DateTime date, uint size, uint duration)
+ internal HistoryEntry (DateTime date, uint size, uint duration)
{
- this.date = date;
- this.size = size;
- this.duration = duration;
+ Object (date: date, size: size, duration: duration);
}
}
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 6a1d337..8fea2e9 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -12,57 +12,58 @@
private class TileImage : Object
{
/* Tile being moved */
- public Tile tile;
+ internal Tile tile;
/* Location of tile */
- public double x;
- public double y;
+ internal double x;
+ internal double y;
/* Co-ordinates to move from */
- public double source_x;
- public double source_y;
+ internal double source_x;
+ internal double source_y;
/* Time started moving */
- public double source_time;
+ internal double source_time;
/* Co-ordinates to target for */
- public double target_x;
- public double target_y;
+ internal double target_x;
+ internal double target_y;
/* Duration of movement */
- public double duration;
+ internal double duration;
- public TileImage (Tile tile)
+ internal TileImage (Tile tile)
{
this.tile = tile;
}
}
-public class PuzzleView : Gtk.DrawingArea
+private class PuzzleView : Gtk.DrawingArea
{
/* Minimum size of a tile */
private const int minimum_size = 80;
/* Puzzle being rendered */
private Puzzle? _puzzle = null;
- public Puzzle puzzle
+ [CCode (notify = false)] internal Puzzle puzzle
{
- get { return _puzzle; }
- set
+ private get { return _puzzle; }
+ internal set
{
if (_puzzle != null)
SignalHandler.disconnect_by_func (_puzzle, null, this);
+
_puzzle = value;
tiles.remove_all ();
- for (var y = 0; y < puzzle.size; y++)
+ for (uint y = 0; y < puzzle.size; y++)
{
- for (var x = 0; x < puzzle.size * 2; x++)
+ for (uint x = 0; x < puzzle.size * 2; x++)
{
- var tile = puzzle.get_tile (x, y);
+ Tile? tile = puzzle.get_tile (x, y);
if (tile == null)
continue;
- var image = new TileImage (tile);
+ TileImage image = new TileImage (tile);
move_tile_to_location (image, x, y);
tiles.insert (tile, image);
}
@@ -74,7 +75,7 @@ public class PuzzleView : Gtk.DrawingArea
}
/* Theme */
- private Theme theme;
+ private Theme theme = new Theme ();
/* Tile being controlled by the mouse */
private TileImage? selected_tile = null;
@@ -88,27 +89,25 @@ public class PuzzleView : Gtk.DrawingArea
private double selected_y_offset;
/* Tile images */
- private HashTable<Tile, TileImage> tiles;
+ private HashTable<Tile, TileImage> tiles = new HashTable<Tile, TileImage> (direct_hash, direct_equal);
/* Animation timer */
- private Timer animation_timer;
+ private Timer animation_timer = new Timer ();
private uint animation_timeout = 0;
- public PuzzleView ()
+ construct
{
- set_events (Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK);
-
- tiles = new HashTable <Tile, TileImage> (direct_hash, direct_equal);
+ set_events (Gdk.EventMask.EXPOSURE_MASK
+ | Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK);
- theme = new Theme ();
-
- animation_timer = new Timer ();
animation_timer.start ();
}
- public bool game_in_progress
+ [CCode (notify = false)] internal bool game_in_progress
{
- get
+ internal get
{
if (puzzle.is_solved)
return false;
@@ -138,10 +137,10 @@ public class PuzzleView : Gtk.DrawingArea
uint x_offset, y_offset, size, gap;
get_dimensions (out x_offset, out y_offset, out size, out gap);
- var target_x = x_offset + x * size;
+ double target_x = (double) (x_offset + x * size);
if (x >= puzzle.size)
target_x += gap;
- var target_y = y_offset + y * size;
+ double target_y = (double) (y_offset + y * size);
move_tile (image, target_x, target_y, duration);
}
@@ -174,13 +173,13 @@ public class PuzzleView : Gtk.DrawingArea
private bool animate_cb ()
{
- var t = animation_timer.elapsed ();
+ double t = animation_timer.elapsed ();
uint x_offset, y_offset, size, gap;
get_dimensions (out x_offset, out y_offset, out size, out gap);
- var animating = false;
- var iter = HashTableIter<Tile, TileImage> (tiles);
+ bool animating = false;
+ HashTableIter<Tile, TileImage> iter = HashTableIter<Tile, TileImage> (tiles);
while (true)
{
Tile tile;
@@ -220,17 +219,17 @@ public class PuzzleView : Gtk.DrawingArea
return false;
}
- public override void get_preferred_width (out int minimum, out int natural)
+ protected override void get_preferred_width (out int minimum, out int natural)
{
- var size = 0;
+ int size = 0;
if (puzzle != null)
size = (int) ((puzzle.size * 2 + 1.5) * minimum_size);
minimum = natural = int.max (size, 500);
}
- public override void get_preferred_height (out int minimum, out int natural)
+ protected override void get_preferred_height (out int minimum, out int natural)
{
- var size = 0;
+ int size = 0;
if (puzzle != null)
size = (int) ((puzzle.size + 1) * minimum_size);
minimum = natural = int.max (size, 300);
@@ -239,8 +238,8 @@ public class PuzzleView : Gtk.DrawingArea
private void get_dimensions (out uint x, out uint y, out uint size, out uint gap)
{
/* Fit in with a half tile border and spacing between boards */
- var width = (uint) (get_allocated_width () / (2 * puzzle.size + 1.5));
- var height = (uint) (get_allocated_height () / (puzzle.size + 1));
+ uint width = (uint) (get_allocated_width () / (2 * puzzle.size + 1.5));
+ uint height = (uint) (get_allocated_height () / (puzzle.size + 1));
size = uint.min (width, height);
gap = size / 2;
x = (get_allocated_width () - 2 * puzzle.size * size - gap) / 2;
@@ -252,10 +251,10 @@ public class PuzzleView : Gtk.DrawingArea
move_tile_to_location (tiles.lookup (tile), x, y, 0.2);
}
- public override bool configure_event (Gdk.EventConfigure event)
+ protected override bool configure_event (Gdk.EventConfigure event)
{
/* Move everything to its correct location */
- var iter = HashTableIter<Tile, TileImage> (tiles);
+ HashTableIter<Tile, TileImage> iter = HashTableIter<Tile, TileImage> (tiles);
while (true)
{
Tile tile;
@@ -272,7 +271,7 @@ public class PuzzleView : Gtk.DrawingArea
return false;
}
- public override bool draw (Cairo.Context context)
+ protected override bool draw (Cairo.Context context)
{
if (puzzle == null)
return false;
@@ -282,17 +281,17 @@ public class PuzzleView : Gtk.DrawingArea
/* Draw arrow */
context.save ();
- var w = gap * 0.5;
- var ax = x_offset + puzzle.size * size + (gap - w) * 0.5;
- var ay = y_offset + puzzle.size * size * 0.5;
+ double w = gap * 0.5;
+ double ax = x_offset + puzzle.size * size + (gap - w) * 0.5;
+ double ay = y_offset + puzzle.size * size * 0.5;
context.translate (ax, ay);
theme.draw_arrow (context, size, gap);
context.restore ();
/* Draw sockets */
- for (var y = 0; y < puzzle.size; y++)
+ for (uint y = 0; y < puzzle.size; y++)
{
- for (var x = 0; x < puzzle.size * 2; x++)
+ for (uint x = 0; x < puzzle.size * 2; x++)
{
context.save ();
if (x >= puzzle.size)
@@ -305,7 +304,7 @@ public class PuzzleView : Gtk.DrawingArea
}
/* Draw stationary tiles */
- var iter = HashTableIter<Tile, TileImage> (tiles);
+ HashTableIter<Tile, TileImage> iter = HashTableIter<Tile, TileImage> (tiles);
while (true)
{
Tile tile;
@@ -377,7 +376,7 @@ public class PuzzleView : Gtk.DrawingArea
uint x_offset, y_offset, size, gap;
get_dimensions (out x_offset, out y_offset, out size, out gap);
- var iter = HashTableIter<Tile, TileImage> (tiles);
+ HashTableIter<Tile, TileImage> iter = HashTableIter<Tile, TileImage> (tiles);
while (true)
{
Tile tile;
@@ -425,23 +424,20 @@ public class PuzzleView : Gtk.DrawingArea
x += size * 0.5 - selected_x_offset;
y += size * 0.5 - selected_x_offset;
- var tile_y = (int) Math.floor ((y - y_offset) / size);
- tile_y = int.max (tile_y, 0);
- tile_y = int.min (tile_y, (int) puzzle.size - 1);
+ int tile_y = ((int) Math.floor ((y - y_offset) / size));
+ tile_y = tile_y.clamp (0, (int) puzzle.size - 1);
/* Check which side we are on */
int tile_x;
if (on_right_half (x))
{
tile_x = (int) puzzle.size + (int) Math.floor ((x - (x_offset + puzzle.size * size + gap)) /
size);
- tile_x = int.max (tile_x, (int) puzzle.size);
- tile_x = int.min (tile_x, 2 * (int) puzzle.size - 1);
+ tile_x = tile_x.clamp ((int) puzzle.size, 2 * (int) puzzle.size - 1);
}
else
{
tile_x = (int) Math.floor ((x - x_offset) / size);
- tile_x = int.max (tile_x, 0);
- tile_x = int.min (tile_x, (int) puzzle.size - 1);
+ tile_x = tile_x.clamp (0, (int) puzzle.size - 1);
}
/* Drop the tile here, or move it back if can't */
@@ -474,7 +470,7 @@ public class PuzzleView : Gtk.DrawingArea
assert_not_reached ();
}
- public override bool button_press_event (Gdk.EventButton event)
+ protected override bool button_press_event (Gdk.EventButton event)
{
if (puzzle.paused)
return false;
@@ -502,7 +498,7 @@ public class PuzzleView : Gtk.DrawingArea
return false;
}
- public override bool button_release_event (Gdk.EventButton event)
+ protected override bool button_release_event (Gdk.EventButton event)
{
if (puzzle.paused)
return false;
@@ -517,7 +513,7 @@ public class PuzzleView : Gtk.DrawingArea
return false;
}
- public override bool motion_notify_event (Gdk.EventMotion event)
+ protected override bool motion_notify_event (Gdk.EventMotion event)
{
if (selected_tile != null)
move_tile (selected_tile, (int) (event.x - selected_x_offset), (int) (event.y -
selected_y_offset));
diff --git a/src/puzzle.vala b/src/puzzle.vala
index 9b87021..fd333bc 100644
--- a/src/puzzle.vala
+++ b/src/puzzle.vala
@@ -9,40 +9,35 @@
* license.
*/
-public class Tile : Object
+private class Tile : Object
{
/* Edge colors */
- public int north;
- public int west;
- public int east;
- public int south;
+ internal int north; // TODO make uint8
+ internal int west;
+ internal int east;
+ internal int south;
/* Solution location */
- public uint x;
- public uint y;
+ [CCode (notify = false)] public uint x { internal get; protected construct; }
+ [CCode (notify = false)] public uint y { internal get; protected construct; }
- public Tile (uint x, uint y)
+ internal Tile (uint x, uint y)
{
- this.x = x;
- this.y = y;
+ Object (x: x, y: y);
}
}
-public class Puzzle : Object
+private class Puzzle : Object
{
- private uint _size;
- public uint size
- {
- get { return _size; }
- }
- private Tile[,] board;
+ [CCode (notify = false)] public uint size { internal get; protected construct; } // TODO make uint8
+ private Tile [,] board;
/* Game timer */
private double clock_elapsed;
private Timer? clock;
private uint clock_timeout;
- public double elapsed
+ [CCode (notify = false)] internal double elapsed
{
get
{
@@ -68,22 +63,22 @@ public class Puzzle : Object
}
internal get { return _paused; }
}
-
- public signal void tile_moved (Tile tile, uint x, uint y);
- public signal void solved ();
- public signal void tick ();
-
- public bool is_solved
+
+ internal signal void tile_moved (Tile tile, uint x, uint y);
+ internal signal void solved ();
+ internal signal void tick ();
+
+ [CCode (notify = false)] internal bool is_solved
{
- get
+ internal get
{
/* Solved if entire left hand side is complete (we ensure only tiles
that fit are allowed */
- for (var x = 0; x < size; x++)
+ for (uint x = 0; x < size; x++)
{
- for (var y = 0; y < size; y++)
+ for (uint y = 0; y < size; y++)
{
- var tile = board[x, y];
+ Tile? tile = board [x, y];
if (tile == null)
return false;
}
@@ -93,57 +88,61 @@ public class Puzzle : Object
}
}
- public Puzzle (uint size)
+ internal Puzzle (uint size)
{
- _size = size;
- board = new Tile[size * 2, size];
- for (var x = 0; x < size; x++)
- for (var y = 0; y < size; y++)
- board[x, y] = new Tile (x, y);
+ Object (size: size);
+ }
+
+ construct
+ {
+ board = new Tile [size * 2, size];
+ for (uint x = 0; x < size; x++)
+ for (uint y = 0; y < size; y++)
+ board [x, y] = new Tile (x, y);
/* Pick random colours for edges */
- for (var x = 0; x < size; x++)
+ for (uint x = 0; x < size; x++)
{
- for (var y = 0; y <= size; y++)
+ for (uint y = 0; y <= size; y++)
{
- var n = Random.int_range (0, 10);
- if (y - 1 >= 0)
- board[x, y - 1].south = n;
+ int32 n = Random.int_range (0, 10);
+ if (y >= 1)
+ board [x, y - 1].south = (int) n;
if (y < size)
- board[x, y].north = n;
+ board [x, y].north = (int) n;
}
}
- for (var x = 0; x <= size; x++)
+ for (uint x = 0; x <= size; x++)
{
- for (var y = 0; y < size; y++)
+ for (uint y = 0; y < size; y++)
{
- var n = Random.int_range (0, 10);
- if (x - 1 >= 0)
- board[x - 1, y].east = n;
+ int32 n = Random.int_range (0, 10);
+ if (x >= 1)
+ board [x - 1, y].east = (int) n;
if (x < size)
- board[x, y].west = n;
+ board [x, y].west = (int) n;
}
}
/* Pick up the tiles... */
- List<Tile> tiles = null;
- for (var x = 0; x < size; x++)
+ List<Tile> tiles = new List<Tile> ();
+ for (uint x = 0; x < size; x++)
{
- for (var y = 0; y < size; y++)
+ for (uint y = 0; y < size; y++)
{
- tiles.append (board[x, y]);
- board[x, y] = null;
+ tiles.append (board [x, y]);
+ board [x, y] = null;
}
}
/* ...and place then randomly on the right hand side */
- for (var x = 0; x < size; x++)
+ for (uint x = 0; x < size; x++)
{
- for (var y = 0; y < size; y++)
+ for (uint y = 0; y < size; y++)
{
- var n = Random.int_range (0, (int32) tiles.length ());
- var tile = tiles.nth_data (n);
- board[x + size, y] = tile;
+ int32 n = Random.int_range (0, (int32) tiles.length ());
+ Tile tile = tiles.nth_data ((uint) n);
+ board [x + size, y] = tile;
tiles.remove (tile);
}
}
@@ -151,45 +150,45 @@ public class Puzzle : Object
start_clock ();
}
- public Tile? get_tile (uint x, uint y)
+ internal Tile? get_tile (uint x, uint y)
{
- return board[x, y];
+ return board [x, y];
}
-
- public void get_tile_location (Tile tile, out uint x, out uint y)
+
+ internal void get_tile_location (Tile tile, out uint x, out uint y)
{
- x = y = 0;
+ y = 0; // garbage
for (x = 0; x < size * 2; x++)
for (y = 0; y < size; y++)
- if (board[x, y] == tile)
+ if (board [x, y] == tile)
return;
}
- public bool tile_fits (uint x0, uint y0, uint x1, uint y1)
+ private bool tile_fits (uint x0, uint y0, uint x1, uint y1)
{
- var tile = board[x0, y0];
+ Tile? tile = board [x0, y0];
if (tile == null)
return false;
- if (x1 > 0 && !(x1 - 1 == x0 && y1 == y0) && board[x1 - 1, y1] != null && board[x1 - 1, y1].east !=
tile.west)
+ if (x1 > 0 && !(x1 - 1 == x0 && y1 == y0) && board [x1 - 1, y1] != null && board [x1 - 1, y1].east
!= tile.west)
return false;
- if (x1 < size - 1 && !(x1 + 1 == x0 && y1 == y0) && board[x1 + 1, y1] != null && board[x1 + 1,
y1].west != tile.east)
+ if (x1 < size - 1 && !(x1 + 1 == x0 && y1 == y0) && board [x1 + 1, y1] != null && board [x1 + 1,
y1].west != tile.east)
return false;
- if (y1 > 0 && !(x1 == x0 && y1 - 1 == y0) && board[x1, y1 - 1] != null && board[x1, y1 - 1].south !=
tile.north)
+ if (y1 > 0 && !(x1 == x0 && y1 - 1 == y0) && board [x1, y1 - 1] != null && board [x1, y1 - 1].south
!= tile.north)
return false;
- if (y1 < size - 1 && !(x1 == x0 && y1 + 1 == y0) && board[x1, y1 + 1] != null && board[x1, y1 +
1].north != tile.south)
+ if (y1 < size - 1 && !(x1 == x0 && y1 + 1 == y0) && board [x1, y1 + 1] != null && board [x1, y1 +
1].north != tile.south)
return false;
return true;
}
-
- public bool can_switch (uint x0, uint y0, uint x1, uint y1)
+
+ internal bool can_switch (uint x0, uint y0, uint x1, uint y1)
{
if (x0 == x1 && y0 == y1)
return false;
- var t0 = board[x0, y0];
- var t1 = board[x1, y1];
+ Tile? t0 = board [x0, y0];
+ Tile? t1 = board [x1, y1];
/* No tiles to switch */
if (t0 == null && t1 == null)
@@ -204,15 +203,15 @@ public class Puzzle : Object
return true;
}
- public void switch_tiles (uint x0, uint y0, uint x1, uint y1)
+ internal void switch_tiles (uint x0, uint y0, uint x1, uint y1)
{
if (x0 == x1 && y0 == y1)
return;
- var t0 = board[x0, y0];
- var t1 = board[x1, y1];
- board[x0, y0] = t1;
- board[x1, y1] = t0;
+ Tile? t0 = board [x0, y0];
+ Tile? t1 = board [x1, y1];
+ board [x0, y0] = t1;
+ board [x1, y1] = t0;
if (t0 != null)
tile_moved (t0, x1, y1);
@@ -226,109 +225,109 @@ public class Puzzle : Object
}
}
- public bool can_move_up
- {
- get
- {
- for (var x = 0; x < size; x++)
- if (board[x, 0] != null)
- return false;
- return true;
- }
- }
+ /*\
+ * * moving tiles
+ \*/
- public void move_up ()
+ internal void move_up ()
{
- if (!can_move_up)
+ if (!can_move_up ())
return;
- for (var y = 1; y < size; y++)
- for (var x = 0; x < size; x++)
+
+ for (uint y = 1; y < size; y++)
+ for (uint x = 0; x < size; x++)
switch_tiles (x, y, x, y - 1);
}
-
- public bool can_move_down
+ private bool can_move_up ()
{
- get
- {
- for (var x = 0; x < size; x++)
- if (board[x, size - 1] != null)
- return false;
- return true;
- }
+ for (uint x = 0; x < size; x++)
+ if (board [x, 0] != null)
+ return false;
+ return true;
}
- public void move_down ()
+ internal void move_down ()
{
- if (!can_move_down)
+ if (!can_move_down ())
return;
- for (var y = (int) size - 2; y >= 0; y--)
- for (var x = 0; x < size; x++)
- switch_tiles (x, y, x, y + 1);
- }
- public bool can_move_left
+ for (uint y = size - 1; y > 0; y--)
+ for (uint x = 0; x < size; x++)
+ switch_tiles (x, y - 1, x, y);
+ }
+ private bool can_move_down ()
{
- get
- {
- for (var y = 0; y < size; y++)
- if (board[0, y] != null)
- return false;
- return true;
- }
+ for (uint x = 0; x < size; x++)
+ if (board [x, size - 1] != null)
+ return false;
+ return true;
}
- public void move_left ()
+ internal void move_left ()
{
- if (!can_move_left)
+ if (!can_move_left ())
return;
- for (var x = 1; x < size; x++)
- for (var y = 0; y < size; y++)
+
+ for (uint x = 1; x < size; x++)
+ for (uint y = 0; y < size; y++)
switch_tiles (x, y, x - 1, y);
}
-
- public bool can_move_right
+ private bool can_move_left ()
{
- get
- {
- for (var y = 0; y < size; y++)
- if (board[size - 1, y] != null)
- return false;
- return true;
- }
+ for (uint y = 0; y < size; y++)
+ if (board [0, y] != null)
+ return false;
+ return true;
}
- public void move_right ()
+ internal void move_right ()
{
- if (!can_move_right)
+ if (!can_move_right ())
return;
- for (var x = (int) size - 2; x >= 0; x--)
- for (var y = 0; y < size; y++)
- switch_tiles (x, y, x + 1, y);
+
+ for (uint x = size - 1; x > 0; x--)
+ for (uint y = 0; y < size; y++)
+ switch_tiles (x - 1, y, x, y);
}
+ private bool can_move_right ()
+ {
+ for (uint y = 0; y < size; y++)
+ if (board [size - 1, y] != null)
+ return false;
+ return true;
+ }
+
+ /*\
+ * * actions
+ \*/
- public void solve ()
+ internal void solve ()
{
List<Tile> wrong_tiles = null;
- for (var x = 0; x < size * 2; x++)
+ for (uint x = 0; x < size * 2; x++)
{
- for (var y = 0; y < size; y++)
+ for (uint y = 0; y < size; y++)
{
- var tile = board[x, y];
+ Tile? tile = board [x, y];
if (tile != null && (tile.x != x || tile.y != y))
wrong_tiles.append (tile);
- board[x, y] = null;
+ board [x, y] = null;
}
}
- foreach (var tile in wrong_tiles)
+ foreach (Tile tile in wrong_tiles)
{
- board[tile.x, tile.y] = tile;
+ board [tile.x, tile.y] = tile;
tile_moved (tile, tile.x, tile.y);
}
-
+
stop_clock ();
}
+ /*\
+ * * clock
+ \*/
+
private void start_clock ()
{
if (clock == null)
@@ -352,16 +351,16 @@ public class Puzzle : Object
if (clock == null)
clock = new Timer ();
else
- clock.continue ();
+ clock.@continue ();
timeout_cb ();
}
private bool timeout_cb ()
{
/* Notify on the next tick */
- var elapsed = clock.elapsed ();
- var next = (int) (elapsed + 1.0);
- var wait = next - elapsed;
+ double elapsed = clock.elapsed ();
+ int next = (int) (elapsed + 1.0);
+ double wait = (double) next - elapsed;
clock_timeout = Timeout.add ((int) (wait * 1000), timeout_cb);
tick ();
diff --git a/src/score-dialog.vala b/src/score-dialog.vala
index 4ef7019..77c8703 100644
--- a/src/score-dialog.vala
+++ b/src/score-dialog.vala
@@ -9,7 +9,7 @@
* license.
*/
-public class ScoreDialog : Gtk.Dialog
+private class ScoreDialog : Gtk.Dialog
{
private History history;
private HistoryEntry? selected_entry = null;
@@ -79,7 +79,7 @@ public class ScoreDialog : Gtk.Dialog
entry_added_cb (entry);
}
- public void set_size (uint size)
+ internal void set_size (uint size)
{
score_model.clear ();
diff --git a/src/theme.vala b/src/theme.vala
index d1d900f..4b557fc 100644
--- a/src/theme.vala
+++ b/src/theme.vala
@@ -9,45 +9,45 @@
* license.
*/
-public class Theme : Object
+private class Theme : Object
{
/* Colors of tiles and text */
- private Cairo.Pattern tile_colors[10];
+ private Cairo.Pattern tile_colors [10];
private Cairo.Pattern paused_color;
- private Cairo.Pattern text_colors[10];
+ private Cairo.Pattern text_colors [10];
- public Theme ()
+ internal Theme ()
{
- tile_colors[0] = make_color_pattern ("#000000");
- tile_colors[1] = make_color_pattern ("#C17D11");
- tile_colors[2] = make_color_pattern ("#CC0000");
- tile_colors[3] = make_color_pattern ("#F57900");
- tile_colors[4] = make_color_pattern ("#EDD400");
- tile_colors[5] = make_color_pattern ("#73D216");
- tile_colors[6] = make_color_pattern ("#3465A4");
- tile_colors[7] = make_color_pattern ("#75507B");
- tile_colors[8] = make_color_pattern ("#BABDB6");
- tile_colors[9] = make_color_pattern ("#FFFFFF");
+ tile_colors [0] = make_color_pattern ("#000000");
+ tile_colors [1] = make_color_pattern ("#C17D11");
+ tile_colors [2] = make_color_pattern ("#CC0000");
+ tile_colors [3] = make_color_pattern ("#F57900");
+ tile_colors [4] = make_color_pattern ("#EDD400");
+ tile_colors [5] = make_color_pattern ("#73D216");
+ tile_colors [6] = make_color_pattern ("#3465A4");
+ tile_colors [7] = make_color_pattern ("#75507B");
+ tile_colors [8] = make_color_pattern ("#BABDB6");
+ tile_colors [9] = make_color_pattern ("#FFFFFF");
paused_color = make_color_pattern ("#CCCCCC");
- text_colors[0] = new Cairo.Pattern.rgb (1, 1, 1);
- text_colors[1] = new Cairo.Pattern.rgb (1, 1, 1);
- text_colors[2] = new Cairo.Pattern.rgb (1, 1, 1);
- text_colors[3] = new Cairo.Pattern.rgb (1, 1, 1);
- text_colors[4] = new Cairo.Pattern.rgb (0, 0, 0);
- text_colors[5] = new Cairo.Pattern.rgb (0, 0, 0);
- text_colors[6] = new Cairo.Pattern.rgb (1, 1, 1);
- text_colors[7] = new Cairo.Pattern.rgb (1, 1, 1);
- text_colors[8] = new Cairo.Pattern.rgb (0, 0, 0);
- text_colors[9] = new Cairo.Pattern.rgb (0, 0, 0);
+ text_colors [0] = new Cairo.Pattern.rgb (1, 1, 1);
+ text_colors [1] = new Cairo.Pattern.rgb (1, 1, 1);
+ text_colors [2] = new Cairo.Pattern.rgb (1, 1, 1);
+ text_colors [3] = new Cairo.Pattern.rgb (1, 1, 1);
+ text_colors [4] = new Cairo.Pattern.rgb (0, 0, 0);
+ text_colors [5] = new Cairo.Pattern.rgb (0, 0, 0);
+ text_colors [6] = new Cairo.Pattern.rgb (1, 1, 1);
+ text_colors [7] = new Cairo.Pattern.rgb (1, 1, 1);
+ text_colors [8] = new Cairo.Pattern.rgb (0, 0, 0);
+ text_colors [9] = new Cairo.Pattern.rgb (0, 0, 0);
}
private Cairo.Pattern make_color_pattern (string color)
{
- var r = (hex_value (color[1]) * 16 + hex_value (color[2])) / 255.0;
- var g = (hex_value (color[3]) * 16 + hex_value (color[4])) / 255.0;
- var b = (hex_value (color[5]) * 16 + hex_value (color[6])) / 255.0;
+ double r = (hex_value (color [1]) * 16 + hex_value (color [2])) / 255.0;
+ double g = (hex_value (color [3]) * 16 + hex_value (color [4])) / 255.0;
+ double b = (hex_value (color [5]) * 16 + hex_value (color [6])) / 255.0;
return new Cairo.Pattern.rgb (r, g, b);
}
@@ -63,13 +63,13 @@ public class Theme : Object
return 0;
}
- public void draw_arrow (Cairo.Context context, uint size, uint gap)
+ internal void draw_arrow (Cairo.Context context, uint size, uint gap)
{
- var w = gap * 0.5;
- var h = size * 1.5;
- var depth = uint.min ((uint) (size * 0.025), 2);
- var dx = 1.4142 * depth;
- var dy = 6.1623 * depth;
+ double w = gap * 0.5;
+ double h = size * 1.5;
+ uint depth = uint.min ((uint) (size * 0.025), 2);
+ double dx = 1.4142 * depth;
+ double dy = 6.1623 * depth;
/* Background */
context.move_to (0, 0);
@@ -100,9 +100,9 @@ public class Theme : Object
context.fill ();
}
- public void draw_socket (Cairo.Context context, uint size)
+ internal void draw_socket (Cairo.Context context, uint size)
{
- var depth = uint.min ((uint) (size * 0.05), 4);
+ uint depth = uint.min ((uint) (size * 0.05), 4);
/* Background */
context.rectangle (depth, depth, size - depth * 2, size - depth * 2);
@@ -132,32 +132,32 @@ public class Theme : Object
context.fill ();
}
- public void draw_paused_tile (Cairo.Context context, uint size)
+ internal void draw_paused_tile (Cairo.Context context, uint size)
{
draw_tile_background (context, size, paused_color, paused_color, paused_color, paused_color);
}
- public void draw_tile (Cairo.Context context, uint size, Tile? tile)
+ internal void draw_tile (Cairo.Context context, uint size, Tile? tile)
{
- draw_tile_background (context, size, tile_colors[tile.north], tile_colors[tile.east],
tile_colors[tile.south], tile_colors[tile.west]);
+ draw_tile_background (context, size, tile_colors [tile.north], tile_colors [tile.east], tile_colors
[tile.south], tile_colors [tile.west]);
context.select_font_face ("Sans", Cairo.FontSlant.NORMAL, Cairo.FontWeight.BOLD);
context.set_font_size (size / 3.5);
- context.set_source (text_colors[tile.north]);
+ context.set_source (text_colors [tile.north]);
draw_number (context, size * 0.5, size / 5, tile.north);
- context.set_source (text_colors[tile.south]);
+ context.set_source (text_colors [tile.south]);
draw_number (context, size * 0.5, size * 4 / 5, tile.south);
- context.set_source (text_colors[tile.east]);
+ context.set_source (text_colors [tile.east]);
draw_number (context, size * 4 / 5, size * 0.5, tile.east);
- context.set_source (text_colors[tile.west]);
+ context.set_source (text_colors [tile.west]);
draw_number (context, size / 5, size * 0.5, tile.west);
}
- private void draw_tile_background (Cairo.Context context, uint size, Cairo.Pattern north_color,
Cairo.Pattern east_color, Cairo.Pattern south_color, Cairo.Pattern west_color)
+ internal void draw_tile_background (Cairo.Context context, uint size, Cairo.Pattern north_color,
Cairo.Pattern east_color, Cairo.Pattern south_color, Cairo.Pattern west_color)
{
- var depth = uint.min ((uint) (size * 0.05), 4);
- var dx = 2.4142 * depth;
- var dy = 1.4142 * depth;
+ uint depth = uint.min ((uint) (size * 0.05), 4);
+ double dx = 2.4142 * depth;
+ double dy = 1.4142 * depth;
/* North */
context.rectangle (0, 0, size, size * 0.5);
@@ -274,7 +274,7 @@ public class Theme : Object
private void draw_number (Cairo.Context context, double x, double y, uint number)
{
- var text = "%u".printf (number);
+ string text = "%u".printf (number);
Cairo.TextExtents extents;
context.text_extents (text, out extents);
context.move_to (x - extents.width / 2.0, y + extents.height / 2.0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]