[ease] [transitions] Added "Intersperse Contents" transition



commit a8b7e81f3918d928a25382092c7f4286e7aa0ab5
Author: Nate Stedman <natesm gmail com>
Date:   Mon Aug 23 01:50:38 2010 -0400

    [transitions] Added "Intersperse Contents" transition

 ease-core/ease-transitions.vala |    7 +++
 ease/ease-slide-actor.vala      |  106 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+), 0 deletions(-)
---
diff --git a/ease-core/ease-transitions.vala b/ease-core/ease-transitions.vala
index 30d4369..78143d8 100644
--- a/ease-core/ease-transitions.vala
+++ b/ease-core/ease-transitions.vala
@@ -35,6 +35,7 @@ public enum Ease.Transition
 	ASSEMBLE,
 	ZOOM,
 	PANEL,
+	INTERSPERSE_CONTENTS,
 	SPIN_CONTENTS,
 	SPRING_CONTENTS,
 	SWING_CONTENTS,
@@ -57,6 +58,7 @@ public enum Ease.Transition
 		                                       ASSEMBLE,
 		                                       ZOOM,
 		                                       PANEL,
+		                                       INTERSPERSE_CONTENTS,
 		                                       SPIN_CONTENTS,
 		                                       SPRING_CONTENTS,
 		                                       SWING_CONTENTS,
@@ -124,6 +126,8 @@ public enum Ease.Transition
 				return ZOOM;
 			case "EASE_TRANSITION_PANEL":
 				return PANEL;
+			case "EASE_TRANSITION_INTERSPERSE_CONTENTS":
+				return INTERSPERSE_CONTENTS;
 			case "EASE_TRANSITION_SPIN_CONTENTS":
 				return SPIN_CONTENTS;
 			case "EASE_TRANSITION_SPRING_CONTENTS":
@@ -153,6 +157,7 @@ public enum Ease.Transition
 			case EXPLODE:
 			case ASSEMBLE:
 			case SWING_CONTENTS:
+			case INTERSPERSE_CONTENTS:
 				return {};
 			
 			case REVOLVING_DOOR:
@@ -237,6 +242,8 @@ public enum Ease.Transition
 				return _("Zoom");
 			case PANEL:
 				return _("Panel");
+			case INTERSPERSE_CONTENTS:
+				return _("Intersperse Contents");
 			case SPIN_CONTENTS:
 				return _("Spin Contents");
 			case SPRING_CONTENTS:
diff --git a/ease/ease-slide-actor.vala b/ease/ease-slide-actor.vala
index 8d4013c..1102688 100644
--- a/ease/ease-slide-actor.vala
+++ b/ease/ease-slide-actor.vala
@@ -509,6 +509,10 @@ internal class Ease.SlideActor : Clutter.Group
 			case Transition.ZOOM:
 				zoom_transition(new_slide, container, length);
 				break;
+			
+			case Transition.INTERSPERSE_CONTENTS:
+				intersperse_contents_transition(new_slide, container, length);
+				break;
 
 			case Transition.SLIDE_CONTENTS:
 				slide_contents_transition(new_slide, container, length);
@@ -1333,6 +1337,108 @@ internal class Ease.SlideActor : Clutter.Group
 				break;
 		}
 	}
+	
+	/**
+	 * Starts a "intersperse contents" transition. This transition unstacks the
+	 * SlideActors.
+	 *
+	 * @param new_slide The new SlideActor.
+	 * @param container The container that holds the displayed SlideActors.
+	 * @param length The length of the transition, in milliseconds.
+	 */
+	private void intersperse_contents_transition(SlideActor new_slide,
+	                                          Clutter.Group container,
+	                                          uint length)
+	{
+		prepare_stack_transition(false, new_slide, container);
+		background.animate(Clutter.AnimationMode.EASE_IN_OUT_SINE,
+		                   length, "opacity", 0);
+		alpha1 = new Clutter.Alpha.full(animation_time,
+		                                Clutter.AnimationMode.EASE_IN_SINE);
+		                                
+		alpha2 = new Clutter.Alpha.full(animation_time,
+		                                Clutter.AnimationMode.EASE_OUT_SINE);
+		                                
+		animation_alpha = new Clutter.Alpha.full(animation_time,
+		                                         Clutter.AnimationMode.LINEAR);
+		
+		float target_x = 0, target_y = 0, orig_x, orig_y;
+		
+		foreach (var actor in contents)
+		{
+			get_intersperse_coords(actor, out target_x, out target_y);
+			
+			actor.animate(Clutter.AnimationMode.EASE_IN_SINE, length,
+			              "y", target_y,
+			              "x", target_x);
+		}
+		
+		foreach (var actor in new_slide.contents)
+		{
+			// store the original position
+			orig_x = actor.x;
+			orig_y = actor.y;
+			
+			// find the interspersed position
+			get_intersperse_coords(actor, out target_x, out target_y);
+			
+			// set the actor off stage
+			actor.x = target_x;
+			actor.y = target_y;
+			
+			// animate back on screen
+			actor.animate(Clutter.AnimationMode.EASE_OUT_SINE, length,
+			              "y", orig_y,
+			              "x", orig_x);
+		}
+	}
+	
+	private void get_intersperse_coords(Clutter.Actor actor, out float target_x,
+	                                                      out float target_y)
+	{
+		var center_x = slide.width / 2;
+		var center_y = slide.height / 2;
+		
+		if ((actor.x + actor.width / 2) - center_x == 0)
+		{
+			target_x = actor.x;
+			target_y = (actor.y + actor.height / 2) > center_y ?
+			           slide.height : -actor.height;
+			return;
+		}
+		
+		var m = ((actor.y + actor.height / 2) - center_y) /
+		        ((actor.x + actor.width / 2) - center_x);
+			
+		var angle = Math.fmod(Math.atan2(m, 1), Math.PI * 2);
+		
+		if (m == 0)
+		{
+			target_x = (actor.x + actor.width / 2) > center_x ?
+			           slide.width : -actor.width;
+			target_y = actor.y;
+		}
+		else if (angle > Math.PI * 1.75 || angle <= Math.PI * 0.25)
+		{
+			target_x = slide.width;
+			target_y = m * target_x + center_y;
+		}
+		else if (angle > Math.PI * 0.25 || angle <= Math.PI * 0.75)
+		{
+			target_y = -actor.height;
+			target_x = (target_y - center_y) / m;
+		}
+		else if (angle > Math.PI * 0.75 || angle <= Math.PI * 1.25)
+		{
+			target_x = -actor.width;
+			target_y = m * target_x + center_y;
+		}
+		else
+		{
+			target_y = slide.height;
+			target_x = (target_y - center_y) / m;
+		}
+	}
 
 	/**
 	 * Starts a "zoom contents" transition. This transition unstacks the



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