[ease] Remove ZoomSlider animation, add AnimatedZoomSlider.



commit 13859608b6046c847580f45bcb60f73043b6769e
Author: Nate Stedman <natesm gmail com>
Date:   Tue Jul 20 18:46:45 2010 -0400

    Remove ZoomSlider animation, add AnimatedZoomSlider.
    
    In the future, I'd like to provide something like
    libease (only GTK+ dependencies) and libease-clutter.
    ZoomSlider is a potentially useful widget that doesn't
    need to have the animation (although it's nice!)
    in all cases.

 Makefile.am                        |    1 +
 src/ease-animated-zoom-slider.vala |   65 ++++++++++++++++++++++++++++++++++++
 src/ease-editor-window.vala        |    4 +-
 src/ease-welcome-window.vala       |    4 +-
 src/ease-zoom-slider.vala          |   33 +++---------------
 5 files changed, 75 insertions(+), 32 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 7a25d50..3cacc72 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -54,6 +54,7 @@ ease_SOURCES = \
 	src/ease-welcome-actor.vala \
 	src/ease-welcome-window.vala \
 	src/ease-zoom-slider.vala \
+	src/ease-animated-zoom-slider.vala \
 	src/main.vala \
 	$(NULL)
 
diff --git a/src/ease-animated-zoom-slider.vala b/src/ease-animated-zoom-slider.vala
new file mode 100644
index 0000000..21bac65
--- /dev/null
+++ b/src/ease-animated-zoom-slider.vala
@@ -0,0 +1,65 @@
+/*  Ease, a GTK presentation application
+    Copyright (C) 2010 Nate Stedman
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * An animated { link ZoomSlider}.
+ *
+ * AnimatedZoomSlider smoothly animates (with ClutterAnimation)
+ * when the + or - buttons are pressed.
+ */
+public class Ease.AnimatedZoomSlider : ZoomSlider, Clutter.Animatable
+{
+	private Clutter.Animation zoom_anim;
+	private const int ZOOM_TIME = 100;
+	private const int ZOOM_MODE = Clutter.AnimationMode.EASE_IN_OUT_SINE;
+	
+	/** 
+	 * Creates a new AnimatedZoomSlider.
+	 *
+	 * @param adjustment The Gtk.Adjustment to use.
+	 * @param button_values The values that the slider should stop on when the
+	 * zoom in and out buttons are pressed.
+	 */
+	public AnimatedZoomSlider(Gtk.Adjustment adjustment, int[] button_values)
+	{
+		base(adjustment, button_values);
+	}
+	
+	protected override void change_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;
+	}
+}
\ No newline at end of file
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index 0289d12..6f829a5 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -477,8 +477,8 @@ public class Ease.EditorWindow : Gtk.Window
 	private ZoomSlider create_zoom_slider()
 	{
 		// create zoom slider
-		zoom_slider = new ZoomSlider(new Gtk.Adjustment(100, 10, 400, 10,
-		                                                50, 50), ZOOM_LEVELS);
+		zoom_slider = new AnimatedZoomSlider(new Gtk.Adjustment(100, 10, 400, 10,
+		                                                        50, 50), ZOOM_LEVELS);
 		zoom_slider.width_request = 200;
 		zoom_slider.value_pos = Gtk.PositionType.RIGHT;
 		zoom_slider.digits = 0;
diff --git a/src/ease-welcome-window.vala b/src/ease-welcome-window.vala
index b2764d6..54d6ac6 100644
--- a/src/ease-welcome-window.vala
+++ b/src/ease-welcome-window.vala
@@ -128,8 +128,8 @@ public class Ease.WelcomeWindow : Gtk.Window
 		align.add(new_button);
 		hbox.pack_start(align, false, false, 0);
 		
-		zoom_slider = new ZoomSlider(new Gtk.Adjustment(100, 100, 400, 10,
-		                                                50, 50), ZOOM_VALUES);
+		zoom_slider = new AnimatedZoomSlider(new Gtk.Adjustment(100, 100, 400, 10,
+		                                                        50, 50), ZOOM_VALUES);
 		hbox.pack_start(zoom_slider, false, false, 0);
 		
 		open_button = new Gtk.Button.from_stock("gtk-open");
diff --git a/src/ease-zoom-slider.vala b/src/ease-zoom-slider.vala
index e75974a..1828cfa 100644
--- a/src/ease-zoom-slider.vala
+++ b/src/ease-zoom-slider.vala
@@ -21,17 +21,13 @@
  * ZoomSlider uses ClutterAnimation to smoothly adjust the slider when th
  * zoom in or zoom out button is clicked.
  */
-public class Ease.ZoomSlider : Gtk.Alignment, Clutter.Animatable
+public class Ease.ZoomSlider : Gtk.Alignment
 {
 	private Gtk.HScale zoom_slider;
 	private Gtk.Button zoom_in_button;
 	private Gtk.Button zoom_out_button;
 	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;
-	
 	/** 
 	 * The position of the zoom slider's value.
 	 */
@@ -160,7 +156,7 @@ public class Ease.ZoomSlider : Gtk.Alignment, Clutter.Animatable
 		{
 			if (zoom_slider.get_value() > values[i])
 			{
-				animate_zoom(values[i]);
+				change_zoom(values[i]);
 				break;
 			}
 		}
@@ -172,34 +168,15 @@ public class Ease.ZoomSlider : Gtk.Alignment, Clutter.Animatable
 		{
 			if (zoom_slider.get_value() < values[i])
 			{
-				animate_zoom(values[i]);
+				change_zoom(values[i]);
 				break;
 			}
 		}
 	}
 	
-	private void animate_zoom(double value)
+	protected virtual void change_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;
+		sliderpos = value;
 	}
 	
 	/** 



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