[swell-foop/arnaudb/add---version: 2/6] No Clutter in SwellFoopWindow.



commit 95f4492890170aab7205c60b7cc4adab4f529332
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu May 14 16:34:51 2020 +0200

    No Clutter in SwellFoopWindow.

 src/game-view.vala | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/window.vala    | 41 +++++++++++------------------------
 2 files changed, 74 insertions(+), 30 deletions(-)
---
diff --git a/src/game-view.vala b/src/game-view.vala
index 1d98ecb..bb78710 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -17,7 +17,66 @@
 
 using Config;
 
-private class GameView : Clutter.Group
+private class GameView : GtkClutter.Embed
+{
+    private Clutter.Stage stage;
+    private GameGroup group;
+
+    construct
+    {
+        stage = (Clutter.Stage) get_stage ();
+        stage.background_color = Clutter.Color.from_string ("#000000");  /* background color is black */
+
+        group = new GameGroup ();
+        stage.add_child (group);
+
+        /* Request an appropriate size for the game view */
+        init_size ();
+    }
+
+    private void init_size ()
+    {
+        stage.set_size (group.width, group.height);
+        set_size_request ((int) stage.width, (int) stage.height);
+    }
+
+    /*\
+    * * proxy calls
+    \*/
+
+    internal void set_game (Game game)
+    {
+        group.game = game;
+        init_size ();
+    }
+
+    internal void set_theme_name (string theme_name)
+    {
+        group.theme_name = theme_name;
+    }
+
+    internal void set_is_zealous (bool is_zealous)
+    {
+        group.is_zealous = is_zealous;
+    }
+
+    internal void board_left_cb ()
+    {
+        group.board_left_cb ();
+    }
+
+    internal void cursor_move (int x, int y)
+    {
+        group.cursor_move (x, y);
+    }
+
+    internal void cursor_click ()
+    {
+        group.cursor_click ();
+    }
+}
+
+private class GameGroup : Clutter.Group
 {
     private TileActor? highlighted = null;
 
@@ -167,7 +226,7 @@ private class GameView : Clutter.Group
 
     internal bool is_zealous { private get; internal set; }
 
-    internal GameView ()
+    construct
     {
         /* Initialize the theme resources */
         themes = new HashTable<string, Theme> (str_hash, str_equal);
diff --git a/src/window.vala b/src/window.vala
index 88731ed..2359dfc 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -34,9 +34,6 @@ private class SwellFoopWindow : ApplicationWindow
     /* Rendering of game */
     private GameView view;
 
-    private Clutter.Stage stage;
-    private GtkClutter.Embed clutter_embed;
-
     private bool game_in_progress = false;
 
     /* Store size options */
@@ -83,7 +80,7 @@ private class SwellFoopWindow : ApplicationWindow
         add_action (settings.create_action ("size"));
 
         add_action (settings.create_action ("zealous"));
-        settings.changed ["zealous"].connect ((_settings, _key_name) => { view.is_zealous = 
_settings.get_boolean (_key_name); });
+        settings.changed ["zealous"].connect ((_settings, _key_name) => { view.set_is_zealous 
(_settings.get_boolean (_key_name)); });
 
         string theme = settings.get_string ("theme");
         if (theme != "colors" && theme != "shapesandcolors")
@@ -103,19 +100,19 @@ private class SwellFoopWindow : ApplicationWindow
         update_score_cb (0);
 
         /* Create a clutter renderer widget */
-        clutter_embed = new GtkClutter.Embed ();
-        clutter_embed.show ();
+        view = new GameView ();
+        view.show ();
         var first_run = settings.get_boolean ("first-run");
 
         if (first_run)
         {
             var stack = build_first_run_stack ();
-            stack.add_named (clutter_embed, "game");
+            stack.add_named (view, "game");
             main_box.pack_start (stack, true, true);
         }
         else
         {
-            main_box.pack_start (clutter_embed, true, true);
+            main_box.pack_start (view, true, true);
             init_keyboard ();
         }
     }
@@ -124,9 +121,6 @@ private class SwellFoopWindow : ApplicationWindow
     {
         Object (application: application, settings: settings);
 
-        stage = (Clutter.Stage) clutter_embed.get_stage ();
-        stage.background_color = Clutter.Color.from_string ("#000000");  /* background color is black */
-
         /* Create an instance of game, either with a saved game, or with initial values for row, column and 
color */
         Size size = get_board_size ();
         game = new Game (size.rows, size.columns, settings.get_int ("colors"), settings.get_value 
("saved-game"));
@@ -139,16 +133,10 @@ private class SwellFoopWindow : ApplicationWindow
         game.complete.connect (complete_cb);
         game.started.connect (started_cb);
 
-        /* Create an instance of game view. This follow the Model-View-Controller paradigm */
-        view = new GameView ();
         /* Initialize the themes needed by actors */
-        view.theme_name = settings.get_string ("theme");
-        view.is_zealous = settings.get_boolean ("zealous");
-        view.game = game;
-        stage.add_child (view);
-        /* Request an appropriate size for the game view */
-        stage.set_size (view.width, view.height);
-        clutter_embed.set_size_request ((int) stage.width, (int) stage.height);
+        view.set_theme_name (settings.get_string ("theme"));
+        view.set_is_zealous (settings.get_boolean ("zealous"));
+        view.set_game (game);
 
         /* When the mouse leaves the window we need to update the view */
         init_motion ();
@@ -233,12 +221,9 @@ private class SwellFoopWindow : ApplicationWindow
         game.update_score.connect (update_score_cb);
         game.complete.connect (complete_cb);
         game.started.connect (started_cb);
-        view.theme_name = settings.get_string ("theme");
-        view.game = game;
-        view.is_zealous = settings.get_boolean ("zealous");
-
-        stage.set_size (view.width, view.height);
-        clutter_embed.set_size_request ((int) stage.width, (int) stage.height);
+        view.set_theme_name (settings.get_string ("theme"));
+        view.set_is_zealous (settings.get_boolean ("zealous"));
+        view.set_game (game);
 
         game_in_progress = false;
 
@@ -270,7 +255,7 @@ private class SwellFoopWindow : ApplicationWindow
     {
         string new_theme = ((!) variant).get_string ();
         action.set_state ((!) variant);
-        view.theme_name = new_theme;
+        view.set_theme_name (new_theme);
         if (settings.get_string ("theme") != new_theme)
             settings.set_string ("theme", new_theme);
     }
@@ -507,7 +492,7 @@ private class SwellFoopWindow : ApplicationWindow
 
     private inline void init_motion ()
     {
-        motion_controller = new EventControllerMotion (clutter_embed);
+        motion_controller = new EventControllerMotion (view);
         motion_controller.set_propagation_phase (PropagationPhase.CAPTURE);
         motion_controller.leave.connect (view.board_left_cb);
     }


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