The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Better zoom and scroll wheel handeling on Mac

These changes was commited to the Birdfont repository Mon, 15 Jun 2015 20:18:13 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Mon, 15 Jun 2015 20:18:13 +0000]

Updated Files

libbirdfont/FontDisplay.vala
libbirdfont/Glyph.vala
libbirdfont/OverView.vala
libbirdfont/SettingsDisplay.vala
libbirdfont/TabContent.vala
libbirdfont/Table.vala
libbirdfont/TableLayout.vala
--- a/libbirdfont/FontDisplay.vala +++ b/libbirdfont/FontDisplay.vala @@ -104,9 +104,9 @@ 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 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 () { }
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -375,25 +375,18 @@ 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 @@ 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); }
--- a/libbirdfont/OverView.vala +++ b/libbirdfont/OverView.vala @@ -266,29 +266,29 @@ 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); + } } }
--- a/libbirdfont/SettingsDisplay.vala +++ b/libbirdfont/SettingsDisplay.vala @@ -219,42 +219,37 @@ 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 (); }
--- a/libbirdfont/TabContent.vala +++ b/libbirdfont/TabContent.vala @@ -202,17 +202,15 @@ } } - 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 @@ } 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 @@ } if (!MainWindow.get_menu ().show_menu) { - GlyphCanvas.current_display.scroll_wheel_down (x, y, -15); + GlyphCanvas.current_display.scroll_wheel (x, y, -15, 0); } }
--- a/libbirdfont/Table.vala +++ b/libbirdfont/Table.vala @@ -210,8 +210,8 @@ 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 @@ 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); }
--- a/libbirdfont/TableLayout.vala +++ b/libbirdfont/TableLayout.vala @@ -211,32 +211,27 @@ 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 ();