[ease/animate_zoom] Animate ZoomSliders when +/- buttons are clicked.



commit 78fb818b3579e28d07d1c8a198cd340c8c7bd42a
Author: Nate Stedman <natesm gmail com>
Date:   Sun May 30 18:34:20 2010 -0400

    Animate ZoomSliders when +/- buttons are clicked.

 src/EditorWindow.vala |   12 +-----------
 src/ZoomSlider.vala   |   43 +++++++++++++++++++++++++++++++++++++++----
 2 files changed, 40 insertions(+), 15 deletions(-)
---
diff --git a/src/EditorWindow.vala b/src/EditorWindow.vala
index 6cd7ba2..5451307 100644
--- a/src/EditorWindow.vala
+++ b/src/EditorWindow.vala
@@ -23,7 +23,7 @@
  * controls. The window is linked to a { link Document}, and all changes
  * are made directly to that object.
  */
-public class Ease.EditorWindow : Gtk.Window, Clutter.Animatable
+public class Ease.EditorWindow : Gtk.Window
 {
 	// interface elements
 	public EditorEmbed embed;
@@ -301,15 +301,5 @@ public class Ease.EditorWindow : Gtk.Window, Clutter.Animatable
 		align.add(vbox);
 		return align;
 	}
-	
-	public bool animate_property(Clutter.Animation animation,
-	                             string property_name,
-	                             Value initial_value,
-	                             Value final_value,
-	                             double progress,
-	                             Value val)
-	{
-		return true;
-	}
 }
 
diff --git a/src/ZoomSlider.vala b/src/ZoomSlider.vala
index dc199e9..39685b5 100644
--- a/src/ZoomSlider.vala
+++ b/src/ZoomSlider.vala
@@ -18,13 +18,17 @@
 /*
  * A widget containing a Gtk.HScale and two zoom buttons
  */
-public class Ease.ZoomSlider : Gtk.Alignment
+public class Ease.ZoomSlider : Gtk.Alignment, Clutter.Animatable
 {
 	private Gtk.HScale zoom_slider;
 	private Gtk.Button zoom_in;
 	private Gtk.Button zoom_out;
 	private int[] values;
 	
+	private Clutter.Animation zoom_anim;
+	private const int ZOOM_TIME = 100;
+	private const int ZOOM_MODE = Clutter.AnimationMode.EASE_IN_OUT_SINE;
+	
 	public Gtk.PositionType value_pos
 	{
 		get { return zoom_slider.value_pos; }
@@ -35,7 +39,13 @@ public class Ease.ZoomSlider : Gtk.Alignment
 	{
 		get { return zoom_slider.digits; }
 		set { zoom_slider.digits = value; }
-	}	
+	}
+	
+	public double sliderpos
+	{
+		get { return zoom_slider.get_value(); }
+		set { zoom_slider.set_value(value); }
+	}
 
 	public ZoomSlider(Gtk.Adjustment adjustment, int[] button_values)
 	{
@@ -82,7 +92,7 @@ public class Ease.ZoomSlider : Gtk.Alignment
 			{
 				if (zoom_slider.get_value() < values[i])
 				{
-					zoom_slider.set_value(values[i]);
+					animate_zoom(values[i]);
 					break;
 				}
 			}
@@ -93,7 +103,7 @@ public class Ease.ZoomSlider : Gtk.Alignment
 			{
 				if (zoom_slider.get_value() > values[i])
 				{
-					zoom_slider.set_value(values[i]);
+					animate_zoom(values[i]);
 					break;
 				}
 			}
@@ -109,5 +119,30 @@ public class Ease.ZoomSlider : Gtk.Alignment
 		return zoom_slider.get_value();
 	}
 	
+	
+	private void animate_zoom(double value)
+	{
+		zoom_anim = new Clutter.Animation();
+		zoom_anim.object = this;
+		zoom_anim.bind("sliderpos", value);
+		zoom_anim.duration = ZOOM_TIME;
+		zoom_anim.mode = ZOOM_MODE;
+		zoom_anim.timeline.start();
+	}
+	
+	private bool animate_property(Clutter.Animation animation,
+	                                      string property_name,
+	                                      GLib.Value initial_value,
+	                                      GLib.Value final_value,
+	                                      double progress,
+	                                      GLib.Value value)
+	{
+		if (property_name != "sliderpos") { return false; }
+		
+		value.set_double(initial_value.get_double() * (1 - progress) + 
+		                 final_value.get_double() * progress);
+		return true;
+	}
+	
 	public signal void value_changed();
 }



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