[iagno] Think rounded square.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Think rounded square.
- Date: Fri, 1 May 2015 21:48:13 +0000 (UTC)
commit e7d47bfcdae077e1fc55bbe853b31c6f5e1d8a2a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Apr 14 16:05:16 2015 +0200
Think rounded square.
data/themes/adwaita.theme.in | 2 +
data/themes/classic.theme.in | 1 +
data/themes/high_contrast.theme.in | 2 +
data/themes/sun_and_star.theme.in | 1 +
src/game-view.vala | 82 ++++++++++++++++++++++++------------
5 files changed, 61 insertions(+), 27 deletions(-)
---
diff --git a/data/themes/adwaita.theme.in b/data/themes/adwaita.theme.in
index 27119a8..cdef55f 100644
--- a/data/themes/adwaita.theme.in
+++ b/data/themes/adwaita.theme.in
@@ -11,6 +11,8 @@ File=black_and_white.svg
Red=0.2
Green=0.4
Blue=0.6
+# Radius=9
+Radius=2
[Mark]
Red=0.2
diff --git a/data/themes/classic.theme.in b/data/themes/classic.theme.in
index a38ed84..301e0ba 100644
--- a/data/themes/classic.theme.in
+++ b/data/themes/classic.theme.in
@@ -11,6 +11,7 @@ File=black_and_white.svg
Red=0.2
Green=0.6
Blue=0.4
+Radius=2
[Mark]
Red=0.5
diff --git a/data/themes/high_contrast.theme.in b/data/themes/high_contrast.theme.in
index ceae514..6ac61a7 100644
--- a/data/themes/high_contrast.theme.in
+++ b/data/themes/high_contrast.theme.in
@@ -11,6 +11,8 @@ File=high_contrast.svg
Red=1.0
Green=1.0
Blue=1.0
+# Radius=9
+Radius=0
[Mark]
Red=0.0
diff --git a/data/themes/sun_and_star.theme.in b/data/themes/sun_and_star.theme.in
index e345baa..bb1020c 100644
--- a/data/themes/sun_and_star.theme.in
+++ b/data/themes/sun_and_star.theme.in
@@ -11,6 +11,7 @@ File=sun_and_star.svg
Red=0.2
Green=0.6
Blue=0.4
+Radius=2
[Mark]
Red=0.2
diff --git a/src/game-view.vala b/src/game-view.vala
index c4593a3..d6016d6 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -36,6 +36,7 @@ public class GameView : Gtk.DrawingArea
private double background_red = 0.2;
private double background_green = 0.6;
private double background_blue = 0.4;
+ private int background_radius = 0;
private double mark_red = 0.2;
private double mark_green = 0.6;
@@ -190,34 +191,35 @@ public class GameView : Gtk.DrawingArea
if (Path.get_dirname (pieces_file) != svg_path)
pieces_file = Path.build_filename (svg_path, "black_and_white.svg");
- background_red = key.get_double ("Background", "Red");
- background_green = key.get_double ("Background", "Green");
- background_blue = key.get_double ("Background", "Blue");
+ background_red = key.get_double ("Background", "Red");
+ background_green = key.get_double ("Background", "Green");
+ background_blue = key.get_double ("Background", "Blue");
+ background_radius = key.get_integer ("Background", "Radius");
- mark_red = key.get_double ("Mark", "Red");
- mark_green = key.get_double ("Mark", "Green");
- mark_blue = key.get_double ("Mark", "Blue");
- mark_width = key.get_integer ("Mark", "Width");
+ mark_red = key.get_double ("Mark", "Red");
+ mark_green = key.get_double ("Mark", "Green");
+ mark_blue = key.get_double ("Mark", "Blue");
+ mark_width = key.get_integer ("Mark", "Width");
- border_red = key.get_double ("Border", "Red");
- border_green = key.get_double ("Border", "Green");
- border_blue = key.get_double ("Border", "Blue");
- border_width = key.get_integer ("Border", "Width");
+ border_red = key.get_double ("Border", "Red");
+ border_green = key.get_double ("Border", "Green");
+ border_blue = key.get_double ("Border", "Blue");
+ border_width = key.get_integer ("Border", "Width");
- spacing_red = key.get_double ("Spacing", "Red");
- spacing_green = key.get_double ("Spacing", "Green");
- spacing_blue = key.get_double ("Spacing", "Blue");
- spacing_width = key.get_integer ("Spacing", "Width");
+ spacing_red = key.get_double ("Spacing", "Red");
+ spacing_green = key.get_double ("Spacing", "Green");
+ spacing_blue = key.get_double ("Spacing", "Blue");
+ spacing_width = key.get_integer ("Spacing", "Width");
- highlight_red = key.get_double ("Highlight", "Red");
- highlight_green = key.get_double ("Highlight", "Green");
- highlight_blue = key.get_double ("Highlight", "Blue");
- highlight_alpha = key.get_double ("Highlight", "Alpha");
+ highlight_red = key.get_double ("Highlight", "Red");
+ highlight_green = key.get_double ("Highlight", "Green");
+ highlight_blue = key.get_double ("Highlight", "Blue");
+ highlight_alpha = key.get_double ("Highlight", "Alpha");
- // margin_width = key.get_integer ("Margin", "Width");
+ // margin_width = key.get_integer ("Margin", "Width");
- sound_flip = key.get_string ("Sound", "Flip");
- sound_gameover = key.get_string ("Sound", "GameOver");
+ sound_flip = key.get_string ("Sound", "Flip");
+ sound_gameover = key.get_string ("Sound", "GameOver");
}
catch (KeyFileError e) // TODO better
{
@@ -276,7 +278,7 @@ public class GameView : Gtk.DrawingArea
/* draw background */
cr.set_source_rgba (background_red, background_green, background_blue, 1.0);
- cr.rectangle (tile_x, tile_y, tile_size, tile_size);
+ rounded_square (cr, tile_x, tile_y, tile_size, 0, background_radius);
cr.fill ();
if (highlight_x == x && highlight_y == y && (show_highlight || highlight_state != 0) &&
!game.is_complete) // TODO on game.is_complete…
@@ -292,10 +294,12 @@ public class GameView : Gtk.DrawingArea
/* draw animated highlight */
cr.set_source_rgba (highlight_red, highlight_green, highlight_blue, highlight_alpha);
- cr.rectangle (tile_x + tile_size * (HIGHLIGHT_MAX - highlight_state) / (2 *
HIGHLIGHT_MAX), // TODO odd/even sizes problem
- tile_y + tile_size * (HIGHLIGHT_MAX - highlight_state) / (2 *
HIGHLIGHT_MAX),
- tile_size * highlight_state / HIGHLIGHT_MAX,
- tile_size * highlight_state / HIGHLIGHT_MAX);
+ rounded_square (cr,
+ tile_x + tile_size * (HIGHLIGHT_MAX - highlight_state) / (2 *
HIGHLIGHT_MAX), // TODO odd/even sizes problem
+ tile_y + tile_size * (HIGHLIGHT_MAX - highlight_state) / (2 *
HIGHLIGHT_MAX),
+ tile_size * highlight_state / HIGHLIGHT_MAX,
+ 0,
+ background_radius);
cr.fill ();
}
@@ -317,6 +321,30 @@ public class GameView : Gtk.DrawingArea
return false;
}
+ private void rounded_square (Cairo.Context cr, double x, double y, int size, double width, double
radius_percent)
+ {
+ if (radius_percent <= 0)
+ {
+ cr.rectangle (x + width / 2.0, y + width / 2.0, size + width, size + width);
+ return;
+ }
+
+ if (radius_percent > 50)
+ radius_percent = 50;
+ double radius_border = radius_percent * size / 100.0;
+ double radius_arc = radius_border - width / 2.0;
+ double x1 = x + radius_border;
+ double y1 = y + radius_border;
+ double x2 = x + size - radius_border;
+ double y2 = y + size - radius_border;
+
+ cr.arc (x1, y1, radius_arc, Math.PI, Math.PI * 3 / 2.0);
+ cr.arc (x2, y1, radius_arc, Math.PI * 3 / 2.0, 0);
+ cr.arc (x2, y2, radius_arc, 0, Math.PI / 2.0);
+ cr.arc (x1, y2, radius_arc, Math.PI / 2.0, Math.PI);
+ cr.arc (x1, y1, radius_arc, Math.PI, Math.PI * 3 / 2.0);
+ }
+
private void load_image (Cairo.Context c, int width, int height)
{
try
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]