Clone in a terminal:
Commit a661ec6
Johan Mattsson - 2016-10-08T15:35:43+00:00
a661ec6610a6697ea26b01707df774e84ddc8fa4johan.mattsson.m@gmail.com

Merge ../birdfont-2.x

Changed files (11)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 4c38ac9..386f701 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -41,15 +41,11 @@ public class GtkWindow : Gtk.Window, NativeWindow { 	string clipboard_svg = ""; 	string inkscape_clipboard = ""; 	-	Scrollbar scrollbar;-	bool scrollbar_supress_signal = false;-	 	ToolboxCanvas toolbox; 	 	Task background_task = new Task(idle); 	 	public GtkWindow (string title) {-		scrollbar = new Scrollbar (Orientation.VERTICAL, new Adjustment (0, 0, 1, 1, 0.01, 0.1)); 		((Gtk.Window)this).set_title ("BirdFont"); 	} 	@@ -61,16 +57,6 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		Signal.connect(this, "notify::is-active", (GLib.Callback) window_focus, null);  		clipboard = Clipboard.get_for_display (get_display (), Gdk.SELECTION_CLIPBOARD);--		scrollbar.value_changed.connect (() => {-			double p;-			-			if (!scrollbar_supress_signal) {-				p = scrollbar.get_value () / (1 - scrollbar.adjustment.page_size);-				FontDisplay display = MainWindow.get_current_display ();-				display.scroll_to (p);-			}-		}); 		 		delete_event.connect (() => { 			MenuTab.quit ();@@ -91,8 +77,6 @@ public class GtkWindow : Gtk.Window, NativeWindow { 			string html = ""; 			FontDisplay fd = tab.get_display (); 			-			scrollbar.set_visible (fd.has_scrollbar ());-			 			if (fd.get_name () == "Preview") { 				uri = Preview.get_uri (); 				html = Preview.get_html_with_absolute_paths ();@@ -123,9 +107,8 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		canvas_box = new Box (Orientation.HORIZONTAL, 0); 		canvas_box.pack_start (glyph_canvas_area, true, true, 0); 		canvas_box.pack_start (html_box, true, true, 0);-		canvas_box.pack_start (scrollbar, false, true, 0);-		tab_box = new Box (Orientation.VERTICAL, 0); 		+		tab_box = new Box (Orientation.VERTICAL, 0);		 		tab_box.pack_start (new TabbarCanvas (MainWindow.get_tab_bar ()), false, false, 0); 		tab_box.pack_start (canvas_box, true, true, 0); @@ -159,9 +142,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		size_allocate.connect(() => { 			GlyphCanvas.redraw (); 		});-		-		scrollbar.set_visible (false);-	+ 		show_all ();  		MainWindow.open_recent_files_tab ();		@@ -202,17 +183,6 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		set_title (@"$(f.full_name)"); 	} -	public void set_scrollbar_size (double size) {-		scrollbar.adjustment.page_size = size;		-		scrollbar.set_visible (size != 0);-	}-	-	public void set_scrollbar_position (double position) {-		scrollbar_supress_signal = true;-		scrollbar.adjustment.value = position * (1 - scrollbar.adjustment.page_size);-		scrollbar_supress_signal = false;-	}- 	public void dump_clipboard_content (Clipboard clipboard, SelectionData selection_data) { 		string d; 		return_if_fail (!is_null (selection_data));diff --git a/libbirdfont/BirdFont.vala b/libbirdfont/BirdFont.valaindex cd435ca..fc121f3 100644--- a/libbirdfont/BirdFont.vala+++ b/libbirdfont/BirdFont.vala@@ -177,7 +177,6 @@ public class BirdFont { 		Theme.set_default_colors ();  		if (theme_version == "" || int.parse (theme_version) < default_theme_version) {- 			Theme.load_theme ("dark.theme"); 			Preferences.set ("theme", "dark.theme"); 		} else {diff --git a/libbirdfont/EmptyTab.vala b/libbirdfont/EmptyTab.valaindex 498260b..ea59ddd 100644--- a/libbirdfont/EmptyTab.vala+++ b/libbirdfont/EmptyTab.vala@@ -40,7 +40,7 @@ public class EmptyTab : FontDisplay { 		cr.rectangle (0, 0, allocation.width, allocation.height); 		cr.fill (); 		cr.restore ();-	}	+	} }  }diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 51d5f49..770a9c0 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -466,7 +466,7 @@ public class Glyph : FontDisplay { 			} 		} -		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	}  	public virtual void add_path (Path p) {@@ -507,7 +507,7 @@ public class Glyph : FontDisplay { 		GridTool.update_lines ();  		if (!is_null (MainWindow.native_window)) {-			MainWindow.native_window.set_scrollbar_size (0);+			MainWindow.scrollbar.set_size (0); 		}  		update_zoom_bar ();diff --git a/libbirdfont/GlyphCanvas.vala b/libbirdfont/GlyphCanvas.valaindex 3903179..40d301c 100644--- a/libbirdfont/GlyphCanvas.vala+++ b/libbirdfont/GlyphCanvas.vala@@ -84,14 +84,15 @@ public class GlyphCanvas : GLib.Object { 		if (unlikely (MenuTab.has_suppress_event ())) {
 			warning ("Do not call redraw from background thread.");
 		} else {
-			signal_redraw_area (x, y, w, h);
+			signal_redraw_area (x, y, w + (int) MainWindow.scrollbar.width, h);
 		}
 	}
 	
 	public static void redraw () {
 		GlyphCanvas c = MainWindow.get_glyph_canvas ();
-		if (!is_null (c)) {
-			c.redraw_area (0, 0, allocation.width, allocation.height);
+		if (!is_null (c) && !is_null (MainWindow.scrollbar)) {+			int w = (int) (allocation.width + MainWindow.scrollbar.width);
+			c.redraw_area (0, 0, w, allocation.height);
 		}
 	}
 }
diff --git a/libbirdfont/MainWindow.vala b/libbirdfont/MainWindow.valaindex 992a32f..4c82376 100644--- a/libbirdfont/MainWindow.vala+++ b/libbirdfont/MainWindow.vala@@ -32,7 +32,7 @@ public class MainWindow : GLib.Object { 	public static Dialog dialog;
 	public static SpacingTab spacing_tab;
 	public static Task blocking_background_task;
-	public static Help help;
+	public static Scrollbar scrollbar; 	
 	/** Number of pixels per mm */
 	public static double units = 1;
@@ -56,15 +56,15 @@ public class MainWindow : GLib.Object { 		dialog = new Dialog ();
 		spacing_tab = new SpacingTab ();
 		blocking_background_task = new Task (null);
-		help = new Help ();
+		scrollbar = new Scrollbar ();		 		
 		tools.select_tool (DrawingTools.bezier_tool);
 	}
++	public static bool has_scrollbar () {+		return scrollbar.is_visible ();+	}	 	
-	public static Help get_help () {
-		return help;
-	}
-
 	public static void abort_task () {
 		blocking_background_task.cancel ();
 	}
@@ -249,26 +249,26 @@ public class MainWindow : GLib.Object { 	
 	public static void hide_scrollbar () {
 		if (!is_null (MainWindow.native_window)) {
-			MainWindow.native_window.set_scrollbar_size (-1);
+			MainWindow.scrollbar.set_size (-1);
 		}
 	}	
 
 	public static void show_scrollbar () {
 		if (!is_null (MainWindow.native_window)) {
-			MainWindow.native_window.set_scrollbar_size (scrollbar_size);
+			MainWindow.scrollbar.set_size (scrollbar_size);
 		}
 	}
 	
 	public static void set_scrollbar_size (double size) {
 		if (!is_null (MainWindow.native_window)) {
 			scrollbar_size = size;
-			MainWindow.native_window.set_scrollbar_size (size);
+			MainWindow.scrollbar.set_size (size);
 		}
 	}
 	
 	public static void set_scrollbar_position (double position) {
 		if (!is_null (MainWindow.native_window)) {
-			MainWindow.native_window.set_scrollbar_position (position);
+			MainWindow.scrollbar.set_position (position);
 		}
 	}
 		
diff --git a/libbirdfont/NativeWindow.vala b/libbirdfont/NativeWindow.valaindex 314d035..017d973 100644--- a/libbirdfont/NativeWindow.vala+++ b/libbirdfont/NativeWindow.vala@@ -27,9 +27,6 @@ public interface NativeWindow : GLib.Object { 	public abstract void set_clipboard (string data); 	public abstract void set_inkscape_clipboard (string data); -	public abstract void set_scrollbar_size (double size);-	public abstract void set_scrollbar_position (double position);-	 	/** Notify the UI about the new font. */ 	public abstract void font_loaded (); diff --git a/libbirdfont/RecentFiles.vala b/libbirdfont/RecentFiles.valaindex b80d7fc..0377d27 100644--- a/libbirdfont/RecentFiles.vala+++ b/libbirdfont/RecentFiles.vala@@ -42,12 +42,16 @@ public class RecentFiles : Table { 		} else if (row.get_index () == RECENT_FONT) { 			return_if_fail (row.get_row_data () is Font); 			f = (Font) row.get_row_data ();+			MainWindow.scrollbar.set_size (0);+			GlyphCanvas.redraw (); 			load_font (f.get_path ()); 		} else if (row.get_index () == BACKUP) { 			return_if_fail (row.get_row_data () is Font); 			f = (Font) row.get_row_data (); 			delete_backup (f.get_file_name ()); 		}++		GlyphCanvas.redraw (); 	}  	public override void update_rows () {diff --git a/libbirdfont/Scrollbar.vala b/libbirdfont/Scrollbar.valanew file mode 100644index 0000000..afcb34f--- /dev/null+++ b/libbirdfont/Scrollbar.vala@@ -0,0 +1,155 @@+/*
+	Copyright (C) 2016 Johan Mattsson
+
+	This library is free software; you can redistribute it and/or modify 
+	it under the terms of the GNU Lesser General Public License as 
+	published by the Free Software Foundation; either version 3 of the 
+	License, or (at your option) any later version.
+
+	This library 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 
+	Lesser General Public License for more details.
+*/
++using Cairo;+
+namespace BirdFont {
+
+public class Scrollbar : GLib.Object {++	public double position = 1;+	public double size = 1;+	public double width = 0;+	public double left_x = 0;+	public double height = 0;+	public double corner = 0;+	public double scroll_max = 1;+	public double margin = 0;++	public double motion_x = 0;+	public double motion_y = 0;+	public bool move = false;++	public Scrollbar () {	+	}++	public bool button_press (uint button, double x, double y) {+		if (!is_visible ()) {+			return false;+		}+		+		double h = height * position * scroll_max;+	+		if (left_x < x < left_x + width &&+			 h - corner < y < h + height * size + corner + 2 * margin) {+			 	+			motion_x = x;+			motion_y = y;+			+			move = true;+		}+		+		return left_x < x < left_x + width && 0 < size < 1;+	}++	public bool button_release (uint button, double x, double y) {+		if (!is_visible ()) {+			return false;+		}+		+		if (move) {+			move = false;+			return true;+		} else if (left_x < x < left_x + width) {+			double h = height * position * scroll_max;+			+			if (y > h + size * height) {+				position += size;+			} +			+			if (y < h) {+				position -= size;+			}+			+			if (position > 1) {+				position = 1;+			} else if (position < 0) {+				position = 0;			+			}+			+			TabContent.scroll_to (position);+			GlyphCanvas.redraw ();+			return true;+		}+		+		return false;+	}+	++	public bool motion (double x, double y) {+		if (!move || !is_visible ()) {+			return false;	+		}++		double p = (y - motion_y) / (height - size * height);+		position += p;++		if (position > 1) {+			position = 1;+		} else if (position < 0) {+			position = 0;			+		}++		TabContent.scroll_to (position);		++		GlyphCanvas.redraw ();+		+		motion_y = y;+		motion_x = x;++		return false;+	}+	+	public void draw (Context cr, WidgetAllocation content_allocation, double width) {+		if (!is_visible ()) {+			return;+		}		+		+		cr.save ();++		this.width = width;		+		this.left_x = content_allocation.width;+		this.height = content_allocation.height;+		this.corner = 4 * Screen.get_scale ();+		this.scroll_max = 1 - size - 2 * corner / height;+		this.margin = 2 * Screen.get_scale ();+				+		Theme.color (cr, "Table Background 1");	+		cr.rectangle (left_x, 0, width, height);		+		cr.fill ();		++		Theme.color (cr, "Tool Foreground");+		double h = height * position * scroll_max;+		+		Widget.draw_rounded_rectangle (cr, left_x + margin, h, width - 2 * margin, height * size + 2 * margin, corner);			+		cr.fill ();+		+		cr.restore ();+	}+	+	public bool is_visible () {+		return 0 < size < 1;+	}++	public void set_size (double size) {+		this.size = size; +	}++	public void set_position (double position) {+		this.position = position;+	}+}++}+ \ No newline at end of filediff --git a/libbirdfont/TabContent.vala b/libbirdfont/TabContent.valaindex 0bd1013..a82a6d4 100644--- a/libbirdfont/TabContent.vala+++ b/libbirdfont/TabContent.vala@@ -72,7 +72,12 @@ public class TabContent : GLib.Object { 	public static void draw (WidgetAllocation allocation, Context cr) { 		AbstractMenu menu; 		Dialog dialog;+		double scollbar_width = 10 * Screen.get_scale (); 		+		if (MainWindow.has_scrollbar()) {+			allocation.width -= (int) scollbar_width;+		}+ 		if (unlikely (MenuTab.has_suppress_event ())) { 			cr.save (); 			Theme.color (cr, "Background 1");@@ -110,6 +115,10 @@ public class TabContent : GLib.Object { 			if (text_input_visible) { 				draw_text_input (allocation, cr); 			}++			if (MainWindow.has_scrollbar()) {+				MainWindow.scrollbar.draw (cr, allocation, scollbar_width);+			} 		}  		Help help = MainWindow.get_help ();@@ -129,6 +138,10 @@ public class TabContent : GLib.Object { 		}  		alloc = GlyphCanvas.get_allocation ();+		+		double scollbar_width = 10 * Screen.get_scale ();+		alloc.width += (int) scollbar_width;+		 		pause_surface = Screen.create_background_surface (alloc.width, alloc.height); 		cr = new Context ((!) pause_surface); 		cr.scale (Screen.get_scale (), Screen.get_scale ());@@ -188,7 +201,11 @@ public class TabContent : GLib.Object { 		}  		if (!text_input_visible) {-			GlyphCanvas.current_display.motion_notify (x, y);+			bool consumed = MainWindow.scrollbar.motion (x, y);+			+			if (!consumed) {+				GlyphCanvas.current_display.motion_notify (x, y);+			} 		} else { 			text_input.motion (x, y); 			GlyphCanvas.redraw ();@@ -212,7 +229,11 @@ public class TabContent : GLib.Object { 			text_input.button_release (button, x, y); 			GlyphCanvas.redraw (); 		} else {-			GlyphCanvas.current_display.button_release (button, x, y);+			bool consumed = MainWindow.scrollbar.button_release (button, x, y);+						+			if (!consumed) {			+				GlyphCanvas.current_display.button_release (button, x, y);+			} 		} 	} @@ -240,7 +261,11 @@ public class TabContent : GLib.Object { 					hide_text_input (); 				} 			} else {-				GlyphCanvas.current_display.button_press (button, x, y);+				bool consumed = MainWindow.scrollbar.button_press (button, x, y);+				+				if (!consumed) { +					GlyphCanvas.current_display.button_press (button, x, y);+				} 			} 		} 	}diff --git a/libbirdfont/Theme.vala b/libbirdfont/Theme.valaindex 9dad90c..96c85d1 100644--- a/libbirdfont/Theme.vala+++ b/libbirdfont/Theme.vala@@ -1,5 +1,5 @@ /*-	Copyright (C) 2015 Johan Mattsson+	Copyright (C) 2015 2016 Johan Mattsson  	This library is free software; you can redistribute it and/or modify  	it under the terms of the GNU Lesser General Public License as @@ -111,8 +111,7 @@ public class Theme : GLib.Object { 		Theme.set_default_color ("Default Background", 238 / 255.0, 239 / 255.0, 243 / 255.0, 1); 		Theme.set_default_color ("Headline Background", 110 / 255.0, 113 / 255.0, 130 / 255.0, 1); 		-		Theme.set_default_color ("Checkbox Background", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1);-		+		Theme.set_default_color ("Checkbox Background", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1);				 		Theme.set_default_color ("Foreground 1", 0, 0, 0, 1); 		 		Theme.set_default_color ("Text Foreground", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1);@@ -324,7 +323,6 @@ public class Theme : GLib.Object { 		Theme.set_default_color ("Headline Background", 0, 0, 0, 1); 		 		Theme.set_default_color ("Checkbox Background", 1, 1, 1, 1);-		 		Theme.set_default_color ("Foreground 1", 0, 0, 0, 1); 		 		Theme.set_default_color ("Text Foreground", 0, 0, 0, 1);

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112