[gnome-games/glchess-vala] Apply board orientation setting
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/glchess-vala] Apply board orientation setting
- Date: Mon, 3 Jan 2011 22:02:34 +0000 (UTC)
commit 4829d247d39ea2b36159f5b59978e2718481bba4
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Jan 4 09:02:20 2011 +1100
Apply board orientation setting
glchess/src/chess-view-2d.vala | 17 +++++++++-
glchess/src/chess-view-3d.vala | 3 +-
glchess/src/chess-view-options.vala | 55 ++++++++++++++++++++++++++---------
glchess/src/glchess.vala | 1 +
4 files changed, 59 insertions(+), 17 deletions(-)
---
diff --git a/glchess/src/chess-view-2d.vala b/glchess/src/chess-view-2d.vala
index dc43a62..2460079 100644
--- a/glchess/src/chess-view-2d.vala
+++ b/glchess/src/chess-view-2d.vala
@@ -26,7 +26,7 @@ private class ChessView2D : ChessView
{
c.translate (get_allocated_width () / 2, get_allocated_height () / 2);
//c.scale (s, s);
- //c.rotate (angle);
+ c.rotate (Math.PI * options.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);
@@ -172,6 +172,7 @@ private class ChessView2D : ChessView
break;
}
+ // FIXME: Pre-render these
Rsvg.Handle handle;
try
{
@@ -184,6 +185,11 @@ private class ChessView2D : ChessView
}
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);
+ if (options.board_side == "facetoface" && piece.player.color == Color.BLACK)
+ c.rotate (Math.PI);
+ c.translate (-square_size / 2, -square_size / 2);
c.scale ((double) square_size / handle.width, (double) square_size / handle.height);
c.set_source_rgb (0, 0, 0);
handle.render_cairo (c);
@@ -201,7 +207,14 @@ private class ChessView2D : ChessView
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)
+ {
+ rank = 7 - rank;
+ file = 7 - file;
+ }
+
if (file < 0 || file >= 8 || rank < 0 || rank >= 8)
return false;
diff --git a/glchess/src/chess-view-3d.vala b/glchess/src/chess-view-3d.vala
index 16c65b1..dfadc94 100644
--- a/glchess/src/chess-view-3d.vala
+++ b/glchess/src/chess-view-3d.vala
@@ -235,7 +235,7 @@ private class ChessView3D : ChessView
glEnable (GL_LIGHT0);
glPushMatrix ();
- //glRotatef (33.0f, 0.0f, 1.0f, 0.0f); // FIXME: Rotate the board here
+ glRotatef ((GLfloat) options.board_angle, 0.0f, 1.0f, 0.0f);
glTranslatef (-OFFSET, 0.0f, OFFSET);
draw_board ();
@@ -455,6 +455,7 @@ private class ChessView3D : ChessView
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
transform_camera ();
+ glRotatef ((GLfloat) options.board_angle, 0.0f, 1.0f, 0.0f);
glTranslatef (-OFFSET, 0.0f, OFFSET);
for (var rank = 0; rank < 8; rank++)
{
diff --git a/glchess/src/chess-view-options.vala b/glchess/src/chess-view-options.vala
index 9df917c..f9e7304 100644
--- a/glchess/src/chess-view-options.vala
+++ b/glchess/src/chess-view-options.vala
@@ -8,8 +8,8 @@ public class ChessViewOptions : Object
private ChessGame? _game = null;
public ChessGame? game
{
- get { return _game; }
- set
+ get { return _game; }
+ set
{
_game = value;
selected_rank = -1;
@@ -28,8 +28,8 @@ public class ChessViewOptions : Object
private int _move_number = -1;
public int move_number
{
- get { return _move_number; }
- set
+ get { return _move_number; }
+ set
{
if (_move_number == value)
return;
@@ -41,36 +41,63 @@ public class ChessViewOptions : Object
private bool _show_numbering = true;
public bool show_numbering
{
- get { return _show_numbering; }
- set { _show_numbering = value; changed (); }
+ 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 (); }
+ 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 (); }
+ 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 (); }
+ 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 (); }
+ get { return _move_format; }
+ set { _move_format = value; changed (); }
}
public void select_square (int file, int rank)
diff --git a/glchess/src/glchess.vala b/glchess/src/glchess.vala
index 8623467..f6d7bd2 100644
--- a/glchess/src/glchess.vala
+++ b/glchess/src/glchess.vala
@@ -94,6 +94,7 @@ public class Application
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);
settings.changed.connect (settings_changed_cb);
settings_changed_cb (settings, "show-3d");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]