[ease: 1/9] Started moving towards enums for transitions.



commit 6a4a270fa74ea21c41f436b1b2cbc282eb73f807
Author: Nate Stedman <natesm gmail com>
Date:   Sat May 29 13:53:55 2010 -0400

    Started moving towards enums for transitions.

 src/Main.vala        |    1 -
 src/Slide.vala       |    4 +-
 src/SlideActor.vala  |  108 +++++++++++-----------
 src/Transitions.vala |  238 ++++++++++++++++++++++++++++++++++++--------------
 4 files changed, 227 insertions(+), 124 deletions(-)
---
diff --git a/src/Main.vala b/src/Main.vala
index 0093c37..3fc9161 100644
--- a/src/Main.vala
+++ b/src/Main.vala
@@ -79,7 +79,6 @@ public static class Ease.Main : GLib.Object
 		ClutterGst.init(ref args);
 
 		// initalize static classes
-		Transitions.init();
 		OpenDialog.init();
 		windows = new Gee.ArrayList<EditorWindow>();
 	
diff --git a/src/Slide.vala b/src/Slide.vala
index a53dc29..815377a 100644
--- a/src/Slide.vala
+++ b/src/Slide.vala
@@ -32,12 +32,12 @@ public class Ease.Slide
 	/**
 	 * The Slide's transition
 	 */
-	public string transition { get; set; }
+	public TransitionType transition { get; set; }
 	
 	/**
 	 * The variant (if any) of the Slide's transition
 	 */
-	public string variant { get; set; }
+	public TransitionVariant variant { get; set; }
 	
 	/**
 	 * The duration of this Slide's transition
diff --git a/src/SlideActor.vala b/src/SlideActor.vala
index b087d16..e953b71 100644
--- a/src/SlideActor.vala
+++ b/src/SlideActor.vala
@@ -204,71 +204,71 @@ public class Ease.SlideActor : Clutter.Group
 
 		switch (slide.transition)
 		{
-			case "Fade":
+			case TransitionType.FADE:
 				fade_transition(new_slide, stack_container, length);
 				break;
 
-			case "Slide":
+			case TransitionType.SLIDE:
 				slide_transition(new_slide, stack_container, length);
 				break;
 
-			case "Drop":
+			case TransitionType.DROP:
 				drop_transition(new_slide, stack_container, length);
 				break;
 
-			case "Pivot":
+			case TransitionType.PIVOT:
 				pivot_transition(new_slide, stack_container, length);
 				break;
 
-			case "Open Door":
+			case TransitionType.OPEN_DOOR:
 				open_door_transition(new_slide, stack_container, length);
 				break;
 
-			case "Reveal":
+			case TransitionType.REVEAL:
 				reveal_transition(new_slide, stack_container, length);
 				break;
 
-			case "Slats":
+			case TransitionType.SLATS:
 				slats_transition(new_slide, stack_container, length);
 				break;
 
-			case "Flip":
+			case TransitionType.FLIP:
 				flip_transition(new_slide, stack_container, length);
 				break;
 
-			case "Revolving Door":
+			case TransitionType.REVOLVING_DOOR:
 				revolving_door_transition(new_slide, stack_container, length);
 				break;
 
-			case "Fall":
+			case TransitionType.FALL:
 				fall_transition(new_slide, stack_container, length);
 				break;
 
-			case "Spin Contents":
+			case TransitionType.SPIN_CONTENTS:
 				spin_contents_transition(new_slide, stack_container, length);
 				break;
 
-			case "Swing Contents":
+			case TransitionType.SWING_CONTENTS:
 				swing_contents_transition(new_slide, stack_container, length);
 				break;
 
-			case "Zoom":
+			case TransitionType.ZOOM:
 				zoom_transition(new_slide, stack_container, length);
 				break;
 
-			case "Slide Contents":
+			case TransitionType.SLIDE_CONTENTS:
 				slide_contents_transition(new_slide, stack_container, length);
 				break;
 
-			case "Spring Contents":
+			case TransitionType.SPRING_CONTENTS:
 				spring_contents_transition(new_slide, stack_container, length);
 				break;
 
-			case "Zoom Contents":
+			case TransitionType.ZOOM_CONTENTS:
 				zoom_contents_transition(new_slide, stack_container, length);
 				break;
 
-			case "Panel":
+			case TransitionType.PANEL:
 				panel_transition(new_slide, stack_container, length);
 				break;
 		}
@@ -290,25 +290,25 @@ public class Ease.SlideActor : Clutter.Group
 	{
 		switch (slide.variant)
 		{
-			case "Up":
+			case TransitionVariant.UP:
 				new_slide.y = slide.parent.height;
 				new_slide.animate(EASE_SLIDE, length, "y", 0);
 				animate(EASE_SLIDE, length, "y", -new_slide.y);
 				break;
 			
-			case "Down":
+			case TransitionVariant.DOWN:
 				new_slide.y = -slide.parent.height;
 				new_slide.animate(EASE_SLIDE, length, "y", 0);
 				animate(EASE_SLIDE, length, "y", -new_slide.y);
 				break;
 			
-			case "Left":
+			case TransitionVariant.LEFT:
 				new_slide.x = slide.parent.width;
 				new_slide.animate(EASE_SLIDE, length, "x", 0);
 				animate(EASE_SLIDE, length, "x", -new_slide.x);
 				break;
 			
-			case "Right":
+			case TransitionVariant.RIGHT:
 				new_slide.x = -slide.parent.width;
 				new_slide.animate(EASE_SLIDE, length, "x", 0);
 				animate(EASE_SLIDE, length, "x", -new_slide.x);
@@ -329,15 +329,15 @@ public class Ease.SlideActor : Clutter.Group
 		float xpos = 0, ypos = 0, angle = 90;
 		switch (slide.variant)
 		{
-			case "Top Right":
+			case TransitionVariant.TOP_RIGHT:
 				xpos = slide.parent.width;
 				angle = -90;
 				break;
-			case "Bottom Left":
+			case TransitionVariant.BOTTOM_LEFT:
 				ypos = slide.parent.height;
 				angle = -90;
 				break;
-			case "Bottom Right":
+			case TransitionVariant.BOTTOM_RIGHT:
 				xpos = slide.parent.width;
 				ypos = slide.parent.height;
 				break;
@@ -382,24 +382,24 @@ public class Ease.SlideActor : Clutter.Group
 		
 		switch (slide.variant)
 		{
-			case "Bottom to Top":
+			case TransitionVariant.BOTTOM_TO_TOP:
 				axis = Clutter.RotateAxis.X_AXIS;
 				positive = 1;
 				y_point = slide.parent.height / 2;
 				break;
 
-			case "Top to Bottom":
+			case TransitionVariant.TOP_TO_BOTTOM:
 				axis = Clutter.RotateAxis.X_AXIS;
 				positive = -1;
 				break;
 
-			case "Left to Right":
+			case TransitionVariant.LEFT_TO_RIGHT:
 				axis = Clutter.RotateAxis.Y_AXIS;
 				positive = 1;
 				x_point = slide.parent.width / 2;
 				break;
 
-			default: // "Right to Left"
+			default: // RIGHT_TO_LEFT
 				axis = Clutter.RotateAxis.Y_AXIS;
 				positive = -1;
 				x_point = slide.parent.width / 2;
@@ -464,23 +464,23 @@ public class Ease.SlideActor : Clutter.Group
 		
 		switch (slide.variant)
 		{
-			case "Left":
+			case TransitionVariant.LEFT:
 				axis = Clutter.RotateAxis.Y_AXIS;
 				positive = 1;
 				break;
 			
-			case "Right":
+			case TransitionVariant.RIGHT:
 				axis = Clutter.RotateAxis.Y_AXIS;
 				positive = -1;
 				x_point = slide.parent.width;
 				break;
 			
-			case "Top":
+			case TransitionVariant.TOP:
 				axis = Clutter.RotateAxis.X_AXIS;
 				positive = -1;
 				break;
 			
-			default: // bottom
+			default: // BOTTOM
 				axis = Clutter.RotateAxis.X_AXIS;
 				positive = 1;
 				y_point = slide.parent.height;
@@ -511,22 +511,22 @@ public class Ease.SlideActor : Clutter.Group
 
 		switch (slide.variant)
 		{
-			case "Top":
+			case TransitionVariant.TOP:
 				new_slide.y = slide.parent.height;
 				animate(EASE_SLIDE, length, "y", -new_slide.y);
 				new_slide.y = 0;
 				break;
-			case "Bottom":
+			case TransitionVariant.BOTTOM:
 				new_slide.y = -slide.parent.height;
 				animate(EASE_SLIDE, length, "y", -new_slide.y);
 				new_slide.y = 0;
 				break;
-			case "Left":
+			case TransitionVariant.LEFT:
 				new_slide.x = slide.parent.width;
 				this.animate(EASE_SLIDE, length, "x", -new_slide.x);
 				new_slide.x = 0;
 				break;
-			case "Right":
+			case TransitionVariant.RIGHT:
 				new_slide.x = -slide.parent.width;
 				animate(EASE_SLIDE, length, "x", -new_slide.x);
 				new_slide.x = 0;
@@ -680,21 +680,21 @@ public class Ease.SlideActor : Clutter.Group
 	{
 		switch (slide.variant)
 		{
-			case "Center":
+			case TransitionVariant.CENTER:
 				new_slide.set_scale_full(0, 0,
 				                         slide.parent.width / 2,
 				                         slide.parent.height / 2);
 				break;
-			case "Top Left":
+			case TransitionVariant.TOP_LEFT:
 				new_slide.set_scale_full(0, 0, 0, 0);
 				break;
-			case "Top Right":
+			case TransitionVariant.TOP_RIGHT:
 				new_slide.set_scale_full(0, 0, slide.parent.width, 0);
 				break;
-			case "Bottom Left":
+			case TransitionVariant.BOTTOM_LEFT:
 				new_slide.set_scale_full(0, 0, 0, slide.parent.height);
 				break;
-			case "Bottom Right":
+			case TransitionVariant.BOTTOM_RIGHT:
 				new_slide.set_scale_full(0, 0,
 				                         slide.parent.width,
 				                         slide.parent.height);
@@ -716,15 +716,15 @@ public class Ease.SlideActor : Clutter.Group
 		
 		switch (slide.variant)
 		{
-			case "Up":
+			case TransitionVariant.UP:
 				pos = slide.parent.height;
 				property = "y";
 				break;
-			case "Down":
+			case TransitionVariant.DOWN:
 				pos = -slide.parent.height;
 				property = "y";
 				break;
-			case "Left":
+			case TransitionVariant.LEFT:
 				pos = slide.parent.width;
 				property = "x";
 				break;
@@ -790,7 +790,7 @@ public class Ease.SlideActor : Clutter.Group
 		alpha2 = new Clutter.Alpha.full(time2,
 		                                Clutter.AnimationMode.EASE_OUT_SINE);
 
-		float angle = slide.variant == "Left" ? -90 : 90;
+		float angle = slide.variant == TransitionVariant.LEFT ? -90 : 90;
 		time1.completed.connect(() => {
 			contents.opacity = 0;
 			time2.start();
@@ -858,28 +858,28 @@ public class Ease.SlideActor : Clutter.Group
 		
 		switch (slide.variant)
 		{
-			case "Right":
+			case TransitionVariant.RIGHT:
 				new_slide.contents.x = -slide.parent.width;
 				new_slide.contents.animate(EASE_SLIDE, length, "x", 0);
 
 				contents.animate(EASE_SLIDE,
 				                 length, "x", -new_slide.contents.x);
 				break;
-			case "Left":
+			case TransitionVariant.LEFT:
 				new_slide.contents.x = slide.parent.width;
 				new_slide.contents.animate(EASE_SLIDE, length, "x", 0);
 
 				contents.animate(EASE_SLIDE,
 				                 length, "x", -new_slide.contents.x);
 				break;
-			case "Up":
+			case TransitionVariant.UP:
 				new_slide.contents.y = slide.parent.height;
 				new_slide.contents.animate(EASE_SLIDE, length, "y", 0);
 
 				contents.animate(EASE_SLIDE,
 				                 length, "y", -new_slide.contents.y);
 				break;
-			case "Down":
+			case TransitionVariant.DOWN:
 				new_slide.contents.y = -slide.parent.height;
 				new_slide.contents.animate(EASE_SLIDE, length, "y", 0);
 
@@ -900,14 +900,14 @@ public class Ease.SlideActor : Clutter.Group
 
 		switch (slide.variant)
 		{
-			case "Up":
+			case TransitionVariant.UP:
 				new_slide.contents.y = slide.parent.height * 1.2f;
 				new_slide.contents.animate(Clutter.AnimationMode.EASE_IN_OUT_ELASTIC,
 				                           length, "y", 0);
 				contents.animate(Clutter.AnimationMode.EASE_IN_OUT_ELASTIC,
 				                 length, "y", -slide.parent.height * 1.2);
 				break;
-			case "Down":
+			case TransitionVariant.DOWN:
 				new_slide.contents.y = -slide.parent.height * 1.2f;
 				new_slide.contents.animate(Clutter.AnimationMode.EASE_IN_OUT_ELASTIC,
 				                           length, "y", 0);
@@ -921,7 +921,7 @@ public class Ease.SlideActor : Clutter.Group
 	                                      Clutter.Group stack_container,
 	                                      uint length)
 	{
-		prepare_stack_transition(slide.variant == "Out",
+		prepare_stack_transition(slide.variant == TransitionVariant.OUT,
 		                         new_slide, stack_container);
 
 		animation_alpha = new Clutter.Alpha.full(animation_time,
@@ -930,7 +930,7 @@ public class Ease.SlideActor : Clutter.Group
 		background.animate(Clutter.AnimationMode.LINEAR, length, "opacity", 0);
 		switch (slide.variant)
 		{
-			case "In":
+			case TransitionVariant.IN:
 				new_slide.contents.set_scale_full(0, 0,
 				                                  slide.parent.width / 2,
 				                                  slide.parent.height / 2);
@@ -948,7 +948,7 @@ public class Ease.SlideActor : Clutter.Group
 					   	               1.0 + 2 * animation_alpha.alpha);
 				});
 				break;
-			case "Out":
+			case TransitionVariant.OUT:
 				new_slide.contents.set_scale_full(0, 0,
 				                                  slide.parent.width / 2,
 				                                  slide.parent.height / 2);
diff --git a/src/Transitions.vala b/src/Transitions.vala
index b13881f..120a6d8 100644
--- a/src/Transitions.vala
+++ b/src/Transitions.vala
@@ -23,48 +23,129 @@
  */
 public static class Ease.Transitions : GLib.Object
 {
-	private static Gee.ArrayList<Transition> Transitions;
+	private const TransitionVariant[] directions = { TransitionVariant.UP,
+	                                               TransitionVariant.DOWN,
+	                                               TransitionVariant.LEFT,
+	                                               TransitionVariant.RIGHT };
+	                                               
+	private static Transition[] transitions = {
+		Transition() { type = TransitionType.NONE, variants = {} },
+		Transition() { type = TransitionType.FADE, variants = {} },
+		Transition() { type = TransitionType.SLIDE, variants = directions },
+		Transition() { type = TransitionType.DROP, variants = {} },
+		Transition() { type = TransitionType.PIVOT,
+		               variants = { TransitionVariant.TOP_LEFT,
+		                            TransitionVariant.TOP_RIGHT,
+		                            TransitionVariant.BOTTOM_LEFT,
+		                            TransitionVariant.BOTTOM_RIGHT } },
+		Transition() { type = TransitionType.FLIP,
+		               variants = { TransitionVariant.TOP_TO_BOTTOM,
+		                            TransitionVariant.BOTTOM_TO_TOP,
+		                            TransitionVariant.LEFT_TO_RIGHT,
+		                            TransitionVariant.RIGHT_TO_LEFT } },
+		Transition() { type = TransitionType.REVOLVING_DOOR, variants = directions },
+		Transition() { type = TransitionType.REVEAL, variants = directions },
+		Transition() { type = TransitionType.FALL, variants = {} },
+		Transition() { type = TransitionType.SLATS, variants = {} },
+		Transition() { type = TransitionType.OPEN_DOOR, variants = {} },
+		Transition() { type = TransitionType.ZOOM,
+		               variants = { TransitionVariant.CENTER,
+		                            TransitionVariant.TOP_LEFT,
+		                            TransitionVariant.TOP_RIGHT,
+		                            TransitionVariant.BOTTOM_LEFT,
+		                            TransitionVariant.BOTTOM_RIGHT } },
+		Transition() { type = TransitionType.PANEL, variants = directions },
+		Transition() { type = TransitionType.SPIN_CONTENTS,
+		               variants = { TransitionVariant.LEFT,
+		                            TransitionVariant.RIGHT } },
+		Transition() { type = TransitionType.SWING_CONTENTS, variants = {} },
+		Transition() { type = TransitionType.SLIDE_CONTENTS, variants = directions },
+		Transition() { type = TransitionType.SPRING_CONTENTS,
+		               variants = { TransitionVariant.UP,
+		                            TransitionVariant.DOWN } },
+		Transition() { type = TransitionType.ZOOM_CONTENTS,
+		               variants = { TransitionVariant.IN,
+		                            TransitionVariant.OUT } }
+	};
 	
-	public static int size { get { return Transitions.size; } }
+	public static int size { get { return transitions.length; } }
 	
 	/**
-	 * Initialize the Transitions class.
+	 * Returns the string name of a transition.
 	 *
-	 * Called when Ease starts.
+	 * @param type The transition type.
 	 */
-	public static void init()
+	public static string get_name(TransitionType type)
 	{
-		Transitions = new Gee.ArrayList<Transition>();
-		string []directions = { _("Up"), _("Down"), _("Left"), _("Right") };
-
-		add_transition(_("None"), {}, 0);
-		add_transition(_("Fade"), {}, 0);
-		add_transition(_("Slide"), directions, 4);
-		add_transition(_("Drop"), {}, 0);
-		add_transition(_("Pivot"), { _("Top Left"), _("Top Right"), _("Bottom Left"), _("Bottom Right") }, 4);
-		add_transition(_("Flip"), { _("Top to Bottom"), _("Bottom to Top"), _("Left to Right"), _("Right to Left") }, 4);
-		add_transition(_("Revolving Door"), directions, 4);
-		add_transition(_("Reveal"), directions, 4);
-		add_transition(_("Fall"), {}, 0);
-		add_transition(_("Slats"), {}, 0);
-		add_transition(_("Open Door"), {}, 0);
-		add_transition(_("Zoom"), { _("Center"), _("Top Left"), _("Top Right"), _("Bottom Left"), _("Bottom Right") }, 5);
-		add_transition(_("Panel"), directions, 4);
-		add_transition(_("Spin Contents"), { _("Left"), _("Right") }, 2);
-		add_transition(_("Swing Contents"), {}, 0);
-		add_transition(_("Slide Contents"), directions, 4);
-		add_transition(_("Spring Contents"), { _("Up"), _("Down") }, 2);
-		add_transition(_("Zoom Contents"), { _("In"), _("Out") }, 2);
+		switch (type)
+		{
+			case TransitionType.NONE:
+				return _("None");
+				break;
+			case TransitionType.FADE:
+				return _("Fade");
+				break;
+			case TransitionType.SLIDE:
+				return _("Slide");
+				break;
+			case TransitionType.DROP:
+				return _("Drop");
+				break;
+			case TransitionType.PIVOT:
+				return _("Pivot");
+				break;
+			case TransitionType.FLIP:
+				return _("Flip");
+				break;
+			case TransitionType.REVOLVING_DOOR:
+				return _("Revolving Door");
+				break;
+			case TransitionType.REVEAL:
+				return _("Reveal");
+				break;
+			case TransitionType.FALL:
+				return _("Fall");
+				break;
+			case TransitionType.SLATS:
+				return _("Slats");
+				break;
+			case TransitionType.OPEN_DOOR:
+				return _("Open Door");
+				break;
+			case TransitionType.ZOOM:
+				return _("Zoom");
+				break;
+			case TransitionType.PANEL:
+				return _("Panel");
+				break;
+			case TransitionType.SPIN_CONTENTS:
+				return _("Spin Contents");
+				break;
+			case TransitionType.SPRING_CONTENTS:
+				return _("Spring Contents");
+				break;
+			case TransitionType.SWING_CONTENTS:
+				return _("Swing Contents");
+				break;
+			case TransitionType.SLIDE_CONTENTS:
+				return _("Slide Contents");
+				break;
+			default: // ZOOM_CONTENTS
+				return _("Zoom Contents");
+				break;
+		}
 	}
 	
-	/**
-	 * Returns the string name of a transition.
-	 *
-	 * @param i The transition index.
-	 */
-	public static string get_name(int i)
+	public string[] names()
 	{
-		return Transitions.get(i).name;
+		var names = new string[transitions.length];
+		
+		for (int i = 0; i < transitions.length; i++)
+		{
+			names[i] = get_name(transitions[i].type);
+		}
+		
+		return names;
 	}
 	
 	/**
@@ -72,17 +153,17 @@ public static class Ease.Transitions : GLib.Object
 	 * 
 	 * @param name The name of the transition.
 	 */
-	public static int get_transition_id(string name)
+	/*public static int get_transition_id(string name)
 	{
-		for (var i = 0; i < Transitions.size; i++)
+		for (var i = 0; i < transitions.length; i++)
 		{
-			if (Transitions.get(i).name == name)
+			if (get_name(transitions[i].type) == name)
 			{
 				return i;
 			}
 		}
 		return 0;
-	}
+	}*/
 	
 	/**
 	 * Returns the ID of a transition, given the names of both.
@@ -90,7 +171,7 @@ public static class Ease.Transitions : GLib.Object
 	 * @param transition The name of the transition.
 	 * @param variant The name of the variant.
 	 */
-	public static int get_variant_id(string transition, string variant)
+	/*public static int get_variant_id(string transition, string variant)
 	{
 		var id = get_transition_id(transition);
 		for (var i = 0; i < Transitions.get(id).count; i++)
@@ -101,42 +182,65 @@ public static class Ease.Transitions : GLib.Object
 			}
 		}
 		return 0;
-	}
+	}*/
 	
 	/**
 	 * Returns an array of variants, given a transition ID.
 	 *
 	 * @param i A transition index.
 	 */
-	public static string[] get_variants(int i)
+	/*public static string[] get_variants(int i)
 	{
 		return Transitions.get(i).variants;
-	}
-	
-	/**
-	 * Returns the size of the variant array, give a transition ID.
-	 *
-	 * @param i A transition index.
-	 */
-	public static int get_variant_count(int i)
-	{
-		return Transitions.get(i).count;
-	}
-	
-	private static void add_transition(string n, string[] v, int c)
-	{
-		Transition t = new Transition();
-		t.name = n;
-		t.variants = v;
-		t.count = c;
-		Transitions.add(t);
-	}
-	
-	private class Transition : GLib.Object
-	{
-		public string name { get; set; }
-		public int count { get; set; }
-		public string[] variants;
-	}
+	}*/
+}
+
+public struct Ease.Transition
+{
+	public TransitionType type;
+	public TransitionVariant[] variants;
+}
+
+public enum Ease.TransitionType
+{
+	NONE,
+	FADE,
+	SLIDE,
+	DROP,
+	PIVOT,
+	FLIP,
+	REVOLVING_DOOR,
+	REVEAL,
+	FALL,
+	SLATS,
+	OPEN_DOOR,
+	ZOOM,
+	PANEL,
+	SPIN_CONTENTS,
+	SPRING_CONTENTS,
+	SWING_CONTENTS,
+	SLIDE_CONTENTS,
+	ZOOM_CONTENTS
+}
+
+public enum Ease.TransitionVariant
+{
+	UP,
+	DOWN,
+	LEFT,
+	RIGHT,
+	BOTTOM,
+	TOP,
+	CENTER,
+	TOP_LEFT,
+	TOP_RIGHT,
+	BOTTOM_LEFT,
+	BOTTOM_RIGHT,
+	TOP_TO_BOTTOM,
+	BOTTOM_TO_TOP,
+	LEFT_TO_RIGHT,
+	RIGHT_TO_LEFT,
+	IN,
+	OUT
 }
 



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