[five-or-more/arnaudb/use-event-controllers: 2/7] Use internal and protected.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [five-or-more/arnaudb/use-event-controllers: 2/7] Use internal and protected.
- Date: Thu, 16 Apr 2020 17:18:57 +0000 (UTC)
commit 3ddd7e64d8b7519e17a5251ac7e56b1fe3c26145
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Mar 12 17:41:12 2020 +0100
Use internal and protected.
src/board.vala | 62 +++++++++++++++++-----------------
src/config.vapi | 8 ++---
src/game.vala | 82 ++++++++++++++++++++++-----------------------
src/main.vala | 16 ++++-----
src/next-pieces-widget.vala | 6 ++--
src/piece-generator.vala | 6 ++--
src/piece.vala | 8 ++---
src/preferences-dialog.vala | 4 +--
src/theme-renderer.vala | 12 +++----
src/view.vala | 12 +++----
src/window.vala | 16 ++++-----
11 files changed, 116 insertions(+), 116 deletions(-)
---
diff --git a/src/board.vala b/src/board.vala
index 3f3eb31..f1b485d 100644
--- a/src/board.vala
+++ b/src/board.vala
@@ -21,35 +21,35 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
-public class Board
+private class Board
{
private Cell[,] grid = null;
- public int n_rows {
- get {
+ internal int n_rows {
+ internal get {
assert (grid != null);
return grid.length[0];
}
}
- public int n_cols {
- get {
+ internal int n_cols {
+ internal get {
assert (grid != null);
return grid.length[1];
}
}
- public signal void grid_changed ();
- public signal void board_changed ();
+ internal signal void grid_changed ();
+ internal signal void board_changed ();
private Cell src;
private Cell dst;
- private Gee.ArrayList<Cell> open = null;
- public Gee.ArrayList<Cell> closed = null;
- public Gee.ArrayList<Cell>? path = null;
+ private Gee.ArrayList<Cell> open = null;
+ internal Gee.ArrayList<Cell> closed = null;
+ internal Gee.ArrayList<Cell>? path = null;
- public Board (int n_rows, int n_cols)
+ internal Board (int n_rows, int n_cols)
{
grid = new Cell[n_rows, n_cols];
for (int col = 0; col < n_cols; col++)
@@ -61,7 +61,7 @@ public class Board
}
}
- public void reset (int n_rows, int n_cols)
+ internal void reset (int n_rows, int n_cols)
{
grid = new Cell[n_rows, n_cols];
@@ -83,30 +83,30 @@ public class Board
board_changed ();
}
- public Cell[,]? get_grid ()
+ internal Cell[,]? get_grid ()
{
return this.grid;
}
- public void set_piece (int row, int col, Piece? piece)
+ internal void set_piece (int row, int col, Piece? piece)
{
grid[row, col].piece = piece;
}
- public Piece? get_piece (int row, int col)
+ internal Piece? get_piece (int row, int col)
{
return grid[row, col].piece;
}
- public Cell? get_cell (int row, int col)
+ internal Cell? get_cell (int row, int col)
{
return grid[row, col];
}
- public Gee.ArrayList<Cell> find_path (int start_row,
- int start_col,
- int end_row,
- int end_col)
+ internal Gee.ArrayList<Cell> find_path (int start_row,
+ int start_col,
+ int end_row,
+ int end_col)
{
reset_path_search ();
@@ -233,15 +233,15 @@ public class Board
}
}
-public class Cell
+private class Cell
{
- public int row;
- public int col;
- public Cell? parent;
- public Piece? piece;
- public int cost;
+ internal int row;
+ internal int col;
+ internal Cell? parent;
+ internal Piece? piece;
+ internal int cost;
- public Cell (int row, int col, Cell? parent, Piece? piece)
+ internal Cell (int row, int col, Cell? parent, Piece? piece)
{
this.row = row;
this.col = col;
@@ -250,7 +250,7 @@ public class Cell
this.cost = int.MAX;
}
- public bool equal (Cell cell)
+ internal bool equal (Cell cell)
{
return this.row == cell.row && this.col == cell.col;
}
@@ -303,7 +303,7 @@ public class Cell
return neighbour;
}
- public Gee.ArrayList<Cell> get_neighbours (Cell[,] board)
+ internal Gee.ArrayList<Cell> get_neighbours (Cell[,] board)
{
Gee.ArrayList<Cell> neighbours = new Gee.ArrayList<Cell> ();
Cell? right = null, left = null, up = null, down = null;
@@ -381,7 +381,7 @@ public class Cell
return list;
}
- public Gee.HashSet<Cell> get_all_directions (Cell[,] board)
+ internal Gee.HashSet<Cell> get_all_directions (Cell[,] board)
{
Gee.ArrayList<Cell>? list;
Gee.HashSet<Cell>? inactivate = new Gee.HashSet<Cell> ();
@@ -418,7 +418,7 @@ public class Cell
}
}
-enum Direction
+private enum Direction
{
RIGHT,
LEFT,
diff --git a/src/config.vapi b/src/config.vapi
index 3f2ffc5..dac1f7c 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -1,4 +1,4 @@
-public const string DATA_DIRECTORY;
-public const string GETTEXT_PACKAGE;
-public const string LOCALE_DIRECTORY;
-public const string VERSION;
+private const string DATA_DIRECTORY;
+private const string GETTEXT_PACKAGE;
+private const string LOCALE_DIRECTORY;
+private const string VERSION;
diff --git a/src/game.vala b/src/game.vala
index 2d04e7c..a9eb387 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -21,88 +21,88 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
-public class Game : Object
+private class Game : Object
{
- public const int N_TYPES = 7;
- public const int N_ANIMATIONS = 4;
- public const int N_MATCH = 5;
+ internal const int N_TYPES = 7;
+ internal const int N_ANIMATIONS = 4;
+ internal const int N_MATCH = 5;
private Settings settings;
private int size;
private NextPiecesGenerator next_pieces_generator;
- public Board board = null;
- public int n_rows {
- get {
+ internal Board? board = null;
+ internal int n_rows {
+ internal get {
assert (board != null);
return board.n_rows;
}
}
- public int n_cols {
- get {
+ internal int n_cols {
+ internal get {
assert (board != null);
return board.n_cols;
}
}
- public int n_next_pieces;
+ internal int n_next_pieces;
private int n_cells;
- public int n_filled_cells;
+ internal int n_filled_cells;
- public Gee.ArrayList<Cell>? current_path = null;
- public bool animating = false;
- public Piece animating_piece;
+ internal Gee.ArrayList<Cell>? current_path = null;
+ internal bool animating = false;
+ internal Piece animating_piece;
- public int score { get; private set; }
+ internal int score { get; private set; }
- public signal void current_path_cell_pos_changed ();
+ internal signal void current_path_cell_pos_changed ();
private int _current_path_cell_pos = -1;
- public int current_path_cell_pos
+ internal int current_path_cell_pos
{
- get { return _current_path_cell_pos; }
- set
+ internal get { return _current_path_cell_pos; }
+ internal set
{
_current_path_cell_pos = value;
current_path_cell_pos_changed ();
}
}
- public signal void queue_changed (Gee.ArrayList<Piece> next_pieces_queue);
+ internal signal void queue_changed (Gee.ArrayList<Piece> next_pieces_queue);
private Gee.ArrayList<Piece> _next_pieces_queue;
- public Gee.ArrayList<Piece> next_pieces_queue
+ internal Gee.ArrayList<Piece> next_pieces_queue
{
- get { return _next_pieces_queue; }
- set
+ internal get { return _next_pieces_queue; }
+ internal set
{
_next_pieces_queue = value;
queue_changed (_next_pieces_queue);
}
}
- const GameDifficulty[] game_difficulty = {
+ private const GameDifficulty[] game_difficulty = {
{ -1, -1, -1, -1 },
{ 7, 7, 5, 3 },
{ 9, 9, 7, 3 },
{ 20, 15, 7, 7 }
};
- public const KeyValue scorecats[] = {
+ internal const KeyValue scorecats[] = {
{ "Small", NC_("board size", "Small") },
{ "Medium", NC_("board size", "Medium") },
{ "Large", NC_("board size", "Large") }
};
- public signal void game_over ();
- public int n_categories = 3;
- public string score_current_category = null;
+ internal signal void game_over ();
+ internal int n_categories = 3;
+ internal string score_current_category = null;
- public StatusMessage status_message { get; set; }
+ internal StatusMessage status_message { get; set; }
- public Game (Settings settings)
+ internal Game (Settings settings)
{
this.settings = settings;
@@ -143,7 +143,7 @@ public class Game : Object
generate_next_pieces ();
}
- public void generate_next_pieces ()
+ internal void generate_next_pieces ()
{
this.next_pieces_queue = this.next_pieces_generator.yield_next_pieces ();
}
@@ -203,13 +203,13 @@ public class Game : Object
return false;
}
- public void next_step ()
+ internal void next_step ()
{
fill_board (this.n_rows, this.n_cols);
generate_next_pieces ();
}
- public bool make_move (int start_row, int start_col, int end_row, int end_col)
+ internal bool make_move (int start_row, int start_col, int end_row, int end_col)
{
current_path = board.find_path (start_row,
start_col,
@@ -229,7 +229,7 @@ public class Game : Object
return true;
}
- public bool animate ()
+ internal bool animate ()
{
animating = true;
@@ -271,13 +271,13 @@ public class Game : Object
return Source.CONTINUE;
}
- public void restart ()
+ internal void restart ()
{
init_game ();
}
}
-public enum BoardSize
+private enum BoardSize
{
UNSET,
SMALL,
@@ -286,7 +286,7 @@ public enum BoardSize
MAX_SIZE,
}
-struct GameDifficulty
+private struct GameDifficulty
{
public int n_cols;
public int n_rows;
@@ -294,13 +294,13 @@ struct GameDifficulty
public int n_next_pieces;
}
-struct KeyValue
+private struct KeyValue
{
- public string key;
- public string name;
+ public string key;
+ public string name;
}
-public enum StatusMessage
+private enum StatusMessage
{
DESCRIPTION,
NO_PATH,
diff --git a/src/main.vala b/src/main.vala
index a878da8..3e05bba 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -21,11 +21,11 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
-public class FiveOrMoreApp: Gtk.Application
+private class FiveOrMoreApp: Gtk.Application
{
- public const string KEY_SIZE = "size";
- public const string KEY_BACKGROUND_COLOR = "background-color";
- public const string KEY_THEME = "ball-theme";
+ internal const string KEY_SIZE = "size";
+ internal const string KEY_BACKGROUND_COLOR = "background-color";
+ internal const string KEY_THEME = "ball-theme";
private Settings settings;
@@ -43,7 +43,7 @@ public class FiveOrMoreApp: Gtk.Application
{"quit", quit }
};
- public static int main (string[] args)
+ private static int main (string[] args)
{
Intl.setlocale (LocaleCategory.ALL, "");
Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIRECTORY);
@@ -57,12 +57,12 @@ public class FiveOrMoreApp: Gtk.Application
return app.run (args);
}
- public FiveOrMoreApp ()
+ private FiveOrMoreApp ()
{
Object (application_id: "org.gnome.five-or-more", flags: ApplicationFlags.FLAGS_NONE);
}
- public override void activate ()
+ protected override void activate ()
{
window.show ();
}
@@ -183,7 +183,7 @@ public class FiveOrMoreApp: Gtk.Application
"website", "https://wiki.gnome.org/Apps/Five%20or%20more");
}
- public override void shutdown ()
+ protected override void shutdown ()
{
settings.set_int ("window-width", window.window_width);
settings.set_int ("window-height", window.window_height);
diff --git a/src/next-pieces-widget.vala b/src/next-pieces-widget.vala
index c2a8ebc..b891676 100644
--- a/src/next-pieces-widget.vala
+++ b/src/next-pieces-widget.vala
@@ -21,7 +21,7 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
-public class NextPiecesWidget : Gtk.DrawingArea
+private class NextPiecesWidget : Gtk.DrawingArea
{
private Settings settings;
private Game? game;
@@ -30,7 +30,7 @@ public class NextPiecesWidget : Gtk.DrawingArea
private Gee.ArrayList<Piece> local_pieces_queue;
private int widget_height = -1;
- public NextPiecesWidget (Settings settings, Game game, ThemeRenderer theme)
+ internal NextPiecesWidget (Settings settings, Game game, ThemeRenderer theme)
{
this.settings = settings;
this.game = game;
@@ -59,7 +59,7 @@ public class NextPiecesWidget : Gtk.DrawingArea
queue_draw ();
}
- public override bool draw (Cairo.Context cr)
+ protected override bool draw (Cairo.Context cr)
{
if (theme == null)
return false;
diff --git a/src/piece-generator.vala b/src/piece-generator.vala
index fea2da2..f9c083c 100644
--- a/src/piece-generator.vala
+++ b/src/piece-generator.vala
@@ -21,13 +21,13 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
-public class NextPiecesGenerator
+private class NextPiecesGenerator
{
private int n_types;
private int n_next_pieces;
private Gee.ArrayList<Piece> pieces;
- public NextPiecesGenerator (int n_next_pieces, int n_types)
+ internal NextPiecesGenerator (int n_next_pieces, int n_types)
{
this.pieces = new Gee.ArrayList<Piece> ();
this.n_next_pieces = n_next_pieces;
@@ -39,7 +39,7 @@ public class NextPiecesGenerator
return GLib.Random.int_range (0, this.n_types);
}
- public Gee.ArrayList<Piece> yield_next_pieces ()
+ internal Gee.ArrayList<Piece> yield_next_pieces ()
{
this.pieces.clear ();
diff --git a/src/piece.vala b/src/piece.vala
index 4af1e68..b2a95da 100644
--- a/src/piece.vala
+++ b/src/piece.vala
@@ -21,16 +21,16 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
-public class Piece
+private class Piece
{
- public int id;
+ internal int id;
- public Piece (int id)
+ internal Piece (int id)
{
this.id = id;
}
- public bool equal (Piece piece)
+ internal bool equal (Piece piece)
{
return this.id == piece.id;
}
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index 30df00d..fdbc42e 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -22,7 +22,7 @@
*/
[GtkTemplate (ui = "/org/gnome/five-or-more/ui/preferences-dialog.ui")]
-public class PreferencesDialog : Gtk.Dialog
+private class PreferencesDialog : Gtk.Dialog
{
private Settings settings;
@@ -55,7 +55,7 @@ public class PreferencesDialog : Gtk.Dialog
warning ("Failed to set color: %s", color.to_string ());
}
- public PreferencesDialog (Settings settings)
+ internal PreferencesDialog (Settings settings)
{
this.settings = settings;
diff --git a/src/theme-renderer.vala b/src/theme-renderer.vala
index 401ed20..9774ddc 100644
--- a/src/theme-renderer.vala
+++ b/src/theme-renderer.vala
@@ -21,11 +21,11 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
-public class ThemeRenderer
+private class ThemeRenderer
{
private Settings settings;
- public const int DEFAULT_SPRITE_SIZE = 20;
+ internal const int DEFAULT_SPRITE_SIZE = 20;
private int sprite_size = DEFAULT_SPRITE_SIZE;
private float sprite_sheet_width;
private float sprite_sheet_height;
@@ -33,7 +33,7 @@ public class ThemeRenderer
private string theme_name;
private Rsvg.Handle? theme = null;
- public const string themes[] = {
+ internal const string themes[] = {
"balls.svg",
"shapes.svg",
"tango.svg",
@@ -42,10 +42,10 @@ public class ThemeRenderer
private Cairo.Pattern? tile_pattern = null;
private Cairo.Context cr_preview;
- public signal void theme_changed ();
+ internal signal void theme_changed ();
private bool is_theme_changed;
- public ThemeRenderer (Settings settings)
+ internal ThemeRenderer (Settings settings)
{
this.settings = settings;
@@ -94,7 +94,7 @@ public class ThemeRenderer
is_theme_changed = true;
}
- public void render_sprite (Cairo.Context cr, int type, int animation, double x, double y, int size)
+ internal void render_sprite (Cairo.Context cr, int type, int animation, double x, double y, int size)
{
if (is_theme_changed || tile_pattern == null || sprite_size != size)
{
diff --git a/src/view.vala b/src/view.vala
index eab2493..3b38777 100644
--- a/src/view.vala
+++ b/src/view.vala
@@ -21,7 +21,7 @@
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
-public class View : Gtk.DrawingArea
+private class View : Gtk.DrawingArea
{
private const int MINIMUM_BOARD_SIZE = 256;
@@ -49,7 +49,7 @@ public class View : Gtk.DrawingArea
private int animation_state;
private uint animation_id;
- public View (Settings settings, Game game, ThemeRenderer theme)
+ internal View (Settings settings, Game game, ThemeRenderer theme)
{
this.settings = settings;
this.game = game;
@@ -155,7 +155,7 @@ public class View : Gtk.DrawingArea
queue_draw_area (keyboard_cursor_x * piece_size, keyboard_cursor_y * piece_size, piece_size,
piece_size);
}
- public override bool key_press_event (Gdk.EventKey event)
+ protected override bool key_press_event (Gdk.EventKey event)
{
uint key = event.keyval;
switch (key)
@@ -275,7 +275,7 @@ public class View : Gtk.DrawingArea
return true;
}
- public override bool button_press_event (Gdk.EventButton event)
+ protected override bool button_press_event (Gdk.EventButton event)
{
if (game == null || game.animating)
return false;
@@ -311,7 +311,7 @@ public class View : Gtk.DrawingArea
board_rectangle.height = piece_size * game.n_rows;
}
- public override bool configure_event (Gdk.EventConfigure event)
+ protected override bool configure_event (Gdk.EventConfigure event)
{
update_sizes (event.width, event.height);
queue_draw ();
@@ -402,7 +402,7 @@ public class View : Gtk.DrawingArea
}
}
- public override bool draw (Cairo.Context cr)
+ protected override bool draw (Cairo.Context cr)
{
if (theme == null)
return false;
diff --git a/src/window.vala b/src/window.vala
index a32f554..430b5d6 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -22,7 +22,7 @@
*/
[GtkTemplate (ui = "/org/gnome/five-or-more/ui/five-or-more.ui")]
-public class GameWindow : Gtk.ApplicationWindow
+private class GameWindow : Gtk.ApplicationWindow
{
[GtkChild]
private Gtk.HeaderBar headerbar;
@@ -38,9 +38,9 @@ public class GameWindow : Gtk.ApplicationWindow
private Settings? settings = null;
private bool window_tiled;
- public bool window_maximized { get; private set; }
- public int window_width { get; private set; }
- public int window_height { get; private set; }
+ internal bool window_maximized { internal get; private set; }
+ internal int window_width { internal get; private set; }
+ internal int window_height { internal get; private set; }
private Game? game = null;
private ThemeRenderer? theme = null;
@@ -53,7 +53,7 @@ public class GameWindow : Gtk.ApplicationWindow
_("Score: %d")
};
- public GameWindow (Gtk.Application app, Settings settings)
+ internal GameWindow (Gtk.Application app, Settings settings)
{
Object (application: app);
@@ -126,7 +126,7 @@ public class GameWindow : Gtk.ApplicationWindow
show_scores ();
}
- public void restart_game ()
+ internal void restart_game ()
{
game.restart ();
}
@@ -136,12 +136,12 @@ public class GameWindow : Gtk.ApplicationWindow
headerbar.set_subtitle (message);
}
- public void show_scores ()
+ internal void show_scores ()
{
highscores.run_dialog ();
}
- public void change_size (BoardSize size)
+ internal void change_size (BoardSize size)
{
var game_size = settings.get_int ("size");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]