Clone in a terminal:
Commit 06d818d
Johan Mattsson - 2013-10-05T16:15:47+00:00
06d818d08bc7fe87b1fca70ec9a5963b852417c9johan.mattsson.m@gmail.com

touchpad scrolling in toolbox

Changed files (11)

Diff

diff --git a/libbirdfont/Argument.vala b/libbirdfont/Argument.valaindex 7386dd3..d2947c2 100644--- a/libbirdfont/Argument.vala+++ b/libbirdfont/Argument.vala@@ -69,6 +69,7 @@ public class Argument : GLib.Object { 				a == "--show-coordinates" ||  				a == "--no-translation" || 				a == "--mac" ||+				a == "--android" || 				a == "--donated") { 				prev = a; 				i++;@@ -203,6 +204,8 @@ public class Argument : GLib.Object { 				return "--slow"; 			case 't':  				return "--test";+			case 'a': +				return "--android"; 		} 		 		return "";@@ -239,6 +242,7 @@ public class Argument : GLib.Object { 		stdout.printf (args.nth (0).data); 		stdout.printf (" [" + t_("FILE") + "] [" + t_("OPTION") + " ...]\n"); +		print_padded ("-a, --android", t_("enable Android customizations")); 		print_padded ("-c, --show-coordinates", t_("show coordinate in glyph view")); 		print_padded ("-e, --exit", t_("exit if a test case fails")); 		print_padded ("-f, --fatal-warning", t_("treat warnings as fatal"));diff --git a/libbirdfont/BirdFont.vala b/libbirdfont/BirdFont.valaindex 02ee706..7f5210e 100644--- a/libbirdfont/BirdFont.vala+++ b/libbirdfont/BirdFont.vala@@ -183,6 +183,7 @@ public class BirdFont { 	public static bool fatal_wanings = false; 	public static bool win32 = false; 	public static bool mac = false;+	public static bool android = false; 	public static string exec_path = ""; 	public static string bundle_path = ""; @@ -205,6 +206,8 @@ public class BirdFont { 		File font_file; 		string exec_path; +		args = new Argument.command_line (arg);+ #if ANDROID 		BirdFont.logging = true; 		init_logfile ();@@ -212,26 +215,24 @@ public class BirdFont { 		__android_log_print (ANDROID_LOG_WARN, "BirdFont", @"libbirdfont version $VERSION"); 		LogLevelFlags log_levels = LogLevelFlags.LEVEL_ERROR | LogLevelFlags.LEVEL_CRITICAL | LogLevelFlags.LEVEL_WARNING; 		Log.set_handler (null, log_levels, android_warning);+		+		android = true; #else 		stdout.printf ("birdfont version %s\n", VERSION); 		stdout.printf ("built on %s\n", BUILD_TIMESTAMP);+		+		android = args.has_argument ("--android"); #endif--		printd ("Args");-		args = new Argument.command_line (arg); 		-		printd ("gettext"); 		if (!args.has_argument ("--no-translation")) { 			init_gettext (); 		} -		printd ("help"); 		if (args.has_argument ("--help")) { 			args.print_help (); 			Process.exit (0); 		} -		printd ("validate"); 		err_arg = args.validate (); 		if (err_arg != 0) { 			stdout.printf (@"Unknown parameter $(arg [err_arg])\n\n");@@ -239,16 +240,13 @@ public class BirdFont { 			Process.exit (0); 		} -		printd ("preferences"); 		Preferences.load (); 		-		printd ("new font"); 		current_font = new Font (); 		current_font.set_name (""); 		current_font.initialised = false; 		current_glyph = new Glyph (""); 		-		printd ("settings"); 		experimental = args.has_argument ("--test"); 		show_coordinates = args.has_argument ("--show-coordinates"); 		fatal_wanings = args.has_argument ("--fatal-warning");@@ -259,8 +257,7 @@ public class BirdFont { #else 		mac = args.has_argument ("--mac"); #endif--		printd ("path");		+	 		if (program_path == null) { 			exec_path = ""; @@ -289,16 +286,13 @@ public class BirdFont { 			} 		} -		printd ("init fatal warnings"); 		if (fatal_wanings) { 			LogLevelFlags levels = LogLevelFlags.LEVEL_ERROR | LogLevelFlags.LEVEL_CRITICAL | LogLevelFlags.LEVEL_WARNING; 			Log.set_handler (null, levels, fatal_warning); 		} 		-		printd ("last file"); 		Preferences.set_last_file (get_current_font ().get_path ()); 		-		printd ("default set"); 		DefaultCharacterSet.create_default_character_sets (); 		DefaultCharacterSet.get_characters_for_prefered_language (); diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 224ba52..a66d6c0 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -32,9 +32,6 @@ public class DrawingTools : ToolCollection  { 	public SpinButton background_scale = new SpinButton (); 	public static SpinButton precision; 	-	public int allocation_width = 0;-	public int allocation_height = 0;-	 	ImageSurface? toolbox_background = null; 	 	public static PointType point_type = PointType.DOUBLE_CURVE;@@ -795,7 +792,7 @@ public class DrawingTools : ToolCollection  { 		 		grid_expander.set_open (true); 		MainWindow.get_toolbox ().update_expanders ();-		MainWindow.get_toolbox ().redraw (0, 0, allocation_width, allocation_height);		+		MainWindow.get_toolbox ().redraw (0, 0, Toolbox.allocation_width, Toolbox.allocation_height);		 	} 	 	public void parse_grid (string spin_button_value) {@@ -825,7 +822,7 @@ public class DrawingTools : ToolCollection  { 		grid_expander.set_open (true); 		tb.update_expanders (); 		-		tb.redraw (0, 0, allocation_width, allocation_height);+		tb.redraw (0, 0, Toolbox.allocation_width, Toolbox.allocation_height); 		 		tb.select_tool (grid_width); 		grid_width.set_active (false);@@ -852,7 +849,7 @@ public class DrawingTools : ToolCollection  { 		} 		 		MainWindow.get_toolbox ().update_expanders ();-		tb.redraw (0, 0, allocation_width, allocation_height);+		tb.redraw (0, 0, Toolbox.allocation_width, Toolbox.allocation_height); 	} 	 	private void add_expander (Expander e) {diff --git a/libbirdfont/Expander.vala b/libbirdfont/Expander.valaindex 0a53e7e..73bfd2f 100644--- a/libbirdfont/Expander.vala+++ b/libbirdfont/Expander.vala@@ -171,18 +171,7 @@ public class Expander : GLib.Object { 	 	public virtual bool set_open (bool o) { 		bool r = (open != o);-		-		if (o) {-			/* // FIXME: DELETE-			margin = 35 * (int)((tool.length () / 4.0) + 1) ;-			if (tool.length () % 4 == 0) {-				margin -= 35;  -			}-			*/-		} else {-			margin = 0;-		}-		+		margin = 0; 		open = o; 		return r; 	}diff --git a/libbirdfont/KerningRange.vala b/libbirdfont/KerningRange.valaindex 44aad28..79038c8 100644--- a/libbirdfont/KerningRange.vala+++ b/libbirdfont/KerningRange.vala@@ -49,6 +49,8 @@ public class KerningRange : Tool { 			if (active) { 				MainWindow.get_tool_tip ().show_text (t_("Right click to edit the class and left click to kern glyphs in the class.")); 			}+			+			return false; 		});  		panel_release_action.connect ((selected, button, tx, ty) => {diff --git a/libbirdfont/OpenFontFormat/HeadTable.vala b/libbirdfont/OpenFontFormat/HeadTable.valaindex 04e1154..dbeae6e 100644--- a/libbirdfont/OpenFontFormat/HeadTable.vala+++ b/libbirdfont/OpenFontFormat/HeadTable.vala@@ -193,7 +193,7 @@ class HeadTable : Table { 		font_data.add_short (ymax); 	 		font_data.add_u16 (0); // mac style-		font_data.add_u16 (2); // smallest recommended size in pixels, ppem+		font_data.add_u16 (8); // smallest recommended size in pixels, ppem 		font_data.add_16 (2); // deprecated direction hint 		font_data.add_16 (loca_offset_size);  // long offset 		font_data.add_16 (0);  // Use current glyph data formatdiff --git a/libbirdfont/OpenFontFormat/Os2Table.vala b/libbirdfont/OpenFontFormat/Os2Table.valaindex 321c4da..c46631c 100644--- a/libbirdfont/OpenFontFormat/Os2Table.vala+++ b/libbirdfont/OpenFontFormat/Os2Table.vala@@ -109,8 +109,14 @@ class Os2Table : Table { 		fd.add_16 (10); // sTypoLineGap  		fd.add_u16 (ascender); // usWinAscent-		fd.add_u16 (-descender); // usWinDescent (not like sTypoDescender)-+		+		if (descender > 0) {+			warning ("usWinDescent is unsigned.");+			fd.add_u16 (0);+		} else {+			fd.add_u16 (-descender); // usWinDescent (not like sTypoDescender)+		}+		 		// FIXME: 		fd.add_u32 (0); // ulCodePageRange1 Bits 0-31 		fd.add_u32 (0); // ulCodePageRange2 Bits 32-63diff --git a/libbirdfont/SpinButton.vala b/libbirdfont/SpinButton.valaindex 9648bd9..876ae96 100644--- a/libbirdfont/SpinButton.vala+++ b/libbirdfont/SpinButton.vala@@ -87,6 +87,8 @@ public class SpinButton : Tool { 					set_int_value (@"$new_value"); 				} 			}+			+			return value_from_motion; 		});  		panel_release_action.connect ((selected, button, tx, ty) => {diff --git a/libbirdfont/Tool.vala b/libbirdfont/Tool.valaindex 8b9624c..f064249 100644--- a/libbirdfont/Tool.vala+++ b/libbirdfont/Tool.vala@@ -60,7 +60,9 @@ public class Tool : GLib.Object { 	 	public signal void panel_press_action (Tool selected, uint button, double x, double y); 	public signal void panel_release_action (Tool selected, uint button, double x, double y);-	public signal void panel_move_action (Tool selected, double x, double y);++	/** @return true is event is consumed. */+	public signal bool panel_move_action (Tool selected, double x, double y); 	 	public signal void draw_action (Tool selected, Context cr, Glyph glyph); 	@@ -222,6 +224,10 @@ public class Tool : GLib.Object { 		 		double scale; +		if (unlikely (w == 0)) {+			warning ("No width for tool.");+		}+ 		cr.save (); 		if (Icons.get_dpi () == 72) { 			scale = w / button_width_72dpi ();@@ -269,16 +275,6 @@ public class Tool : GLib.Object { 		} 		 		cr.restore ();-		-		// FIXME: DELETE-		/*-		cr.save ();-		cr.set_line_width (2);-		cr.set_source_rgba (0/255.0, 100/255.0, 0/255.0, 1);-		cr.rectangle (x, y, w, h);-		cr.stroke ();-		cr.restore ();-		*/ 	}  	/** Run pending events in main loop before continuing. */diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 7a7d0ba..5b17973 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -34,8 +34,13 @@ public class Toolbox : GLib.Object  { 	 	ImageSurface? toolbox_background = null; 	+	/** Scrolling with scroll wheel */ 	bool scrolling_toolbox = false; 	+	/** Scroll with touch pad. */+	bool scrolling_touch = false;+	double scroll_y = 0;+	 	public Toolbox (GlyphCanvas glyph_canvas, TabBar tab_bar) { 		current_tool = new Tool ("no_icon"); @@ -94,6 +99,9 @@ public class Toolbox : GLib.Object  { 				} 			} 		}+		+		scrolling_touch = true;+		scroll_y = y; 	} 	 	public void release (uint button, double x, double y) {@@ -112,6 +120,8 @@ public class Toolbox : GLib.Object  { 				} 			} 		}+		+		scrolling_touch = false; 	}  	public void scroll_up (double x, double y) {@@ -129,19 +139,29 @@ public class Toolbox : GLib.Object  { 		} 		 		if (!action) {-			current_set.scroll += 35;-			-			if (current_set.scroll > 0) {-				current_set.scroll = 0;-			}-			-			update_expanders ();-			suppress_scroll ();	+			scroll_current_set (35); 		} 		 		redraw_tool_box (); 	} +	void scroll_current_set (double d) {+		current_set.scroll += d;+		+		if (current_set.scroll > 0) {+			current_set.scroll = 0;+		}++		if (current_set.content_height < allocation_height) {+			current_set.scroll = 0;+		} else if (current_set.content_height + current_set.scroll < allocation_height) {+			current_set.scroll = allocation_height - current_set.content_height;+		}+					+		update_expanders ();+		suppress_scroll ();	+	}+ 	public void scroll_down (double x, double y) { 		bool action = false; @@ -155,18 +175,9 @@ public class Toolbox : GLib.Object  { 				} 			} 		}-		+ 		if (!action) {-			current_set.scroll -= 35;-			-			if (current_set.content_height < allocation_height) {-				current_set.scroll = 0;-			} else if (current_set.content_height + current_set.scroll < allocation_height) {-				current_set.scroll = allocation_height - current_set.content_height;-			}-			-			update_expanders ();-			suppress_scroll ();+			scroll_current_set (-35); 		}  		redraw_tool_box ();@@ -184,6 +195,8 @@ public class Toolbox : GLib.Object  { 	public void move (double x, double y) { 		bool update; 		bool a;+		bool consumed = false;+		 		foreach (Expander exp in current_set.get_expanders ()) { 			a = exp.is_over (x, y); 			update = exp.set_active (a);@@ -208,15 +221,23 @@ public class Toolbox : GLib.Object  { 						redraw (0, 0, allocation_width, allocation_height); 					} 					-					t.panel_move_action (t, x, y);+					if (t.panel_move_action (t, x, y)) {+						consumed = true;+					} 				} 			} 		}+		+		if (scrolling_touch && !consumed && BirdFont.android) {+			scroll_current_set (y - scroll_y);+			scroll_y = y;+			redraw_tool_box ();+		} 	}  	public static void redraw_tool_box () { 		Toolbox t = MainWindow.get_toolbox ();-		t.redraw (0, 0, t.allocation_width, t.allocation_height);+		t.redraw (0, 0, allocation_width, allocation_height); 	} 	 	public void reset_active_tool () {diff --git a/scripts/build.py b/scripts/build.pyindex 78ae0ef..0a9c150 100644--- a/scripts/build.py+++ b/scripts/build.py@@ -128,6 +128,7 @@ def birdfont_export(prefix, cc, cflags, ldflags, valac, valaflags, library): 	run(cc + " " + ldflags + " \ 		build/birdfont-export/*.o \ 		-Lbuild/bin/ -lbirdfont \+		-lm \ 		$(pkg-config --libs """ + config.GEE + """) \ 		$(pkg-config --libs libxml-2.0) \ 		$(pkg-config --libs gio-2.0) \

Contact

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