[ease] [welcome] Added highlight to selected preview



commit d7e8f4371a732e759a289c67b0865bd3b5e62af4
Author: Nate Stedman <natesm gmail com>
Date:   Fri Jul 23 23:00:00 2010 -0400

    [welcome] Added highlight to selected preview
    
    - Preview selection is more obvious
    - New utility functions for finding theme colors.

 src/ease-editor-embed.vala  |   43 ++++---------------------------------------
 src/ease-utilities.vala     |   39 +++++++++++++++++++++++++++++++++++++++
 src/ease-welcome-actor.vala |   22 ++++++++++++++++++++++
 3 files changed, 65 insertions(+), 39 deletions(-)
---
diff --git a/src/ease-editor-embed.vala b/src/ease-editor-embed.vala
index 3db88f5..b567050 100644
--- a/src/ease-editor-embed.vala
+++ b/src/ease-editor-embed.vala
@@ -105,21 +105,11 @@ public class Ease.EditorEmbed : ScrollableEmbed
 	private float orig_h;
 	
 	/**
-	 * The split string for parsing GTK colors.
-	 */
-	private const string SPLIT = "\n;";
-	
-	/**
 	 * The gtk background color identifier.
 	 */
 	private const string BG_COLOR = "bg_color:";
 	
 	/**
-	 * The gtk background color prefix.
-	 */
-	private const string PREFIX = "#";
-	
-	/**
 	 * The shade factor of the EditorEmbed's background relative to typical
 	 * GTK background color.
 	 */
@@ -189,35 +179,10 @@ public class Ease.EditorEmbed : ScrollableEmbed
 		// don't fade actors out when zoomed out
 		get_stage().use_fog = false;
 		
-		// find the appropriate color
-		var settings = Gtk.Settings.get_default();
-		var colors = settings.gtk_color_scheme.split_set(SPLIT);
-		for (int i = 0; i < colors.length; i++)
-		{
-			colors[i] = colors[i].strip();
-			
-			if (colors[i].has_prefix(BG_COLOR))
-			{
-				for (; !colors[i].has_prefix(PREFIX) && colors[i].length > 3;
-			         colors[i] = colors[i].substring(1, colors[i].length - 1));
-				
-				Gdk.Color gdk_color;
-				Gdk.Color.parse(colors[i], out gdk_color);
-				
-				Clutter.Color clutter_color = { (uchar)(gdk_color.red / 256),
-				                                (uchar)(gdk_color.green / 256),
-				                                (uchar)(gdk_color.blue / 256),
-				                                255};
-				
-				Clutter.Color out_color;
-				
-				clutter_color.shade(SHADE_FACTOR, out out_color);
-				
-				get_stage().color = out_color;
-				
-				break;
-			}
-		}
+		// set the background to a faded version of the normal gtk background
+		Clutter.Color out_color;
+		theme_clutter_color(BG_COLOR).shade(SHADE_FACTOR, out out_color);
+		get_stage().color = out_color;
 		
 		document = d;
 		set_size_request(320, 240);
diff --git a/src/ease-utilities.vala b/src/ease-utilities.vala
index 18995f0..060906c 100644
--- a/src/ease-utilities.vala
+++ b/src/ease-utilities.vala
@@ -243,6 +243,45 @@ namespace Ease
 				from.copy(to, FileCopyFlags.OVERWRITE, null, null);
 			});
 	}
+	
+	/**
+	 * Locates a color in the current GTK theme.
+	 *
+	 * @param color The color to find.
+	 */
+	public Gdk.Color? theme_color(string color)
+	{
+		// find the appropriate color
+		var settings = Gtk.Settings.get_default();
+		var colors = settings.gtk_color_scheme.split_set("\n;");
+		for (int i = 0; i < colors.length; i++)
+		{
+			colors[i] = colors[i].strip();
+			
+			if (colors[i].has_prefix(color))
+			{
+				for (; !colors[i].has_prefix("#") && colors[i].length > 3;
+			         colors[i] = colors[i].substring(1, colors[i].length - 1));
+				
+				Gdk.Color gdk_color;
+				Gdk.Color.parse(colors[i], out gdk_color);
+				return gdk_color;
+			}
+		}
+		
+		warning("Could not find color: %s", color);
+		return null;
+	}
+	
+	/**
+	 * Locates a color in the current GTK theme, as a Clutter.Color.
+	 *
+	 * @param color The color to find.
+	 */
+	public Clutter.Color theme_clutter_color(string color)
+	{
+		return Transformations.gdk_color_to_clutter_color(theme_color(color));
+	}
 
 	public double dmax(double a, double b)
 	{
diff --git a/src/ease-welcome-actor.vala b/src/ease-welcome-actor.vala
index 0368bb6..fcaeaab 100644
--- a/src/ease-welcome-actor.vala
+++ b/src/ease-welcome-actor.vala
@@ -42,6 +42,11 @@ public class Ease.WelcomeActor : Clutter.Group
 	private Clutter.Rectangle rect;
 	
 	/**
+	 * A highlight rectangle placed around the actor when it is selected.
+	 */
+	private Clutter.Rectangle hilight_rect;
+	
+	/**
 	 * The theme previewed by this WelcomeActor.
 	 */
 	public Theme theme;
@@ -63,6 +68,8 @@ public class Ease.WelcomeActor : Clutter.Group
 	private const Clutter.Color RECT_BG = {0, 0, 0, 255};
 	private const Clutter.Color RECT_B_C = {150, 150, 150, 255};
 	private const int RECT_B_W = 1;
+	private const Clutter.Color HLRECT_C = {255, 255, 0, 255};
+	private const int HLRECT_W = 2;
 	
 	/**
 	 * The slide identifier to display as a preview.
@@ -98,6 +105,16 @@ public class Ease.WelcomeActor : Clutter.Group
 		rect.y = -RECT_B_W;
 		add_actor(rect);
 		
+		// create the highlight rectangle
+		hilight_rect = new Clutter.Rectangle();
+		hilight_rect.color = {0, 0, 0, 255};
+		hilight_rect.opacity = 0;
+		hilight_rect.border_color = HLRECT_C;
+		hilight_rect.border_width = HLRECT_W;
+		hilight_rect.x = -HLRECT_W;
+		hilight_rect.y = -HLRECT_W;
+		add_actor(hilight_rect);
+		
 		// create the theme title actor
 		text = new Clutter.Text.full(FONT_NAME, theme.title, TEXT_COLOR);
 		text.height = TEXT_HEIGHT;
@@ -159,6 +176,9 @@ public class Ease.WelcomeActor : Clutter.Group
 		rect.width = roundd(w) + RECT_B_W * 2;
 		rect.height = roundd(h) + RECT_B_W * 2;
 		
+		hilight_rect.width = roundd(w) + HLRECT_W * 2;
+		hilight_rect.height = roundd(h) + HLRECT_W * 2;
+		
 		text.x = roundd(w / 2 - text.width / 2);
 		text.y = roundd(h + TEXT_OFFSET);
 		
@@ -176,6 +196,7 @@ public class Ease.WelcomeActor : Clutter.Group
 	{
 		is_selected = false;
 		slide_actor.animate(FADE_EASE, FADE_TIME, "opacity", FADE_OPACITY);
+		hilight_rect.animate(FADE_EASE, FADE_TIME, "opacity", 0);
 	}
 	
 	/**
@@ -185,6 +206,7 @@ public class Ease.WelcomeActor : Clutter.Group
 	{
 		is_selected = true;
 		slide_actor.animate(FADE_EASE, FADE_TIME, "opacity", 255);
+		hilight_rect.animate(FADE_EASE, FADE_TIME, "opacity", 255);
 	}
 	
 	/**



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