Clone in a terminal:
Commit a6b7035
Johan Mattsson - 2014-07-21T21:06:05+00:00
a6b703514be002be8c035cf5f47f070f7b456d7fjohan.mattsson.m@gmail.com

Scroll and zoom with tap events and ignore double click events from overview tab.

Changed files (9)

Diff

diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 47249d1..e7bef68 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -221,7 +221,7 @@ public class DrawingTools : ToolCollection  { 			} 		}); 		-		if (BirdFont.has_argument ("--test")) {+		if (BirdFont.has_argument ("--test") || BirdFont.android) { 			draw_tool_modifiers.add_tool (object_stroke); 		} diff --git a/libbirdfont/FontDisplay.vala b/libbirdfont/FontDisplay.valaindex 330d040..a57a3c0 100644--- a/libbirdfont/FontDisplay.vala+++ b/libbirdfont/FontDisplay.vala@@ -91,25 +91,22 @@ public abstract class FontDisplay : GLib.Object { 		last_tap_y = -1; 	} 	-	public virtual void tap_move (int x, int y) {+	public virtual void tap_move (int finger, int x, int y) { 		double d;-		-		motion_notify (x, y);--		d = y - last_tap_y;		-		if (last_tap_y > -1 && fabs (d) > 15) { // FIXME: pixels, other units are better-			if (d > 0) {-				scroll_wheel_up (x, y);-			} else {-				scroll_wheel_down (x, y);+		if (finger == 0) {+			motion_notify (x, y);+			+			d = y - last_tap_y;		+			if (last_tap_y > -1 && fabs (d) > 15) { // FIXME: pixels, other units are better+				if (d > 0) {+					scroll_wheel_up (x, y);+				} else {+					scroll_wheel_down (x, y);+				} 			}+			+			last_tap_y = y; 		}-		-		last_tap_y = y;-	}-	-	/** Both fingers are moving. */-	public virtual void tap_move_delta (int x0, int y0, int x1, int y1) { 	}  	public virtual void zoom_in () {diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex b653ac5..7474e88 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -37,6 +37,17 @@ public class Glyph : FontDisplay { 	double pointer_begin_x = 0; 	double pointer_begin_y = 0; +	// Tap last tap event position in pixels+	int last_tap0_y = 0;+	int last_tap0_x = 0;+	int last_tap1_y = 0;+	int last_tap1_x = 0;+	double zoom_distance = 0;+	bool change_view; ++	+	bool ignore_input = false;+	 	// Current pointer position 	public double motion_x = 0; 	public double motion_y = 0;@@ -349,6 +360,17 @@ public class Glyph : FontDisplay { 	} 	 	public override void selected_canvas () {+		TimeoutSource input_delay;+		+		ignore_input = true; // make sure that tripple clicks in overview are ignored++		input_delay = new TimeoutSource (250);+		input_delay.set_callback(() => {+			ignore_input = false;+			return false;+		});+		input_delay.attach (null);+		 		add_help_lines (); 		KeyBindings.set_require_modifier (false); 		glyph_sequence = Preferences.get ("glyph_sequence");@@ -702,6 +724,7 @@ public class Glyph : FontDisplay { 	 	public override void button_press (uint button, double ex, double ey) {				 		bool moving_lines = false;+			 		pointer_begin_x = ex; 		pointer_begin_y = ey; 		@@ -1869,6 +1892,115 @@ public class Glyph : FontDisplay { 	public override void move_view (double x, double y) { 		view_offset_x += x / view_zoom;  		view_offset_y += y / view_zoom;+		GlyphCanvas.redraw ();+	}++	/** Scroll or zoom from tap events. */+	public void change_view_event (int finger, int x, int y) {+		double tap_direction;+		double dx, dy;+		double last_distance, new_distance;++		dx = 0;+		dy = 0;++		new_distance = 0;+		+		if (finger == 0) {+			dx = last_tap0_x - x;+			dy = last_tap0_y - y;+			new_distance = Path.distance (last_tap1_x, x, last_tap1_y, y);+			+			// FIXME: DELETE+			warning (@"last_tap0_y $last_tap0_y last_tap0_x $last_tap0_x");+		}+		+		if (finger == 1) {+			dx = last_tap1_x - x;+			dy = last_tap1_y - y;+			new_distance = Path.distance (last_tap0_x, x, last_tap0_y, y);+			warning (@"last_tap0_y $last_tap0_y last_tap0_x $last_tap0_x"); // FIXME: DELETE+		}+		+		last_distance = Path.distance (last_tap0_x, last_tap1_x, last_tap0_y, last_tap1_y);+		+		warning (@"last_distance $last_distance  zoom_distance $zoom_distance  new_distance $new_distance");+		+		if (fabs (new_distance - last_distance) < 10 * MainWindow.units) {+			move_view (dx / 2, dy / 2); +			// divide by 2 because change_view_event will be called for both fingers+		} else {+			if (fabs (zoom_distance - new_distance) > 5 * MainWindow.units) { +				if (new_distance > last_distance) {+					zoom_in ();+				} else  {+					zoom_out ();+				}+				+				zoom_distance = new_distance;+			}+		}+	}++	public override void tap_down (int finger, int x, int y) {+		TimeoutSource delay;+		+		if (finger == 0) {+			delay = new TimeoutSource (70);+			delay.set_callback(() => {+				if (!change_view && !ignore_input) {+					button_press (1, x, y);+				}+				return false;+			});+			delay.attach (null);+			+			last_tap0_x = x;+			last_tap0_y = y;+		}+		+		if (finger == 1) {+			change_view = true;+			last_tap1_x = x;+			last_tap1_y = y;+		}+	}+	+	public override void tap_up (int finger, int x, int y) {+		if (finger == 0) {+			button_release (1, x, y);+			+			last_tap0_x = -1;+			last_tap0_y = -1;+		}+		+		if (finger == 1) {+			last_tap1_x = -1;+			last_tap1_y = -1;+			+			change_view = false;+			zoom_distance = 0;+		}+	}+		+	public override void tap_move (int finger, int x, int y) {+		double d;++		if (!change_view) {+			motion_notify (x, y);+		} else {+			change_view_event (finger, x, y);+		}+						+		if (finger == 0) {+			last_tap0_x = x;+			last_tap0_y = y;+		}+		+		if (finger == 1) {+			last_tap1_x = x;+			last_tap1_y = y;+		} 	} } diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex 446d95c..be894d7 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -653,6 +653,8 @@ public class OverView : FontDisplay { 		font.add_glyph_collection (previous_collection); 		 		deleted_glyphs.remove_at (deleted_glyphs.size - 1);+		+		redraw_area (0, 0, allocation.width, allocation.height); 	} 	 	public void store_undo_state (GlyphCollection gc) {diff --git a/libbirdfont/PenTool.vala b/libbirdfont/PenTool.valaindex a19184c..f5e9046 100644--- a/libbirdfont/PenTool.vala+++ b/libbirdfont/PenTool.vala@@ -131,11 +131,11 @@ public class PenTool : Tool { 			} else if (GridTool.has_ttf_grid ()) { 				GridTool.ttf_grid (ref x, ref y); 			}-			+ 			if (BirdFont.android) { 				point_selection_image = true; 			}-					+				 			last_point_x = x; 			last_point_y = y; 		});@@ -852,15 +852,13 @@ public class PenTool : Tool { 		double ratio; 		PointSelection ps; 		-		if (move_selected_handle) {+		if (active_handle.active) { 			i = Path.edit_point_handle_image;-		} else if (move_selected) {-			if (selected_points.size > 0) {-				ps = selected_points.get (selected_points.size - 1);-				-				i = (ps.point.type == PointType.CUBIC) -					? Path.cubic_edit_point_image : Path.edit_point_image;-			}+		} else if (selected_points.size > 0) {+			ps = selected_points.get (selected_points.size - 1);+			+			i = (ps.point.type == PointType.CUBIC) +				? Path.cubic_edit_point_image : Path.edit_point_image; 		} 		 		if (i != null) {@@ -1151,6 +1149,9 @@ public class PenTool : Tool { 		set_point_type (selected_point); 		set_default_handle_positions (); 		+		selected_points.clear ();+		add_selected_point (new_point.point, new_point.path);+		 		return new_point; 	} diff --git a/libbirdfont/ResizeTool.vala b/libbirdfont/ResizeTool.valaindex 9987724..5e14bf0 100644--- a/libbirdfont/ResizeTool.vala+++ b/libbirdfont/ResizeTool.vala@@ -223,7 +223,7 @@ class ResizeTool : Tool { 		h = rp.xmax - rp.xmin;  		ratio = 1;-		ratio -= 0.7 * PenTool.precision * (Glyph.path_coordinate_y (last_resize_y) - Glyph.path_coordinate_y (y)) / h;		+		ratio -= 0.5 * PenTool.precision * (Glyph.path_coordinate_y (last_resize_y) - Glyph.path_coordinate_y (y)) / h;		  		return ratio; 	}diff --git a/libbirdfont/TabContent.vala b/libbirdfont/TabContent.valaindex 4ff03e6..6ef7040 100644--- a/libbirdfont/TabContent.vala+++ b/libbirdfont/TabContent.vala@@ -160,21 +160,12 @@ public class TabContent : GLib.Object { 		GlyphCanvas.current_display.tap_up (finger, x, y); 	} 	-	public static void tap_move (int x, int y) {+	public static void tap_move (int finger, int x, int y) { 		if (MenuTab.suppress_event) { 			return; 		} 		-		GlyphCanvas.current_display.tap_move (x, y);-	}-	-	/** Both fingers are moving. */-	public static void tap_move_delta (int x0, int y0, int x1, int y1) {-		if (MenuTab.suppress_event) {-			return;-		}-		-		GlyphCanvas.current_display.tap_move_delta (x0, y0, x1, y1);+		GlyphCanvas.current_display.tap_move (finger, x, y); 	} 		 	public static void undo () {diff --git a/libbirdfont/TestBirdFont.vala b/libbirdfont/TestBirdFont.valaindex 34f71be..69c9497 100644--- a/libbirdfont/TestBirdFont.vala+++ b/libbirdfont/TestBirdFont.vala@@ -199,9 +199,6 @@ class TestBirdFont : GLib.Object { 	public void run_all_tests () {
 		TimeoutSource idle = new TimeoutSource (20);
 		
-		// FIXME: DELETE
-		// MenuTab.new_file ();
-		
 		idle.set_callback(() => {
 			int s = AtomicInt.get (ref state);
 			
diff --git a/scripts/Application.mk b/scripts/Application.mkindex f05229c..54a07ab 100644--- a/scripts/Application.mk+++ b/scripts/Application.mk@@ -1 +1,2 @@-APP_ABI := armeabi armeabi-v7a+APP_ABI := armeabi +# armeabi-v7a

Contact

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