The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Give press event method a name

These changes was commited to the Birdfont repository Mon, 04 May 2015 10:39:29 +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, 04 May 2015 10:39:29 +0000]

Updated Files

libbirdfont/ForesightTool.vala
libbirdfont/PenTool.vala
libbirdfont/StrokeTool.vala
--- a/libbirdfont/ForesightTool.vala +++ b/libbirdfont/ForesightTool.vala @@ -37,6 +37,9 @@ public bool skip_deselect = false; + static int press_counter = 0; + bool button_pressed = false; + public ForesightTool (string name) { base (name, t_ ("Create Beziér curves")); @@ -50,6 +53,8 @@ MainWindow.get_current_glyph ().clear_active_paths (); MainWindow.set_cursor (NativeWindow.VISIBLE); state = NONE; + + print (@"select press_action\n"); }); deselect_action.connect ((self) => { @@ -61,101 +66,24 @@ MainWindow.set_cursor (NativeWindow.VISIBLE); state = NONE; + + print (@"deselect press_action\n"); }); press_action.connect ((self, b, x, y) => { - PenTool p = (PenTool) PointTool.pen (); - PointSelection ps; - EditPoint first_point; - bool clockwise; - Path? path = null; - bool one_point = false; - - MainWindow.set_cursor (NativeWindow.HIDDEN); - - if (b == 2) { - stop_drawing (); - return; - } - - BirdFont.get_current_font ().touch (); - MainWindow.get_current_glyph ().store_undo_state (); - - last_move_x = x; - last_move_y = y; - - if (previous_point > 0) { - previous_point = 0; - state = MOVE_POINT; - } else { - if (state == MOVE_POINT) { - state = MOVE_HANDLES; - - path = PenTool.find_path_to_join (); - - if (path != null) { - one_point = (((!) path).points.size == 1); - } - - if (p.has_join_icon ()) { - // FIXME: last activa path in list - ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path); - ps.point.set_tie_handle (false); - - ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path); - ps.point.set_tie_handle (false); - - first_point = PenTool.active_path.points.get (0); - clockwise = PenTool.active_path.is_clockwise (); - - PenTool.move_selected = false; - p.release_action (p, 2, x, y); - - PenTool.move_selected = false; - p.press_action (p, 2, x, y); - - if (ps.path.has_point (first_point)) { - ps.path.reverse (); - } - - if (clockwise && PenTool.active_path.is_clockwise ()) { - ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path); - } else { - ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path); - } - - PenTool.selected_points.clear (); - PenTool.selected_points.add (ps); - PenTool.selected_point = ps.point; - - state = MOVE_LAST_HANDLE; - - if (one_point) { - p.press_action (p, 2, x, y); - state = NONE; - } - } - } - } - - if (state == NONE) { - state = MOVE_POINT; - PenTool.active_path = get_active_path (); - - add_new_point (x, y); - - PenTool.last_point_x = Glyph.path_coordinate_x (x); - PenTool.last_point_y = Glyph.path_coordinate_y (y); - - move_action (this, x, y); - state = MOVE_FIRST_HANDLE; - release_action(this, b, x, y); - } + press (b, x, y); }); release_action.connect ((self, b, x, y) => { PenTool p = (PenTool) PointTool.pen (); PointSelection last; + + if (!button_pressed) { + warning ("!button_pressed"); + return; + } + + print (@"bezier release_action\n"); if (state == MOVE_HANDLES || state == MOVE_FIRST_HANDLE) { if (state != MOVE_FIRST_HANDLE) { @@ -191,6 +119,7 @@ } current_path.hide_end_handle = true; + button_pressed = false; }); move_action.connect ((self, x, y) => { @@ -328,6 +257,104 @@ Tool p = PointTool.pen (); p.draw_action (p, cairo_context, glyph); }); + } + + public void press (int b, int x, int y) { + PenTool p = (PenTool) PointTool.pen (); + PointSelection ps; + EditPoint first_point; + bool clockwise; + Path? path = null; + bool one_point = false; + + if (button_pressed) { + warning ("no release event"); + return; + } + button_pressed = true; + + MainWindow.set_cursor (NativeWindow.HIDDEN); + + print (@"$(press_counter++) bezier press_action\n"); + + if (b == 2) { + stop_drawing (); + return; + } + + BirdFont.get_current_font ().touch (); + MainWindow.get_current_glyph ().store_undo_state (); + + last_move_x = x; + last_move_y = y; + + if (previous_point > 0) { + previous_point = 0; + state = MOVE_POINT; + } else { + if (state == MOVE_POINT) { + state = MOVE_HANDLES; + + path = PenTool.find_path_to_join (); + + if (path != null) { + one_point = (((!) path).points.size == 1); + } + + if (p.has_join_icon ()) { + // FIXME: last activa path in list + ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path); + ps.point.set_tie_handle (false); + + ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path); + ps.point.set_tie_handle (false); + + first_point = PenTool.active_path.points.get (0); + clockwise = PenTool.active_path.is_clockwise (); + + PenTool.move_selected = false; + p.release_action (p, 2, x, y); + + PenTool.move_selected = false; + p.press_action (p, 2, x, y); + + if (ps.path.has_point (first_point)) { + ps.path.reverse (); + } + + if (clockwise && PenTool.active_path.is_clockwise ()) { + ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path); + } else { + ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path); + } + + PenTool.selected_points.clear (); + PenTool.selected_points.add (ps); + PenTool.selected_point = ps.point; + + state = MOVE_LAST_HANDLE; + + if (one_point) { + p.press_action (p, 2, x, y); + state = NONE; + } + } + } + } + + if (state == NONE) { + state = MOVE_POINT; + PenTool.active_path = get_active_path (); + + add_new_point (x, y); + + PenTool.last_point_x = Glyph.path_coordinate_x (x); + PenTool.last_point_y = Glyph.path_coordinate_y (y); + + move_action (this, x, y); + state = MOVE_FIRST_HANDLE; + release_action(this, b, x, y); + } } public void stop_drawing () { @@ -338,8 +365,14 @@ if (state != NONE) { a = get_active_path (); - if (a.is_open () && state != NONE) { + if (a.is_open ()) { a.delete_last_point (); + + a.get_first_point ().set_reflective_handles (false); + a.get_first_point ().set_tie_handle (false); + + a.get_last_point ().set_reflective_handles (false); + a.get_last_point ().set_tie_handle (false); } } @@ -356,7 +389,9 @@ public Path get_active_path () { Glyph g = MainWindow.get_current_glyph (); - return_val_if_fail (g.active_paths.size > 0, new Path ()); + if (g.active_paths.size == 0) { + return new Path (); + } return g.active_paths.get (g.active_paths.size -1); } @@ -380,6 +415,7 @@ PointSelection last; double handle_x, handle_y; + print (@"add_new_point: $(PenTool.active_path.points.size)\n"); PenTool p = (PenTool) PointTool.pen (); if (PenTool.active_path.points.size == 0) {
--- a/libbirdfont/PenTool.vala +++ b/libbirdfont/PenTool.vala @@ -76,6 +76,9 @@ public static double simplification_threshold = 0.5; public static bool retain_angle = false; + bool button_pressed = false; + + static int press_counter = 0; public PenTool (string name) { base (name, t_("Add new points")); @@ -101,7 +104,16 @@ MainWindow.get_current_glyph ().clear_active_paths (); }); - press_action.connect ((self, b, x, y) => { + press_action.connect ((self, b, x, y) => { + if (button_pressed) { + warning ("Unexpected event"); + return; + } + + print (@"$(press_counter++) pen press_action\n"); + + button_pressed = true; + // retain path direction clockwise = new Gee.ArrayList<Path> (); counter_clockwise = new Gee.ArrayList<Path> (); @@ -144,7 +156,7 @@ last_point_x = Glyph.path_coordinate_x (x); last_point_y = Glyph.path_coordinate_y (y); - if (!move_selected_handle && !move_selected) { + if (!move_selected_handle && !move_selected && !button_pressed) { press (b, x, y, true); } else { warning ("double click suppressed"); @@ -203,6 +215,8 @@ p.get_last_point ().set_reflective_handles (false); } } + + button_pressed = false; }); move_action.connect ((self, x, y) => { @@ -868,6 +882,11 @@ Glyph? g = MainWindow.get_current_glyph (); Glyph glyph = (!) g; PointSelection ps; + + if (move_selected_handle) { + warning ("moving handle"); + return; + } return_if_fail (g != null); @@ -978,9 +997,6 @@ if (p.is_open () && p.points.size >= 1 && (active_edit_point == p.points.get (0) || active_edit_point == p.points.get (p.points.size - 1))) { - active_path = p; - glyph.set_active_path (p); - update_selection (); reverse = true; control_point_event (x, y); @@ -1539,6 +1555,9 @@ if (distance < contact_surface) { set_active_edit_point (e.point, e.path); + + active_path = e.path; + g.add_active_path (active_path); } } @@ -1563,6 +1582,8 @@ active_path = new_point.path; glyph.clear_active_paths (); glyph.add_active_path (new_point.path); + + print (@"PointSelection new_point_action; $(glyph.active_paths.size)\n"); move_selected = true;
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -1664,7 +1664,10 @@ Path path = original_path.copy (); - path.add_hidden_double_points (); // FIXME: + if (path.points.size > 1) { + path.add_hidden_double_points (); // FIXME: + } + foreach (EditPoint ep in path.points) { if (ep.type == PointType.DOUBLE_CURVE || ep.type == PointType.LINE_DOUBLE_CURVE) { PenTool.convert_point_type (ep, PointType.QUADRATIC); @@ -1708,8 +1711,8 @@ p2 = path.points.get ((i + 1) % path.points.size); p3 = path.points.get ((i + 2) % path.points.size); - tolerance = 0.13 / sqrt (stroke_width); - // tolerance = 2 / sqrt (stroke_width); + //tolerance = 0.13 / sqrt (stroke_width); + tolerance = 1.6 / sqrt (stroke_width); step_increment = 1.05; step_size = 0.039 / stroke_width;