[ease] [core] Added Ease.Image



commit f8d39fff0179badf65babf41473436dfd8f5645d
Author: Nate Stedman <natesm gmail com>
Date:   Wed Jul 28 16:49:20 2010 -0400

    [core] Added Ease.Image
    
    Ease.Image contains the "image" and "image_source" properties
    that were formerly in Background.

 ease-core/Makefile.am                 |    1 +
 ease-core/ease-background-widget.vala |   18 +++++-----
 ease-core/ease-background.vala        |   45 ++++++++------------------
 ease-core/ease-image.vala             |   57 +++++++++++++++++++++++++++++++++
 ease-core/ease-slide.vala             |   18 +++++-----
 ease-core/ease-theme.vala             |    3 +-
 6 files changed, 92 insertions(+), 50 deletions(-)
---
diff --git a/ease-core/Makefile.am b/ease-core/Makefile.am
index 5eac9d4..7ef729e 100644
--- a/ease-core/Makefile.am
+++ b/ease-core/Makefile.am
@@ -27,6 +27,7 @@ libease_core_0_3_la_SOURCES = \
 	ease-html-exporter.vala \
 	ease-image-actor.vala \
 	ease-image-element.vala \
+	ease-image.vala \
 	ease-iterable-models.vala \
 	ease-media-element.vala \
 	ease-shape-element.vala \
diff --git a/ease-core/ease-background-widget.vala b/ease-core/ease-background-widget.vala
index 5032443..0eb6725 100644
--- a/ease-core/ease-background-widget.vala
+++ b/ease-core/ease-background-widget.vala
@@ -174,7 +174,7 @@ public class Ease.BackgroundWidget : Gtk.Alignment
 		var action = new UndoAction(background, "background-type");
 		
 		// ease doesn't provide a default for images, so one must be requested
-		if (type == BackgroundType.IMAGE && background.image == null)
+		if (type == BackgroundType.IMAGE && background.image.filename == null)
 		{
 			var dialog = new Gtk.FileChooserDialog(BG_DIALOG_TITLE,
 			                                       widget_window(this),
@@ -189,9 +189,9 @@ public class Ease.BackgroundWidget : Gtk.Alignment
 					try
 					{
 						var fname = dialog.get_filename();
-						background.image_source = fname;
+						background.image.source = fname;
 						var i = document.add_media_file(fname);
-						background.image = i;
+						background.image.filename = i;
 					}
 					catch (GLib.Error e)
 					{
@@ -294,9 +294,9 @@ public class Ease.BackgroundWidget : Gtk.Alignment
 		// set the button's filename when the action is applied
 		action.applied.connect((a) => {
 			// if slide changes, this is still ok
-			if (background.image_source != null)
+			if (background.image.source != null)
 			{
-				bg_image.set_filename(background.image_source);
+				bg_image.set_filename(background.image.source);
 			}
 			else
 			{
@@ -308,9 +308,9 @@ public class Ease.BackgroundWidget : Gtk.Alignment
 		
 		try
 		{
-			background.image_source = sender.get_filename();
+			background.image.source = sender.get_filename();
 			var i = document.add_media_file(sender.get_filename());
-			background.image = i;
+			background.image.filename = i;
 		}
 		catch (GLib.Error e)
 		{
@@ -402,9 +402,9 @@ public class Ease.BackgroundWidget : Gtk.Alignment
 				box_image.show_all();
 				
 				background.background_type = BackgroundType.IMAGE;
-				if (background.image_source != null)
+				if (background.image.source != null)
 				{
-					bg_image.set_filename(background.image_source);
+					bg_image.set_filename(background.image.source);
 				}
 				else
 				{
diff --git a/ease-core/ease-background.vala b/ease-core/ease-background.vala
index c7f048b..f8104a6 100644
--- a/ease-core/ease-background.vala
+++ b/ease-core/ease-background.vala
@@ -24,7 +24,7 @@ public class Ease.Background : GLib.Object
 	/**
 	 * The background background_type of this element.
 	 */
-	public BackgroundType background_type { get; set; }
+	public BackgroundType background_type { get; internal set; }
 	
 	/**
 	 * The background color, if this element uses a solid color for a
@@ -33,7 +33,7 @@ public class Ease.Background : GLib.Object
 	 * To use this property, { link background_type} must also be set to
 	 * { link BackgroundType.COLOR}.
 	 */
-	public Color color { get; set; default = Color.black; }
+	public Color color { get; internal set; default = Color.black; }
 	
 	/**
 	 * The background gradient, if this slide uses a gradient for a background.
@@ -41,26 +41,18 @@ public class Ease.Background : GLib.Object
 	 * To use this property, { link background_type} must also be set to
 	 * { link BackgroundType.GRADIENT}.
 	 */
-	public Gradient gradient { get; set;
+	public Gradient gradient { get; internal set;
 	                           default = Gradient.default_background; }
 	
 	/**
-	 * The background image, if this element uses an image for a background.
 	 *
-	 * To use this property, { link background_type} must also be set to
-	 * { link BackgroundType.IMAGE}.
-	 */
-	public string image { get; set; }
-	
-	/**
-	 * The original path to the background image. This path is used in the UI.
 	 */
-	public string image_source { get; set; }
+	public Image image { get; internal set; default = new Image(); }
 	
 	/**
 	 * Emitted when an image file is added to this background.
 	 */
-	public signal void image_added(string image_path);
+	internal signal void image_added(string image_path);
 	
 	/**
 	 * Creates a new Background.
@@ -84,8 +76,9 @@ public class Ease.Background : GLib.Object
 	{
 		if (obj.has_member(Theme.BACKGROUND_IMAGE))
 		{
-			image = obj.get_string_member(Theme.BACKGROUND_IMAGE);
-			image_source = obj.get_string_member(Theme.BACKGROUND_IMAGE_SOURCE);
+			image.filename = obj.get_string_member(Theme.BACKGROUND_IMAGE);
+			image.source =
+				obj.get_string_member(Theme.BACKGROUND_IMAGE_SOURCE);
 		}
 		if (obj.has_member(Theme.BACKGROUND_COLOR))
 		{
@@ -108,8 +101,9 @@ public class Ease.Background : GLib.Object
 	{
 		if (image != null)
 		{
-			obj.set_string_member(Theme.BACKGROUND_IMAGE, image);
-			obj.set_string_member(Theme.BACKGROUND_IMAGE_SOURCE, image_source);
+			obj.set_string_member(Theme.BACKGROUND_IMAGE, image.filename);
+			obj.set_string_member(Theme.BACKGROUND_IMAGE_SOURCE,
+			                      image.source);
 		}
 		if (color != null)
 		{
@@ -120,7 +114,8 @@ public class Ease.Background : GLib.Object
 			obj.set_string_member(Theme.BACKGROUND_GRADIENT,
 			                      gradient.to_string());
 		}
-		obj.set_string_member(Theme.BACKGROUND_TYPE, background_type.to_string());
+		obj.set_string_member(Theme.BACKGROUND_TYPE,
+		                      background_type.to_string());
 	}
 	
 	/**
@@ -142,19 +137,7 @@ public class Ease.Background : GLib.Object
 				gradient.set_cairo(cr, width, height);
 				break;
 			case BackgroundType.IMAGE:
-				try
-				{
-					string full = Path.build_filename(path, image);
-					var pixbuf = new Gdk.Pixbuf.from_file_at_scale(full,
-			    	                                               width,
-			    	                                               height,
-			    	                                               false);
-					Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
-				}
-				catch (Error e)
-				{
-					critical("Error rendering image background: %s", e.message);
-				}
+				image.set_cairo(cr, width, height, path);
 				break;
 		}
 	}
diff --git a/ease-core/ease-image.vala b/ease-core/ease-image.vala
new file mode 100644
index 0000000..5ccc0b2
--- /dev/null
+++ b/ease-core/ease-image.vala
@@ -0,0 +1,57 @@
+/*  Ease, a GTK presentation application
+    Copyright (C) 2010 Nate Stedman
+
+    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 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+public class Ease.Image : GLib.Object
+{
+	/**
+	 * The background image, if this element uses an image for a background.
+	 *
+	 * To use this property, { link background_type} must also be set to
+	 * { link BackgroundType.IMAGE}.
+	 */
+	public string filename { get; set; }
+	
+	/**
+	 * The original path to the background image. This path is used in the UI.
+	 */
+	public string source { get; set; }
+	
+	/**
+	 * Sets up a CairoContext to render this image.
+	 *
+	 * @param cr The context to set up.
+	 * @param width The width of the rendering.
+	 * @param height The height of the rendering.
+	 * @param path The base path to any possible media files.
+	 */
+	public void set_cairo(Cairo.Context cr, int width, int height, string path)
+	{
+		try
+		{
+			string full = Path.build_filename(path, filename);
+			var pixbuf = new Gdk.Pixbuf.from_file_at_scale(full,
+	    	                                               width,
+	    	                                               height,
+	    	                                               false);
+			Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
+		}
+		catch (Error e)
+		{
+			critical("Error rendering image background: %s", e.message);
+		}
+	}
+}
diff --git a/ease-core/ease-slide.vala b/ease-core/ease-slide.vala
index 0e190d7..1dc92d7 100644
--- a/ease-core/ease-slide.vala
+++ b/ease-core/ease-slide.vala
@@ -78,7 +78,7 @@ public class Ease.Slide : GLib.Object, UndoSource
 		owned get
 		{
 			string p = parent == null ? theme.path : parent.path;
-			return Path.build_filename(p, background.image);
+			return Path.build_filename(p, background.image.filename);
 		}
 	}
 	
@@ -228,8 +228,8 @@ public class Ease.Slide : GLib.Object, UndoSource
 		// read the slide's background properties
 		if (obj.has_member(Theme.BACKGROUND_IMAGE))
 		{
-			background.image = obj.get_string_member(Theme.BACKGROUND_IMAGE);
-			background.image_source =
+			background.image.filename = obj.get_string_member(Theme.BACKGROUND_IMAGE);
+			background.image.source =
 				obj.get_string_member("background-image-source");
 		}
 		if (obj.has_member(Theme.BACKGROUND_COLOR))
@@ -290,11 +290,11 @@ public class Ease.Slide : GLib.Object, UndoSource
 		obj.set_string_member("title", title);
 		
 		// write the slide's background properties
-		if (background.image != null)
+		if (background.image.filename != null)
 		{
-			obj.set_string_member(Theme.BACKGROUND_IMAGE, background.image);
+			obj.set_string_member(Theme.BACKGROUND_IMAGE, background.image.filename);
 			obj.set_string_member("background-image-source",
-			                      background.image_source);
+			                      background.image.source);
 		}
 		if (background.color != null)
 		{
@@ -472,7 +472,7 @@ public class Ease.Slide : GLib.Object, UndoSource
 		html += "<div class=\"slide\" id=\"slide" +
 		        index.to_string() + "\" ";
 		
-		if (background.image == null)
+		if (background.image.filename == null)
 		{
 			// give the slide a background color
 			html += "style=\"background-color: " +
@@ -485,13 +485,13 @@ public class Ease.Slide : GLib.Object, UndoSource
 			html += ">";
 			
 			// add the background image
-			html += "<img src=\"" + exporter.basename + " " + background.image +
+			html += "<img src=\"" + exporter.basename + " " + background.image.filename +
 			        "\" alt=\"Background\" width=\"" +
 			        parent.width.to_string() + "\" height=\"" +
 			        parent.height.to_string() + "\"/>";
 
 			// copy the image file
-			exporter.copy_file(background.image, parent.path);
+			exporter.copy_file(background.image.filename, parent.path);
 		}
 		
 		// add tags for each Element
diff --git a/ease-core/ease-theme.vala b/ease-core/ease-theme.vala
index 47322cc..634294d 100644
--- a/ease-core/ease-theme.vala
+++ b/ease-core/ease-theme.vala
@@ -339,7 +339,8 @@ public class Ease.Theme : GLib.Object
 				slide.background.background_type = BackgroundType.GRADIENT;
 				break;
 			case BACKGROUND_TYPE_IMAGE:
-				slide.background.image = master_get(master, BACKGROUND_IMAGE);
+				slide.background.image.filename =
+					master_get(master, BACKGROUND_IMAGE);
 				slide.background.background_type = BackgroundType.IMAGE;
 				break;
 				



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