[f-spot] refactor the Blings to avoid a level of inheritance



commit 35bdccbd26d3941398a874a9cef2a0760dc1f017
Author: Stephane Delcroix <stephane delcroix org>
Date:   Tue Apr 28 15:00:50 2009 +0200

    refactor the Blings to avoid a level of inheritance
    
    the easing function is now a EasingFunction property, instead of an abstract method to override. It keeps the tree united instead of having to subclass Animation for each kind fo animation (Double, Point, ...) AND EasingFunction (Cubic, Back, ...)
---
 src/Bling/{EasedAnimation.cs => Animation.cs}     |   31 ++++-----------------
 src/Bling/{BackAnimation.cs => BackEase.cs}       |   19 ++++++++++---
 src/Bling/{CubicAnimation.cs => CubicEase.cs}     |   10 +++++--
 src/Bling/DoubleAnimation.cs                      |   29 +++++++++++++++++++
 src/Bling/DoubleBackAnimation.cs                  |   29 -------------------
 src/Bling/DoubleCubicAnimation.cs                 |   24 ----------------
 src/Bling/DoubleLinearAnimation.cs                |   25 -----------------
 src/Bling/DoubleQuinticAnimation.cs               |   24 ----------------
 src/Bling/EasingMode.cs                           |    8 +++---
 src/Bling/LinearAnimation.cs                      |   25 -----------------
 src/Bling/{QuinticAnimation.cs => QuinticEase.cs} |   10 +++++--
 src/Makefile.am                                   |   16 +++++------
 src/Widgets/Filmstrip.cs                          |    5 +--
 13 files changed, 77 insertions(+), 178 deletions(-)

diff --git a/src/Bling/EasedAnimation.cs b/src/Bling/Animation.cs
similarity index 77%
rename from src/Bling/EasedAnimation.cs
rename to src/Bling/Animation.cs
index 7060edf..6806961 100644
--- a/src/Bling/EasedAnimation.cs
+++ b/src/Bling/Animation.cs
@@ -1,5 +1,5 @@
 //
-// FSpot.Bling.EasedAnimation,cs
+// FSpot.Bling.Animation,cs
 //
 // Author(s):
 //	Stephane Delcroix  <stephane delcroix org>
@@ -14,7 +14,7 @@ using System.ComponentModel;
 
 namespace FSpot.Bling
 {
-	public abstract class EasedAnimation<T>
+	public abstract class Animation<T>
 	{
 		enum AnimationState {
 			NotRunning = 0,
@@ -30,26 +30,23 @@ namespace FSpot.Bling
 		T to;
 		Action<T> action;
 		AnimationState state;
-		EasingMode easingmode;
 
-		public EasedAnimation ()
+		public Animation ()
 		{
 			from = default (T);
 			to = default (T);
 			duration = TimeSpan.Zero;
 			action = null;
 			state = AnimationState.NotRunning;
-			easingmode = EasingMode.In;
 		}
 
-		public EasedAnimation (T from, T to, TimeSpan duration, Action<T> action)
+		public Animation (T from, T to, TimeSpan duration, Action<T> action)
 		{
 			this.from = from;
 			this.to = to;
 			this.duration = duration;
 			this.action = action;
 			state = AnimationState.NotRunning;
-			easingmode = EasingMode.In;
 		}
 
 		public void Pause ()
@@ -109,19 +106,9 @@ namespace FSpot.Bling
 			starttime = DateTimeOffset.Now;
 		}
 
-		public double Ease (double normalizedTime)
+		protected virtual double Ease (double normalizedTime)
 		{
-			switch (easingmode) {
-			case EasingMode.In:
-				return EaseInCore (normalizedTime);
-			case EasingMode.Out:
-				return 1.0 - EaseInCore (1 - normalizedTime);
-			case EasingMode.InOut:
-				return (normalizedTime <= 0.5
-					? EaseInCore (normalizedTime * 2) * 0.5
-					: 1.0 - EaseInCore ((1 - normalizedTime) * 2) * 0.5);
-			}
-			throw new InvalidOperationException ("Unknown value for EasingMode");
+			return normalizedTime;
 		}
 
 		bool Handler ()
@@ -138,17 +125,11 @@ namespace FSpot.Bling
 			return true;
 		}
 
-		protected abstract double EaseInCore (double percentage);
 		protected abstract T Interpolate (T from, T to, double progress);
 
 		public event EventHandler Completed;
 		public event EventHandler<ProgressChangedEventArgs> ProgressChanged;
 
-		public EasingMode EasingMode {
-			get { return easingmode; }
-			set { easingmode = value; }
-		}
-
 		public bool IsRunning {
 			get { return state == AnimationState.Running; }
 		}
diff --git a/src/Bling/BackAnimation.cs b/src/Bling/BackEase.cs
similarity index 61%
rename from src/Bling/BackAnimation.cs
rename to src/Bling/BackEase.cs
index 7f22c1a..6d04fc2 100644
--- a/src/Bling/BackAnimation.cs
+++ b/src/Bling/BackEase.cs
@@ -1,5 +1,5 @@
 //
-// FSpot.Bling.BackAnimation,cs
+// FSpot.Bling.BackEase.cs
 //
 // Author(s):
 //	Stephane Delcroix  <stephane delcroix org>
@@ -10,15 +10,26 @@
 using System;
 
 namespace FSpot.Bling
-{	public abstract class BackAnimation<T>: EasedAnimation<T>
+{	public abstract class BackEase : EasingFunction
 	{
 		double amplitude;
 
-		public BackAnimation (T from, T to, TimeSpan duration, Action<T> action) : this (from, to, duration, action, 0)
+		public BackEase () : this (1.0)
 		{
 		}
 
-		public BackAnimation (T from, T to, TimeSpan duration, Action<T> action, double amplitude) : base (from, to, duration, action)
+		public BackEase (double amplitude) : base ()
+		{
+			if (amplitude < 0)
+				throw new ArgumentOutOfRangeException ("amplitude");
+			this.amplitude = amplitude;
+		}
+
+		public BackEase (EasingMode easingMode) : this (easingMode, 1.0)
+		{
+		}
+
+		public BackEase (EasingMode easingMode, double amplitude) : base (easingMode)
 		{
 			if (amplitude < 0)
 				throw new ArgumentOutOfRangeException ("amplitude");
diff --git a/src/Bling/CubicAnimation.cs b/src/Bling/CubicEase.cs
similarity index 59%
rename from src/Bling/CubicAnimation.cs
rename to src/Bling/CubicEase.cs
index 28f3032..4b3863b 100644
--- a/src/Bling/CubicAnimation.cs
+++ b/src/Bling/CubicEase.cs
@@ -1,5 +1,5 @@
 //
-// FSpot.Bling.CubicAnimation,cs
+// FSpot.Bling.CubicEase.cs
 //
 // Author(s):
 //	Stephane Delcroix  <stephane delcroix org>
@@ -10,9 +10,13 @@
 using System;
 
 namespace FSpot.Bling
-{	public abstract class CubicAnimation<T>: EasedAnimation<T>
+{	public class CubicEase : EasingFunction
 	{
-		public CubicAnimation (T from, T to, TimeSpan duration, Action<T> action) : base (from, to, duration, action)
+		public CubicEase () : base ()
+		{
+		}
+
+		public CubicEase (EasingMode easingMode) : base (easingMode)
 		{
 		}
 
diff --git a/src/Bling/DoubleAnimation.cs b/src/Bling/DoubleAnimation.cs
new file mode 100644
index 0000000..6893b1d
--- /dev/null
+++ b/src/Bling/DoubleAnimation.cs
@@ -0,0 +1,29 @@
+//
+// FSpot.Bling.DoubleAnimation,cs
+//
+// Author(s):
+//	Stephane Delcroix  <stephane delcroix org>
+//
+// This is free software. See COPYING for details
+//
+
+using System;
+
+namespace FSpot.Bling
+{	public class DoubleAnimation : EasedAnimation<double>
+	{
+		public DoubleAnimation (double from, double to, TimeSpan duration, Action<double> action) : base (from, to, duration, action)
+		{
+		}
+
+		public DoubleAnimation (double from, double to, TimeSpan duration, Action<double> action, EasingFunction easingFunction) : base (from, to, duration, action, easingFunction)
+		{
+		}
+
+		protected override double Interpolate (double from, double to, double progress)
+		{
+			return from + progress * (to - from);
+		}
+	}
+}
+
diff --git a/src/Bling/DoubleBackAnimation.cs b/src/Bling/DoubleBackAnimation.cs
deleted file mode 100644
index 892ca23..0000000
--- a/src/Bling/DoubleBackAnimation.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-//
-// FSpot.Bling.DoubleBackAnimation,cs
-//
-// Author(s):
-//	Stephane Delcroix  <stephane delcroix org>
-//
-// This is free software. See COPYING for details
-//
-
-using System;
-
-namespace FSpot.Bling
-{	public class DoubleBackAnimation : BackAnimation<double>
-	{
-		public DoubleBackAnimation (double from, double to, TimeSpan duration, Action<double> action, double amplitude) : base (from, to, duration, action, amplitude)
-		{
-		}
-
-		public DoubleBackAnimation (double from, double to, TimeSpan duration, Action<double> action) : this (from, to, duration, action, 0)
-		{
-		}
-
-		protected override double Interpolate (double from, double to, double progress)
-		{
-			return from + progress * (to - from);
-		}
-	}
-}
-
diff --git a/src/Bling/DoubleCubicAnimation.cs b/src/Bling/DoubleCubicAnimation.cs
deleted file mode 100644
index 876fd37..0000000
--- a/src/Bling/DoubleCubicAnimation.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// FSpot.Bling.DoubleCubicAnimation,cs
-//
-// Author(s):
-//	Stephane Delcroix  <stephane delcroix org>
-//
-// This is free software. See COPYING for details
-//
-
-using System;
-
-namespace FSpot.Bling
-{	public class DoubleCubicAnimation : CubicAnimation<double>
-	{
-		public DoubleCubicAnimation (double from, double to, TimeSpan duration, Action<double> action) : base (from, to, duration, action)
-		{
-		}
-
-		protected override double Interpolate (double from, double to, double progress)
-		{
-			return from + progress * (to - from);
-		}
-	}
-}
diff --git a/src/Bling/DoubleLinearAnimation.cs b/src/Bling/DoubleLinearAnimation.cs
deleted file mode 100644
index 53ad7fc..0000000
--- a/src/Bling/DoubleLinearAnimation.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-//
-// FSpot.Bling.DoubleLinearAnimation,cs
-//
-// Author(s):
-//	Stephane Delcroix  <stephane delcroix org>
-//
-// This is free software. See COPYING for details
-//
-
-using System;
-
-namespace FSpot.Bling
-{	public class DoubleLinearAnimation : LinearAnimation<double>
-	{
-		public DoubleLinearAnimation (double from, double to, TimeSpan duration, Action<double> action) : base (from, to, duration, action)
-		{
-		}
-
-		protected override double Interpolate (double from, double to, double progress)
-		{
-			return from + progress * (to - from);
-		}
-	}
-}
-
diff --git a/src/Bling/DoubleQuinticAnimation.cs b/src/Bling/DoubleQuinticAnimation.cs
deleted file mode 100644
index 6944df1..0000000
--- a/src/Bling/DoubleQuinticAnimation.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// FSpot.Bling.DoubleQuinticAnimation,cs
-//
-// Author(s):
-//	Stephane Delcroix  <stephane delcroix org>
-//
-// This is free software. See COPYING for details
-//
-
-using System;
-
-namespace FSpot.Bling
-{	public class DoubleQuinticAnimation : QuinticAnimation<double>
-	{
-		public DoubleQuinticAnimation (double from, double to, TimeSpan duration, Action<double> action) : base (from, to, duration, action)
-		{
-		}
-
-		protected override double Interpolate (double from, double to, double progress)
-		{
-			return from + progress * (to - from);
-		}
-	}
-}
diff --git a/src/Bling/EasingMode.cs b/src/Bling/EasingMode.cs
index b8e3cb2..4aa773d 100644
--- a/src/Bling/EasingMode.cs
+++ b/src/Bling/EasingMode.cs
@@ -1,5 +1,5 @@
 //
-// FSpot.Bling.EasingMode,cs
+// FSpot.Bling.EasingMode.cs
 //
 // Author(s):
 //	Stephane Delcroix  <stephane delcroix org>
@@ -10,9 +10,9 @@
 namespace FSpot.Bling
 {
 	public enum EasingMode {
-		In = 0,
-		Out,
-		InOut,
+		EaseIn = 0,
+		EaseOut,
+		EaseInOut,
 	}
 }
 
diff --git a/src/Bling/LinearAnimation.cs b/src/Bling/LinearAnimation.cs
deleted file mode 100644
index 4930126..0000000
--- a/src/Bling/LinearAnimation.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-//
-// FSpot.Bling.LinearAnimation,cs
-//
-// Author(s):
-//	Stephane Delcroix  <stephane delcroix org>
-//
-// This is free software. See COPYING for details
-//
-
-using System;
-
-namespace FSpot.Bling
-{
-	public abstract class LinearAnimation<T> : EasedAnimation<T>
-	{
-		public LinearAnimation (T from, T to, TimeSpan duration, Action<T> action) : base (from, to, duration, action)
-		{
-		}
-
-		protected override double EaseInCore (double normalizedTime)
-		{
-			return normalizedTime;
-		}
-	}
-}
diff --git a/src/Bling/QuinticAnimation.cs b/src/Bling/QuinticEase.cs
similarity index 61%
rename from src/Bling/QuinticAnimation.cs
rename to src/Bling/QuinticEase.cs
index fc758dc..d0d78cd 100644
--- a/src/Bling/QuinticAnimation.cs
+++ b/src/Bling/QuinticEase.cs
@@ -1,5 +1,5 @@
 //
-// FSpot.Bling.QuinticAnimation,cs
+// FSpot.Bling.QuinticEase.cs
 //
 // Author(s):
 //	Stephane Delcroix  <stephane delcroix org>
@@ -10,9 +10,13 @@
 using System;
 
 namespace FSpot.Bling
-{	public abstract class QuinticAnimation<T>: EasedAnimation<T>
+{	public abstract class QuinticEase : EasingFunction
 	{
-		public QuinticAnimation (T from, T to, TimeSpan duration, Action<T> action) : base (from, to, duration, action)
+		public QuinticEase () : base ()
+		{
+		}
+		
+		public QuinticEase (EasingMode easingMode) : base (easingMode)
 		{
 		}
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 67efb79..d3ec6b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -68,16 +68,14 @@ JOBSCHEDULER_CSDISTFILES =				\
 	$(srcdir)/JobScheduler/Scheduler.cs
 
 WIDGETS_CSDISTFILES =				\
-	$(srcdir)/Bling/BackAnimation.cs	\
-	$(srcdir)/Bling/CubicAnimation.cs	\
-	$(srcdir)/Bling/DoubleBackAnimation.cs	\
-	$(srcdir)/Bling/DoubleCubicAnimation.cs	\
-	$(srcdir)/Bling/DoubleLinearAnimation.cs\
-	$(srcdir)/Bling/DoubleQuinticAnimation.cs\
-	$(srcdir)/Bling/EasedAnimation.cs	\
+	$(srcdir)/Bling/Animation.cs		\
+	$(srcdir)/Bling/BackEase.cs		\
+	$(srcdir)/Bling/DoubleAnimation.cs	\
+	$(srcdir)/Bling/CubicEase.cs		\
+	$(srcdir)/Bling/EasingFunction.cs	\
 	$(srcdir)/Bling/EasingMode.cs		\
-	$(srcdir)/Bling/LinearAnimation.cs	\
-	$(srcdir)/Bling/QuinticAnimation.cs	\
+	$(srcdir)/Bling/EasedAnimation.cs	\
+	$(srcdir)/Bling/QuinticEase.cs		\
 	$(srcdir)/Widgets/ComplexMenuItem.cs	\
 	$(srcdir)/Widgets/CustomPrintWidget.cs	\
 	$(srcdir)/Widgets/HighlightedBox.cs	\
diff --git a/src/Widgets/Filmstrip.cs b/src/Widgets/Filmstrip.cs
index b916906..31424b6 100644
--- a/src/Widgets/Filmstrip.cs
+++ b/src/Widgets/Filmstrip.cs
@@ -29,7 +29,7 @@ namespace FSpot.Widgets
 //		public event OrientationChangedHandler OrientationChanged;
 		public event EventHandler PositionChanged;
 
-		DoubleCubicAnimation animation;
+		DoubleAnimation animation;
 
 		bool extendable = true;
 		public bool Extendable {
@@ -305,8 +305,7 @@ namespace FSpot.Widgets
 			thumb_cache = new DisposableCache<Uri, Pixbuf> (30);
 			ThumbnailGenerator.Default.OnPixbufLoaded += HandlePixbufLoaded;
 
-			animation = new DoubleCubicAnimation (0, 0, TimeSpan.FromSeconds (4), SetPositionCore);
-			animation.EasingMode = EasingMode.Out;
+			animation = new DoubleAnimation (0, 0, TimeSpan.FromSeconds (4), SetPositionCore, new CubicEase (EasingMode.EaseOut));
 		}
 	
 		int min_length = 400;



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