[gnome-chess] Add a pause overlay



commit 0d75e6dbe8ff1519773bfb1f07070cb0a38b823c
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Aug 18 21:02:38 2013 -0500

    Add a pause overlay
    
    Hide the state of the board when paused, like Mahjongg and Mines

 src/chess-game.vala    |   14 ++++++++++++++
 src/chess-scene.vala   |   12 ++++++++++++
 src/chess-view-2d.vala |    7 +++++++
 src/chess-view-3d.vala |    9 +++++++++
 src/chess-view.vala    |   21 +++++++++++++++++++++
 src/gnome-chess.vala   |    2 +-
 6 files changed, 64 insertions(+), 1 deletions(-)
---
diff --git a/src/chess-game.vala b/src/chess-game.vala
index 9dc0360..53d3717 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -1269,10 +1269,14 @@ public class ChessGame
     public signal void started ();
     public signal void turn_started (ChessPlayer player);
     public signal void moved (ChessMove move);
+    public signal void superpaused ();
+    public signal void unpaused ();
     public signal void undo ();
     public signal void ended ();
 
     public bool is_paused { get; private set; default = false; }
+    /* Like normal pause, but also draw pause game overlay */
+    public bool is_superpaused { get; private set; default = false; }
     
     public ChessState current_state
     {
@@ -1508,12 +1512,22 @@ public class ChessGame
         }
     }
 
+    public void superpause ()
+    {
+        is_superpaused = true;
+        pause ();
+        /* Draw the pause game overlay */
+        superpaused ();
+    }
+
     public void unpause ()
     {
         if (clock != null && result == ChessResult.IN_PROGRESS && is_paused)
         {
             clock.unpause ();
             is_paused = false;
+            is_superpaused = false;
+            unpaused ();
         }
     }
 
diff --git a/src/chess-scene.vala b/src/chess-scene.vala
index a0407a8..5b635e6 100644
--- a/src/chess-scene.vala
+++ b/src/chess-scene.vala
@@ -93,6 +93,8 @@ public class ChessScene : Object
             selected_rank = -1;
             selected_file = -1;
             _game.moved.connect (moved_cb);
+            _game.superpaused.connect (paused_cb);
+            _game.unpaused.connect (unpaused_cb);
             _game.undo.connect (undo_cb);
             update_board ();
         }
@@ -236,6 +238,16 @@ public class ChessScene : Object
         update_board ();
     }
 
+    private void paused_cb (ChessGame game)
+    {
+        changed ();
+    }
+
+    private void unpaused_cb (ChessGame game)
+    {
+        changed ();
+    }
+
     private void undo_cb (ChessGame game)
     {
         update_board ();
diff --git a/src/chess-view-2d.vala b/src/chess-view-2d.vala
index 9ed2f33..bac0bf2 100644
--- a/src/chess-view-2d.vala
+++ b/src/chess-view-2d.vala
@@ -199,6 +199,13 @@ private class ChessView2D : ChessView
             c.restore ();
         }
 
+        /* Draw pause overlay */
+        if (scene.game.is_superpaused)
+        {
+            draw_paused_overlay (c);
+            return true;
+        }
+
         /* Draw the pieces */
         foreach (var model in scene.pieces)
         {
diff --git a/src/chess-view-3d.vala b/src/chess-view-3d.vala
index 048ea43..a857c1e 100644
--- a/src/chess-view-3d.vala
+++ b/src/chess-view-3d.vala
@@ -239,6 +239,15 @@ private class ChessView3D : ChessView
 
     public override bool draw (Cairo.Context c)
     {
+        if (scene.game.is_superpaused)
+        {
+            glXMakeCurrent (display, X.None, (GLX.Context) null);
+            c.translate (get_allocated_width () / 2, get_allocated_height () / 2);
+            c.rotate (Math.PI * scene.board_angle / 180.0);
+            draw_paused_overlay (c);
+            return true;
+        }
+
         GLfloat[] jitters = {0.0033922635f, 0.3317967229f, 0.2806016275f, -0.2495619123f, -0.273817106f, 
-0.086844639f};
 
         if (!start_gl ())
diff --git a/src/chess-view.vala b/src/chess-view.vala
index 98c4ded..e51354b 100644
--- a/src/chess-view.vala
+++ b/src/chess-view.vala
@@ -26,4 +26,25 @@ public abstract class ChessView : Gtk.DrawingArea
     {
         queue_draw ();
     }
+
+    protected void draw_paused_overlay (Cairo.Context c)
+    {
+        c.save ();
+
+        /* Have to be opaque since I haven't figured out how to hide the pieces in 3D view */
+        c.set_source_rgba (0, 0, 0, 1);
+        c.paint ();
+
+        c.select_font_face ("Sans", Cairo.FontSlant.NORMAL, Cairo.FontWeight.BOLD);
+        c.set_font_size (get_allocated_width () * 0.125);
+
+        var text = _("Paused");
+        Cairo.TextExtents extents;
+        c.text_extents (text, out extents);
+        c.move_to (-extents.width / 2.0, extents.height / 2.0);
+        c.set_source_rgb (1, 1, 1);
+        c.show_text (text);
+
+        c.restore ();
+    }
 }
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index c4ea29c..ba70e11 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -1259,7 +1259,7 @@ public class Application : Gtk.Application
         if (game.is_paused)
             game.unpause ();
         else
-            game.pause ();
+            game.superpause ();
 
         Gtk.ToolButton tool_button = (Gtk.ToolButton) pause_button;
 


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