Commit 3d3b345
Better zoom and scroll wheel handeling on Mac
Changed files (7)
modifiedlibbirdfont/FontDisplay.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/SettingsDisplay.valamodifiedlibbirdfont/TabContent.valamodifiedlibbirdfont/Table.valamodifiedlibbirdfont/TableLayout.vala
Diff
@@ -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 () { } @@ -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); } @@ -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);+ } } } @@ -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 (); }@@ -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); } } @@ -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); }@@ -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 ();