Clone in a terminal:
Commit 3d3b345
Johan Mattsson - 2015-06-15T20:18:13+00:00
3d3b345f957314f961b7530112fe370a7df0742bjohan.mattsson.m@gmail.com

Better zoom and scroll wheel handeling on Mac

Changed files (7)

Diff

diff --git a/libbirdfont/FontDisplay.vala b/libbirdfont/FontDisplay.valaindex 9647582..ebd84e0 100644--- a/libbirdfont/FontDisplay.vala+++ b/libbirdfont/FontDisplay.vala@@ -104,9 +104,9 @@ public abstract class FontDisplay : GLib.Object { 			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, 15);+					scroll_wheel (x, y, 15, 0); 				} else {-					scroll_wheel_down (x, y, 15);+					scroll_wheel (x, y, 15, 0); 				} 			} 			@@ -141,12 +141,10 @@ public abstract class FontDisplay : GLib.Object { 	public virtual void next_view () { 	} 	-	public virtual void scroll_wheel_up (double x, double y, double pixeldelta) {+	public virtual void scroll_wheel (double x, double y,+		double pixeldelta_x,  double pixeldelta_y) { 	} 	-	public virtual void scroll_wheel_down (double x, double y, double pixeldelta) {-	}- 	public virtual void undo () { 	} diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 65ecf4d..64ad63b 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -375,25 +375,18 @@ public class Glyph : FontDisplay { 		return background_image; 	} 		-	public override void scroll_wheel_up (double x, double y, double pixeldelta) {-		if (KeyBindings.has_alt ()) {-			zoom_in_at_point (x, y);-		} else if (KeyBindings.has_ctrl ()) { -			view_offset_x -= pixeldelta / view_zoom;-		} else {-			view_offset_y -= pixeldelta / view_zoom;-		}-		-		redraw_area (0, 0, allocation.width, allocation.height);-	}-	-	public override void scroll_wheel_down (double x, double y, double pixeldelta) {-		if (KeyBindings.has_alt ()) {-			zoom_out_at_point (x, y);-		} else	if (KeyBindings.has_ctrl ()) { -			view_offset_x -= pixeldelta / view_zoom;-		} else {-			view_offset_y -= pixeldelta / view_zoom;+	public override void scroll_wheel (double x, double y, +		double pixeldelta_x, double pixeldelta_y) {+			+		if (KeyBindings.has_alt () || KeyBindings.has_ctrl ()) {+			if (pixeldelta_y > 0) {+				zoom_in_at_point (x, y, pixeldelta_y);+			} else {+				zoom_out_at_point (x, y, pixeldelta_y);+			}+		} else { +			view_offset_x -= pixeldelta_x / view_zoom;+			view_offset_y -= pixeldelta_y / view_zoom; 		} 		 		redraw_area (0, 0, allocation.width, allocation.height);@@ -1777,13 +1770,14 @@ public class Glyph : FontDisplay { 		cr.restore (); 	}	 -	private void zoom_in_at_point (double x, double y) {-		int n = -10;+	private void zoom_in_at_point (double x, double y, double amount = 15) {+		int n = (int) (-amount); 		zoom_at_point (x, y, n); 	} 		-	private void zoom_out_at_point (double x, double y) {-		int n = (int) (10.0 * ((allocation.width - 10.0) / allocation.width));+	private void zoom_out_at_point (double x, double y, double amount = 15) {+		double a = -amount;+		int n = (int) (a * ((allocation.width - a) / allocation.width)); 		zoom_at_point (x, y, n); 	} 	diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex cc866be..eeed239 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -266,29 +266,29 @@ public class OverView : FontDisplay { 		return true; 	} -	public override void scroll_wheel_up (double x, double y, double pixeldelta) {-		key_up ();-		update_scrollbar ();-		GlyphCanvas.redraw ();-		hide_menu ();--		selected_item = get_selected_item ();-		selected_items.clear ();-		if (selected_item.glyphs != null) {-			selected_items.add ((!) selected_item.glyphs);-		}-	}+	public override void scroll_wheel (double x, double y, double pixeldelta, double dy) {+		if (dy > 0) {+			key_up ();+			update_scrollbar ();+			GlyphCanvas.redraw ();+			hide_menu (); 	-	public override void scroll_wheel_down (double x, double y, double pixeldelta) {-		key_down ();-		update_scrollbar ();-		GlyphCanvas.redraw ();-		hide_menu ();--		selected_item = get_selected_item ();-		selected_items.clear ();-		if (selected_item.glyphs != null) {-			selected_items.add ((!) selected_item.glyphs);+			selected_item = get_selected_item ();+			selected_items.clear ();+			if (selected_item.glyphs != null) {+				selected_items.add ((!) selected_item.glyphs);+			}+		} else {+			key_down ();+			update_scrollbar ();+			GlyphCanvas.redraw ();+			hide_menu ();+	+			selected_item = get_selected_item ();+			selected_items.clear ();+			if (selected_item.glyphs != null) {+				selected_items.add ((!) selected_item.glyphs);+			} 		} 	} 	diff --git a/libbirdfont/SettingsDisplay.vala b/libbirdfont/SettingsDisplay.valaindex a9e79ba..bb42edf 100644--- a/libbirdfont/SettingsDisplay.vala+++ b/libbirdfont/SettingsDisplay.vala@@ -219,42 +219,37 @@ public abstract class SettingsDisplay : FontDisplay { 		return true; 	} 	-	public override void scroll_wheel_down (double x, double y, double pixeldelta) {-		foreach (SettingsItem s in tools) {-			if (s.handle_events && s.button != null) {-				if (((!) s.button).is_over (x, y)) {-					((!) s.button).scroll_wheel_down_action ((!) s.button);-					return;+	public override void scroll_wheel (double x, double y, double pixeldelta, double dy) {+		if (dy > 0) {+			foreach (SettingsItem s in tools) {+				if (s.handle_events && s.button != null) {+					if (((!) s.button).is_over (x, y)) {+						((!) s.button).scroll_wheel_down_action ((!) s.button);+						return;+					} 				} 			}+		} else {+			foreach (SettingsItem s in tools) {+				if (s.handle_events && s.button != null) {+					if (((!) s.button).is_over (x, y)) {+						((!) s.button).scroll_wheel_up_action ((!) s.button);+						return;+					}+				}+			}		 		} 		-		scroll += 25 * MainWindow.units;+		scroll += dy * MainWindow.units;  		if (scroll + allocation.height >=  content_height) { 			scroll = content_height - allocation.height; 		}-		-		update_scrollbar ();-		GlyphCanvas.redraw ();-	}-	-	public override void scroll_wheel_up (double x, double y, double pixeldelta) {-		foreach (SettingsItem s in tools) {-			if (s.handle_events && s.button != null) {-				if (((!) s.button).is_over (x, y)) {-					((!) s.button).scroll_wheel_up_action ((!) s.button);-					return;-				}-			}-		}-		-		scroll -= 25 * MainWindow.units;-		+ 		if (scroll < 0) { 			scroll = 0; 		}-		+				 		update_scrollbar (); 		GlyphCanvas.redraw (); 	}diff --git a/libbirdfont/TabContent.vala b/libbirdfont/TabContent.valaindex 546e421..889ce15 100644--- a/libbirdfont/TabContent.vala+++ b/libbirdfont/TabContent.vala@@ -202,17 +202,15 @@ public class TabContent : GLib.Object { 		} 	} 	-	public static void scroll_wheel_pixel_delta (double x, double y, double pixeldelta) {+	public static void scroll_wheel_pixel_delta (double x, double y, +		double pixeldelta_x, double pixeldelta_y) {+			 		if (MenuTab.suppress_event) { 			return; 		} 		 		if (!MainWindow.get_menu ().show_menu) {-			if (pixeldelta > 0) {-				GlyphCanvas.current_display.scroll_wheel_up (x, y, pixeldelta);-			} else {-				GlyphCanvas.current_display.scroll_wheel_down (x, y, pixeldelta);-			}+			GlyphCanvas.current_display.scroll_wheel (x, y, pixeldelta_x, pixeldelta_y); 		}		 	} 		@@ -222,7 +220,7 @@ public class TabContent : GLib.Object { 		} 		 		if (!MainWindow.get_menu ().show_menu) {-			GlyphCanvas.current_display.scroll_wheel_up (x, y, 15);+			GlyphCanvas.current_display.scroll_wheel (x, y, 15, 0); 		} 	} 	@@ -232,7 +230,7 @@ public class TabContent : GLib.Object { 		} 		 		if (!MainWindow.get_menu ().show_menu) {-			GlyphCanvas.current_display.scroll_wheel_down (x, y, -15);+			GlyphCanvas.current_display.scroll_wheel (x, y, -15, 0); 		} 	} diff --git a/libbirdfont/Table.vala b/libbirdfont/Table.valaindex 1825214..65b907d 100644--- a/libbirdfont/Table.vala+++ b/libbirdfont/Table.vala@@ -210,8 +210,8 @@ public abstract class Table : FontDisplay { 		return true; 	} 	-	public override void scroll_wheel_down (double x, double y, double pixeldelta) {-		scroll += 30  * MainWindow.units;+	public override void scroll_wheel (double x, double y, double pixeldelta, double dy) {+		scroll += dy * MainWindow.units;  		if (scroll > page_height - allocation.height) { 			scroll = page_height - allocation.height;@@ -220,18 +220,11 @@ public abstract class Table : FontDisplay { 		if (allocation.height > page_height) { 			scroll = 0; 		} -		-		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);-	}-	-	public override void scroll_wheel_up (double x, double y, double pixeldelta) {-		scroll -= 30 * MainWindow.units;-		+ 		if (scroll < 0) { 			scroll = 0; 		}-		+				 		update_scrollbar (); 		redraw_area (0, 0, allocation.width, allocation.height); 	}diff --git a/libbirdfont/TableLayout.vala b/libbirdfont/TableLayout.valaindex f7eb495..d797629 100644--- a/libbirdfont/TableLayout.vala+++ b/libbirdfont/TableLayout.vala@@ -211,32 +211,27 @@ public class TableLayout : FontDisplay { 		return true; 	} 	-	public override void scroll_wheel_down (double x, double y, double pixeldelta) {-		scroll += 25 * MainWindow.units;-		-		if (scroll + allocation.height >=  content_height) {-			scroll = content_height - allocation.height;-			+	public override void scroll_wheel (double x, double y, double pixeldelta, double dy) {+		scroll += dy * MainWindow.units;++		if (dy > 0){			+			if (scroll + allocation.height >=  content_height) {+				scroll = content_height - allocation.height;+				+				if (scroll < 0) {+					scroll = 0;+				}+			}+		} else { 			if (scroll < 0) { 				scroll = 0;-			}+			}		 		} 		 		update_scrollbar (); 		GlyphCanvas.redraw (); 	} 	-	public override void scroll_wheel_up (double x, double y, double pixeldelta) {-		scroll -= 25 * MainWindow.units;-		-		if (scroll < 0) {-			scroll = 0;-		}-		-		update_scrollbar ();-		GlyphCanvas.redraw ();-	}- 	public override void selected_canvas () { 		update_scrollbar (); 		GlyphCanvas.redraw ();

Contact

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