Commit d8f331d
right shift in glyph view adjusts precision
Changed files (11)
modifiedsrc/BackgroundSelection.valamodifiedsrc/Context.valamodifiedsrc/FontDisplay.valamodifiedsrc/Glyph.valamodifiedsrc/GlyphCanvas.valamodifiedsrc/KeyBindings.valamodifiedsrc/MainWindow.valamodifiedsrc/OverView.valamodifiedsrc/Path.valamodifiedsrc/PenTool.valamodifiedsrc/Tool.vala
Diff
@@ -275,10 +275,10 @@ class BackgroundSelection : FontDisplay { } } - public override void key_press (EventKey e) {+ public override void key_press (uint e) { } - public override void key_release (EventKey e) {+ public override void key_release (uint e) { } public override void motion_notify (EventMotion e) {@@ -207,14 +207,14 @@ class ContextDisplay : FontDisplay { } } - public override void key_press (EventKey e) {- unichar c = (unichar) e.keyval;+ public override void key_press (uint keyval) {+ unichar c = (unichar) keyval; Font f = Supplement.get_current_font (); string name; - if (e.type == EventType.KEY_PRESS && (KeyBindings.singleton.modifier == NONE || KeyBindings.singleton.modifier == SHIFT)) {+ if (KeyBindings.singleton.modifier == NONE || KeyBindings.singleton.modifier == SHIFT) { - if (e.keyval == Key.BACK_SPACE && row.length () > 0) { + if (keyval == Key.BACK_SPACE && row.length () > 0) { row.first ().data.glyph.remove_link (row.first ().data.glyph.last ()); } @@ -86,10 +86,10 @@ public abstract class FontDisplay : GLib.Object { public virtual void selected_canvas () { } - public virtual void key_press (EventKey e) {+ public virtual void key_press (uint keyval) { } - public virtual void key_release (EventKey e) {+ public virtual void key_release (uint keyval) { } public virtual void motion_notify (EventMotion e) {@@ -495,8 +495,16 @@ class Glyph : FontDisplay { } } - public override void key_press (EventKey e) { - if (e.keyval == Key.DEL) {+ public override void key_release (uint keyval) { + Tool t;+ t = MainWindow.get_toolbox ().get_current_tool ();+ t.key_release_action (t, keyval); + }++ public override void key_press (uint keyval) { + Tool t;+ + if (keyval == Key.DEL) { if (active_paths.length () != 0) { foreach (Path p in active_paths) {@@ -510,8 +518,10 @@ class Glyph : FontDisplay { if (selected_point != null) { delete_edit_point ((!) selected_point); }- }+ + t = MainWindow.get_toolbox ().get_current_tool ();+ t.key_press_action (t, keyval); } /** Delete edit point from path. */@@ -527,13 +537,13 @@ class Glyph : FontDisplay { public override void motion_notify (EventMotion e) { Tool t;+ t = MainWindow.get_toolbox ().get_current_tool (); - if (KeyBindings.has_ctrl ()) {+ if (move_view && KeyBindings.has_ctrl ()) { move_view_offset (e.x, e.y); return; }- - t = MainWindow.get_toolbox ().get_current_tool ();+ t.move_action (t, (int) e.x, (int) e.y); if (Supplement.show_coordinates) {@@ -1548,11 +1558,9 @@ class Glyph : FontDisplay { } private void move_view_offset (double x, double y) {- if (move_view) {- view_offset_x = move_offset_x + (pointer_begin_x - x) * (1/view_zoom);- view_offset_y = move_offset_y + (pointer_begin_y - y) * (1/view_zoom);- redraw_area (0, 0, allocation.width, allocation.height);- }+ view_offset_x = move_offset_x + (pointer_begin_x - x) * (1/view_zoom);+ view_offset_y = move_offset_y + (pointer_begin_y - y) * (1/view_zoom);+ redraw_area (0, 0, allocation.width, allocation.height); } public void store_undo_state () {@@ -106,16 +106,6 @@ class GlyphCanvas : DrawingArea { return true; }); - key_press_event.connect ((t, e)=> { - key_press (e); - return true; - }); - - key_release_event.connect ((t, e)=> { - key_release (e); - return true; - }); - scroll_event.connect ((t, e)=> { if (e.direction == Gdk.ScrollDirection.UP) { current_display.scroll_wheel_up (e); @@ -128,11 +118,11 @@ class GlyphCanvas : DrawingArea { } - public void key_release (EventKey e) { + public void key_release (uint e) { current_display.key_release (e); } - public void key_press (EventKey e) { + public void key_press (uint e) { current_display.key_press (e); } @@ -564,16 +564,15 @@ class KeyBindings { return singleton.modifier_ctrl; } - public void key_press (EventKey event) {- bool press = (event.type == EventType.KEY_PRESS);- uint key = event.keyval;+ public void key_release (uint keyval) {+ set_modifier (keyval, false);+ }+ + public void key_press (uint keyval) {+ uint key = keyval; ShortCut? short_cut; - set_modifier (key, press);- - if (!press) {- return;- }+ set_modifier (keyval, true); if (get_short_cut (modifier, key, out short_cut)) { if (short_cut != null)@@ -584,21 +583,13 @@ class KeyBindings { foreach (Tool t in exp.tool) { t.set_active (false); - if (t.key == event.keyval && t.modifier_flag == modifier) {+ if (t.key == keyval && t.modifier_flag == modifier) { if (!(require_modifier && (modifier == NONE || modifier == SHIFT))) { MainWindow.get_toolbox ().select_tool (t); } } } }- - /* // FIXA- foreach (Tool t in MainWindow.get_content_display ().tools) { - if (t.key == event.keyval && t.modifier_flag == modifier) {- t.select_action (t);- }- }- * */ } } @@ -43,6 +43,8 @@ public class MainWindow : Gtk.Window { static DrawingArea margin_right; static OverView over_view; + + static List<uint> key_pressed = new List<uint> (); public MainWindow (string title) { singleton = this; @@ -285,8 +287,18 @@ public class MainWindow : Gtk.Window { public static int global_key_bindings (Widget grab_widget, EventKey event, void* data) { MainWindow window = get_singleton (); - window.glyph_canvas.key_press (event); - window.key_bindings.key_press (event); + foreach (uint k in key_pressed) { + if (k == event.keyval) { + key_pressed.remove_all (k); + window.glyph_canvas.key_release (event.keyval); + window.key_bindings.key_release (event.keyval); + return 0; + } + } + + key_pressed.append (event.keyval); + window.glyph_canvas.key_press (event.keyval); + window.key_bindings.key_press (event.keyval); return 0; } @@ -703,17 +703,11 @@ class OverView : FontDisplay { } public void open_current_glyph () {- EventKey e = { 0 };- e.type = EventType.KEY_PRESS;- e.keyval = Key.ENTER;- key_press (e);+ key_press (Key.ENTER); } public void select_next_glyph () {- EventKey e = { 0 };- e.type = EventType.KEY_PRESS;- e.keyval = Key.RIGHT;- key_press (e);+ key_press (Key.RIGHT); } public void key_right () { @@ -765,19 +759,15 @@ class OverView : FontDisplay { return glyph_range.get_char (selected); } - public override void key_press (EventKey e) {+ public override void key_press (uint keyval) { redraw_area (0, 0, allocation.width, allocation.height); close_menus ();- - if (e.type != EventType.KEY_PRESS) {- return;- } if (KeyBindings.modifier == CTRL) { return; } - switch (e.keyval) {+ switch (keyval) { case Key.ENTER: open_glyph_signal (get_selected_char ()); return;@@ -815,7 +805,7 @@ class OverView : FontDisplay { return; } - scroll_to_char (e.keyval);+ scroll_to_char (keyval); } public void delete_selected_glyph () {@@ -745,7 +745,7 @@ class Path { return is_over_coordinate_var (x, y, 0.1); } - public double distance (double ax, double bx, double ay, double by) {+ public static double distance (double ax, double bx, double ay, double by) { return Math.fabs (Math.sqrt (Math.pow (ax - bx, 2) + Math.pow (ay - by, 2))); } @@ -41,10 +41,15 @@ class PenTool : Tool { private static double last_point_x = 0; private static double last_point_y = 0; + private static bool adjust_precision = false;+ private static double adjust_precision_begin_x = 0;+ private static double adjust_precision_begin_y = 0;+ private static double precision = 1;+ public PenTool (string name) {- base (name, "Edit path", 'p', CTRL);+ base (name, "Edit path", ',', CTRL); - select_action.connect((self) => {+ select_action.connect ((self) => { }); deselect_action.connect ((self) => {@@ -53,21 +58,23 @@ class PenTool : Tool { CutTool.force_direction (); glyph.close_path (); - move_point_on_path = false; // Fixa: this might be better as toggle buttons+ move_point_on_path = false; begin_new_point_on_path = false; }); - press_action.connect((self, b, x, y) => {+ press_action.connect ((self, b, x, y) => { last_point_x = x; last_point_y = y;+ + precision = 1; press (b, x, y); }); - double_click_action.connect((self, b, x, y) => {+ double_click_action.connect ((self, b, x, y) => { }); - release_action.connect((self, b, ix, iy) => {+ release_action.connect ((self, b, ix, iy) => { double x = ix; double y = iy; Glyph g = MainWindow.get_current_glyph ();@@ -82,18 +89,46 @@ class PenTool : Tool { edit_active_corner = false; selected_handle = new EditPointHandle.empty ();- active_handle = new EditPointHandle.empty (); + active_handle = new EditPointHandle.empty (); }); - move_action.connect((self, x, y) => {+ move_action.connect ((self, x, y) => { move (x, y); });+ + key_press_action.connect ((self, keyval) => {+ if (keyval == Key.SHIFT_LEFT) {+ adjust_precision = true;+ + adjust_precision_begin_x = last_point_x;+ adjust_precision_begin_y = last_point_y;+ }+ });+ + key_release_action.connect ((self, keyval) => {+ if (keyval == Key.SHIFT_LEFT) {+ adjust_precision = false;+ precision = 1.0 / Path.distance (adjust_precision_begin_x, last_point_x, adjust_precision_begin_y, last_point_y);+ + precision *= 30;+ + if (precision > 1) {+ precision = 1;+ } + }+ }); } public void move (double x, double y) { Glyph glyph = MainWindow.get_current_glyph (); EditPoint ep; + if (adjust_precision) {+ last_point_x = x;+ last_point_y = y;+ return;+ }+ control_point_event (x, y); curve_active_corner_event (x, y); set_default_handle_positions ();@@ -119,7 +154,7 @@ class PenTool : Tool { selected_handle.move_to (x, y); } else { selected_handle.set_point_type (PointType.CURVE);- selected_handle.move_delta (x - last_point_x, y - last_point_y);+ selected_handle.move_delta ((x - last_point_x) * precision, (y - last_point_y) * precision); } selected_handle.parent.recalculate_linear_handles ();@@ -135,7 +170,7 @@ class PenTool : Tool { // move edit point if (move_selected) {- glyph.move_selected_edit_point_delta (x - last_point_x, y - last_point_y);+ glyph.move_selected_edit_point_delta ((x - last_point_x) * precision, (y - last_point_y) * precision); ep = (!) glyph.selected_point; if (tie_x_or_y_coordinates) {@@ -53,6 +53,9 @@ class Tool : GLib.Object { public signal void move_action (Tool selected, int x, int y); public signal void release_action (Tool selected, int button, int x, int y); + public signal void key_press_action (Tool selected, uint32 keyval);+ public signal void key_release_action (Tool selected, uint32 keyval);+ 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);