[gnome-games/gsoc-seed-games] [lightsoff] Factor out theme loading code
- From: Tim Horton <hortont src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/gsoc-seed-games] [lightsoff] Factor out theme loading code
- Date: Sun, 12 Jul 2009 02:42:50 +0000 (UTC)
commit e24a60840c7dd2343a4ee9506e6acd9df01a990d
Author: Tim Horton <hortont424 gmail com>
Date: Sat Jul 11 22:33:18 2009 -0400
[lightsoff] Factor out theme loading code
lightsoff/Makefile.am | 6 +++-
lightsoff/data/themes/tango/theme.js | 41 +++++++--------------------------
lightsoff/data/themes/up/theme.js | 41 +++++++--------------------------
lightsoff/src/Settings.js | 3 +-
lightsoff/src/ThemeLoader.js | 21 +++++++++++++++++
lightsoff/src/main.js | 3 +-
lightsoff/src/path.js.in | 1 +
7 files changed, 48 insertions(+), 68 deletions(-)
---
diff --git a/lightsoff/Makefile.am b/lightsoff/Makefile.am
index f8bbd52..a370c04 100644
--- a/lightsoff/Makefile.am
+++ b/lightsoff/Makefile.am
@@ -12,7 +12,8 @@ lightsoff_DATA = \
src/LED.js \
src/Settings.js \
data/settings.ui \
- data/main-window.ui
+ data/main-window.ui \
+ src/ThemeLoader.js
bin_SCRIPTS = \
src/lightsoff
@@ -39,7 +40,8 @@ EXTRA_DIST = \
src/LED.js \
src/Settings.js \
data/settings.ui \
- data/main-window.ui
+ data/main-window.ui \
+ src/ThemeLoader.js
install-schemas-local: $(schema_DATA)
if GCONF_SCHEMAS_INSTALL
diff --git a/lightsoff/data/themes/tango/theme.js b/lightsoff/data/themes/tango/theme.js
index 1e88916..5e09714 100644
--- a/lightsoff/data/themes/tango/theme.js
+++ b/lightsoff/data/themes/tango/theme.js
@@ -1,38 +1,15 @@
-file_prefix = imports.path.file_prefix;
-
Clutter = imports.gi.Clutter;
+ThemeLoader = imports.ThemeLoader;
var name = "Tango";
-var setup_done = false;
-var light = [ load_svg("off.svg"), load_svg("on.svg") ];
-var arrow = load_svg("arrow.svg");
-var backing = load_svg("backing.svg");
-var led_back = load_svg("led-back.svg");
-var highlight = load_svg("highlight.svg");
-
-function setup(a)
-{
- if(setup_done)
- return;
- setup_done = true;
- a.add_actor(light[0]);
- a.add_actor(light[1]);
- a.add_actor(arrow);
- a.add_actor(backing);
- a.add_actor(led_back);
- a.add_actor(highlight);
-}
+var light = [ ThemeLoader.load_svg("tango", "off.svg"),
+ ThemeLoader.load_svg("tango", "on.svg") ];
+var arrow = ThemeLoader.load_svg("tango", "arrow.svg");
+var backing = ThemeLoader.load_svg("tango", "backing.svg");
+var led_back = ThemeLoader.load_svg("tango", "led-back.svg");
+var highlight = ThemeLoader.load_svg("tango", "highlight.svg");
-// helper functions should be put somewhere global
+var loaded = false;
+var textures = [light[0], light[1], arrow, backing, led_back, highlight];
-function load_svg(file)
-{
- // TODO: either imports should set the cwd (and this can go away),
- // or we need some quick way to compose paths. Really, we need that anyway.
-
- var tx = new Clutter.Texture({filename: file_prefix + "themes/tango/" + file});
- tx.filter_quality = Clutter.TextureQuality.HIGH;
- tx.hide();
- return tx;
-}
diff --git a/lightsoff/data/themes/up/theme.js b/lightsoff/data/themes/up/theme.js
index 3b416bb..e20b52a 100644
--- a/lightsoff/data/themes/up/theme.js
+++ b/lightsoff/data/themes/up/theme.js
@@ -1,38 +1,15 @@
-file_prefix = imports.path.file_prefix;
-
Clutter = imports.gi.Clutter;
+ThemeLoader = imports.ThemeLoader;
var name = "Shine";
-var setup_done = false;
-var light = [ load_svg("off.svg"), load_svg("on.svg") ];
-var arrow = load_svg("arrow.svg");
-var backing = load_svg("backing.svg");
-var led_back = load_svg("led-back.svg");
-var highlight = load_svg("highlight.svg");
-
-function setup(a)
-{
- if(setup_done)
- return;
- setup_done = true;
- a.add_actor(light[0]);
- a.add_actor(light[1]);
- a.add_actor(arrow);
- a.add_actor(backing);
- a.add_actor(led_back);
- a.add_actor(highlight);
-}
+var light = [ ThemeLoader.load_svg("up", "off.svg"),
+ ThemeLoader.load_svg("up", "on.svg") ];
+var arrow = ThemeLoader.load_svg("up", "arrow.svg");
+var backing = ThemeLoader.load_svg("up", "backing.svg");
+var led_back = ThemeLoader.load_svg("up", "led-back.svg");
+var highlight = ThemeLoader.load_svg("up", "highlight.svg");
-// helper functions should be put somewhere global
+var loaded = false;
+var textures = [light[0], light[1], arrow, backing, led_back, highlight];
-function load_svg(file)
-{
- // TODO: either imports should set the cwd (and this can go away),
- // or we need some quick way to compose paths. Really, we need that anyway.
-
- var tx = new Clutter.Texture({filename: file_prefix + "themes/up/" + file});
- tx.filter_quality = Clutter.TextureQuality.HIGH;
- tx.hide();
- return tx;
-}
diff --git a/lightsoff/src/Settings.js b/lightsoff/src/Settings.js
index 346af5d..1f5b8bf 100644
--- a/lightsoff/src/Settings.js
+++ b/lightsoff/src/Settings.js
@@ -3,6 +3,7 @@ Gio = imports.gi.Gio;
GtkBuilder = imports.gtkbuilder;
main = imports.main;
GConf = imports.gi.GConf;
+ThemeLoader = imports.ThemeLoader;
GConf.init(Seed.argv);
@@ -68,7 +69,7 @@ handlers = {
return;
theme = new_theme;
- theme.setup(main.stage);
+ ThemeLoader.load_theme(main.stage, theme);
try
{
diff --git a/lightsoff/src/ThemeLoader.js b/lightsoff/src/ThemeLoader.js
new file mode 100644
index 0000000..f5374ab
--- /dev/null
+++ b/lightsoff/src/ThemeLoader.js
@@ -0,0 +1,21 @@
+Clutter = imports.gi.Clutter;
+
+function load_svg(theme, file)
+{
+ var tx = new Clutter.Texture({filename: imports.path.file_prefix + "themes/"
+ + theme + "/" + file});
+ tx.filter_quality = Clutter.TextureQuality.HIGH;
+ tx.hide();
+ return tx;
+}
+
+function load_theme(stage, theme)
+{
+ if(theme.loaded)
+ return;
+
+ theme.loaded = true;
+
+ for(actor in theme.textures)
+ stage.add_actor(theme.textures[actor]);
+}
diff --git a/lightsoff/src/main.js b/lightsoff/src/main.js
index 372cb16..67c1ccb 100755
--- a/lightsoff/src/main.js
+++ b/lightsoff/src/main.js
@@ -16,6 +16,7 @@ GnomeGamesSupport.stock_init();
Game = imports.Game;
Settings = imports.Settings;
About = imports.About;
+themes = imports.ThemeLoader;
handlers = {
show_settings: function(selector, ud)
@@ -57,7 +58,7 @@ stage.color = {alpha:255};
window.show_all();
stage.show_all();
-Settings.theme.setup(stage);
+themes.load_theme(stage, Settings.theme);
var game = new Game.GameView();
stage.add_actor(game);
diff --git a/lightsoff/src/path.js.in b/lightsoff/src/path.js.in
new file mode 100644
index 0000000..7675357
--- /dev/null
+++ b/lightsoff/src/path.js.in
@@ -0,0 +1 @@
+file_prefix = '@prefix@' + "/share/gnome-games/lightsoff/";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]