[five-or-more/arnaudb/wip/gtk4: 32/37] Use an AspectFrame.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [five-or-more/arnaudb/wip/gtk4: 32/37] Use an AspectFrame.
- Date: Tue, 4 Aug 2020 15:17:06 +0000 (UTC)
commit 3073553b040f7cc34b71ce5d40113fbbad2b0989
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Mar 27 15:40:32 2020 +0100
Use an AspectFrame.
data/ui/five-or-more.ui | 11 ++++++++++-
src/view.vala | 5 +++++
src/window.vala | 16 ++++++++++++----
3 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/data/ui/five-or-more.ui b/data/ui/five-or-more.ui
index 17b9116..22341dc 100644
--- a/data/ui/five-or-more.ui
+++ b/data/ui/five-or-more.ui
@@ -145,7 +145,16 @@
</object>
</child>
<child>
- <object class="GamesGridFrame" id="grid_frame"/>
+ <object class="GtkAspectFrame" id="grid_frame">
+ <property name="obey-child">False</property>
+ <property name="ratio">1.0</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="margin-top">10</property>
+ <property name="margin-start">10</property>
+ <property name="margin-end">10</property>
+ <property name="margin-bottom">10</property>
+ </object>
</child>
</template>
</interface>
diff --git a/src/view.vala b/src/view.vala
index c572212..2a24642 100644
--- a/src/view.vala
+++ b/src/view.vala
@@ -321,6 +321,8 @@ private class View : DrawingArea
piece_size = (width - 1) / game.n_cols;
board_rectangle.width = piece_size * game.n_cols;
board_rectangle.height = piece_size * game.n_rows;
+ board_rectangle.x = (width - board_rectangle.width) / 2;
+ board_rectangle.y = (height - board_rectangle.height) / 2;
}
private void fill_background (Cairo.Context cr)
@@ -419,9 +421,12 @@ private class View : DrawingArea
update_sizes (new_width, new_height);
fill_background (cr);
+ cr.save ();
+ cr.translate (board_rectangle.x, board_rectangle.y);
draw_gridlines (cr);
draw_shapes (cr);
draw_cursor_box (cr);
draw_path (cr);
+ cr.restore ();
}
}
diff --git a/src/window.vala b/src/window.vala
index ae95186..546a8f4 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -33,7 +33,7 @@ private class GameWindow : ApplicationWindow
private Box preview_hbox;
[GtkChild]
- private Games.GridFrame grid_frame;
+ private AspectFrame grid_frame;
private GLib.Settings settings = new GLib.Settings ("org.gnome.five-or-more");
private bool window_tiled;
@@ -97,6 +97,7 @@ private class GameWindow : ApplicationWindow
default: assert_not_reached ();
}
((SimpleAction) board_size_action).set_state (board_size_string);
+ update_ratio (board_size);
game = new Game (board_size);
theme = new ThemeRenderer (settings);
@@ -108,8 +109,6 @@ private class GameWindow : ApplicationWindow
NextPiecesWidget next_pieces_widget = new NextPiecesWidget (settings, game, theme);
preview_hbox.pack_start (next_pieces_widget);
- grid_frame.set (game.n_cols, game.n_rows);
- game.board.board_changed.connect (() => { grid_frame.set (game.n_cols, game.n_rows); });
game.notify["score"].connect ((s, p) => { set_status_message
(status[StatusMessage.NONE].printf(game.score)); });
game.notify["status-message"].connect ((s, p) => { set_status_message
(status[game.status_message].printf(game.score)); });
set_status_message (status[game.status_message]);
@@ -118,7 +117,7 @@ private class GameWindow : ApplicationWindow
SimpleAction reset_background_action = (SimpleAction) lookup_action ("reset-bg");
game_view.notify ["background-color"].connect (() => { reset_background_action.set_enabled
(game_view.background_color != View.default_background_color); });
settings.bind (FiveOrMoreApp.KEY_BACKGROUND_COLOR, game_view, "background-color",
SettingsBindFlags.DEFAULT);
- grid_frame.add (game_view);
+ grid_frame.set_child (game_view);
init_scores_dialog ();
}
@@ -169,6 +168,14 @@ private class GameWindow : ApplicationWindow
headerbar.set_subtitle (message);
}
+ private void update_ratio (int size)
+ {
+ if (size == /* large */ 3)
+ grid_frame.ratio = 4.0f/3.0f;
+ else
+ grid_frame.ratio = 1.0f;
+ }
+
/*\
* * Scores dialog
\*/
@@ -270,6 +277,7 @@ private class GameWindow : ApplicationWindow
default: assert_not_reached ();
}
settings.set_int (FiveOrMoreApp.KEY_SIZE, size);
+ update_ratio (size);
}
private inline void new_game (/* SimpleAction action, Variant? parameter */)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]