[ease] [general] Improved background handling



commit d24e5db61c14a0db28ca27deba8c49fc656bb7dc
Author: Nate Stedman <natesm gmail com>
Date:   Sat Jul 24 04:24:40 2010 -0400

    [general] Improved background handling
    
    - Colors, gradients, and images are now supported in
      both themes and documents.
    - SlideActor uses cairo to render the background
    - Added themes: Blue, Green, Red, Goddard

 Makefile.am                                      |   32 +++---
 configure.ac                                     |    2 +-
 data/Makefile.am                                 |   10 ++
 data/theme-defaults.json                         |    3 +-
 {themes => data/themes}/Black/Theme.json         |    0
 data/themes/Blue/Theme.json                      |   13 ++
 data/themes/Goddard/Media/default.jpg            |  Bin 0 -> 132275 bytes
 {themes/Black => data/themes/Goddard}/Theme.json |    5 +-
 data/themes/Green/Theme.json                     |   13 ++
 {themes/Black => data/themes/Red}/Theme.json     |    5 +-
 {themes => data/themes}/White/Theme.json         |    0
 {themes => data/themes}/build.sh                 |    0
 examples/Transitions/Document.json               |   98 ++++++++++------
 src/ease-gradient.vala                           |   50 ++++++++-
 src/ease-json-parser.vala                        |   27 ++++-
 src/ease-slide-actor.vala                        |   37 ++----
 src/ease-slide.vala                              |  142 ++++++++++++++++++----
 src/ease-theme.vala                              |   25 ++++-
 src/ease-welcome-actor.vala                      |    6 +-
 19 files changed, 350 insertions(+), 118 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 52ab9ee..6fee01c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -61,19 +61,20 @@ ease_SOURCES = \
 	$(NULL)
 
 # ease_VALAFLAGS = $(EASE_PACKAGES)
-VALAFLAGS = --pkg glib-2.0 \
-		--pkg gtk+-2.0 \
-		--pkg clutter-1.0 \
-		--pkg gdk-2.0 \
-		--pkg gee-1.0 \
-		--pkg clutter-gtk-0.10 \
-		--pkg cogl-1.0 \
-		--pkg gio-2.0 \
-		--pkg json-glib-1.0\
-		--pkg libarchive\
-		--pkg gmodule-2.0\
-		-g \
-		$(NULL)
+VALAFLAGS = \
+	--pkg glib-2.0 \
+	--pkg gtk+-2.0 \
+	--pkg clutter-1.0 \
+	--pkg gdk-2.0 \
+	--pkg gee-1.0 \
+	--pkg clutter-gtk-0.10 \
+	--pkg cogl-1.0 \
+	--pkg gio-2.0 \
+	--pkg json-glib-1.0\
+	--pkg libarchive\
+	--pkg gmodule-2.0\
+	-g \
+	$(NULL)
 
 SUBDIRS = po data
 
@@ -89,15 +90,12 @@ DISTCLEANFILES = data/ease.desktop \
 
 ACLOCAL_AMFLAGS = -I m4
 
-themedir = $(datadir)/ease/themes
-theme_DATA = $(wildcard $(top_srcdir)/themes/*.easetheme)
-
 doc: src/*.vala
 	rm -rf doc
 	valadoc --internal --private --pkg "json-glib-1.0" --pkg "gee-1.0"  --pkg "clutter-gtk-0.10" --pkg "libarchive" --directory=./doc --basedir=src ./src/*.vala
 	gnome-open doc/doc/Ease.html
 
 archive: themes/* examples/*
-	sh themes/build.sh
+	sh data/themes/build.sh
 	sh examples/build.sh
 
diff --git a/configure.ac b/configure.ac
index 98104e7..7fdd951 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,7 +44,7 @@ AC_SUBST(GETTEXT_PACKAGE)
 AM_GLIB_GNU_GETTEXT
 
 dnl Package Themes
-AC_CONFIG_COMMANDS([build-themes], [sh themes/build.sh])
+AC_CONFIG_COMMANDS([build-themes], [sh data/themes/build.sh])
 
 dnl Package Example .ease files
 AC_CONFIG_COMMANDS([build-examples], [sh examples/build.sh])
diff --git a/data/Makefile.am b/data/Makefile.am
index ba8b5f5..e9a6bbf 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -13,6 +13,16 @@ ui_DATA = $(wildcard $(top_srcdir)/data/ui/*.ui)
 jsondir = $(datadir)/ease
 json_DATA = theme-defaults.json
 
+themedir = $(datadir)/ease/themes
+theme_DATA = \
+	themes/White.easetheme \
+	themes/Black.easetheme \
+	themes/Blue.easetheme \
+	themes/Red.easetheme \
+	themes/Green.easetheme \
+	themes/Goddard.easetheme \
+	$(NULL)
+
 EXTRA_DIST = \
     $(ui_DATA) \
     $(svg_DATA) \
diff --git a/data/theme-defaults.json b/data/theme-defaults.json
index 22d1c3c..5b28d38 100644
--- a/data/theme-defaults.json
+++ b/data/theme-defaults.json
@@ -1,6 +1,7 @@
 {
 	"master-defaults" : {
-		"background-color" : "1, 1, 1"
+		"background-color" : "1, 1, 1",
+		"background-type" : "background-type-color"
 	},
 	
 	"element-defaults" : {
diff --git a/themes/Black/Theme.json b/data/themes/Black/Theme.json
similarity index 100%
copy from themes/Black/Theme.json
copy to data/themes/Black/Theme.json
diff --git a/data/themes/Blue/Theme.json b/data/themes/Blue/Theme.json
new file mode 100644
index 0000000..807b09e
--- /dev/null
+++ b/data/themes/Blue/Theme.json
@@ -0,0 +1,13 @@
+{
+	"title" : "Blue",
+	"author" : "Nate Stedman <natesm gmail com>",
+	
+	"master-defaults" : {
+		"background-type" : "background-type-gradient",
+		"background-gradient" : "0.4, 0.52, 0.65 | 0.24, 0.31, 0.4 | linear | 0"
+	},
+	
+	"element-defaults" : {
+		"text-color" : "1, 1, 1"
+	}
+}
diff --git a/data/themes/Goddard/Media/default.jpg b/data/themes/Goddard/Media/default.jpg
new file mode 100644
index 0000000..dcf93e8
Binary files /dev/null and b/data/themes/Goddard/Media/default.jpg differ
diff --git a/themes/Black/Theme.json b/data/themes/Goddard/Theme.json
similarity index 54%
copy from themes/Black/Theme.json
copy to data/themes/Goddard/Theme.json
index 1235945..2ded4c9 100644
--- a/themes/Black/Theme.json
+++ b/data/themes/Goddard/Theme.json
@@ -1,9 +1,10 @@
 {
-	"title" : "Black",
+	"title" : "Goddard",
 	"author" : "Nate Stedman <natesm gmail com>",
 	
 	"master-defaults" : {
-		"background-color" : "0, 0, 0"
+		"background-type" : "background-type-image",
+		"background-image" : "Media/default.jpg"
 	},
 	
 	"element-defaults" : {
diff --git a/data/themes/Green/Theme.json b/data/themes/Green/Theme.json
new file mode 100644
index 0000000..6f9d3fb
--- /dev/null
+++ b/data/themes/Green/Theme.json
@@ -0,0 +1,13 @@
+{
+	"title" : "Green",
+	"author" : "Nate Stedman <natesm gmail com>",
+	
+	"master-defaults" : {
+		"background-type" : "background-type-gradient",
+		"background-gradient" : "0.1, 0.2, 0.1 | 0.2, 0.4, 0.2 | linear-mirrored | 0"
+	},
+	
+	"element-defaults" : {
+		"text-color" : "1, 1, 1"
+	}
+}
diff --git a/themes/Black/Theme.json b/data/themes/Red/Theme.json
similarity index 50%
rename from themes/Black/Theme.json
rename to data/themes/Red/Theme.json
index 1235945..85cbf9d 100644
--- a/themes/Black/Theme.json
+++ b/data/themes/Red/Theme.json
@@ -1,9 +1,10 @@
 {
-	"title" : "Black",
+	"title" : "Red",
 	"author" : "Nate Stedman <natesm gmail com>",
 	
 	"master-defaults" : {
-		"background-color" : "0, 0, 0"
+		"background-type" : "background-type-gradient",
+		"background-gradient" : "1.0, 0.3, 0.1 | 0.7, 0, 0 | radial | 0"
 	},
 	
 	"element-defaults" : {
diff --git a/themes/White/Theme.json b/data/themes/White/Theme.json
similarity index 100%
rename from themes/White/Theme.json
rename to data/themes/White/Theme.json
diff --git a/themes/build.sh b/data/themes/build.sh
similarity index 100%
rename from themes/build.sh
rename to data/themes/build.sh
diff --git a/examples/Transitions/Document.json b/examples/Transitions/Document.json
index 883fc69..4e818f6 100644
--- a/examples/Transitions/Document.json
+++ b/examples/Transitions/Document.json
@@ -3,7 +3,8 @@
   "slides" : [
     {
       "transition" : "1",
-      "background-color" : "0.13, 0.13, 0.13, 0.13",
+      "background-color" : "0.13, 0.13, 0.13",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -48,7 +49,8 @@
     },
     {
       "transition" : "2",
-      "background-color" : "1.0, 1.0, 1.0, 1.0",
+      "background-color" : "1, 1, 1, 1",
+      "background-type" : "background-type-color",
       "variant" : "2",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -66,7 +68,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "900",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "36"
         },
@@ -83,7 +85,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "500",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "16"
         }
@@ -93,7 +95,9 @@
     },
     {
       "transition" : "3",
-      "background-color" : "0.13, 0.13, 0.13, 0.13",
+      "background-color" : "0.13, 0.13, 0.13",
+      "background-type" : "background-type-color",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -138,7 +142,8 @@
     },
     {
       "transition" : "4",
-      "background-color" : "1.0, 1.0, 1.0, 1.0",
+      "background-color" : "1, 1, 1, 1",
+      "background-type" : "background-type-color",
       "variant" : "7",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -156,7 +161,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "900",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "36"
         },
@@ -173,7 +178,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "500",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "16"
         }
@@ -183,7 +188,9 @@
     },
     {
       "transition" : "5",
-      "background-color" : "0.13, 0.13, 0.13, 0.13",
+      "background-color" : "0.13, 0.13, 0.13",
+      "background-type" : "background-type-color",
+      "background-type" : "background-type-color",
       "variant" : "13",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -228,7 +235,8 @@
     },
     {
       "transition" : "6",
-      "background-color" : "1.0, 1.0, 1.0, 1.0",
+      "background-color" : "1, 1, 1, 1",
+      "background-type" : "background-type-color",
       "variant" : "2",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -246,7 +254,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "900",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "36"
         },
@@ -263,7 +271,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "500",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "16"
         }
@@ -273,7 +281,9 @@
     },
     {
       "transition" : "7",
-      "background-color" : "0.13, 0.13, 0.13, 0.13",
+      "background-color" : "0.13, 0.13, 0.13",
+      "background-type" : "background-type-color",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -318,7 +328,8 @@
     },
     {
       "transition" : "8",
-      "background-color" : "1.0, 1.0, 1.0, 1.0",
+      "background-color" : "1, 1, 1, 1",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -336,7 +347,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "900",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "36"
         },
@@ -353,7 +364,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "500",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "16"
         }
@@ -363,7 +374,9 @@
     },
     {
       "transition" : "10",
-      "background-color" : "0.13, 0.13, 0.13, 0.13",
+      "background-color" : "0.13, 0.13, 0.13",
+      "background-type" : "background-type-color",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -408,7 +421,8 @@
     },
     {
       "transition" : "11",
-      "background-color" : "1.0, 1.0, 1.0, 1.0",
+      "background-color" : "1, 1, 1, 1",
+      "background-type" : "background-type-color",
       "variant" : "6",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -426,7 +440,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "900",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "36"
         },
@@ -443,7 +457,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "500",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "16"
         }
@@ -453,7 +467,9 @@
     },
     {
       "transition" : "12",
-      "background-color" : "0.13, 0.13, 0.13, 0.13",
+      "background-color" : "0.13, 0.13, 0.13",
+      "background-type" : "background-type-color",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -498,7 +514,8 @@
     },
     {
       "transition" : "13",
-      "background-color" : "1.0, 1.0, 1.0, 1.0",
+      "background-color" : "1, 1, 1, 1",
+      "background-type" : "background-type-color",
       "variant" : "2",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -516,7 +533,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "900",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "36"
         },
@@ -533,7 +550,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "500",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "16"
         }
@@ -543,7 +560,9 @@
     },
     {
       "transition" : "15",
-      "background-color" : "0.13, 0.13, 0.13, 0.13",
+      "background-color" : "0.13, 0.13, 0.13",
+      "background-type" : "background-type-color",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -588,7 +607,8 @@
     },
     {
       "transition" : "16",
-      "background-color" : "1.0, 1.0, 1.0, 1.0",
+      "background-color" : "1, 1, 1, 1",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -606,7 +626,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "900",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "36"
         },
@@ -623,7 +643,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "500",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "16"
         }
@@ -633,7 +653,9 @@
     },
     {
       "transition" : "14",
-      "background-color" : "0.13, 0.13, 0.13, 0.13",
+      "background-color" : "0.13, 0.13, 0.13",
+      "background-type" : "background-type-color",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -678,7 +700,8 @@
     },
     {
       "transition" : "17",
-      "background-color" : "1.0, 1.0, 1.0, 1.0",
+      "background-color" : "1, 1, 1, 1",
+      "background-type" : "background-type-color",
       "variant" : "15",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -696,7 +719,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "900",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "36"
         },
@@ -713,7 +736,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "500",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "16"
         }
@@ -723,7 +746,9 @@
     },
     {
       "transition" : "9",
-      "background-color" : "0.13, 0.13, 0.13, 0.13",
+      "background-color" : "0.13, 0.13, 0.13",
+      "background-type" : "background-type-color",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -768,7 +793,8 @@
     },
     {
       "transition" : "0",
-      "background-color" : "1.0, 1.0, 1.0, 1.0",
+      "background-color" : "1, 1, 1, 1",
+      "background-type" : "background-type-color",
       "variant" : "0",
       "automatically_advance" : "true",
       "advance_delay" : "0.5",
@@ -786,7 +812,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "900",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "36"
         },
@@ -803,7 +829,7 @@
           "text-align" : "left",
           "width" : "964",
           "text-weight" : "500",
-          "text-color" : "0.13, 0.13, 0.13, 0.13",
+          "text-color" : "0.13, 0.13, 0.13",
           "text-font" : "Sans",
           "text-size" : "16"
         }
diff --git a/src/ease-gradient.vala b/src/ease-gradient.vala
index 0f3f960..80d9ca6 100644
--- a/src/ease-gradient.vala
+++ b/src/ease-gradient.vala
@@ -83,7 +83,7 @@ public class Ease.Gradient : GLib.Object
 	 */
 	public Gradient.from_string(string str)
 	{
-		var split = str.split(SPLIT);
+		var split = str.replace(" ", "").split(SPLIT);
 		start = new Color.from_string(split[0]);
 		end = new Color.from_string(split[1]);
 		mode = GradientMode.from_string(split[2]);
@@ -110,6 +110,54 @@ public class Ease.Gradient : GLib.Object
 		end = start;
 		start = temp;
 	}
+	
+	/**
+	 * Renders the gradient to the given Cairo context at the specified size.
+	 *
+	 * @param cr The Cairo context to render to.
+	 * @param width The width of the rendered rectangle.
+	 * @param height The height of the rendered rectangle.
+	 */
+	public void cairo_render_rect(Cairo.Context cr, int width, int height)
+	{
+		cr.save();
+		cr.rectangle(0, 0, width, height);
+		
+		Cairo.Pattern pattern;
+		switch (mode)
+		{
+			case GradientMode.LINEAR:				
+				pattern = new Cairo.Pattern.linear(0, 0, 0, height);
+				pattern.add_color_stop_rgba(0, start.red, start.green,
+						                    start.blue, start.alpha);
+				pattern.add_color_stop_rgba(1, end.red, end.green,
+						                    end.blue, end.alpha);
+				break;
+			case GradientMode.LINEAR_MIRRORED:
+				pattern = new Cairo.Pattern.linear(0, 0, 0, height);
+				pattern.add_color_stop_rgba(0, start.red, start.green,
+						                    start.blue, start.alpha);
+				pattern.add_color_stop_rgba(0.5, end.red, end.green,
+						                    end.blue, end.alpha);
+				pattern.add_color_stop_rgba(1, start.red, start.green,
+						                    start.blue, start.alpha);
+				break;
+			default: // radial
+				pattern = new Cairo.Pattern.radial(width / 2, height / 2, 0,
+				                                       width / 2, height / 2,
+				                                       width / 2);
+				pattern.add_color_stop_rgba(0, start.red, start.green,
+						                    start.blue, start.alpha);
+				pattern.add_color_stop_rgba(1, end.red, end.green,
+						                    end.blue, end.alpha);
+				break;
+		}
+		
+		cr.set_source(pattern);
+		cr.fill();
+		
+		cr.restore();
+	}
 }
 
 /**
diff --git a/src/ease-json-parser.vala b/src/ease-json-parser.vala
index 16bc490..cbf28c1 100644
--- a/src/ease-json-parser.vala
+++ b/src/ease-json-parser.vala
@@ -93,16 +93,25 @@ public static class Ease.JSONParser
 		slide.title = obj.get_string_member("title");
 		
 		// read the slide's background properties
-		if (obj.has_member("background_image"))
+		if (obj.has_member(Theme.BACKGROUND_IMAGE))
 		{
-			slide.background_image = obj.get_string_member("background_image");
+			slide.background_image =
+				obj.get_string_member(Theme.BACKGROUND_IMAGE);
 		}
-		else
+		if (obj.has_member(Theme.BACKGROUND_COLOR))
 		{
 			slide.background_color =
 				new Color.from_string(
 					obj.get_string_member(Theme.BACKGROUND_COLOR));
 		}
+		if (obj.has_member(Theme.BACKGROUND_GRADIENT))
+		{
+			slide.background_gradient =
+				new Gradient.from_string(
+					obj.get_string_member(Theme.BACKGROUND_GRADIENT));
+		}
+		slide.background_type = BackgroundType.from_string(
+			obj.get_string_member(Theme.BACKGROUND_TYPE));
 		
 		// parse the elements
 		var elements = obj.get_array_member("elements");
@@ -200,13 +209,21 @@ public static class Ease.JSONParser
 		// write the slide's background properties
 		if (slide.background_image != null)
 		{
-			obj.set_string_member("background_image", slide.background_image);
+			obj.set_string_member(Theme.BACKGROUND_IMAGE,
+			                      slide.background_image);
 		}
-		else
+		if (slide.background_color != null)
 		{
 			obj.set_string_member(Theme.BACKGROUND_COLOR,
 			                      slide.background_color.to_string());
 		}
+		if (slide.background_gradient != null)
+		{
+			obj.set_string_member(Theme.BACKGROUND_GRADIENT,
+			                      slide.background_gradient.to_string());
+		}
+		obj.set_string_member(Theme.BACKGROUND_TYPE,
+		                      slide.background_type.to_string());
 		
 		// add the slide's elements
 		var elements = new Json.Array();
diff --git a/src/ease-slide-actor.vala b/src/ease-slide-actor.vala
index e94c43e..0f8a87f 100644
--- a/src/ease-slide-actor.vala
+++ b/src/ease-slide-actor.vala
@@ -32,7 +32,7 @@ public class Ease.SlideActor : Clutter.Group
 	/**
 	 * The actor for the slide's background.
 	 */
-	public Clutter.Actor background;
+	public Clutter.CairoTexture background;
 
 	/**
 	 * The group for the slide's contents.
@@ -184,8 +184,7 @@ public class Ease.SlideActor : Clutter.Group
 	public SlideActor.blank(Document document, Clutter.Color color)
 	{
 		// create the background
-		background = new Clutter.Rectangle();
-		((Clutter.Rectangle)background).color = color;
+		background = new Clutter.CairoTexture(document.width, document.height);
 		
 		// create a blank contents actor
 		contents = new Clutter.Group();
@@ -245,33 +244,23 @@ public class Ease.SlideActor : Clutter.Group
 	 */
 	private void set_background()
 	{
-		if (background != null)
+		if (background == null)
 		{
-			if (background.get_parent() == this)
-			{
-				remove_actor(background);
-			}
+			background = new Clutter.CairoTexture((uint)width_px,
+			                                      (uint)height_px);
 		}
-
-		if (slide.background_image != null)
+		
+		// render the background
+		try
 		{
-			try
-			{
-				background = new Clutter.Texture();
-				(background as Clutter.Texture).set_from_file(
-					slide.background_abs);
-			}
-			catch (GLib.Error e)
-			{
-				stdout.printf(_("Error loading background: %s"), e.message);
-			}
+			var cr = background.create();
+			slide.cairo_render_background(cr, (int)width_px, (int)height_px);
 		}
-		else // the background is a solid color
+		catch (GLib.Error e)
 		{
-			var rect = new Clutter.Rectangle();
-			rect.color = slide.background_color.clutter;
-			background = rect;
+			critical("Error rendering slide actor background: %s", e.message);
 		}
+		
 		background.width = width_px;
 		background.height = height_px;
 
diff --git a/src/ease-slide.vala b/src/ease-slide.vala
index bc0cb23..375bbab 100644
--- a/src/ease-slide.vala
+++ b/src/ease-slide.vala
@@ -63,15 +63,58 @@ public class Ease.Slide : GLib.Object
 	 */
 	public double advance_delay { get; set; }
 	
+	public BackgroundType background_type { get; set; }
+	
 	/**
-	 * The background color, if there is no background image
+	 * The background color, if this slide uses a solid color for a background.
+	 *
+	 * Setting this property sets { link background_type} to
+	 * { link BackgroundType.COLOR}.
 	 */
-	public Color background_color;
+	public Color background_color
+	{
+		get { return background_color_priv; }
+		set
+		{
+			background_color_priv = value;
+			background_type = BackgroundType.COLOR;
+		}
+	}
+	private Color background_color_priv;
 	
 	/**
-	 * The background image, if one is set
+	 * The background gradient, if this slide uses a gradient for a background.
+	 *
+	 * Setting this property sets { link background_type} to
+	 * { link BackgroundType.GRADIENT}.
 	 */
-	public string background_image { get; set; }
+	public Gradient background_gradient
+	{
+		get { return background_gradient_priv; }
+		set
+		{
+			background_gradient_priv = value;
+			background_type = BackgroundType.GRADIENT;
+		}
+	}
+	private Gradient background_gradient_priv;
+	
+	/**
+	 * The background image, if this slide uses an image for a background.
+	 *
+	 * Setting this property sets { link background_type} to
+	 * { link BackgroundType.IMAGE}.
+	 */
+	public string background_image
+	{
+		get { return background_image_priv; }
+		set
+		{
+			background_image_priv = value;
+			background_type = BackgroundType.IMAGE;
+		}
+	}
+	private string background_image_priv;
 	
 	/**
 	 * The absolute path of the background image, if one is set.
@@ -255,27 +298,7 @@ public class Ease.Slide : GLib.Object
 	public void cairo_render_sized(Cairo.Context context,
 	                               int w, int h) throws GLib.Error
 	{
-		// write the background color if there is no image
-		if (background_image == null)
-		{
-			context.rectangle(0, 0, w, h);
-			background_color.set_cairo(context);
-			context.fill();
-		}
-		
-		// otherwise, write the image
-		else
-		{
-			var pixbuf = new Gdk.Pixbuf.from_file_at_scale(background_abs,
-			                                                h,
-			                                                w,
-			                                                false);
-		
-			Gdk.cairo_set_source_pixbuf(context, pixbuf, 0, 0);
-		
-			context.rectangle(0, 0, w, h);
-			context.fill();
-		}
+		cairo_render_background(context, w, h);
 		
 		foreach (var e in elements)
 		{
@@ -283,6 +306,37 @@ public class Ease.Slide : GLib.Object
 		}
 	}
 	
+	/** 
+	 * Draws the slide's background to a Cairo.Context at a specified size.
+	 *
+	 * @param cr The Cairo.Context to draw to.
+	 * @param w The width to render at.
+	 * @param h The height to render at.
+	 */
+	public void cairo_render_background(Cairo.Context cr,
+	                                    int w, int h) throws GLib.Error
+	{
+		switch (background_type)
+		{
+			case BackgroundType.COLOR:
+				cr.rectangle(0, 0, w, h);
+				background_color.set_cairo(cr);
+				cr.fill();
+				break;
+			case BackgroundType.GRADIENT:
+				background_gradient.cairo_render_rect(cr, w, h);
+				break;
+			case BackgroundType.IMAGE:
+				var pixbuf = new Gdk.Pixbuf.from_file_at_scale(background_abs,
+			                                                   w, h,
+			                                                   false);
+				Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
+				cr.rectangle(0, 0, w, h);
+				cr.fill();
+				break;
+		}
+	}
+	
 	/**
 	 * Creates HTML markup for this Slide.
 	 * 
@@ -333,3 +387,41 @@ public class Ease.Slide : GLib.Object
 		html += "</div>\n";
 	}
 }
+
+public enum Ease.BackgroundType
+{
+	COLOR,
+	GRADIENT,
+	IMAGE;
+	
+	/**
+	 * Returns a string representation of this BackgroundType.
+	 */
+	public string to_string()
+	{
+		switch (this)
+		{
+			case COLOR: return Theme.BACKGROUND_TYPE_COLOR;
+			case GRADIENT: return Theme.BACKGROUND_TYPE_GRADIENT;
+			case IMAGE: return Theme.BACKGROUND_TYPE_IMAGE;
+		}
+		return "undefined";
+	}
+	
+	/**
+	 * Creates a BackgroundType from a string representation.
+	 */
+	public static BackgroundType from_string(string str)
+	{
+		switch (str)
+		{
+			case Theme.BACKGROUND_TYPE_COLOR: return COLOR;
+			case Theme.BACKGROUND_TYPE_GRADIENT: return GRADIENT;
+			case Theme.BACKGROUND_TYPE_IMAGE: return IMAGE;
+		}
+		
+		warning("%s is not a gradient type", str);
+		return COLOR;
+	}
+}
+
diff --git a/src/ease-theme.vala b/src/ease-theme.vala
index 62867e0..e0fd28d 100644
--- a/src/ease-theme.vala
+++ b/src/ease-theme.vala
@@ -57,8 +57,16 @@ public class Ease.Theme : GLib.Object
 	
 	// master slide properties
 	public const string BACKGROUND_COLOR = "background-color";
+	public const string BACKGROUND_GRADIENT = "background-gradient";
+	public const string BACKGROUND_IMAGE = "background-image";
 	public const string S_IDENTIFIER = "slide-identifier";
 	
+	// background types
+	private const string BACKGROUND_TYPE = "background-type";
+	private const string BACKGROUND_TYPE_COLOR = "background-type-color";
+	private const string BACKGROUND_TYPE_GRADIENT = "background-type-gradient";
+	private const string BACKGROUND_TYPE_IMAGE = "background-type-image";
+	
 	// text content types
 	private const string TITLE_TEXT = "title-text";
 	private const string AUTHOR_TEXT = "author-text";
@@ -314,8 +322,21 @@ public class Ease.Theme : GLib.Object
 		Slide slide = new Slide();
 		
 		// set the slide background property
-		slide.background_color = new Color.
-			from_string(master_get(master, BACKGROUND_COLOR));
+		switch (master_get(master, BACKGROUND_TYPE))
+		{
+			case BACKGROUND_TYPE_COLOR:
+				slide.background_color = new Color.
+					from_string(master_get(master, BACKGROUND_COLOR));
+				break;
+			case BACKGROUND_TYPE_GRADIENT:
+				slide.background_gradient = new Gradient.
+					from_string(master_get(master, BACKGROUND_GRADIENT));
+				break;
+			case BACKGROUND_TYPE_IMAGE:
+				slide.background_image = master_get(master, BACKGROUND_IMAGE);
+				break;
+				
+		}
 		
 		switch (master)
 		{
diff --git a/src/ease-welcome-actor.vala b/src/ease-welcome-actor.vala
index fcaeaab..02a6cfa 100644
--- a/src/ease-welcome-actor.vala
+++ b/src/ease-welcome-actor.vala
@@ -49,7 +49,7 @@ public class Ease.WelcomeActor : Clutter.Group
 	/**
 	 * The theme previewed by this WelcomeActor.
 	 */
-	public Theme theme;
+	public Theme theme { get; set; }
 	
 	// display the name of the theme
 	private const string FONT_NAME = "Sans 8";
@@ -155,7 +155,9 @@ public class Ease.WelcomeActor : Clutter.Group
 		// render
 		try
 		{
-			create_slide(w, h).cairo_render_sized(slide_actor.create(), w, h);
+			var slide = create_slide(w, h);
+			slide.theme = theme;
+			slide.cairo_render_sized(slide_actor.create(), w, h);
 		}
 		catch (GLib.Error e)
 		{



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]