[ease/animate_zoom: 2/6] Selectable WelcomeActors.



commit 187cc0dfe340f841f14930441d1140212c5ee9bb
Author: Nate Stedman <natesm gmail com>
Date:   Wed May 19 20:59:40 2010 -0400

    Selectable WelcomeActors.

 src/libease/ScrollableEmbed.vala |    6 ++-
 src/libease/WelcomeActor.vala    |   57 ++++++++++++++-----------------------
 src/libease/WelcomeWindow.vala   |    7 ++++-
 3 files changed, 32 insertions(+), 38 deletions(-)
---
diff --git a/src/libease/ScrollableEmbed.vala b/src/libease/ScrollableEmbed.vala
index f9f29f5..eb5aa07 100644
--- a/src/libease/ScrollableEmbed.vala
+++ b/src/libease/ScrollableEmbed.vala
@@ -111,12 +111,14 @@ public class Ease.ScrollableEmbed : Gtk.HBox
 				case Gdk.ScrollDirection.UP:
 					v_adjust.value = Math.fmin(v_adjust.upper,
 					                 Math.fmax(v_adjust.lower,
-					                           v_adjust.value - v_adjust.step_increment));
+					                           v_adjust.value -
+					                           v_adjust.step_increment));
 					break;
 				case Gdk.ScrollDirection.DOWN:
 					v_adjust.value = Math.fmin(v_adjust.upper,
 					                 Math.fmax(v_adjust.lower,
-					                           v_adjust.value + v_adjust.step_increment));
+					                           v_adjust.value +
+					                           v_adjust.step_increment));
 					break;
 			}
 			return false;
diff --git a/src/libease/WelcomeActor.vala b/src/libease/WelcomeActor.vala
index d03a5d9..b001441 100644
--- a/src/libease/WelcomeActor.vala
+++ b/src/libease/WelcomeActor.vala
@@ -24,10 +24,16 @@
 public class Ease.WelcomeActor : Clutter.Rectangle
 {
 	private Gee.ArrayList<WelcomeActor> others;
-	private bool selected = false;
-	private bool faded = false;
+	private bool is_selected = false;
 	
-	public WelcomeActor(int w, ref Gee.ArrayList<WelcomeActor> o)
+	// constants
+	private const int FADE_TIME = 200;
+	private const int FADE_EASE = Clutter.AnimationMode.EASE_IN_OUT_SINE;
+	private const int FADE_VALUE = 100;
+	
+	public signal void selected();
+	
+	public WelcomeActor(int w, Gee.ArrayList<WelcomeActor> o)
 	{
 		width = w;
 		others = o;
@@ -39,57 +45,38 @@ public class Ease.WelcomeActor : Clutter.Rectangle
 		color.from_string("Pink");
 		set_color(color);
 		
-		color = Clutter.Color();
-		color.from_string("White");
-		set_border_color(color);
+		set_border_color({255, 255, 255, 255});
 		set_border_width(2);
+		set_reactive(true);
 	}
 	
 	public void clicked()
 	{
-		stdout.printf("clicked!\n");
-		if (selected)
+		if (!is_selected)
 		{
 			// unfade the others
 			foreach (var a in others)
+			{
 				if (a != this)
-					a.unfade();
-			
-			deselect();
-		}
-		else
-		{
-			// fade the others
-			foreach (var a in others)
-				if (a != this)
+				{
 					a.fade();
-			
-			select();
+				}
+			}
+			unfade();
+			selected();
 		}
 	}
 	
 	private void fade()
 	{
-		faded = true;
-		animate(Clutter.AnimationMode.EASE_IN_OUT_SINE, 250, "alpha", 0.5f);
+		is_selected = false;
+		animate(FADE_EASE, FADE_TIME, "opacity", FADE_VALUE);
 	}
 	
 	private void unfade()
 	{
-		faded = false;
-		animate(Clutter.AnimationMode.EASE_IN_OUT_SINE, 250, "alpha", 1);
-	}
-	
-	private void select()
-	{
-		selected = true;
-		//animate(Clutter.AnimationMode.EASE_IN_OUT_SINE, 250, "alpha", 0.5f);
-	}
-	
-	private void deselect()
-	{
-		selected = false;
-		//animate(Clutter.AnimationMode.EASE_IN_OUT_SINE, 250, "alpha", 1);
+		is_selected = true;
+		animate(FADE_EASE, FADE_TIME, "opacity", 255);
 	}
 }
 
diff --git a/src/libease/WelcomeWindow.vala b/src/libease/WelcomeWindow.vala
index 733219f..c9e3bac 100644
--- a/src/libease/WelcomeWindow.vala
+++ b/src/libease/WelcomeWindow.vala
@@ -93,6 +93,7 @@ public class Ease.WelcomeWindow : Gtk.Window
 		hbox.pack_start(align, false, false, 0);
 		
 		new_button = new Gtk.Button.with_label("New Presentation");
+		new_button.sensitive = false;
 		new_button.image = new Gtk.Image.from_stock("gtk-new", Gtk.IconSize.BUTTON);
 		align = new Gtk.Alignment(0, 0.5f, 0, 0);
 		align.add(new_button);
@@ -121,9 +122,13 @@ public class Ease.WelcomeWindow : Gtk.Window
 		// create the previews
 		for (var i = 0; i < 10; i++)
 		{
-			var act = new WelcomeActor(preview_width, ref previews);
+			var act = new WelcomeActor(preview_width, previews);
 			previews.add(act);
 			preview_container.add_actor(act);
+			
+			act.selected.connect(() => {
+				new_button.sensitive = true;
+			});
 		}
 		embed.contents.add_actor(preview_container);
 		embed.contents.show_all();



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