[five-or-more/gsoc-vala-port: 18/29] Add theme selection
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [five-or-more/gsoc-vala-port: 18/29] Add theme selection
- Date: Mon, 13 Aug 2018 05:50:42 +0000 (UTC)
commit 71d50637591dd6a812e41a0d1fa3f18520cf82c5
Author: Ruxandra Simion <ruxandra simion93 gmail com>
Date: Thu Aug 2 22:24:32 2018 +0300
Add theme selection
data/five-or-more-vala-preferences.ui | 32 ++++++++++++++++++++++++++++++++
src-vala/preferences-dialog.vala | 32 ++++++++++++++++++++++++++++++--
src-vala/theme-renderer.vala | 10 ++++++++--
src-vala/view.vala | 6 ++++++
4 files changed, 76 insertions(+), 4 deletions(-)
---
diff --git a/data/five-or-more-vala-preferences.ui b/data/five-or-more-vala-preferences.ui
index d46975d..aabb21f 100644
--- a/data/five-or-more-vala-preferences.ui
+++ b/data/five-or-more-vala-preferences.ui
@@ -52,6 +52,38 @@
<property name="hexpand">True</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">_Theme:</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="theme_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="active">0</property>
+ <items>
+ <item translatable="yes">balls</item>
+ <item translatable="yes">dots</item>
+ <item translatable="yes">gumball</item>
+ <item translatable="yes">shapes</item>
+ </items>
+ </object>
+ <packing>
+ <!-- <property name="expand">False</property>
+ <property name="fill">True</property> -->
+ </packing>
+ </child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
diff --git a/src-vala/preferences-dialog.vala b/src-vala/preferences-dialog.vala
index 606bec1..38d18fa 100644
--- a/src-vala/preferences-dialog.vala
+++ b/src-vala/preferences-dialog.vala
@@ -3,6 +3,9 @@ public class PreferencesDialog : Gtk.Dialog
{
private Settings settings;
+ [GtkChild]
+ private Gtk.ComboBoxText theme_box;
+
[GtkChild]
private Gtk.ColorButton color_button;
@@ -13,10 +16,26 @@ public class PreferencesDialog : Gtk.Dialog
[GtkChild]
private Gtk.RadioButton radiobutton_large;
+ private void theme_set_cb (Gtk.ComboBox self)
+ {
+ var combo_box_text = self as Gtk.ComboBoxText;
+ var theme = combo_box_text.get_active_text ();
+ foreach (var t in ThemeRenderer.themes)
+ {
+ if (t.split (".")[0] == theme)
+ {
+ if (!settings.set_string ("ball-theme", t))
+ warning ("Failed to set theme: %s", t);
+
+ return;
+ }
+ }
+ }
+
private void color_set_cb (Gtk.ColorButton self)
{
var color = self.get_rgba ();
- if (!settings.set_string ("background-color", color.to_string ()))
+ if (!settings.set_string (FiveOrMoreApp.KEY_BACKGROUND_COLOR, color.to_string ()))
warning ("Failed to set color: %s", color.to_string ());
}
@@ -43,7 +62,7 @@ public class PreferencesDialog : Gtk.Dialog
switch (result)
{
case Gtk.ResponseType.OK:
- if (!settings.set_int ("size", size))
+ if (!settings.set_int (FiveOrMoreApp.KEY_SIZE, size))
warning ("Failed to set size: %d", size);
button.set_active (true);
break;
@@ -73,6 +92,15 @@ public class PreferencesDialog : Gtk.Dialog
{
this.settings = settings;
+ /* Set up theme */
+ string theme = settings.get_string (FiveOrMoreApp.KEY_THEME);
+ for (int id = 0; id < ThemeRenderer.themes.length; id++)
+ {
+ if (ThemeRenderer.themes[id] == theme)
+ theme_box.set_active (id);
+ }
+ theme_box.changed.connect (theme_set_cb);
+
/* Set up board color */
var color_str = settings.get_string (FiveOrMoreApp.KEY_BACKGROUND_COLOR);
Gdk.RGBA color = Gdk.RGBA ();
diff --git a/src-vala/theme-renderer.vala b/src-vala/theme-renderer.vala
index f84ef41..a04f318 100644
--- a/src-vala/theme-renderer.vala
+++ b/src-vala/theme-renderer.vala
@@ -4,11 +4,17 @@ public class ThemeRenderer
public const int DEFAULT_SPRITE_SIZE = 20;
private int sprite_size = DEFAULT_SPRITE_SIZE;
+ private float sprite_sheet_width;
+ private float sprite_sheet_height;
private string theme_name;
private Rsvg.Handle? theme = null;
- private float sprite_sheet_width;
- private float sprite_sheet_height;
+ public const string themes[] = {
+ "balls.svg",
+ "dots.png",
+ "gumball.png",
+ "shapes.svg",
+ };
private Cairo.Pattern? tile_pattern = null;
private Cairo.Context cr_preview;
diff --git a/src-vala/view.vala b/src-vala/view.vala
index f4ae8c9..f1e7486 100644
--- a/src-vala/view.vala
+++ b/src-vala/view.vala
@@ -27,6 +27,12 @@ public class View : Gtk.DrawingArea
this.game = game;
this.theme = theme;
+ settings.changed[FiveOrMoreApp.KEY_THEME].connect (() => {
+ game.board.grid_changed ();
+ game.queue_changed (game.next_pieces_queue);
+ queue_draw ();
+ });
+
background_color = Gdk.RGBA ();
set_background_color ();
settings.changed[FiveOrMoreApp.KEY_BACKGROUND_COLOR].connect (() => {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]