[ease] Polish the appearance of the EditorEmbed.



commit e61f56e6b91a9f7f988b27d9619983321a1eeb3f
Author: Nate Stedman <natesm gmail com>
Date:   Fri Jun 4 19:18:21 2010 -0400

    Polish the appearance of the EditorEmbed.
    
    - There is now a Gtk.Frame surrounding it, instead of various Separators
    - Background color is a shade of the user's GTK theme's background color
    - Scrollbars have padding relative to the embed, and line up with the edges of it.

 src/EditorEmbed.vala     |   42 ++++++++++++++++++++++++++++++++--
 src/EditorWindow.vala    |    2 -
 src/ScrollableEmbed.vala |   56 ++++++++++++++++++++++++++++++++++++++++++---
 src/WelcomeWindow.vala   |    2 +-
 4 files changed, 92 insertions(+), 10 deletions(-)
---
diff --git a/src/EditorEmbed.vala b/src/EditorEmbed.vala
index 3a5f469..b0fde05 100644
--- a/src/EditorEmbed.vala
+++ b/src/EditorEmbed.vala
@@ -53,12 +53,18 @@ public class Ease.EditorEmbed : ScrollableEmbed
 	private float mouse_x;
 	private float mouse_y;
 	
-	// the origin position of a dragged element
+	// the original position of a dragged element
 	private float orig_x;
 	private float orig_y;
 	private float orig_w;
 	private float orig_h;
 	
+	// constants
+	private const string SPLIT = "\n;";
+	private const string BG_COLOR = "bg_color:";
+	private const string PREFIX = "#";
+	private const double SHADE_FACTOR = 0.9;
+	
 	private Document document;
 	public float zoom;
 	public bool zoom_fit;
@@ -77,7 +83,7 @@ public class Ease.EditorEmbed : ScrollableEmbed
 	 */
 	public EditorEmbed(Document d, EditorWindow w)
 	{
-		base(true);
+		base(true, true);
 		win = w;
 		
 		// don't fade actors out when zoomed out
@@ -85,7 +91,37 @@ public class Ease.EditorEmbed : ScrollableEmbed
 
 		// set up the background
 		view_background = new Clutter.Rectangle();
-		view_background.color = {200, 200, 200, 255};
+		
+		// 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);
+				
+				view_background.color = out_color;
+				
+				break;
+			}
+		}
+		
 		contents.add_actor(view_background);
 		
 		document = d;
diff --git a/src/EditorWindow.vala b/src/EditorWindow.vala
index e4265a0..f9433dd 100644
--- a/src/EditorWindow.vala
+++ b/src/EditorWindow.vala
@@ -95,7 +95,6 @@ public class Ease.EditorWindow : Gtk.Window
 		vbox.pack_start(create_menu_bar(), false, false, 0);
 		main_toolbar = new MainToolbar();
 		vbox.pack_start(main_toolbar, false, false, 0);
-		vbox.pack_start(new Gtk.HSeparator(), false, false, 0);
 		vbox.pack_start(hbox, true, true, 0);
 		vbox.pack_end(create_bottom_bar(), false, false, 0);
 		
@@ -316,7 +315,6 @@ public class Ease.EditorWindow : Gtk.Window
 		hbox.pack_start(zoom_slider, false, false, 0);
 		
 		var vbox = new Gtk.VBox(false, 0);
-		vbox.pack_start(new Gtk.HSeparator(), false, false, 0);
 		vbox.pack_start(hbox, true, true, 2);
 		
 		var align = new Gtk.Alignment(1, 1, 1, 1);
diff --git a/src/ScrollableEmbed.vala b/src/ScrollableEmbed.vala
index eb5aa07..4b5b888 100644
--- a/src/ScrollableEmbed.vala
+++ b/src/ScrollableEmbed.vala
@@ -32,10 +32,15 @@ public class Ease.ScrollableEmbed : Gtk.HBox
 	// scrolling
 	private Gtk.HScrollbar h_scrollbar;
 	private Gtk.VScrollbar v_scrollbar;
+	private Gtk.Alignment h_padder;
+	private Gtk.Alignment v_padder;
 	private Gtk.Adjustment h_adjust;
 	private Gtk.Adjustment v_adjust;
 	private Gtk.Adjustment z_adjust;
 	
+	// constants
+	private const int FRAME_PADDING = 2;
+	
 	public bool has_horizontal { get; private set; }
 
 	public float width
@@ -62,8 +67,9 @@ public class Ease.ScrollableEmbed : Gtk.HBox
 	 *
 	 * @param horizontal If true, the ScrollableEmbed has a horizontal
 	 * scrollbar in addition to the vertical scrollbar.
+	 * @param has_frame If the EditorEmbed should have a frame around its stage.
 	 */
-	public ScrollableEmbed(bool horizontal)
+	public ScrollableEmbed(bool horizontal, bool has_frame)
 	{
 		has_horizontal = horizontal;
 		
@@ -83,16 +89,58 @@ public class Ease.ScrollableEmbed : Gtk.HBox
 		stage.add_actor(viewport);
 		viewport.child = contents;
 
+		// add the embed to a frame if requested
 		var vbox = new Gtk.VBox(false, 0);
-		vbox.pack_start(embed, true, true, 0);
+		if (has_frame)
+		{
+			// create the frame
+			var frame = new Gtk.Frame(null);
+			frame.shadow_type = Gtk.ShadowType.IN;
+			frame.add(embed);
+			
+			// add the frame to padded alignment
+			var align = new Gtk.Alignment(0, 0, 1, 1);
+			align.set_padding(0, horizontal ? FRAME_PADDING : 0,
+			                  0, FRAME_PADDING);
+			align.add(frame);
+			
+			vbox.pack_start(align, true, true, 0);
+		}
+		else
+		{
+			vbox.pack_start(embed, true, true, 0);
+		}
 		
 		if (has_horizontal)
 		{
-			vbox.pack_start(h_scrollbar, false, false, 0);
+			// this widget shifts the scrollbar to line up with the frame
+			h_padder = new Gtk.Alignment(0, 0, 0, 0);
+			
+			var hscroll_box = new Gtk.HBox(false, 0);
+			hscroll_box.pack_start(h_scrollbar, true, true, 0);
+			hscroll_box.pack_start(h_padder, false, false, 0);
+			vbox.pack_start(hscroll_box, false, false, 0);
+			
+			// so that the vertical scrollbar doesn't extend to the bottom
+			// of the horizontal scrollbar, a padding widget is added
+			v_padder = new Gtk.Alignment(0, 0, 0, 0);
+			
+			var vscroll_box = new Gtk.VBox(false, 0);
+			vscroll_box.pack_start(v_scrollbar, true, true, 0);
+			vscroll_box.pack_start(v_padder, false, false, 0);
+			pack_end(vscroll_box, false, false, 0);
+			
+			h_scrollbar.size_allocate.connect((sender, rect) => {
+				h_padder.width_request = FRAME_PADDING;
+				v_padder.height_request = rect.height + FRAME_PADDING;
+			});
+		}
+		else
+		{
+			pack_end(v_scrollbar, false, false, 0);
 		}
 
 		pack_start(vbox, true, true, 0);
-		pack_start(v_scrollbar, false, false, 0);
 		
 		stage.show_all();
 		
diff --git a/src/WelcomeWindow.vala b/src/WelcomeWindow.vala
index bed54a8..f62cd2a 100644
--- a/src/WelcomeWindow.vala
+++ b/src/WelcomeWindow.vala
@@ -123,7 +123,7 @@ public class Ease.WelcomeWindow : Gtk.Window
 		hbox.pack_end(align, false, false, 0);
 		
 		// create the upper UI - the embed
-		embed = new ScrollableEmbed(false);
+		embed = new ScrollableEmbed(false, false);
 
 		// create the preview container
 		preview_container = new Clutter.Group();



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