[ease/animate_zoom: 4/6] Added ZoomSlider widget to clean up WelcomeWindow code.



commit 11313c44806eced48ae136f07ae3f3a2dbc1074b
Author: Nate Stedman <natesm gmail com>
Date:   Wed May 19 23:04:37 2010 -0400

    Added ZoomSlider widget to clean up WelcomeWindow code.
    
    This will also be used in EditorWindow.

 src/libease/WelcomeWindow.vala |   52 +++------------------
 src/libease/ZoomSlider.vala    |   97 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 44 deletions(-)
---
diff --git a/src/libease/WelcomeWindow.vala b/src/libease/WelcomeWindow.vala
index 0c6596c..cd3ff0a 100644
--- a/src/libease/WelcomeWindow.vala
+++ b/src/libease/WelcomeWindow.vala
@@ -43,9 +43,7 @@ public class Ease.WelcomeWindow : Gtk.Window
 	private float preview_aspect;
 
 	// zoom widgets
-	private Gtk.HScale zoom_slider;
-	private Gtk.Button zoom_in;
-	private Gtk.Button zoom_out;
+	private ZoomSlider zoom_slider;
 	
 	// constants
 	private const int[] RESOLUTIONS_X = {800,
@@ -64,6 +62,8 @@ public class Ease.WelcomeWindow : Gtk.Window
 	private const int ANIM_TIME = 75;
 	private const int ANIM_EASE = Clutter.AnimationMode.LINEAR;
 	
+	private int[] ZOOM_VALUES = {100, 150, 200, 250, 400};
+	
 	public WelcomeWindow()
 	{
 		title = "New Presentation";
@@ -102,7 +102,9 @@ public class Ease.WelcomeWindow : Gtk.Window
 		align.add(new_button);
 		hbox.pack_start(align, false, false, 0);
 		
-		hbox.pack_start(create_zoom_bar(), false, false, 0);
+		zoom_slider = new ZoomSlider(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");
 		align = new Gtk.Alignment(0, 0.5f, 0, 0);
@@ -261,7 +263,8 @@ public class Ease.WelcomeWindow : Gtk.Window
 		// set the size of the background
 		preview_background.width = embed.width;
 		preview_background.height = x_position != 0
-		                          ? y_pixels + preview_width * preview_aspect + PREVIEW_PADDING
+		                          ? y_pixels + preview_width * preview_aspect +
+		                            PREVIEW_PADDING
 		                          : y_pixels + PREVIEW_PADDING;
 
 		// always fill the background
@@ -270,44 +273,5 @@ public class Ease.WelcomeWindow : Gtk.Window
 			preview_background.height = embed.height;
 		}
 	}
-	
-	private Gtk.Alignment create_zoom_bar()
-	{
-		var hbox = new Gtk.HBox(false, 5);
-		
-		// create zoom slider
-		zoom_slider = new Gtk.HScale(new Gtk.Adjustment(100, 100, 400, 10,
-		                                                50, 50));
-		zoom_slider.width_request = 200;
-		zoom_slider.draw_value = false;
-		zoom_slider.digits = 0;
-		
-		// zoom in button
-		zoom_in = new Gtk.Button();
-		zoom_in.add(new Gtk.Image.from_stock("gtk-zoom-in", Gtk.IconSize.MENU));
-		zoom_in.relief = Gtk.ReliefStyle.NONE;
-		
-		// zoom out button
-		zoom_out = new Gtk.Button();
-		zoom_out.add(new Gtk.Image.from_stock("gtk-zoom-out", Gtk.IconSize.MENU));
-		zoom_out.relief = Gtk.ReliefStyle.NONE;
-		
-		// put it all together
-		var align = new Gtk.Alignment(0, 0.5f, 1, 0);
-		align.add(zoom_out);
-		hbox.pack_start(align, false, false, 0);
-		
-		align = new Gtk.Alignment(0, 0.5f, 1, 0);
-		align.add(zoom_slider);
-		hbox.pack_start(align, false, false, 0);
-		
-		align = new Gtk.Alignment(0, 0.5f, 1, 0);
-		align.add(zoom_in);
-		hbox.pack_start(align, false, false, 0);
-		
-		align = new Gtk.Alignment(1, 1, 1, 1);
-		align.add(hbox);
-		return align;
-	}
 }
 
diff --git a/src/libease/ZoomSlider.vala b/src/libease/ZoomSlider.vala
new file mode 100644
index 0000000..02bc483
--- /dev/null
+++ b/src/libease/ZoomSlider.vala
@@ -0,0 +1,97 @@
+/*  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/>.
+*/
+
+/*
+ * A widget containing a Gtk.HScale and two zoom buttons
+ */
+public class Ease.ZoomSlider : Gtk.Alignment
+{
+	private Gtk.HScale zoom_slider;
+	private Gtk.Button zoom_in;
+	private Gtk.Button zoom_out;
+	private int[] values;
+
+	public ZoomSlider(Gtk.Adjustment adjustment, int[] button_values)
+	{
+		values = button_values;
+		
+		var hbox = new Gtk.HBox(false, 5);
+		
+		// create zoom slider
+		zoom_slider = new Gtk.HScale(adjustment);
+		zoom_slider.width_request = 200;
+		zoom_slider.draw_value = false;
+		zoom_slider.digits = 0;
+		
+		// zoom in button
+		zoom_in = new Gtk.Button();
+		zoom_in.add(new Gtk.Image.from_stock("gtk-zoom-in", Gtk.IconSize.MENU));
+		zoom_in.relief = Gtk.ReliefStyle.NONE;
+		
+		// zoom out button
+		zoom_out = new Gtk.Button();
+		zoom_out.add(new Gtk.Image.from_stock("gtk-zoom-out", Gtk.IconSize.MENU));
+		zoom_out.relief = Gtk.ReliefStyle.NONE;
+		
+		// put it all together
+		var align = new Gtk.Alignment(0, 0.5f, 1, 0);
+		align.add(zoom_out);
+		hbox.pack_start(align, false, false, 0);
+		
+		align = new Gtk.Alignment(0, 0.5f, 1, 0);
+		align.add(zoom_slider);
+		hbox.pack_start(align, false, false, 0);
+		
+		align = new Gtk.Alignment(0, 0.5f, 1, 0);
+		align.add(zoom_in);
+		hbox.pack_start(align, false, false, 0);
+		
+		set(1, 1, 1, 1);
+		add(hbox);
+		
+		zoom_slider.value_changed.connect(() => value_changed());
+		
+		zoom_in.clicked.connect(() => {
+			for (var i = 0; i < values.length; i++)
+			{
+				if (zoom_slider.get_value() < values[i])
+				{
+					zoom_slider.set_value(values[i]);
+					break;
+				}
+			}
+		});
+		
+		zoom_out.clicked.connect(() => {
+			for (var i = values.length - 1; i > -1; i--)
+			{
+				if (zoom_slider.get_value() > values[i])
+				{
+					zoom_slider.set_value(values[i]);
+					break;
+				}
+			}
+		});
+	}
+	
+	public double get_value()
+	{
+		return zoom_slider.get_value();
+	}
+	
+	public signal void value_changed();
+}



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