[gnome-tetravex] Introduce another theme.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tetravex] Introduce another theme.
- Date: Thu, 10 Oct 2019 03:41:54 +0000 (UTC)
commit 1318f3c0eec476452a7bc1040345ea7194bb79eb
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Oct 2 04:14:57 2019 +0200
Introduce another theme.
Welcome Synesthesia, a
think-different theme.
data/org.gnome.Tetravex.gschema.xml | 1 +
po/POTFILES.in | 1 +
po/POTFILES.skip | 1 +
src/app-menu.ui | 12 +-
src/meson.build | 3 +-
src/puzzle-view.vala | 20 +++-
src/theme-synesthesia.vala | 233 ++++++++++++++++++++++++++++++++++++
7 files changed, 262 insertions(+), 9 deletions(-)
---
diff --git a/data/org.gnome.Tetravex.gschema.xml b/data/org.gnome.Tetravex.gschema.xml
index 254c1cd..362b94f 100644
--- a/data/org.gnome.Tetravex.gschema.xml
+++ b/data/org.gnome.Tetravex.gschema.xml
@@ -3,6 +3,7 @@
<value value="0" nick="extrusion"/>
<value value="1" nick="neoretro"/>
<value value="2" nick="nostalgia"/>
+ <value value="3" nick="synesthesia"/>
</enum>
<schema id="org.gnome.Tetravex" path="/org/gnome/Tetravex/" gettext-domain="gnome-tetravex">
<key name="grid-size" type="i">
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6bca6e2..6ba9966 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -13,3 +13,4 @@ src/score-dialog.vala
src/theme-extrusion.vala
src/theme-neoretro.vala
src/theme-nostalgia.vala
+src/theme-synesthesia.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 43a1ad7..27438b3 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -5,3 +5,4 @@ src/score-dialog.c
src/theme-extrusion.c
src/theme-neoretro.c
src/theme-nostalgia.c
+src/theme-synesthesia.c
diff --git a/src/app-menu.ui b/src/app-menu.ui
index 619bd96..1d4cd3a 100644
--- a/src/app-menu.ui
+++ b/src/app-menu.ui
@@ -16,23 +16,29 @@
<attribute name="label" translatable="yes">A_ppearance</attribute>
<section>
<item>
- <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that
appears when pressing Alt); set theme to Adwaita; other possible themes are Neo_Retro and _Nostalgia -->
+ <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that
appears when pressing Alt); set theme to Adwaita; other possible themes are Neo_Retro, _Nostalgia and
_Synesthesia -->
<attribute name="label" translatable="yes">_Extrusion</attribute>
<attribute name="action">app.theme</attribute>
<attribute name="target">extrusion</attribute>
</item>
<item>
- <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that
appears when pressing Alt); set theme to NeoRetro; other possible themes are _Extrusion and _Nostalgia -->
+ <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that
appears when pressing Alt); set theme to NeoRetro; other possible themes are _Extrusion, _Nostalgia and
_Synesthesia -->
<attribute name="label" translatable="yes">Neo_Retro</attribute>
<attribute name="action">app.theme</attribute>
<attribute name="target">neoretro</attribute>
</item>
<item>
- <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that
appears when pressing Alt); set theme to Nostalgia; other possible themes are _Extrusion and Neo_Retro -->
+ <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that
appears when pressing Alt); set theme to Nostalgia; other possible themes are _Extrusion, Neo_Retro and
_Synesthesia -->
<attribute name="label" translatable="yes">_Nostalgia</attribute>
<attribute name="action">app.theme</attribute>
<attribute name="target">nostalgia</attribute>
</item>
+ <item>
+ <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that
appears when pressing Alt); set theme to Synesthesia; other possible themes are _Extrusion, Neo_Retro and
_Nostalgia -->
+ <attribute name="label" translatable="yes">_Synesthesia</attribute>
+ <attribute name="action">app.theme</attribute>
+ <attribute name="target">synesthesia</attribute>
+ </item>
</section>
</submenu>
</section>
diff --git a/src/meson.build b/src/meson.build
index 0124bad..5269f8c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -11,7 +11,8 @@ sources = files (
'score-dialog.vala',
'theme-extrusion.vala',
'theme-neoretro.vala',
- 'theme-nostalgia.vala'
+ 'theme-nostalgia.vala',
+ 'theme-synesthesia.vala'
)
gnome_tetravex = executable (
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index c27fee9..0fe08bc 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -124,6 +124,7 @@ private class PuzzleView : Gtk.DrawingArea
case "extrusion" : theme = new ExtrusionTheme (); break;
case "neoretro" : theme = new NeoRetroTheme (); break;
case "nostalgia" : theme = new NostalgiaTheme (); break;
+ case "synesthesia": theme = new SynesthesiaTheme (); break;
}
if (tilesize != 0)
@@ -435,9 +436,13 @@ private class PuzzleView : Gtk.DrawingArea
if (!iter.next (out tile, out image))
break;
- if ((selected_tile != null && image == (!) selected_tile)
- || (image.x != image.target_x)
- || (image.y != image.target_y))
+ if (selected_tile != null && image == (!) selected_tile)
+ continue;
+ if (selected_tile == null && last_selected_tile != null && image == (!) last_selected_tile)
+ continue;
+
+ if (image.x != image.target_x
+ || image.y != image.target_y)
{
moving_tiles.prepend (image);
continue;
@@ -446,11 +451,16 @@ private class PuzzleView : Gtk.DrawingArea
draw_image (context, image);
}
+ /* Draw moving tiles on top of static tiles; in the order they want */
foreach (unowned TileImage image in moving_tiles)
draw_image (context, image);
- /* Redraw last selected tile, fixing problem seen when interverting multiple times two contiguous
tiles */
- if (selected_tile == null && last_selected_tile != null)
+ /* Draw selected tile –if any– at the end, as it is always on top; else */
+ if (selected_tile != null)
+ draw_image (context, (!) selected_tile);
+
+ /* draw last selected tile instead, fixing problem seen when interverting multiple times two
contiguous tiles */
+ else if (last_selected_tile != null)
draw_image (context, (!) last_selected_tile);
/* Draw pause overlay */
diff --git a/src/theme-synesthesia.vala b/src/theme-synesthesia.vala
new file mode 100644
index 0000000..7579ece
--- /dev/null
+++ b/src/theme-synesthesia.vala
@@ -0,0 +1,233 @@
+/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2019 Arnaud Bonatti
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
+ * license.
+ */
+
+private class SynesthesiaTheme : Theme
+{
+ /*\
+ * * colors arrays
+ \*/
+
+ private Cairo.Pattern text_colors [10];
+ private Cairo.Pattern paused_color;
+ private Cairo.Pattern tile_color;
+
+ construct
+ { // based on GNOME color palette
+ text_colors [0] = make_color_pattern ("3d3846"); // black // Dark 3
+ text_colors [1] = make_color_pattern ("E01B24"); // red // Red 3
+ text_colors [2] = make_color_pattern ("FF7800"); // orange // Orange 3
+ text_colors [3] = make_color_pattern ("F8E45C"); // yellow // Yellow 2
+ text_colors [4] = make_color_pattern ("57E389"); // green // Green 2
+ text_colors [5] = make_color_pattern ("865E3C"); // brown // Brown 4
+ text_colors [6] = make_color_pattern ("1CD5D8"); // green blue
+ text_colors [7] = make_color_pattern ("1a5fb4"); // dark blue // Blue 5
+ text_colors [8] = make_color_pattern ("9141AC"); // purple // Purple 3
+ text_colors [9] = make_color_pattern ("f6f5f4"); // white // Light 2
+
+ paused_color = make_color_pattern ("CCCCCC");
+ tile_color = make_color_pattern ("CDCADA", /* transparency */ true);
+ }
+
+ private static Cairo.Pattern make_color_pattern (string color, bool transparency = false)
+ {
+ double r = (hex_value (color [0]) * 16 + hex_value (color [1])) / 255.0;
+ double g = (hex_value (color [2]) * 16 + hex_value (color [3])) / 255.0;
+ double b = (hex_value (color [4]) * 16 + hex_value (color [5])) / 255.0;
+ return new Cairo.Pattern.rgba (r, g, b, transparency ? 0.6 : 1.0);
+ }
+
+ private static double hex_value (char c)
+ {
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ else if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ else
+ return 0;
+ }
+
+ /*\
+ * * configuring variables
+ \*/
+
+ private uint size = 0;
+
+ /* arrow */
+ private double arrow_half_h;
+ private double neg_arrow_half_h;
+ private double arrow_w;
+ private double arrow_x;
+
+ /* socket */
+ private uint tile_depth;
+ private double size_minus_tile_depth;
+ private double size_minus_two_tile_depths; // socket only
+ private Cairo.MeshPattern socket_pattern;
+ private Cairo.Matrix matrix; // also used for tile
+
+ /* tile only */
+ private uint tile_margin;
+ private int tile_size;
+ private double half_size;
+ private double half_tile_size;
+
+ /* numbers */
+ private double font_size;
+ private double north_number_y;
+ private double south_number_y;
+ private double east_number_x;
+ private double west_number_x;
+
+ internal override void configure (uint new_size)
+ {
+ if (size != 0 && size == new_size)
+ return;
+
+ /* arrow */
+ arrow_w = new_size * PuzzleView.gap_factor * 0.5;
+ arrow_x = (new_size * PuzzleView.gap_factor - arrow_w) * 0.5;
+ arrow_half_h = arrow_w * Math.SQRT2 / 2.0;
+ neg_arrow_half_h = -arrow_half_h;
+
+ /* socket and tiles */
+ matrix = Cairo.Matrix.identity ();
+ matrix.scale (1.0 / new_size, 1.0 / new_size);
+
+ /* socket */
+ tile_depth = uint.min ((uint) (new_size * 0.05), 4);
+ size_minus_tile_depth = (double) new_size - tile_depth;
+ size_minus_two_tile_depths = (double) (new_size - tile_depth * 2);
+
+ socket_pattern = new Cairo.MeshPattern ();
+ socket_pattern.begin_patch ();
+ socket_pattern.move_to (0.5, 0.0);
+ socket_pattern.line_to (1.0, 0.5);
+ socket_pattern.line_to (0.5, 1.0);
+ socket_pattern.line_to (0.0, 0.5);
+ socket_pattern.set_corner_color_rgba (0, 0.45, 0.45, 0.45, 0.5);
+ socket_pattern.set_corner_color_rgba (1, 0.6 , 0.6 , 0.6 , 0.5);
+ socket_pattern.set_corner_color_rgba (2, 0.7 , 0.7 , 0.7 , 0.5);
+ socket_pattern.set_corner_color_rgba (3, 0.55, 0.55, 0.55, 0.5);
+ socket_pattern.end_patch ();
+ socket_pattern.set_matrix (matrix);
+
+ /* tile */
+ tile_margin = uint.min ((uint) (new_size * 0.05), 2) - 1;
+ tile_size = (int) new_size - (int) tile_margin * 2;
+ half_size = new_size * 0.5;
+ half_tile_size = tile_size * 0.5;
+
+ /* numbers */
+ font_size = new_size * 4.0 / 19.0;
+ north_number_y = new_size * 4.0 / 18.0;
+ south_number_y = new_size * 14.0 / 18.0;
+ east_number_x = new_size * 15.0 / 19.0;
+ west_number_x = new_size * 4.0 / 19.0;
+
+ /* end */
+ size = new_size;
+ }
+
+ /*\
+ * * drawing arrow
+ \*/
+
+ internal override void draw_arrow (Cairo.Context context)
+ {
+ context.translate (arrow_x, 0.0);
+
+ context.move_to (0.0, 0.0);
+ context.line_to (arrow_w, arrow_half_h);
+ context.line_to (arrow_w, neg_arrow_half_h);
+ context.close_path ();
+ context.set_source_rgba (0.5, 0.5, 0.6, 0.4);
+ context.fill ();
+ }
+
+ /*\
+ * * drawing sockets
+ \*/
+
+ internal override void draw_socket (Cairo.Context context)
+ {
+ context.save ();
+
+ context.translate (tile_margin, tile_margin);
+
+ context.set_source (socket_pattern);
+ context.move_to (half_tile_size, 0.0 );
+ context.line_to (tile_size , half_tile_size);
+ context.line_to (half_tile_size, tile_size );
+ context.line_to (0.0 , half_tile_size);
+ context.close_path ();
+ context.fill_preserve ();
+
+ context.set_line_width (1.0);
+ context.set_source_rgba (0.4, 0.4, 0.4, 0.3);
+ context.stroke ();
+
+ context.restore ();
+ }
+
+ /*\
+ * * drawing tiles
+ \*/
+
+ internal override void draw_paused_tile (Cairo.Context context)
+ {
+ draw_tile_background (context, paused_color);
+ }
+
+ internal override void draw_tile (Cairo.Context context, Tile tile)
+ {
+ draw_tile_background (context, tile_color);
+
+ context.select_font_face ("Cantarell", Cairo.FontSlant.NORMAL, Cairo.FontWeight.BOLD);
+ context.set_font_size (font_size);
+ draw_number (context, text_colors [tile.north], half_size, north_number_y, tile.north);
+ draw_number (context, text_colors [tile.south], half_size, south_number_y, tile.south);
+ draw_number (context, text_colors [tile.east ], east_number_x , half_size, tile.east);
+ draw_number (context, text_colors [tile.west ], west_number_x , half_size, tile.west);
+ }
+
+ private void draw_tile_background (Cairo.Context context, Cairo.Pattern pattern)
+ {
+ context.save ();
+
+ context.rectangle (0.0, 0.0, size, size);
+ context.clip ();
+
+ context.translate (tile_margin, tile_margin);
+
+ context.set_source (pattern);
+ context.rectangle (0.0, 0.0, tile_size, tile_size);
+ context.fill_preserve ();
+
+ context.set_line_width (1.0);
+ context.set_source_rgba (0.5, 0.5, 0.6, 0.4);
+ context.stroke ();
+
+ context.restore ();
+ }
+
+ private static void draw_number (Cairo.Context context, Cairo.Pattern text_color, double x, double y,
uint8 number)
+ {
+ context.set_source (text_color);
+
+ string text = "%hu".printf (number);
+ Cairo.TextExtents extents;
+ context.text_extents (text, out extents);
+ context.move_to (x - extents.width / 2.0, y + extents.height / 2.0);
+ context.show_text (text);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]