[ease] [transitions] Added start of "explode" transition



commit 74c4ca845366cb4f7d7ae01f9c4079ae7a6cb6dc
Author: Nate Stedman <natesm gmail com>
Date:   Mon Jul 26 02:15:13 2010 -0400

    [transitions] Added start of "explode" transition
    
    Needs some work. Performance could be greatly improved,
    as could the appearance (but that would come with the
    increased particle count that improved performance would
    allow).

 Makefile.am               |    1 +
 src/ease-slide-actor.vala |   95 +++++++++++++++++++++++++++++++++++++++++++++
 src/ease-transitions.vala |   83 +++++++++++++++++++++------------------
 3 files changed, 141 insertions(+), 38 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 34ed6a1..ef60e4b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -82,6 +82,7 @@ SUBDIRS = po data
 
 ease_LDADD = \
 	$(EASE_LIBS) \
+	-lm \
 	$(NULL)
 
 EXTRA_DIST = data/ease.desktop.in.in  \
diff --git a/src/ease-slide-actor.vala b/src/ease-slide-actor.vala
index 3c4ba41..35d8685 100644
--- a/src/ease-slide-actor.vala
+++ b/src/ease-slide-actor.vala
@@ -120,6 +120,11 @@ public class Ease.SlideActor : Clutter.Group
 	private const int REFLECTION_OPACITY = 70;
 	
 	/**
+	 * The number of particles across the slide in the explode transition.
+	 */
+	private const int EXPLODE_PARTICLES = 10;
+	
+	/**
 	 * Emitted when a subactor of this SlideActor is removed.
 	 */
 	public signal void ease_actor_removed(Actor actor);
@@ -500,6 +505,10 @@ public class Ease.SlideActor : Clutter.Group
 			case Transition.PANEL:
 				panel_transition(new_slide, container, length);
 				break;
+			
+			case Transition.EXPLODE:
+				explode_transition(new_slide, container, length);
+				break;
 				
 			default: // FADE, or something undefined
 				fade_transition(new_slide, container, length);
@@ -1370,6 +1379,92 @@ public class Ease.SlideActor : Clutter.Group
 				break;
 		}
 	}
+	
+	/**
+	 * Starts an "Explode" transition
+	 *
+	 * @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 explode_transition(SlideActor new_slide,
+	                                Clutter.Group container,
+	                                uint length)
+	{
+		// hide the real SlideActor
+		reparent(container);
+		new_slide.reparent(container);
+		x = slide.parent.width;
+
+		// make an array for the particles
+		var v_count = (int)Math.ceil(1 / slide.parent.aspect * EXPLODE_PARTICLES);
+		var count = EXPLODE_PARTICLES * v_count;
+		var particles = new Clutter.Clone[count];
+		
+		// calculate the size of each particle
+		var size = (float)slide.parent.width / EXPLODE_PARTICLES;
+		float center_x = slide.parent.width / 2;
+		float center_y = slide.parent.height / 2;
+
+		// create the particles
+		int i;
+		for (int vpos = 0; vpos < v_count; vpos++)
+		{
+			for (int hpos = 0; hpos < EXPLODE_PARTICLES; hpos++)
+			{
+				// make a new particle
+				i = vpos * EXPLODE_PARTICLES + hpos;
+				particles[i] = new Clutter.Clone(this);
+				
+				// clip the particle
+				particles[i].set_clip(hpos * size, vpos * size, size, size);
+				
+				var atan = Math.atan2f(center_y - vpos * size,
+				                       center_x - hpos * size);
+				
+				// move to the target position
+				particles[i].animate(Clutter.AnimationMode.EASE_IN_SINE,
+				                     explode_time(length),
+				                     "x", -Math.cosf(atan) * explode_dist(),
+				                     "y", -Math.sinf(atan) * explode_dist(),
+				                     "depth", explode_depth(),
+				                     "opacity", 0);
+				
+				container.add_actor(particles[i]);
+				particles[i].show();
+			}
+		}
+
+		// make an alpha for easing
+		animation_alpha = new Clutter.Alpha.full(animation_time,
+		                        Clutter.AnimationMode.EASE_IN_OUT_BACK);
+
+		// animate
+		animation_time.new_frame.connect((m) => {
+		});
+
+		animation_time.completed.connect(() => {
+			for (int j = 0; j < count; j++)
+			{
+				container.remove_actor(particles[j]);
+			}
+		});
+	}
+	
+	private float explode_dist()
+	{
+		return Random.int_range(10, 200);
+	}
+	
+	private float explode_depth()
+	{
+		return Random.int_range(-5, 50);
+	}
+	
+	private uint explode_time(uint time)
+	{
+		return (uint)(0.25 * time + Random.next_double() * 0.75 * time);
+	}
 
 	/**
 	 * Clamps a double to an opacity value, an unsigned 8-bit integer.
diff --git a/src/ease-transitions.vala b/src/ease-transitions.vala
index cc81e1f..bbb9a2a 100644
--- a/src/ease-transitions.vala
+++ b/src/ease-transitions.vala
@@ -31,6 +31,7 @@ public enum Ease.Transition
 	FALL,
 	SLATS,
 	OPEN_DOOR,
+	EXPLODE,
 	ZOOM,
 	PANEL,
 	SPIN_CONTENTS,
@@ -51,6 +52,7 @@ public enum Ease.Transition
 		                                       FALL,
 		                                       SLATS,
 		                                       OPEN_DOOR,
+		                                       EXPLODE,
 		                                       ZOOM,
 		                                       PANEL,
 		                                       SPIN_CONTENTS,
@@ -112,6 +114,8 @@ public enum Ease.Transition
 				return SLATS;
 			case "EASE_TRANSITION_OPEN_DOOR":
 				return OPEN_DOOR;
+			case "EASE_TRANSITION_EXPLODE":
+				return EXPLODE;
 			case "EASE_TRANSITION_ZOOM":
 				return ZOOM;
 			case "EASE_TRANSITION_PANEL":
@@ -136,54 +140,55 @@ public enum Ease.Transition
 	{
 		switch (this)
 		{
-			case Transition.NONE:
-			case Transition.FADE:
-			case Transition.DROP:
-			case Transition.FALL:
-			case Transition.SLATS:
-			case Transition.OPEN_DOOR:
-			case Transition.SWING_CONTENTS:
+			case NONE:
+			case FADE:
+			case DROP:
+			case FALL:
+			case SLATS:
+			case OPEN_DOOR:
+			case EXPLODE:
+			case SWING_CONTENTS:
 				return {};
 			
-			case Transition.REVOLVING_DOOR:
-			case Transition.REVEAL:
-			case Transition.SLIDE:
-			case Transition.PANEL:
-			case Transition.SLIDE_CONTENTS:
+			case REVOLVING_DOOR:
+			case REVEAL:
+			case SLIDE:
+			case PANEL:
+			case SLIDE_CONTENTS:
 				return { TransitionVariant.LEFT,
 				         TransitionVariant.RIGHT,
 				         TransitionVariant.UP,
 				         TransitionVariant.DOWN };
 			
 			
-			case Transition.PIVOT:
+			case PIVOT:
 				return { TransitionVariant.TOP_LEFT,
 				         TransitionVariant.TOP_RIGHT,
 				         TransitionVariant.BOTTOM_LEFT,
 				         TransitionVariant.BOTTOM_RIGHT };
 				         
-			case Transition.FLIP:
+			case FLIP:
 				return { TransitionVariant.LEFT_TO_RIGHT,
 				         TransitionVariant.RIGHT_TO_LEFT,
 				         TransitionVariant.TOP_TO_BOTTOM,
 				         TransitionVariant.BOTTOM_TO_TOP };
 			
-			case Transition.ZOOM:
+			case ZOOM:
 				return { TransitionVariant.CENTER,
 				         TransitionVariant.TOP_LEFT,
 				         TransitionVariant.TOP_RIGHT,
 				         TransitionVariant.BOTTOM_LEFT,
 				         TransitionVariant.BOTTOM_RIGHT };
 
-			case Transition.SPIN_CONTENTS:
+			case SPIN_CONTENTS:
 				return { TransitionVariant.LEFT,
 				         TransitionVariant.RIGHT };
 			
-			case Transition.SPRING_CONTENTS:
+			case SPRING_CONTENTS:
 				return { TransitionVariant.UP,
 				         TransitionVariant.DOWN };
 				         
-			case Transition.ZOOM_CONTENTS:
+			case ZOOM_CONTENTS:
 				return { TransitionVariant.IN,
 				         TransitionVariant.OUT };
 			
@@ -197,41 +202,43 @@ public enum Ease.Transition
 	{
 		switch (this)
 		{
-			case Transition.NONE:
+			case NONE:
 				return _("None");
-			case Transition.FADE:
+			case FADE:
 				return _("Fade");
-			case Transition.SLIDE:
+			case SLIDE:
 				return _("Slide");
-			case Transition.DROP:
+			case DROP:
 				return _("Drop");
-			case Transition.PIVOT:
+			case PIVOT:
 				return _("Pivot");
-			case Transition.FLIP:
+			case FLIP:
 				return _("Flip");
-			case Transition.REVOLVING_DOOR:
+			case REVOLVING_DOOR:
 				return _("Revolving Door");
-			case Transition.REVEAL:
+			case REVEAL:
 				return _("Reveal");
-			case Transition.FALL:
+			case FALL:
 				return _("Fall");
-			case Transition.SLATS:
+			case SLATS:
 				return _("Slats");
-			case Transition.OPEN_DOOR:
+			case OPEN_DOOR:
 				return _("Open Door");
-			case Transition.ZOOM:
+			case EXPLODE:
+				return _("Explode");
+			case ZOOM:
 				return _("Zoom");
-			case Transition.PANEL:
+			case PANEL:
 				return _("Panel");
-			case Transition.SPIN_CONTENTS:
+			case SPIN_CONTENTS:
 				return _("Spin Contents");
-			case Transition.SPRING_CONTENTS:
+			case SPRING_CONTENTS:
 				return _("Spring Contents");
-			case Transition.SWING_CONTENTS:
+			case SWING_CONTENTS:
 				return _("Swing Contents");
-			case Transition.SLIDE_CONTENTS:
+			case SLIDE_CONTENTS:
 				return _("Slide Contents");
-			case Transition.ZOOM_CONTENTS:
+			case ZOOM_CONTENTS:
 				return _("Zoom Contents");
 			default:
 				critical("Undefined transition %i", this);
@@ -245,10 +252,10 @@ public enum Ease.Transition
  */
 public enum Ease.TransitionVariant
 {
-	UP,
-	DOWN,
 	LEFT,
 	RIGHT,
+	UP,
+	DOWN,	
 	BOTTOM,
 	TOP,
 	CENTER,



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