[iagno] Scoreboard, first try.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Scoreboard, first try.
- Date: Mon, 16 Feb 2015 18:20:10 +0000 (UTC)
commit a40d021d0bf8e5dbe3fa46d50c5ded7c7a921554
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Feb 16 04:23:11 2015 +0100
Scoreboard, first try.
data/Makefile.am | 5 +-
data/dark.svg | 298 -----------------------------------------------
data/iagno.css | 5 +-
data/iagno.ui | 40 +-----
data/light.svg | 192 ------------------------------
data/mark.svg | 125 --------------------
src/game-view.vala | 131 +++++++++++++++++----
src/iagno.gresource.xml | 5 -
src/iagno.vala | 12 +-
src/themes-dialog.vala | 2 +-
10 files changed, 129 insertions(+), 686 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 87ad1b6..51c6360 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -6,10 +6,7 @@ dist_noinst_DATA = \
iagno-themes.ui \
iagno-menus.ui \
iagno.ui \
- iagno.css \
- dark.svg \
- light.svg \
- mark.svg
+ iagno.css
themedir = $(datadir)/iagno/themes/svg
theme_DATA = \
diff --git a/data/iagno.css b/data/iagno.css
index 7965668..b80e2f6 100644
--- a/data/iagno.css
+++ b/data/iagno.css
@@ -18,13 +18,16 @@
* with this application. If not, see <http://www.gnu.org/licenses/>.
*/
-/* Labels' fonts */
+/* Labels' tweaks */
GtkLabel.bold-label {
font-weight: bold;
}
GtkLabel.italic-label {
font-style: italic;
}
+GtkGrid#scoreboard GtkLabel {
+ padding: 5px 2px;
+}
/* Themes' dialog listbox */
GtkListBox#themes-listbox GtkImage {
diff --git a/data/iagno.ui b/data/iagno.ui
index 830fab2..2b9b31a 100644
--- a/data/iagno.ui
+++ b/data/iagno.ui
@@ -289,29 +289,23 @@
<property name="spacing">6</property>
<child>
<object class="GtkGrid">
+ <property name="name">scoreboard</property>
<property name="visible">True</property>
<property name="halign">center</property>
<property name="column-spacing">12</property>
- <property name="row-spacing">18</property>
+ <property name="row-spacing">0</property>
+ <property name="column-homogeneous">True</property>
+ <property name="row-homogeneous">True</property>
<property name="margin-end">12</property>
<child>
- <object class="GtkImage" id="mark-icon-dark">
- <property name="resource">/org/gnome/iagno/images/mark.svg</property>
+ <object class="GtkDrawingArea" id="scoreboard">
<property name="visible">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkImage">
- <property name="resource">/org/gnome/iagno/images/dark.svg</property>
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="left-attach">1</property>
- <property name="top-attach">0</property>
+ <property name="width">2</property><!-- yeah, this sounds stupid, but... -->
+ <property name="height">2</property>
</packing>
</child>
<child>
@@ -328,26 +322,6 @@
</packing>
</child>
<child>
- <object class="GtkImage" id="mark-icon-light">
- <property name="resource">/org/gnome/iagno/images/mark.svg</property>
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="left-attach">0</property>
- <property name="top-attach">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkImage">
- <property name="resource">/org/gnome/iagno/images/light.svg</property>
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="left-attach">1</property>
- <property name="top-attach">1</property>
- </packing>
- </child>
- <child>
<object class="GtkLabel" id="light-score-label">
<property name="visible">True</property>
<property name="label">00</property>
diff --git a/src/game-view.vala b/src/game-view.vala
index 4074965..39080e4 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -20,6 +20,16 @@
public class GameView : Gtk.DrawingArea
{
+ private Gtk.DrawingArea _scoreboard;
+ public Gtk.DrawingArea scoreboard {
+ private get { return _scoreboard; }
+ set
+ {
+ _scoreboard = value;
+ _scoreboard.draw.connect (draw_scoreboard);
+ }
+ }
+
/* Theme */
private string pieces_file;
@@ -54,6 +64,7 @@ public class GameView : Gtk.DrawingArea
/* Pre-rendered image */
private uint render_size = 0;
private Cairo.Pattern? tiles_pattern = null;
+ private Cairo.Pattern? scoreboard_tiles_pattern = null;
/* The images being showed on each location */
private int[,] pixmaps;
@@ -61,6 +72,9 @@ public class GameView : Gtk.DrawingArea
/* Animation timer */
private uint animate_timeout = 0;
+ private double cursor = 0;
+ private int current_player_number = 0;
+
public signal void move (int x, int y);
/* Used for a delay between the last move and flipping the pieces */
@@ -79,8 +93,8 @@ public class GameView : Gtk.DrawingArea
if (_game != null)
{
_game.square_changed.connect (square_changed_cb);
- for (var x = 0; x < game.size; x++)
- for (var y = 0; y < game.size; y++)
+ for (int x = 0; x < game.size; x++)
+ for (int y = 0; y < game.size; y++)
pixmaps[x, y] = get_pixmap (_game.get_owner (x, y));
}
queue_draw ();
@@ -117,6 +131,8 @@ public class GameView : Gtk.DrawingArea
// redraw all
tiles_pattern = null;
+ // scoreboard_tiles_pattern = null;
+ scoreboard.queue_draw ();
queue_draw ();
}
}
@@ -183,7 +199,7 @@ public class GameView : Gtk.DrawingArea
private void calculate ()
{
- var size = int.min (get_allocated_width (), get_allocated_height ());
+ int size = int.min (get_allocated_width (), get_allocated_height ());
/* tile_size includes a grid spacing */
tile_size = (size - 2 * border_width + spacing_width) / game.size;
/* board_size includes its borders */
@@ -202,7 +218,7 @@ public class GameView : Gtk.DrawingArea
render_size = tile_size;
var surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, tile_size
* 8, tile_size * 4);
var c = new Cairo.Context (surface);
- load_image (c);
+ load_image (c, tile_size * 8, tile_size * 4);
tiles_pattern = new Cairo.Pattern.for_surface (surface);
}
@@ -241,10 +257,10 @@ public class GameView : Gtk.DrawingArea
if (pixmaps[x, y] == 0)
continue;
- var tile_x = x * tile_size;
- var tile_y = y * tile_size;
- var texture_x = (pixmaps[x, y] % 8) * tile_size;
- var texture_y = (pixmaps[x, y] / 8) * tile_size;
+ int tile_x = x * tile_size;
+ int tile_y = y * tile_size;
+ int texture_x = (pixmaps[x, y] % 8) * tile_size;
+ int texture_y = (pixmaps[x, y] / 8) * tile_size;
var matrix = Cairo.Matrix.identity ();
matrix.translate (texture_x - tile_x, texture_y - tile_y);
@@ -257,11 +273,8 @@ public class GameView : Gtk.DrawingArea
return false;
}
- private void load_image (Cairo.Context c)
+ private void load_image (Cairo.Context c, int width, int height)
{
- var width = tile_size * 8;
- var height = tile_size * 4;
-
try
{
var h = new Rsvg.Handle.from_file (pieces_file);
@@ -297,16 +310,16 @@ public class GameView : Gtk.DrawingArea
/* Show the result by laying the tiles with winning color first */
if (flip_final_result_now && game.is_complete)
{
- var n = y * game.size + x;
- var winning_color = Player.LIGHT;
- var losing_color = Player.DARK;
- var n_winning_tiles = game.n_light_tiles;
- var n_losing_tiles = game.n_dark_tiles;
+ int n = y * game.size + x;
+ Player winning_color = Player.LIGHT;
+ Player losing_color = Player.DARK;
+ int n_winning_tiles = game.n_light_tiles;
+ int n_losing_tiles = game.n_dark_tiles;
if (n_losing_tiles > n_winning_tiles)
{
winning_color = Player.DARK;
losing_color = Player.LIGHT;
- var t = n_winning_tiles;
+ int t = n_winning_tiles;
n_winning_tiles = n_losing_tiles;
n_losing_tiles = t;
}
@@ -360,11 +373,11 @@ public class GameView : Gtk.DrawingArea
private bool animate_cb ()
{
- var animating = false;
+ bool animating = false;
- for (var x = 0; x < game.size; x++)
+ for (int x = 0; x < game.size; x++)
{
- for (var y = 0; y < game.size; y++)
+ for (int y = 0; y < game.size; y++)
{
var old = pixmaps[x, y];
square_changed_cb (x, y);
@@ -408,4 +421,80 @@ public class GameView : Gtk.DrawingArea
return true;
}
+
+ /*\
+ * * Scoreboard
+ \*/
+
+ private bool draw_scoreboard (Cairo.Context cr)
+ {
+ int height = scoreboard.get_allocated_height ();
+ int width = scoreboard.get_allocated_width ();
+
+ cr.set_line_cap (Cairo.LineCap.ROUND);
+ cr.set_line_join (Cairo.LineJoin.ROUND);
+
+ cr.save ();
+
+ cr.set_source_rgba (spacing_red, spacing_green, spacing_blue, 1.0);
+ cr.set_line_width (spacing_width);
+
+ cr.translate (0, current_player_number * height / 2.0);
+ cr.move_to (height / 4.0, height / 8.0);
+ cr.line_to (width - 5.0 * height / 8.0, height / 4.0);
+ cr.line_to (height / 4.0, 3.0 * height / 8.0);
+ cr.stroke ();
+
+ cr.restore ();
+
+ // if (scoreboard_tiles_pattern == null)
+ // {
+ /* prepare drawing of pieces */
+ var surface = new Cairo.Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, height *
4, height * 2);
+ var c = new Cairo.Context (surface);
+ load_image (c, height * 4, height * 2);
+ scoreboard_tiles_pattern = new Cairo.Pattern.for_surface (surface);
+
+ cr.translate (width - height / 2.0, 0);
+ var matrix = Cairo.Matrix.identity ();
+
+ /* draw dark piece */
+ matrix.translate (height / 2.0, 0);
+ scoreboard_tiles_pattern.set_matrix (matrix);
+ cr.set_source (scoreboard_tiles_pattern);
+ cr.rectangle (0, 0, height / 2.0, height / 2.0);
+ cr.fill ();
+
+ /* draw white piece */
+ matrix.translate (3 * height, height);
+ scoreboard_tiles_pattern.set_matrix (matrix);
+ cr.set_source (scoreboard_tiles_pattern);
+ cr.rectangle (0, height / 2.0, height / 2.0, height / 2.0);
+ cr.fill ();
+ // }
+
+ // TODO
+ /* if (cursor > current_player_number)
+ {
+ cursor -= 0.14;
+ if (cursor < 0)
+ cursor = 0;
+ scoreboard.queue_draw ();
+ }
+ else if (cursor < current_player_number)
+ {
+ cursor += 0.14;
+ if (cursor > 1)
+ cursor = 1;
+ scoreboard.queue_draw ();
+ } */
+
+ return true;
+ }
+
+ public void update_scoreboard ()
+ {
+ current_player_number = (game.current_color == Player.DARK) ? 0 : 1;
+ scoreboard.queue_draw (); // TODO queue_draw_area (…), or only refresh part of the DrawingArea, or
both
+ }
}
diff --git a/src/iagno.gresource.xml b/src/iagno.gresource.xml
index 7e29f66..be67380 100644
--- a/src/iagno.gresource.xml
+++ b/src/iagno.gresource.xml
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
- <gresource prefix="/org/gnome/iagno/images">
- <file preprocess="xml-stripblanks" alias="dark.svg">../data/dark.svg</file>
- <file preprocess="xml-stripblanks" alias="light.svg">../data/light.svg</file>
- <file preprocess="xml-stripblanks" alias="mark.svg">../data/mark.svg</file>
- </gresource>
<gresource prefix="/org/gnome/iagno/ui">
<file preprocess="xml-stripblanks" alias="iagno.ui">../data/iagno.ui</file>
<file preprocess="xml-stripblanks" alias="themes.ui">../data/iagno-themes.ui</file>
diff --git a/src/iagno.vala b/src/iagno.vala
index d14b7d0..6e29b33 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -44,8 +44,6 @@ public class Iagno : Gtk.Application
private Gtk.Window window;
private Gtk.HeaderBar headerbar;
private GameView view;
- private Gtk.Image mark_icon_dark;
- private Gtk.Image mark_icon_light;
private Gtk.Label dark_score_label;
private Gtk.Label light_score_label;
private Gtk.Stack main_stack;
@@ -229,6 +227,7 @@ public class Iagno : Gtk.Application
/* View construction */
view = new GameView ();
+ view.scoreboard = builder.get_object ("scoreboard") as Gtk.DrawingArea;
view.move.connect (player_move_cb);
view.theme = settings.get_string ("theme");
view.halign = Gtk.Align.FILL;
@@ -241,8 +240,6 @@ public class Iagno : Gtk.Application
headerbar = builder.get_object ("headerbar") as Gtk.HeaderBar;
light_score_label = builder.get_object ("light-score-label") as Gtk.Label;
dark_score_label = builder.get_object ("dark-score-label") as Gtk.Label;
- mark_icon_dark = builder.get_object ("mark-icon-dark") as Gtk.Image;
- mark_icon_light = builder.get_object ("mark-icon-light") as Gtk.Image;
/* Changing screen */
main_stack = builder.get_object ("main_stack") as Gtk.Stack;
@@ -436,8 +433,8 @@ public class Iagno : Gtk.Application
dark_score_label.set_text (_("%.2d").printf (game.n_dark_tiles));
light_score_label.set_text (_("%.2d").printf (game.n_light_tiles));
- mark_icon_dark.visible = (game.current_color == Player.DARK);
- mark_icon_light.visible = (game.current_color == Player.LIGHT);
+ // mark_icon_dark.visible = (game.current_color == Player.DARK);
+ // mark_icon_light.visible = (game.current_color == Player.LIGHT);
}
private void undo_move_cb ()
@@ -465,6 +462,7 @@ public class Iagno : Gtk.Application
update_ui ();
play_sound (Sound.FLIP);
+ view.update_scoreboard ();
}
private void turn_ended_cb ()
@@ -482,6 +480,7 @@ public class Iagno : Gtk.Application
{
/* for the move that just ended */
play_sound (Sound.FLIP);
+ view.update_scoreboard ();
/*
* Get the computer to move after a delay, so it looks like it's
@@ -501,6 +500,7 @@ public class Iagno : Gtk.Application
{
/* for the move that just ended */
play_sound (Sound.FLIP);
+ view.update_scoreboard ();
game.pass ();
if (game.current_color == Player.DARK)
diff --git a/src/themes-dialog.vala b/src/themes-dialog.vala
index 7222cb2..fc9e185 100644
--- a/src/themes-dialog.vala
+++ b/src/themes-dialog.vala
@@ -67,7 +67,7 @@ public class ThemesDialog : Dialog
img.visible = true;
img.width_request = 50;
img.icon_name = "object-select-symbolic";
- var lbl = new Label (key.get_locale_string ("Theme", "Name")); // TODO test translation
+ var lbl = new Label (key.get_locale_string ("Theme", "Name"));
lbl.visible = true;
lbl.xalign = 0;
var data = new Label (filename);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]