← Back to team overview

elementaryart team mailing list archive

[Merge] lp:~kekun-plazas/granite/scale-with-bubble into lp:granite

 

Adrien Plazas has proposed merging lp:~kekun-plazas/granite/scale-with-bubble into lp:granite.

Requested reviews:
  elementary desktop team (elementaryart)

For more details, see:
https://code.launchpad.net/~kekun-plazas/granite/scale-with-bubble/+merge/64146
-- 
https://code.launchpad.net/~kekun-plazas/granite/scale-with-bubble/+merge/64146
Your team elementary desktop team is requested to review the proposed merge of lp:~kekun-plazas/granite/scale-with-bubble into lp:granite.
=== modified file 'lib/Makefile.am'
--- lib/Makefile.am	2011-05-24 14:29:21 +0000
+++ lib/Makefile.am	2011-06-10 10:21:19 +0000
@@ -56,6 +56,7 @@
 	Widgets/DatePicker.vala \
 	Widgets/Entries.vala \
 	Widgets/FlowBox.vala \
+	Widgets/ScaleWithBubble.vala \
 	Widgets/TimePicker.vala \
 	Widgets/ToolButtonWithMenu.vala \
 	$(NULL)

=== added file 'lib/Widgets/ScaleWithBubble.vala'
--- lib/Widgets/ScaleWithBubble.vala	1970-01-01 00:00:00 +0000
+++ lib/Widgets/ScaleWithBubble.vala	2011-06-10 10:21:19 +0000
@@ -0,0 +1,211 @@
+//  
+//  Copyright (C) 2011 Adrien Plazas
+// 
+//  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/>.
+// 
+// 
+//  Authors:
+//      Adrien Plazas <kekun.plazas@xxxxxxxxxxx>
+//      ammonkey <am.monkeyd@xxxxxxxxx>
+// 
+
+using Gtk;
+using Gdk;
+
+namespace Granite.Widgets
+{
+	class HScaleWithBubble : HScale
+	{
+		private Gtk.CssProvider provider;
+		private Bubble bubble;
+		public bool bubble_on_top = false;
+		
+		public HScaleWithBubble(Adjustment adjustment)
+		{ init(); }
+		
+		public HScaleWithBubble.with_range(double min, double max, double step)
+		{ init(); }
+		
+		private void init()
+		{
+			bubble = new Bubble();
+			
+			button_press_event.connect(() => { show_bubble(); return false;});
+			move_slider.connect(show_bubble);
+			button_release_event.connect(() => { bubble.hide(); return false;});
+			value_changed.connect(refresh_bubble_position);		
+			
+			refresh_bubble_position();
+			show_all();
+		}
+		
+		private void show_bubble()
+		{
+			refresh_bubble_position();
+			bubble.show();
+		}
+			
+		private void refresh_bubble_position()
+		{
+			if (visible)
+			{
+				int x;
+				int y;
+				get_window().get_origin(out x, out y);
+				Allocation scale_allocation;
+				get_allocation(out scale_allocation);
+				Allocation bubble_allocation;
+				bubble.get_allocation(out bubble_allocation);
+				
+				Adjustment adjustment = get_adjustment();
+				double scale_percent = (get_value() - adjustment.get_lower()) / (adjustment.get_upper() - adjustment.get_lower());
+				
+				x += scale_allocation.x + (int) ((double) scale_allocation.width * scale_percent) - (int) ((double) bubble_allocation.width * scale_percent);
+				if (bubble_on_top)
+				{ y += scale_allocation.y - bubble_allocation.height; }
+				else
+				{ y += scale_allocation.y + scale_allocation.height; }
+				bubble.move(x, y);
+			}
+		}
+					
+		public void append(Widget widget)
+		{ bubble.append(widget); }
+	}
+	
+	class VScaleWithBubble : VScale
+	{
+		private Gtk.CssProvider provider;
+		private Bubble bubble;
+		public bool bubble_on_left = false;
+		
+		public VScaleWithBubble(Adjustment adjustment)
+		{ init(); }
+		
+		public VScaleWithBubble.with_range(double min, double max, double step)
+		{ init(); }
+		
+		private void init()
+		{
+			bubble = new Bubble();
+			
+			button_press_event.connect(() => { show_bubble(); return false;});
+			move_slider.connect(show_bubble);
+			button_release_event.connect(() => { bubble.hide(); return false;});
+			value_changed.connect(refresh_bubble_position);		
+			
+			refresh_bubble_position();
+			show_all();
+		}
+		
+		private void show_bubble()
+		{
+			refresh_bubble_position();
+			bubble.show();
+		}
+			
+		private void refresh_bubble_position()
+		{
+			if (visible)
+			{
+				int x;
+				int y;
+				get_window().get_origin(out x, out y);
+				Allocation scale_allocation;
+				get_allocation(out scale_allocation);
+				Allocation bubble_allocation;
+				bubble.get_allocation(out bubble_allocation);
+				
+				Adjustment adjustment = get_adjustment();
+				double scale_percent = (get_value() - adjustment.get_lower()) / (adjustment.get_upper() - adjustment.get_lower());
+				
+				if (bubble_on_left)
+				{ x += scale_allocation.x - bubble_allocation.width; }
+				else
+				{ x += scale_allocation.x + scale_allocation.width; }
+				y += scale_allocation.y + (int) ((double) scale_allocation.height * scale_percent) - (int) ((double) bubble_allocation.height * scale_percent);
+				bubble.move(x, y);
+			}
+		}
+					
+		public void append(Widget widget)
+		{ bubble.append(widget); }
+	}
+	
+	class Bubble : Gtk.Window
+	{
+		private Gtk.CssProvider provider;
+		private Menu menu;
+		private VBox box;
+		
+		public Bubble()
+		{
+			set_decorated(false);
+			set_resizable (false);
+			set_has_resize_grip (false);
+			app_paintable = true;
+
+			define_style();
+			set_visual (screen.get_rgba_visual());
+			
+			/* fake menu to use css */
+			menu = new Menu ();
+			menu.get_style_context ().add_provider (provider, 600);
+			menu.get_style_context ().add_class ("bubble-window");
+			
+			box = new VBox(false, 0);
+			box.margin_top = 7;
+			box.margin_left = 7;
+			box.margin_right = 7;
+			box.margin_bottom = 7;
+			
+			box.show();
+			add(box);
+		}
+
+		private void define_style ()
+		{
+			string css_file = "Bubble.css";
+			provider = new Gtk.CssProvider();
+			try
+			{ provider.load_from_path(css_file); }
+			catch (Error e)
+			{ stderr.printf("Error: %s\n", e.message); }
+			get_style_context ().add_provider (provider, 600);
+		}
+		
+		protected override bool draw (Cairo.Context cr)
+		{
+			Allocation vba;
+			get_allocation (out vba);
+			
+			var ctx = menu.get_style_context ();
+			render_background (ctx, cr,
+			                   vba.x, vba.y, 
+												 vba.width, vba.height);
+			render_frame (ctx, cr,
+			              vba.x, vba.y, 
+			              vba.width, vba.height);
+			
+			propagate_draw (box, cr);
+			
+			return true;
+		}
+		
+		public void append (Gtk.Widget widget)
+		{ 
+			box.pack_start(widget); 
+		}
+	}
+}

=== modified file 'lib/Widgets/ToolButtonWithMenu.vala'
--- lib/Widgets/ToolButtonWithMenu.vala	2011-05-23 17:56:18 +0000
+++ lib/Widgets/ToolButtonWithMenu.vala	2011-06-10 10:21:19 +0000
@@ -229,11 +229,14 @@
             menu.select_first (true);
 
             try {
-                menu.popup (null,
-                            null,
-                            get_menu_position,
-                            (ev == null) ? 0 : ev.button,
-                            (ev == null) ? get_current_event_time() : ev.time);
+						    for (int i = 0; i < 2; i++) {
+							      // Update the menu's size, then show it
+                    menu.popup (null,
+                                null,
+                                get_menu_position,
+                                (ev == null) ? 0 : ev.button,
+                                (ev == null) ? get_current_event_time() : ev.time);
+                 }
             } finally {
                 // Highlight the parent
                 if (menu.attach_widget != null)
@@ -269,6 +272,8 @@
             menu.attach_widget.get_window().get_origin (out x, out y);
             Allocation allocation;
             menu.attach_widget.get_allocation(out allocation);
+            Allocation menu_allocation;
+            menu.get_allocation(out menu_allocation);
 
             x += allocation.x;
 
@@ -276,8 +281,12 @@
                 x += allocation.width;
                 x -= menu_width;
             }
+            else{
+						    x += allocation.width / 2;
+                x -= menu_allocation.width / 2;
+            }
 
-            y += allocation.y;
+            y += allocation.y + 4;
 
             int width, height;
             menu.get_size_request(out width, out height);


Follow ups