[five-or-more/arnaudb/wip/gtk4: 26/28] Use an AspectFrame.



commit b11588c2acac84cd49499edffad4380249e33d2a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Mar 27 15:40:32 2020 +0100

    Use an AspectFrame.

 data/five-or-more.ui | 11 ++++++++++-
 src/view.vala        |  5 +++++
 src/window.vala      |  4 +---
 3 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/data/five-or-more.ui b/data/five-or-more.ui
index 5606ade..46c6909 100644
--- a/data/five-or-more.ui
+++ b/data/five-or-more.ui
@@ -90,7 +90,16 @@
       </object>
     </child>
     <child>
-      <object class="GamesGridFrame" id="grid_frame"/>
+      <object class="GtkAspectFrame" id="grid_frame">
+        <property name="shadow-type">none</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 8f673af..417a003 100644
--- a/src/view.vala
+++ b/src/view.vala
@@ -326,6 +326,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 inline void on_size_allocate (int width, int height)
@@ -427,9 +429,12 @@ private class View : DrawingArea
             return;
 
         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 0a33199..5c8dc4b 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -36,7 +36,7 @@ private class GameWindow : ApplicationWindow
     private MenuButton primary_menu_button;
 
     [GtkChild]
-    private Games.GridFrame grid_frame;
+    private AspectFrame grid_frame;
 
     public GLib.Settings settings { private get; protected construct; }
     private bool window_tiled;
@@ -70,8 +70,6 @@ private class GameWindow : ApplicationWindow
         NextPiecesWidget next_pieces_widget = new NextPiecesWidget (settings, game, theme);
         preview_hbox.add (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]);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]