mistelix r16 - in trunk: . extensions/Effects extensions/Effects/Contrast extensions/Effects/Grayscale extensions/Effects/RotateImage extensions/Effects/SepiaTone po src/core src/datamodel src/widgets



Author: jmas
Date: Fri Apr 10 14:32:39 2009
New Revision: 16
URL: http://svn.gnome.org/viewvc/mistelix?rev=16&view=rev

Log:
2009-04-10 Jordi Mas <jmas softcatala org>

	* configure.in: New effects structure
	* src/widgets/SlideShowImageView.cs: New effects structure
	* src/core/EffectManager.cs: New effects structure
	* src/core/SlideImage.cs: New effects structure
	* src/datamodel/Effect.cs: New effects structure
	* src/datamodel/SlideShowProjectElement.cs: New effects structure
	* extensions/Effects/: revamped effects



Added:
   trunk/extensions/Effects/Grayscale/   (props changed)
   trunk/extensions/Effects/Grayscale/Grayscale.addin.xml
   trunk/extensions/Effects/Grayscale/Grayscale.cs
   trunk/extensions/Effects/Grayscale/Makefile.am
   trunk/extensions/Effects/SepiaTone/   (props changed)
   trunk/extensions/Effects/SepiaTone/Makefile.am
   trunk/extensions/Effects/SepiaTone/SepiaTone.addin.xml
   trunk/extensions/Effects/SepiaTone/SepiaTone.cs
Removed:
   trunk/extensions/Effects/Contrast/
   trunk/extensions/Effects/RotateImage/
Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/extensions/Effects/Makefile.am
   trunk/po/POTFILES.in
   trunk/src/core/EffectManager.cs
   trunk/src/core/SlideImage.cs
   trunk/src/datamodel/Effect.cs
   trunk/src/datamodel/SlideShowProjectElement.cs
   trunk/src/widgets/SlideShowImageView.cs

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Fri Apr 10 14:32:39 2009
@@ -135,7 +135,6 @@
 extensions/SlideTransitions/Fade/Makefile
 extensions/SlideTransitions/BarWipe/Makefile
 extensions/Effects/Makefile
-extensions/Effects/RotateImage/Makefile
-extensions/Effects/Brightness/Makefile
-extensions/Effects/Contrast/Makefile
+extensions/Effects/Grayscale/Makefile
+extensions/Effects/SepiaTone/Makefile
 ])

Added: trunk/extensions/Effects/Grayscale/Grayscale.addin.xml
==============================================================================
--- (empty file)
+++ trunk/extensions/Effects/Grayscale/Grayscale.addin.xml	Fri Apr 10 14:32:39 2009
@@ -0,0 +1,17 @@
+<Addin namespace="Mistelix"
+	version="0.10"
+	name="Grayscale"
+	description="Convert image colors to grayscale"
+	author="Jordi Mas"
+	url=""
+	defaultEnabled="true"
+	category="Effects">
+
+	<Dependencies>
+		<Addin id="Mistelix" version="0.10"/>
+	</Dependencies>
+
+	<Extension path="/Mistelix/Effects">
+		<Effects type="Mistelix.Effects.Grayscale" />
+	</Extension>
+</Addin>

Added: trunk/extensions/Effects/Grayscale/Grayscale.cs
==============================================================================
--- (empty file)
+++ trunk/extensions/Effects/Grayscale/Grayscale.cs	Fri Apr 10 14:32:39 2009
@@ -0,0 +1,73 @@
+//
+// Copyright (C) 2009 Jordi Mas i Hernandez, jmas softcatala org
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Mono.Unix;
+
+using Mistelix.DataModel;
+using Mistelix.Effects;
+
+namespace Mistelix.Effects
+{
+	public class Grayscale: Effect
+	{
+		public Grayscale ()
+		{
+		}
+
+		public override string DisplayName {
+			get { return Catalog.GetString ("Grayscale"); }
+		}
+
+		public override string Name {
+			get { return ("grayscale"); }
+		}
+
+		public override SlideImage Apply (SlideImage org)
+		{
+			SlideImage image;
+			byte r, g, b, intensity;
+
+			image = new SlideImage ();
+			image.CopyProperties (org);
+			image.Pixels = new byte [org.Stride * org.Height];
+
+			for (int i = 0; i < org.Stride * org.Height; i += org.Channels)
+			{
+				r = (byte) org.Pixels [i];
+				g = (byte) org.Pixels [i + 1];
+				b = (byte) org.Pixels [i + 2];
+
+				intensity = (byte) ((double)r * 0.30 + (double)g * 0.59 + (double)b * 0.11);
+				image.Pixels [i + 0] = intensity;
+				image.Pixels [i + 1] = intensity;
+				image.Pixels [i + 2] = intensity;
+	
+				if (org.Channels == 4) // Alpha
+					image.Pixels [i + 3] = 0xff;
+			}
+	
+			return image;
+		}		
+	}
+}

Added: trunk/extensions/Effects/Grayscale/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/extensions/Effects/Grayscale/Makefile.am	Fri Apr 10 14:32:39 2009
@@ -0,0 +1,39 @@
+PLUGIN_NAME = Grayscale
+
+PLUGIN_MANIFEST = $(PLUGIN_NAME).addin.xml
+
+PLUGIN_ASSEMBLY = $(PLUGIN_NAME).dll
+
+PLUGIN_SOURCES =			\
+	$(srcdir)/Grayscale.cs
+
+REFS =					\
+	-r:$(top_builddir)/src/mistelix.exe
+
+PKGS =					\
+	-pkg:gtk-sharp-2.0
+
+RESOURCES =				\
+	-resource:$(srcdir)/$(PLUGIN_MANIFEST)
+
+all: $(PLUGIN_ASSEMBLY)
+
+mpack: $(PLUGIN_ASSEMBLY)
+	mautil p $(PLUGIN_ASSEMBLY)
+
+$(PLUGIN_ASSEMBLY): $(PLUGIN_SOURCES) $(PLUGIN_MANIFEST)
+	$(CSC) -target:library -out:$@ $(CSC_DEFINES) $(PLUGIN_SOURCES) $(REFS) $(PKGS) $(ASSEMBLIES) $(RESOURCES) -r:Mono.Posix
+
+plugindir = $(pkglibdir)/extensions
+
+plugin_DATA =			\
+	$(PLUGIN_ASSEMBLY)
+
+EXTRA_DIST = 			\
+	$(PLUGIN_SOURCES)	\
+	$(PLUGIN_MANIFEST)
+
+CLEANFILES =			\
+	$(PLUGIN_ASSEMBLY)	\
+	$(PLUGIN_ASSEMBLY).mdb	\
+	*.mpack

Modified: trunk/extensions/Effects/Makefile.am
==============================================================================
--- trunk/extensions/Effects/Makefile.am	(original)
+++ trunk/extensions/Effects/Makefile.am	Fri Apr 10 14:32:39 2009
@@ -1,4 +1,3 @@
 SUBDIRS = 			\
-	RotateImage	\
-	Brightness	\
-	Contrast
+	Grayscale	\
+	SepiaTone

Added: trunk/extensions/Effects/SepiaTone/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/extensions/Effects/SepiaTone/Makefile.am	Fri Apr 10 14:32:39 2009
@@ -0,0 +1,39 @@
+PLUGIN_NAME = SepiaTone
+
+PLUGIN_MANIFEST = $(PLUGIN_NAME).addin.xml
+
+PLUGIN_ASSEMBLY = $(PLUGIN_NAME).dll
+
+PLUGIN_SOURCES =			\
+	$(srcdir)/SepiaTone.cs
+
+REFS =					\
+	-r:$(top_builddir)/src/mistelix.exe
+
+PKGS =					\
+	-pkg:gtk-sharp-2.0
+
+RESOURCES =				\
+	-resource:$(srcdir)/$(PLUGIN_MANIFEST)
+
+all: $(PLUGIN_ASSEMBLY)
+
+mpack: $(PLUGIN_ASSEMBLY)
+	mautil p $(PLUGIN_ASSEMBLY)
+
+$(PLUGIN_ASSEMBLY): $(PLUGIN_SOURCES) $(PLUGIN_MANIFEST)
+	$(CSC) -target:library -out:$@ $(CSC_DEFINES) $(PLUGIN_SOURCES) $(REFS) $(PKGS) $(ASSEMBLIES) $(RESOURCES) -r:Mono.Posix
+
+plugindir = $(pkglibdir)/extensions
+
+plugin_DATA =			\
+	$(PLUGIN_ASSEMBLY)
+
+EXTRA_DIST = 			\
+	$(PLUGIN_SOURCES)	\
+	$(PLUGIN_MANIFEST)
+
+CLEANFILES =			\
+	$(PLUGIN_ASSEMBLY)	\
+	$(PLUGIN_ASSEMBLY).mdb	\
+	*.mpack

Added: trunk/extensions/Effects/SepiaTone/SepiaTone.addin.xml
==============================================================================
--- (empty file)
+++ trunk/extensions/Effects/SepiaTone/SepiaTone.addin.xml	Fri Apr 10 14:32:39 2009
@@ -0,0 +1,17 @@
+<Addin namespace="Mistelix"
+	version="0.10"
+	name="SepiaTone"
+	description="Convert image colors to sepia tone"
+	author="Jordi Mas"
+	url=""
+	defaultEnabled="true"
+	category="Effects">
+
+	<Dependencies>
+		<Addin id="Mistelix" version="0.10"/>
+	</Dependencies>
+
+	<Extension path="/Mistelix/Effects">
+		<Effects type="Mistelix.Effects.SepiaTone" />
+	</Extension>
+</Addin>

Added: trunk/extensions/Effects/SepiaTone/SepiaTone.cs
==============================================================================
--- (empty file)
+++ trunk/extensions/Effects/SepiaTone/SepiaTone.cs	Fri Apr 10 14:32:39 2009
@@ -0,0 +1,79 @@
+//
+// Copyright (C) 2009 Jordi Mas i Hernandez, jmas softcatala org
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Mono.Unix;
+
+using Mistelix.DataModel;
+using Mistelix.Effects;
+
+namespace Mistelix.Effects
+{
+	public class SepiaTone: Effect
+	{
+		public SepiaTone ()
+		{
+
+		}
+
+		public override string DisplayName {
+			get { return Catalog.GetString ("Sepia Tone"); }
+		}
+
+		public override string Name {
+			get { return ("sepiatone"); }
+		}
+
+		public override SlideImage Apply (SlideImage org)
+		{
+			SlideImage image;
+			double r, g, b, intensity;
+
+			image = new SlideImage ();
+			image.CopyProperties (org);
+			image.Pixels = new byte [org.Stride * org.Height];
+
+			for (int i = 0; i < org.Stride * org.Height; i += org.Channels)
+			{
+				r = (double) org.Pixels [i];
+				g = (double) org.Pixels [i + 1];
+				b = (double) org.Pixels [i + 2];
+
+				intensity = (0.299 * r + 0.587 * g + 0.114 * b);
+
+				r = 0.94 * intensity;
+				g = 0.78 * intensity;
+				b = 0.54 * intensity;
+
+				image.Pixels [i + 0] = (byte) r;
+				image.Pixels [i + 1] = (byte) g;
+				image.Pixels [i + 2] = (byte) b;
+	
+				if (org.Channels == 4) // Alpha
+					image.Pixels [i + 3] = 0xff;
+			}
+	
+			return image;
+		}		
+	}
+}

Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in	(original)
+++ trunk/po/POTFILES.in	Fri Apr 10 14:32:39 2009
@@ -1,6 +1,6 @@
 [encoding: UTF-8]
-extensions/Effects/Brightness/Brightness.cs
-extensions/Effects/Contrast/Contrast.cs
+extensions/Effects/Grayscale/Grayscale.cs
+extensions/Effects/SepiaTone/SepiaTone.cs
 extensions/SlideTransitions/Fade/Fade.cs
 mistelix.desktop.in
 src/core/Dependencies.cs

Modified: trunk/src/core/EffectManager.cs
==============================================================================
--- trunk/src/core/EffectManager.cs	(original)
+++ trunk/src/core/EffectManager.cs	Fri Apr 10 14:32:39 2009
@@ -30,10 +30,6 @@
 namespace Mistelix.Core
 {
 	// Manages all the available effects
-	//
-	// Different that in transitions, where even if there are no transitions at set of images from source
-	// to target should be created for effects we do not need a NoneEffect. Additionally, transitions are
-	// stateless and effects are not.
 	public static class EffectManager
 	{
 		static ExtensionNodeList effects;

Modified: trunk/src/core/SlideImage.cs
==============================================================================
--- trunk/src/core/SlideImage.cs	(original)
+++ trunk/src/core/SlideImage.cs	Fri Apr 10 14:32:39 2009
@@ -180,13 +180,17 @@
 
 		public DataImageSurface GetThumbnail (int width, int height)
 		{
+			PixelFormat pixelformat_src;
 			SlideImage slide = new SlideImage ();
 			slide.CopyProperties (this);
-			slide.pixel_format = PixelFormat.CAIRO_ARGB;
 			slide.LoadAndScaleImage (width, height);
-			//slide.ProcessImage ();
 			slide.ProcessEffects ();
 
+			pixelformat_src = slide.pixel_format; // Pixel format of current buffer
+			slide.pixel_format = PixelFormat.CAIRO_ARGB; // New target format
+			slide.LoadFromPixelData (slide.pixels, pixelformat_src,
+				width, height, width * slide.channels, slide.channels);
+
 			return new DataImageSurface (DataImageSurface.Allocate (slide.Pixels),
 				Cairo.Format.ARGB32, slide.width, slide.height, slide.stride);
 		}
@@ -334,7 +338,10 @@
 			raw_image.Scale (processed_image, offset_x, offset_y, w, h, offset_x, offset_y, 
 				(double) w / (double) raw_image.Width, (double)h /(double) raw_image.Height, InterpType.Hyper);
 
-			LoadPixBuffer (processed_image);
+			LoadFromPixelData (processed_image.Pixels, 
+				processed_image.NChannels == 3 ? PixelFormat.PIXBUF_RGB : PixelFormat.PIXBUF_ARGB,
+				processed_image.Width, processed_image.Height,
+				processed_image.Rowstride, processed_image.NChannels);
 
 			raw_image.Dispose ();
 			processed_image.Dispose ();
@@ -381,35 +388,46 @@
 		public void ProcessEffects ()
 		{
 			SlideImage processed, previous;
+			Effect effect;
 
 			if (Effects == null)
 				return;
 
 			previous = processed = this;
 
-			foreach (Effect effect in Effects)
+			foreach (string name in Effects)
 			{
 				Logger.Debug ("SlideImage.ProcessEffects -> effect {0}", name);
+				effect = EffectManager.CreateFromName (name);
 				previous = processed;
-				processed = effect.ApplyEffect (processed);
-				previous.ReleasePixels ();
+				processed = effect.Apply (processed);
 			}
-
+ 
 			CopyProperties (processed);
 			Pixels = processed.Pixels;
 		}
 
-		void LoadPixBuffer (Gdk.Pixbuf buf)
+		void LoadFromPixelData (IntPtr data, PixelFormat format_src, int width_src, int height_src, int stride_src, int channels_src)
+		{
+			int len = stride_src * height_src;
+			byte[] source = new byte [len];
+
+			Marshal.Copy (data, source, 0, len);
+			LoadFromPixelData (source, format_src, width_src, height_src, stride_src, channels_src);
+		}
+
+		void LoadFromPixelData (byte[] source, PixelFormat format_src, int width_src, int height_src, int stride_src, int channels_src)
 		{
 			if ((pixel_format == PixelFormat.CAIRO_ARGB && pixel_format == PixelFormat.PIXBUF_RGB) ||
-					(buf.NChannels != 3 && buf.NChannels != 4)) {
+					(channels_src != 3 && channels_src != 4)) {
 				throw new InvalidOperationException (
-						String.Format ("Could not process SlideImage.LoadPixBuffer requested format {0} image {1}", 
-						pixel_format, buf.NChannels));
+						String.Format ("Could not process SlideImage.LoadFromPixelData requested format {0} image {1}", 
+						pixel_format, channels_src));
 			}
 
-			int src, len, channels_src;
-			byte [] source;
+			int src, len;
+
+			Logger.Debug ("LoadFromPixelData f:{0} w:{1} h:{2} s:{3} c:{4}", format_src, width_src, height_src, stride_src, channels_src);
 
 			switch (pixel_format) {
 			case PixelFormat.PIXBUF_RGB:
@@ -425,20 +443,14 @@
 				throw new InvalidOperationException ("Unsupported format");
 			}
 
-			// Move source data to an array
-			src = 0;
-			channels_src = buf.NChannels;
-			len = buf.Rowstride * buf.Height;
-			source = new byte [len];
-			Marshal.Copy (buf.Pixels, source, 0, len);
-
 			// Target data array
-			width = buf.Width;
-			height = buf.Height;
+			width = width_src;
+			height = height_src;
 			stride = channels * width;
 			len = stride * height;
 			pixels = new byte [len];
-						
+				
+			src = 0;		
 			for (int trg = 0; trg < len; trg = trg + channels) {
 
 				if (pixel_format == PixelFormat.CAIRO_ARGB) {

Modified: trunk/src/datamodel/Effect.cs
==============================================================================
--- trunk/src/datamodel/Effect.cs	(original)
+++ trunk/src/datamodel/Effect.cs	Fri Apr 10 14:32:39 2009
@@ -31,79 +31,25 @@
 	//
 	// Interface that defines an effect to apply to an image
 	//
-	// Effects are applied to an image and have
-	//	Â A set of UI controls that set the extension (exposed as menu options)
-	//	Â A string value that is stored for the effect. This can be the rotation angle, brightness level, etc.
-	//
 	public abstract class Effect
 	{
-		public class OptionIDEventArgs : EventArgs
+		public class EffectEventArgs : EventArgs
 		{
-			int id;
-
-			public OptionIDEventArgs (int id)
-			{
-				this.id = id;
-			}
-			public int ID {
-				get { return id; }
-			}
-		}
-
-		public class UIOption
-		{	
-			string name;
-			int id;
-			EventHandler handler;
-
-			public UIOption (string name, int id, EventHandler handler)
-			{
-				this.name = name;
-				this.id = id;
-				this.handler = handler;
-			}
-
-			public string Name {
-				get { return name; }
-				set { name = value; }
-			}
-	
-			public EventHandler Handler {
-				get { return handler; }
-				set { handler = value; }
-			}
-
-			public int ID {
-				get { return id; }
-			}
-		}
+			Effect effect;
 
-		public struct Storage
-		{	
-			string name;
-			string _value;
-
-			public Storage (string name, string _value)
+			public EffectEventArgs (Effect effect)
 			{
-				Name = name;
-				Value = _value;
+				this.effect = effect;
 			}
-
-			public string Name {
-				get { return name; }
-				set { name = value; }
-			}
-
-			public string Value {
-				get { return _value; }
-				set { _value = value; }
+			public Effect Effect {
+				get { return effect; }
 			}
 		}
 
-		public delegate void UIOptionEventHandler (object sender, OptionIDEventArgs e);
+		public delegate void UIOptionEventHandler (object sender, EffectEventArgs e);
 		public virtual event UIOptionEventHandler UIOptionInvoked;
 
-		public abstract SlideImage ApplyEffect (SlideImage slideimage);
+		public abstract SlideImage Apply (SlideImage slideimage);
 
 		public abstract string DisplayName {
 			get;
@@ -113,33 +59,18 @@
 			get;
 		}
 
-		public abstract UIOption [] Options {
-			get;
-		}
-
-		public virtual string Value {
-			get {return null; }
-			set {}
-		}
-
-		// This method invokes the EventHandler associated to an option as
-		// it was called by the user
-		public virtual void InvokeOption (int id)
+		// Generic UI handle called from the client UI
+		public void OnUIEventHandle (object obj, EventArgs e)
 		{
-			Logger.Debug ("Effect.InvokeOption -> id:{0}", id);
-
-			if (id > Options.Length)
-				throw new ArgumentException (String.Format ("Effect.InvokeOption -> Option with ID {0} does not exist", id));
-
-			Options[id].Handler (this, EventArgs.Empty);
+			OnUIOptionInvoked (this);
 		}
-		
+
 		// Fires the UIOptionInvoked notification
-		public virtual void OnUIOptionInvoked (int id)
+		public virtual void OnUIOptionInvoked (Effect effect)
 		{
-			Logger.Debug ("Effect.OnUIOptionInvoked -> id:{0}", id);
+			Logger.Debug ("Effect.OnUIOptionInvoked -> id:{0}", effect);
 			if (UIOptionInvoked != null)
-				UIOptionInvoked (this, new OptionIDEventArgs (id));
+				UIOptionInvoked (this, new EffectEventArgs (effect));
 		}
 	}
 }

Modified: trunk/src/datamodel/SlideShowProjectElement.cs
==============================================================================
--- trunk/src/datamodel/SlideShowProjectElement.cs	(original)
+++ trunk/src/datamodel/SlideShowProjectElement.cs	Fri Apr 10 14:32:39 2009
@@ -91,50 +91,13 @@
 			int shown_time; 
 			string transition;
 			TextPosition position;
-			List <Effect> effects;
+			List <string> effects;
 
-			// Used by the application to set / get effects
-			[XmlIgnoreAttribute]
-			public List <Effect> Effects {
+			public List <string> Effects {
 				get { return effects;}
 				set { effects = value;}
 			}
 
-			// Used by serialization  set / get effects
-			public Effect.Storage [] EffectList {
-				get {
-					if (effects == null)
-						return null;
-
-					Effect.Storage[] storage = new Effect.Storage [effects.Count];
-					int pos = 0;
-
-					foreach (Effect effect in effects)
-						storage [pos++] = new Effect.Storage (effect.Name, effect.Value);
-
-					return storage;
-				}
-				set {
-					if (value == null || value.Length == 0)
-						return;
-
-					Effect effect;
-
-					foreach (Effect.Storage stored in value)
-					{
-						effect = EffectManager.CreateFromName (stored.Name);
-	
-						if (effect == null) {
-							Logger.Error ("SlideShowProjectElement.Storage-> No class found to handle effect {0}", stored.Name);
-							continue;
-						}
-
-						effect.Value = stored.Value;
-						AddEffect (effect);						
-					}
-				}
-			}
-
 			// Text description
 			[XmlElementAttribute ("title")]
 			public string Title {
@@ -168,35 +131,21 @@
 				get { return position;}
 				set { position = value;}
 			}
-
 			
 			protected Image () {}
 
-			public Effect FindEffect (string effect_name)
-			{
-				if (effects == null)
-					return null;
-
-				// This O(N) but we always expect very few elements 
-				foreach (Effect previous in effects) 
-					if (String.Compare (previous.Name, effect_name) == 0)
-						return previous; // Element already present
-				
-				return null;
-			}
-
-			public Effect AddEffect (Effect effect)
+			public bool AddEffect (Effect effect)
 			{
 				if (effects == null)
-					effects = new List <Effect> ();
+					effects = new List <string> ();
 
-				// This O(N) but we always expect very few elements 
-				foreach (Effect previous in effects)
-					if (String.Compare (previous.Name, effect.Name) == 0)
-						return previous; // Element already present
+				// This O(N) but we always expect very few elements
+				foreach (string previous in effects) 
+					if (String.Compare (previous, effect.Name) == 0)
+						return false; // Effect already present
 
-				effects.Add (effect);
-				return effect;
+				effects.Add (effect.Name);
+				return true;
 			}
 		}
 	}

Modified: trunk/src/widgets/SlideShowImageView.cs
==============================================================================
--- trunk/src/widgets/SlideShowImageView.cs	(original)
+++ trunk/src/widgets/SlideShowImageView.cs	Fri Apr 10 14:32:39 2009
@@ -495,22 +495,16 @@
 					effects = new Effect [nodelist.Count];
 					int pos = 0;
 					
-					// The Effect class objects created here are just used to handle the effect
-					// user UI and used as stateless objects, just to capture user actions.
-					// The user actions are then transformed at OnEffect to the proper effect 
-					// for every image that are not stateless since they have the Value property
 					foreach (TypeExtensionNode node in nodelist) {
 						Effect effect = (Effect) node.CreateInstance ();
 						effect.UIOptionInvoked += new Effect.UIOptionEventHandler (OnEffect);
 						effects [pos] = effect;
 						pos++;
 					}
-					
 				}
 
 				foreach (Effect effect in effects)
-					foreach (Effect.UIOption option in effect.Options)
-						menu.AddItem (option.Name, option.Handler);
+					menu.AddItem (effect.DisplayName, effect.OnUIEventHandle);
 			}
 
 			menu.AddItem (Catalog.GetString ("Remove all effects"), OnRemoveEffects);
@@ -642,7 +636,7 @@
 			((IDisposable)cr).Dispose ();
 		}
 
-		void OnEffect (object sender, Effect.OptionIDEventArgs e)
+		void OnEffect (object sender, Effect.EffectEventArgs e)
 		{
 			TreeIter iter;
 			TreePath[] paths;
@@ -655,9 +649,9 @@
 			if (paths.Length == 0)
 				return;
 
-			effect = (Effect) sender;
+			effect = e.Effect;
 
-			Logger.Debug ("OnEffect {0} id:{1} (elements selected {2})", effect.Name, e.ID, paths.Length);
+			Logger.Debug ("OnEffect {0} (elements selected {1})", effect.Name, paths.Length);
 
 			for (int i = 0; i < paths.Length; i++)
 			{
@@ -667,16 +661,11 @@
 				prev_image = (DataImageSurface) store.GetValue (iter, COL_CAIROIMAGE);
 				image = (SlideImage) store.GetValue (iter, COL_OBJECT);
 
-				image_effect = image.FindEffect (effect.Name);
-
-				if (image_effect == null) {
-					image_effect = EffectManager.CreateFromName (effect.Name);
-					image.AddEffect (image_effect);
-				}
-				
-				// Inform the effect class that this option ID has been invoked
-				// if the object did have a previous status will be taked into account
-				image_effect.InvokeOption (e.ID);
+				image_effect = EffectManager.CreateFromName (effect.Name);
+				if (image.AddEffect (image_effect) == false)
+					continue;
+								
+				image = image_effect.Apply (image);
 
 				cairo_image = image.GetThumbnail (thumbnail_width, thumbnail_height);
 				store.SetValue (iter, COL_CAIROIMAGE, cairo_image);



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