[gnome-games] chess: Add back animation



commit 01af2e4b1082a75b52d4e011b5c92b9f453a24d3
Author: Robert Ancell <robert ancell canonical com>
Date:   Sat Feb 19 17:54:50 2011 +1100

    chess: Add back animation

 glchess/src/Makefile.am             |    2 +-
 glchess/src/chess-game.vala         |   54 +++++--
 glchess/src/chess-scene.vala        |  303 +++++++++++++++++++++++++++++++++++
 glchess/src/chess-view-2d.vala      |   77 +++++-----
 glchess/src/chess-view-3d.vala      |   59 ++++---
 glchess/src/chess-view-options.vala |  134 ---------------
 glchess/src/chess-view.vala         |   12 +-
 glchess/src/glchess.vala            |   54 +++---
 8 files changed, 452 insertions(+), 243 deletions(-)
---
diff --git a/glchess/src/Makefile.am b/glchess/src/Makefile.am
index 2fb8831..2621357 100644
--- a/glchess/src/Makefile.am
+++ b/glchess/src/Makefile.am
@@ -17,10 +17,10 @@ glchess_SOURCES = \
 	chess-engine-uci.vala \
 	chess-game.vala \
 	chess-pgn.vala \
+	chess-scene.vala \
 	chess-view.vala \
 	chess-view-2d.vala \
 	chess-view-3d.vala \
-	chess-view-options.vala \
 	history.vala
 
 test_chess_game_SOURCES = \
diff --git a/glchess/src/chess-game.vala b/glchess/src/chess-game.vala
index 8d1bd3b..f2ab88d 100644
--- a/glchess/src/chess-game.vala
+++ b/glchess/src/chess-game.vala
@@ -777,12 +777,14 @@ public class ChessState
                 return ChessResult.WHITE_WON;
             }
         }
-        else if (!can_move (current_player))
+
+        if (!can_move (current_player))
         {
             rule = ChessRule.STALEMATE;
             return ChessResult.DRAW;
         }
-        else if (last_move.victim != null && !have_sufficient_material ())
+
+        if (last_move != null && last_move.victim != null && !have_sufficient_material ())
         {
             rule = ChessRule.INSUFFICIENT_MATERIAL;
             return ChessResult.DRAW;
@@ -1161,6 +1163,8 @@ public class ChessGame
     public ChessResult result;
     public ChessRule rule;
     public List<ChessState> move_stack;
+    
+    private int hold_count = 0;
 
     public const string STANDARD_SETUP = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
 
@@ -1169,22 +1173,27 @@ public class ChessGame
     public signal void moved (ChessMove move);
     public signal void undo ();
     public signal void ended ();
+    
+    public ChessState current_state
+    {
+       get { return move_stack.data; }
+    }
 
     public ChessPlayer white
     {
-        get { return move_stack.data.players[Color.WHITE]; }
+        get { return current_state.players[Color.WHITE]; }
     }
     public ChessPlayer black
     {
-        get { return move_stack.data.players[Color.BLACK]; }
+        get { return current_state.players[Color.BLACK]; }
     }
     public ChessPlayer current_player
     {
-        get { return move_stack.data.current_player; }
+        get { return current_state.current_player; }
     }
     public ChessPlayer opponent
     {
-        get { return move_stack.data.opponent; }
+        get { return current_state.opponent; }
     }
     private ChessClock? _clock;
     public ChessClock? clock
@@ -1236,7 +1245,7 @@ public class ChessGame
         if (player != current_player)
             return false;
 
-        var state = move_stack.data.copy ();
+        var state = current_state.copy ();
         state.number++;
         if (!state.move (move, apply))
             return false;
@@ -1251,9 +1260,33 @@ public class ChessGame
         if (state.last_move.moved_rook != null)
             state.last_move.moved_rook.moved ();
         moved (state.last_move);
+        complete_move ();
 
+        return true;
+    }
+
+    public void add_hold ()
+    {
+        hold_count++;
+    }
+
+    public void remove_hold ()
+    {
+        return_if_fail (hold_count > 0);
+
+        hold_count--;
+        if (hold_count == 0)
+            complete_move ();
+    }
+
+    private void complete_move ()
+    {
+        /* Wait until the hold is removed */
+        if (hold_count > 0)
+            return;
+            
         ChessRule rule;
-        var result = state.get_result (out rule);
+        var result = current_state.get_result (out rule);
         if (result != ChessResult.IN_PROGRESS)
         {
             stop (result, rule);
@@ -1265,8 +1298,6 @@ public class ChessGame
             current_player.start_turn ();
             turn_started (current_player);
         }
-
-        return true;
     }
 
     private void undo_cb (ChessPlayer player)
@@ -1302,7 +1333,7 @@ public class ChessGame
         if (!is_started)
             return false;
 
-        if (move_stack.data.halfmove_clock >= 50)
+        if (current_state.halfmove_clock >= 50)
             stop (ChessResult.DRAW, ChessRule.FIFTY_MOVES);
         else if (is_three_fold_repeat ())
             stop (ChessResult.DRAW, ChessRule.THREE_FOLD_REPETITION);
@@ -1375,7 +1406,6 @@ public class ChessGame
     {
         var count = 1;
 
-        var current_state = move_stack.data;
         foreach (var state in move_stack.next)
         {
             if (current_state.equals (state))
diff --git a/glchess/src/chess-scene.vala b/glchess/src/chess-scene.vala
new file mode 100644
index 0000000..bbd8d1d
--- /dev/null
+++ b/glchess/src/chess-scene.vala
@@ -0,0 +1,303 @@
+public class ChessModel
+{
+    public ChessPiece piece;
+    public double x;
+    public double y;
+    public double target_x;
+    public double target_y;
+    public bool under_threat;
+
+    public bool moving 
+    {
+        get { return x != target_x || y != target_y; }
+    }
+
+    public ChessModel (ChessPiece piece, double x, double y)
+    {
+        this.piece = piece;
+        this.x = this.target_x = x;
+        this.y = this.target_y = y;        
+    }
+
+    public bool move_to (double x, double y)
+    {
+        if (target_x == x && target_y == y)
+            return false;
+
+        target_x = x;
+        target_y = y;
+
+        return true;
+    }
+
+    public bool animate (double timestep)
+    {
+        if (!moving)
+            return false;
+
+        x = update_position (timestep, x, target_x);
+        y = update_position (timestep, y, target_y);
+        return true;
+    }
+
+    private double update_position (double timestep, double value, double target)
+    {
+        var distance = Math.fabs (target - value);
+        var step = timestep * 4.0;
+
+        if (step > distance)
+            step = distance;
+
+        if (target > value)
+            return value + step;
+        else
+            return value - step;
+    }
+}
+
+public class ChessScene : Object
+{
+    public List<ChessModel> pieces = null;
+
+    public bool animating = false;
+    private Timer animation_timer;
+    private double animation_time;
+
+    public signal void changed ();
+
+    public int selected_rank = -1;
+    public int selected_file = -1;
+
+    private ChessGame? _game = null;
+    public ChessGame? game
+    {
+        get { return _game; }
+        set
+        {
+            _game = value;
+            selected_rank = -1;
+            selected_file = -1;
+            _game.moved.connect (moved_cb);
+            update_board ();
+        }
+    }
+
+    public ChessPiece? get_selected_piece ()
+    {
+        if (game == null || selected_rank < 0)
+            return null;
+        return game.get_piece (selected_rank, selected_file, move_number);
+    }
+
+    private int _move_number = -1;
+    public int move_number
+    {
+        get { return _move_number; }
+        set
+        {
+            if (_move_number == value)
+                return;
+            _move_number = value;
+            update_board ();
+        }
+    }
+
+    private bool _show_numbering = true;
+    public bool show_numbering
+    {
+         get { return _show_numbering; }
+         set { _show_numbering = value; changed (); }
+    }
+
+    private bool _show_move_hints = true;
+    public bool show_move_hints
+    {
+         get { return _show_move_hints; }
+         set { _show_move_hints = value; changed (); }
+    }
+
+    private string _theme_name = "simple";
+    public string theme_name
+    {
+        get { return _theme_name; }
+        set { _theme_name = value; changed (); }
+    }
+
+    private bool _show_3d_smooth = false;
+    public bool show_3d_smooth
+    {
+         get { return _show_3d_smooth; }
+         set { _show_3d_smooth = value; changed (); }
+    }
+
+    private string _board_side = "human";
+    public string board_side
+    {
+         get { return _board_side; }
+         set { _board_side = value; changed (); }
+    }
+
+    public double board_angle
+    {
+         get
+         {
+             switch (board_side)
+             {
+             default:
+             case "white":
+             case "facetoface":
+                 return 0.0;
+             case "black":
+                 return 180.0;
+             case "human":
+                 return 0.0; // FIXME
+             case "current":
+                 return game.current_player.color == Color.WHITE ? 0.0 : 180.0;
+             }
+         }
+    }
+
+    private string _move_format = "human";
+    public string move_format
+    {
+        get { return _move_format; }
+        set { _move_format = value; changed (); }
+    }
+    
+    public ChessScene ()
+    {
+        animation_timer = new Timer ();
+    }
+
+    public void select_square (int file, int rank)
+    {
+        if (game == null)
+            return;
+
+        /* Can only control when showing the current move */
+        if (move_number != -1)
+            return;
+
+        ChessPiece? piece = game.get_piece (rank, file, move_number);
+
+        /* Deselect by clicking on the same square */
+        if (file == selected_file && rank == selected_rank)
+        {
+            selected_rank = selected_file = -1;
+        }
+        /* Select new piece */
+        else if (piece != null && piece.player == game.current_player)
+        {
+            selected_rank = rank;
+            selected_file = file;
+        }
+        /* Move to this square */
+        else if (selected_file != -1)
+        {
+            if (game.current_player.move_with_coords(selected_rank, selected_file, rank, file))
+                selected_rank = selected_file = -1;            
+        }
+        
+        update_board ();
+        changed ();
+    }
+
+    private void moved_cb (ChessGame game, ChessMove move)
+    {
+        update_board ();
+    }
+    
+    private ChessModel? find_model (ChessPiece piece)
+    {
+        foreach (var model in pieces)
+            if (model.piece == piece)
+                return model;
+        return null;
+    }
+
+    private void update_board ()
+    {
+        if (game == null)
+            return;
+
+        var board_changed = false;
+        var need_animation = false;
+        List<ChessModel> new_pieces = null;
+        for (int rank = 0; rank < 8; rank++)
+        {
+            for (int file = 0; file < 8; file++)
+            {
+                var piece = game.get_piece (rank, file, move_number);
+                if (piece == null)
+                    continue;
+                var model = find_model (piece);
+                if (model == null)
+                {
+                    model = new ChessModel (piece, (double) file, (double) rank);
+                    board_changed = true;
+                }
+
+                if (model.move_to ((double) file, (double) rank))
+                {
+                    board_changed = true;
+                    need_animation = true;
+                }
+
+                model.under_threat = false;
+                if (selected_rank > 0 &&
+                    game.current_player.move_with_coords (selected_rank, selected_file, rank, file, false))
+                    model.under_threat = true;
+
+                new_pieces.append (model);
+            }
+        }
+        /* If only removed pieces then the lengths will be different */
+        if (new_pieces.length () != pieces.length ())
+            board_changed = true;
+
+        if (!board_changed)
+            return;
+            
+        /* Have to do this as Vala can't assign the value, and copy doesn't ref the objects */
+        pieces = null;
+        foreach (var model in new_pieces)
+            pieces.append (model);
+        changed ();
+
+        if (need_animation && !animating)
+        {
+            animating = true;
+            animation_timer.start ();
+            animation_time = 0;
+            game.add_hold ();
+
+            /* Animate every 10ms (up to 100fps) */
+            Timeout.add (10, animate_cb);
+        }
+    }
+
+    private bool animate_cb ()
+    {
+        /* Get the duration since the last tick */
+        var old_time = animation_time;
+        animation_time = animation_timer.elapsed ();
+        var timestep = animation_time - old_time;
+
+        var animate_count = 0;
+        foreach (var model in pieces)
+        {
+            if (model.animate (timestep))
+                animate_count++;
+        }
+        animating = animate_count > 0;
+
+        changed ();
+
+        if (animating)
+            return true;
+
+        animating = false;
+        game.remove_hold ();
+        return false;
+    }
+}
diff --git a/glchess/src/chess-view-2d.vala b/glchess/src/chess-view-2d.vala
index 9981882..290a2e8 100644
--- a/glchess/src/chess-view-2d.vala
+++ b/glchess/src/chess-view-2d.vala
@@ -11,7 +11,7 @@ private class ChessView2D : ChessView
     {
         get { return square_size / 2; }
     }
-    
+
     public ChessView2D ()
     {
         add_events (Gdk.EventMask.BUTTON_PRESS_MASK);
@@ -35,7 +35,7 @@ private class ChessView2D : ChessView
         Rsvg.Handle handle;
         try
         {
-            handle = new Rsvg.Handle.from_file (Path.build_filename (Config.PKGDATADIR, "pieces", options.theme_name, name + ".svg", null));
+            handle = new Rsvg.Handle.from_file (Path.build_filename (Config.PKGDATADIR, "pieces", scene.theme_name, name + ".svg", null));
         }
         catch (Error e)
         {
@@ -59,7 +59,7 @@ private class ChessView2D : ChessView
     private void load_theme ()
     {
         /* Skip if already loaded */
-        if (options.theme_name == loaded_theme_name && model_surface != null && square_size == model_surface.get_height ())
+        if (scene.theme_name == loaded_theme_name && model_surface != null && square_size == model_surface.get_height ())
             return;
 
         model_surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 12 * square_size, square_size);
@@ -80,7 +80,7 @@ private class ChessView2D : ChessView
         render_piece (c1, c2, "blackQueen", 10);
         render_piece (c1, c2, "blackKing", 11);
 
-        loaded_theme_name = options.theme_name;
+        loaded_theme_name = scene.theme_name;
     }
 
     public override bool draw (Cairo.Context c)
@@ -89,15 +89,15 @@ private class ChessView2D : ChessView
 
         c.translate (get_allocated_width () / 2, get_allocated_height () / 2);
         //c.scale (s, s);
-        c.rotate (Math.PI * options.board_angle / 180.0);
+        c.rotate (Math.PI * scene.board_angle / 180.0);
 
         int bord_size = (int) Math.ceil (square_size * 4 + border_size);
         c.set_source_rgb (0x2e/255.0, 0x34/255.0, 0x36/255.0);
         c.rectangle (-bord_size, -bord_size, bord_size * 2, bord_size * 2);
         c.fill ();
 
-        var selected_piece = options.get_selected_piece ();
-        if (options.move_number != -1)
+        var selected_piece = scene.get_selected_piece ();
+        if (scene.move_number != -1)
             selected_piece = null;
         int selected_offset = 0;
         if (selected_piece != null)
@@ -123,7 +123,7 @@ private class ChessView2D : ChessView
             }
         }
 
-        if (options.show_numbering)
+        if (scene.show_numbering)
         {
             string[] files = { "a", "b", "c", "d", "e", "f", "g", "h" };
             string[] ranks = { "8", "7", "6", "5", "4", "3", "2", "1" };
@@ -180,46 +180,47 @@ private class ChessView2D : ChessView
             }
         }
 
-        if (options.game == null)
-            return true;
+        /* Draw the pieces */
+        foreach (var model in scene.pieces)
+        {
+            c.save ();
+            c.translate ((model.x - 4) * square_size, (3 - model.y) * square_size);
+            c.translate (square_size / 2, square_size / 2);
+            c.rotate (-Math.PI * scene.board_angle / 180.0);
+
+            draw_piece (c,
+                        model.piece == selected_piece ? selected_model_surface : model_surface,
+                        model.piece, model.under_threat && scene.show_move_hints ? 0.8 : 1.0);
+
+            c.restore ();
+        }
 
+        /* Draw shadow piece on squares that can be moved to */
         for (int rank = 0; rank < 8; rank++)
         {
             for (int file = 0; file < 8; file++)
             {
-                c.save ();
-                c.translate ((file - 4) * square_size, (3 - rank) * square_size);
-                c.translate (square_size / 2, square_size / 2);
-                c.rotate (-Math.PI * options.board_angle / 180.0);
-
-                bool can_take = false;
-                if (selected_piece != null && options.show_move_hints &&
-                    selected_piece.player.move_with_coords (options.selected_rank, options.selected_file, rank, file, false))
-                    can_take = true;
-
-                /* Draw the piece in this square */
-                ChessPiece? piece = options.game.get_piece (rank, file, options.move_number);
-                if (piece != null)
-                    draw_piece (c,
-                                piece == selected_piece ? selected_model_surface : model_surface,
-                                piece, can_take ? 0.8 : 1.0);
-
-                /* Draw shadow piece on squares that can be moved to */
-                if (can_take)
+                if (scene.move_number == -1 && selected_piece != null && scene.show_move_hints &&
+                    selected_piece.player.move_with_coords (scene.selected_rank, scene.selected_file, rank, file, false))
+                {
+                    c.save ();
+                    c.translate ((file - 4) * square_size, (3 - rank) * square_size);
+                    c.translate (square_size / 2, square_size / 2);
+                    c.rotate (-Math.PI * scene.board_angle / 180.0);
+
                     draw_piece (c, model_surface, selected_piece, 0.1);
 
-                c.restore ();
+                    c.restore ();
+                }
             }
         }
- 
+
         return true;
     }
     
     private void draw_piece (Cairo.Context c, Cairo.ImageSurface surface, ChessPiece piece, double alpha)
     {
-        c.save ();
-        
-        if (options.board_side == "facetoface" && piece.color == Color.BLACK)
+        if (scene.board_side == "facetoface" && piece.color == Color.BLACK)
             c.rotate (Math.PI);
 
         var size = surface.get_height ();
@@ -232,20 +233,18 @@ private class ChessView2D : ChessView
         c.rectangle (0, 0, size, size);
         c.clip ();
         c.paint_with_alpha (alpha);
-
-        c.restore ();
     }
 
     public override bool button_press_event (Gdk.EventButton event)
     {
-        if (options.game == null || event.button != 1)
+        if (scene.game == null || event.button != 1)
             return false;
 
         int file = (int) Math.floor((event.x - 0.5 * get_allocated_width () + square_size * 4) / square_size);
         int rank = 7 - (int) Math.floor((event.y - 0.5 * get_allocated_height () + square_size * 4) / square_size);
 
         // FIXME: Use proper Cairo rotation matrix
-        if (options.board_angle == 180.0)
+        if (scene.board_angle == 180.0)
         {
             rank = 7 - rank;
             file = 7 - file;
@@ -254,7 +253,7 @@ private class ChessView2D : ChessView
         if (file < 0 || file >= 8 || rank < 0 || rank >= 8)
             return false;
 
-        options.select_square (file, rank);
+        scene.select_square (file, rank);
 
         return true;
     }
diff --git a/glchess/src/chess-view-3d.vala b/glchess/src/chess-view-3d.vala
index 115a773..7f902c0 100644
--- a/glchess/src/chess-view-3d.vala
+++ b/glchess/src/chess-view-3d.vala
@@ -235,7 +235,7 @@ private class ChessView3D : ChessView
             return true;
 
         var n_passes = 1;
-        if (options.show_3d_smooth)
+        if (scene.show_3d_smooth)
         {
             glClear (GL_ACCUM_BUFFER_BIT);
             n_passes = 3;
@@ -251,7 +251,7 @@ private class ChessView3D : ChessView
 
             glMatrixMode (GL_PROJECTION);
             glLoadIdentity ();
-            if (options.show_3d_smooth)
+            if (scene.show_3d_smooth)
                 accPerspective (60.0f, (float) get_allocated_width () / get_allocated_height (), 0.1f, 1000, jitters[i*2], jitters[i*2+1], 0, 0, 1);
             else
                 gluPerspective (60.0f, (float) get_allocated_width () / get_allocated_height (), 0.1f, 1000);
@@ -265,7 +265,7 @@ private class ChessView3D : ChessView
             glEnable (GL_LIGHT0);
 
             glPushMatrix ();
-            glRotatef ((GLfloat) options.board_angle, 0.0f, 1.0f, 0.0f);
+            glRotatef ((GLfloat) scene.board_angle, 0.0f, 1.0f, 0.0f);
             glTranslatef (-OFFSET, 0.0f, OFFSET);
 
             draw_board ();
@@ -274,11 +274,11 @@ private class ChessView3D : ChessView
 
             glPopMatrix ();
 
-            if (options.show_3d_smooth)
+            if (scene.show_3d_smooth)
                 glAccum (GL_ACCUM, 1.0f / n_passes);
         }
 
-        if (options.show_3d_smooth)
+        if (scene.show_3d_smooth)
             glAccum (GL_RETURN, 1);
 
         glXSwapBuffers (display, drawable);
@@ -396,42 +396,53 @@ private class ChessView3D : ChessView
 
     private void draw_pieces ()
     {
-        if (options.game == null)
+        if (scene.game == null)
             return;
 
         glEnable (GL_DEPTH_TEST);
         glEnable (GL_TEXTURE_2D);
         glBindTexture (GL_TEXTURE_2D, piece_texture);
 
-        var selected_piece = options.get_selected_piece ();
+        var selected_piece = scene.get_selected_piece ();
+
+        /* Draw the pieces */
+        foreach (var model in scene.pieces)
+        {
+            glPushMatrix ();
+            glTranslatef (BOARD_BORDER + (GLfloat) model.x * SQUARE_WIDTH + SQUARE_WIDTH / 2,
+                          0.0f,
+                          -(BOARD_BORDER + (GLfloat) model.y * SQUARE_WIDTH + SQUARE_WIDTH / 2));
+
+            /* Raise the selected piece up */
+            if (model.piece == selected_piece)
+                glTranslatef (0.0f, SQUARE_WIDTH * 0.4f, 0.0f);
+
+            render_piece (model.piece);
+
+            glPopMatrix ();
+        }
+
+        /* Draw shadow piece on squares that can be moved to */
         for (int rank = 0; rank < 8; rank++)
         {
             for (int file = 0; file < 8; file++)
             {
-                glPushMatrix ();
-                glTranslatef (BOARD_BORDER + file * SQUARE_WIDTH + SQUARE_WIDTH / 2, 0.0f, -(BOARD_BORDER + rank * SQUARE_WIDTH + SQUARE_WIDTH / 2));
-
-                ChessPiece? piece = options.game.get_piece (rank, file, options.move_number);
-                if (piece != null)
+                if (scene.move_number == -1 && scene.show_move_hints && selected_piece != null && selected_piece.player.move_with_coords (scene.selected_rank, scene.selected_file, rank, file, false))
                 {
                     glPushMatrix ();
-                    if (piece == selected_piece)
-                        glTranslatef (0.0f, SQUARE_WIDTH * 0.4f, 0.0f);
-                    render_piece (piece);
-                    glPopMatrix ();
-                }
+                    glTranslatef (BOARD_BORDER + file * SQUARE_WIDTH + SQUARE_WIDTH / 2,
+                                  0.0f,
+                                  -(BOARD_BORDER + rank * SQUARE_WIDTH + SQUARE_WIDTH / 2));
 
-                if (options.move_number == -1 && options.show_move_hints && selected_piece != null && selected_piece.player.move_with_coords (options.selected_rank, options.selected_file, rank, file, false))
-                {
                     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                     glEnable (GL_BLEND);
                     glDisable (GL_DEPTH_TEST);
                     render_piece (selected_piece, 0.1f);
                     glEnable (GL_DEPTH_TEST);
                     glDisable (GL_BLEND);
-                }
 
-                glPopMatrix ();
+                    glPopMatrix ();
+                }
             }
         }
 
@@ -485,7 +496,7 @@ private class ChessView3D : ChessView
 
     public override bool button_press_event (Gdk.EventButton event)
     {
-        if (options.game == null || event.button != 1)
+        if (scene.game == null || event.button != 1)
             return false;
 
         if (!start_gl ())
@@ -509,7 +520,7 @@ private class ChessView3D : ChessView
         glMatrixMode (GL_MODELVIEW);
         glLoadIdentity ();
         transform_camera ();
-        glRotatef ((GLfloat) options.board_angle, 0.0f, 1.0f, 0.0f);
+        glRotatef ((GLfloat) scene.board_angle, 0.0f, 1.0f, 0.0f);
         glTranslatef (-OFFSET, 0.0f, OFFSET);
         for (var rank = 0; rank < 8; rank++)
         {
@@ -544,7 +555,7 @@ private class ChessView3D : ChessView
         {
             var rank = buffer[3];
             var file = buffer[4];
-            options.select_square (file, rank);
+            scene.select_square (file, rank);
         }
 
         return true;
diff --git a/glchess/src/chess-view.vala b/glchess/src/chess-view.vala
index 2c617f5..9d3c648 100644
--- a/glchess/src/chess-view.vala
+++ b/glchess/src/chess-view.vala
@@ -1,18 +1,18 @@
 public class ChessView : Gtk.DrawingArea
 {
-    private ChessViewOptions _options;
-    public ChessViewOptions options
+    private ChessScene _scene;
+    public ChessScene scene
     {
-        get { return _options; }
+        get { return _scene; }
         set
         {
-            _options = value;
-            _options.changed.connect (options_changed_cb);
+            _scene = value;
+            _scene.changed.connect (scene_changed_cb);
             queue_draw ();
         }
     }
 
-    private void options_changed_cb (ChessViewOptions options)
+    private void scene_changed_cb (ChessScene scene)
     {
         queue_draw ();
     }
diff --git a/glchess/src/glchess.vala b/glchess/src/glchess.vala
index 10854b2..e0506ca 100644
--- a/glchess/src/glchess.vala
+++ b/glchess/src/glchess.vala
@@ -12,7 +12,7 @@ public class Application
     private Gtk.Label info_title_label;
     private Gtk.Label info_label;
     private Gtk.Container view_container;
-    private ChessViewOptions view_options;
+    private ChessScene scene;
     private ChessView view;
     private Gtk.Widget undo_menu;
     private Gtk.Widget undo_button;
@@ -102,14 +102,14 @@ public class Application
         info_label.show ();
         vbox.pack_start (info_label, true, true, 0);
 
-        view_options = new ChessViewOptions ();
-        view_options.changed.connect (options_changed_cb);
-        settings.bind ("show-move-hints", view_options, "show-move-hints", SettingsBindFlags.GET);
-        settings.bind ("show-numbering", view_options, "show-numbering", SettingsBindFlags.GET);
-        settings.bind ("piece-theme", view_options, "theme-name", SettingsBindFlags.GET);
-        settings.bind ("show-3d-smooth", view_options, "show-3d-smooth", SettingsBindFlags.GET);
-        settings.bind ("move-format", view_options, "move-format", SettingsBindFlags.GET);
-        settings.bind ("board-side", view_options, "board-side", SettingsBindFlags.GET);
+        scene = new ChessScene ();
+        scene.changed.connect (scene_changed_cb);
+        settings.bind ("show-move-hints", scene, "show-move-hints", SettingsBindFlags.GET);
+        settings.bind ("show-numbering", scene, "show-numbering", SettingsBindFlags.GET);
+        settings.bind ("piece-theme", scene, "theme-name", SettingsBindFlags.GET);
+        settings.bind ("show-3d-smooth", scene, "show-3d-smooth", SettingsBindFlags.GET);
+        settings.bind ("move-format", scene, "move-format", SettingsBindFlags.GET);
+        settings.bind ("board-side", scene, "board-side", SettingsBindFlags.GET);
 
         settings.changed.connect (settings_changed_cb);
         settings_changed_cb (settings, "show-3d");
@@ -168,7 +168,7 @@ public class Application
             else
                 view = new ChessView2D ();
             view.set_size_request (300, 300);
-            view.options = view_options;
+            view.scene = scene;
             view_container.add (view);
             view.show ();
         }
@@ -179,7 +179,7 @@ public class Application
         if (game == null)
             return;
 
-        var move_number = view_options.move_number;
+        var move_number = scene.move_number;
         var n_moves = (int) game.n_moves;
         if (move_number < 0)
             move_number += 1 + n_moves;
@@ -205,7 +205,7 @@ public class Application
         history_combo.set_active (move_number);
     }
 
-    private void options_changed_cb (ChessViewOptions options)
+    private void scene_changed_cb (ChessScene scene)
     {
         update_history_panel ();
     }
@@ -270,7 +270,7 @@ public class Application
         if (game.clock != null)
             game.clock.tick.connect (game_clock_tick_cb);
 
-        view_options.game = game;
+        scene.game = game;
         info_bar.hide ();
         save_menu.sensitive = false;
         save_as_menu.sensitive = false;
@@ -586,7 +586,7 @@ public class Application
                                              N_("Black king at %1$s takes the white queen at %2$s")};
 
         var move_text = "";
-        switch (view_options.move_format)
+        switch (scene.move_format)
         {
         case "human":
             int index;
@@ -641,7 +641,7 @@ public class Application
         set_move_text (iter, move);
 
         /* Follow the latest move */
-        if (move.number == game.n_moves && view_options.move_number == -1)
+        if (move.number == game.n_moves && scene.move_number == -1)
             history_combo.set_active_iter (iter);
 
         save_menu.sensitive = true;
@@ -670,7 +670,7 @@ public class Application
         model.remove (iter);
 
         /* If watching this move, go back one */
-        if (view_options.move_number > game.n_moves || view_options.move_number == -1)
+        if (scene.move_number > game.n_moves || scene.move_number == -1)
         {
             model.iter_nth_child (out iter, null, model.iter_n_children (null) - 1);
             history_combo.set_active_iter (iter);
@@ -928,44 +928,44 @@ public class Application
         combo.model.get (iter, 1, out move_number, -1);
         if (game == null || move_number == game.n_moves)
             move_number = -1;
-        view_options.move_number = move_number;
+        scene.move_number = move_number;
     }
 
     [CCode (cname = "G_MODULE_EXPORT history_latest_clicked_cb", instance_pos = -1)]
     public void history_latest_clicked_cb (Gtk.Widget widget)
     {
-        view_options.move_number = -1;
+        scene.move_number = -1;
     }
 
     [CCode (cname = "G_MODULE_EXPORT history_next_clicked_cb", instance_pos = -1)]
     public void history_next_clicked_cb (Gtk.Widget widget)
     {
-        if (view_options.move_number == -1)
+        if (scene.move_number == -1)
             return;
 
-        int move_number = view_options.move_number + 1;
+        int move_number = scene.move_number + 1;
         if (move_number >= game.n_moves)
-            view_options.move_number = -1;
+            scene.move_number = -1;
         else
-            view_options.move_number = move_number;
+            scene.move_number = move_number;
     }
 
     [CCode (cname = "G_MODULE_EXPORT history_previous_clicked_cb", instance_pos = -1)]
     public void history_previous_clicked_cb (Gtk.Widget widget)
     {
-        if (view_options.move_number == 0)
+        if (scene.move_number == 0)
             return;
 
-        if (view_options.move_number == -1)
-            view_options.move_number = (int) game.n_moves - 1;
+        if (scene.move_number == -1)
+            scene.move_number = (int) game.n_moves - 1;
         else
-            view_options.move_number = view_options.move_number - 1;
+            scene.move_number = scene.move_number - 1;
     }
 
     [CCode (cname = "G_MODULE_EXPORT history_start_clicked_cb", instance_pos = -1)]
     public void history_start_clicked_cb (Gtk.Widget widget)
     {
-        view_options.move_number = 0;
+        scene.move_number = 0;
     }
 
     [CCode (cname = "G_MODULE_EXPORT toggle_fullscreen_cb", instance_pos = -1)]



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