Commit e749eab
Create new paths with the Beziér tool
Changed files (5)
modifiedlibbirdfont/ForesightTool.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/PenTool.valamodifiedlibbirdfont/StrokeTool.valamodifiedlibbirdfont/TrackTool.vala
Diff
@@ -47,6 +47,7 @@ public class ForesightTool : Tool { p.release_action (p, 1, last_move_x, last_move_y); } + MainWindow.get_current_glyph ().clear_active_paths (); MainWindow.set_cursor (NativeWindow.VISIBLE); state = NONE; });@@ -67,16 +68,24 @@ public class ForesightTool : Tool { PointSelection ps; EditPoint first_point; bool clockwise;+ Path? path = null;+ bool one_point = false; MainWindow.set_cursor (NativeWindow.HIDDEN); if (b == 2) { p.release_action (p, 1, x, y);+ + if (PenTool.active_path.is_open ()) {+ PenTool.active_path.delete_last_point ();+ }+ p.press_action (p, 2, x, y); p.release_action (p, 2, x, y); current_path.hide_end_handle = true; state = NONE; MainWindow.set_cursor (NativeWindow.VISIBLE);+ MainWindow.get_current_glyph ().clear_active_paths (); return; } @@ -90,25 +99,16 @@ public class ForesightTool : Tool { previous_point = 0; state = MOVE_POINT; } else { - if (state == NONE) {- state = MOVE_POINT;- add_new_point (x, y);+ if (state == MOVE_POINT) { + state = MOVE_HANDLES; - PenTool.last_point_x = Glyph.path_coordinate_x (x);- PenTool.last_point_y = Glyph.path_coordinate_y (y);+ path = PenTool.find_path_to_join (); - move_action (this, x, y);- state = MOVE_FIRST_HANDLE;- release_action(this, b, x, y);- } else if (state == MOVE_POINT) { - state = MOVE_HANDLES;+ if (path != null) {+ one_point = (((!) path).points.size == 1);+ } - if (p.has_join_icon ()) { - if (unlikely (PenTool.active_path.points.size == 0)) {- warning ("No point to join.");- return;- }-+ if (p.has_join_icon ()) { ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path); ps.point.set_tie_handle (false); @@ -117,13 +117,13 @@ public class ForesightTool : Tool { 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 (); }@@ -139,8 +139,25 @@ public class ForesightTool : Tool { 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;+ 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);+ } } }); @@ -608,10 +608,6 @@ public class Path { reverse_points (); if (unlikely (direction == is_clockwise ())) {- stderr.printf ("Error: Direction did not change after reversing path.\n");- stderr.printf (@"Length: $(points.size)\n");- stderr.printf (@"No particular direction can be derived: $no_derived_direction \n");- warning ("Path.reverse () failed.\n"); return false; } @@ -972,13 +972,10 @@ public class PenTool : Tool { move_point_on_path = true; if (active_edit_point != null) {- glyph.clear_active_paths (); glyph.add_active_path (active_path);- DrawingTools.update_stroke_settings (); - if (KeyBindings.modifier == SHIFT) { if (((!)active_edit_point).is_selected () && selected_points.size > 1) { ((!)active_edit_point).set_selected (false);@@ -1017,7 +1014,7 @@ public class PenTool : Tool { } } - private static Path? find_path_to_join () {+ public static Path? find_path_to_join () { Path? m = null; Glyph glyph = MainWindow.get_current_glyph (); EditPoint ep_last, ep_first;@@ -1148,7 +1145,39 @@ public class PenTool : Tool { return; } - return_if_fail (path.points.size > 1);+ return_if_fail (path.points.size > 0);+ + px = Glyph.reverse_path_coordinate_x (((!) active_edit_point).x);+ py = Glyph.reverse_path_coordinate_y (((!) active_edit_point).y);+ + if (path.points.size == 1) {+ glyph.delete_path (path);+ glyph.clear_active_paths ();++ foreach (Path merge in glyph.path_list) {+ if (merge.points.size > 0) {+ if (is_close_to_point (merge.points.get (merge.points.size - 1), px, py)) {+ glyph.add_active_path (merge);+ active_path = merge;+ merge.reopen ();+ glyph.open_path ();+ return;+ }+ + if (is_close_to_point (merge.points.get (0), px, py)) {+ glyph.add_active_path (merge);+ active_path = merge;+ merge.reverse ();+ clear_directions ();+ merge.reopen ();+ glyph.open_path ();+ return;+ }+ }+ }+ + return;+ } if (active_edit_point == path.points.get (0)) { path.reverse ();@@ -1165,8 +1194,6 @@ public class PenTool : Tool { } // join path with it self- px = Glyph.reverse_path_coordinate_x (((!) active_edit_point).x);- py = Glyph.reverse_path_coordinate_y (((!) active_edit_point).y); if (is_endpoint ((!) active_edit_point) && is_close_to_point (path.points.get (0), px, py)) { @@ -1183,6 +1210,7 @@ public class PenTool : Tool { } remove_all_selected_points ();+ return; } @@ -1193,7 +1221,7 @@ public class PenTool : Tool { } // we need both start and end points- if (merge.points.size < 1 || path.points.size < 1) {+ if (merge.points.size <= 1 || path.points.size <= 1) { continue; } @@ -1205,28 +1233,34 @@ public class PenTool : Tool { return_if_fail (merge.points.size > 0); - if (is_close_to_point (merge.points.get (0), px, py)) {- union = merge_open_paths (path, merge); + if (is_close_to_point (merge.points.get (0), px, py)) { + if (path.points.size == 1) {+ warning ("path.points.size == 1\n");+ } else if (merge.points.size == 1) {+ warning ("merge.points.size == 1\n");+ } else {+ union = merge_open_paths (path, merge); - glyph.add_path (union);- glyph.delete_path (path);- glyph.delete_path (merge);- glyph.clear_active_paths ();- glyph.add_active_path (union);- - union.reopen ();- union.create_list ();- - force_direction ();- - if (direction_changed) {- path.reverse ();- update_selection ();+ glyph.add_path (union);+ glyph.delete_path (path);+ glyph.delete_path (merge);+ glyph.clear_active_paths ();+ glyph.add_active_path (union);+ + union.reopen ();+ union.create_list ();+ + force_direction ();+ + if (direction_changed) {+ path.reverse ();+ update_selection ();+ }+ + union.update_region_boundaries ();+ + return; }- - union.update_region_boundaries ();- - return; } } @@ -1245,7 +1279,7 @@ public class PenTool : Tool { distance = sqrt (fabs (pow (px - x, 2)) + fabs (pow (py - y, 2))); - return (distance < 8 * MainWindow.units);+ return (distance < 7 * MainWindow.units); } /** Show the user that curves will be merged on release. */@@ -1670,14 +1670,14 @@ public class StrokeTool : Tool { } public static PathList create_stroke (Path path, double thickness) {- PathList pl = new PathList ();+ PathList pl; EditPoint p1, p2, p3; EditPoint previous, previous_inside, start; Path side1, side2; double x, y, x2, y2, x3, y3;- int size = path.is_open () ? path.points.size - 1 : path.points.size;+ int size; bool flat, f_next, f_bigger; int i; @@ -1689,10 +1689,15 @@ public class StrokeTool : Tool { EditPointHandle l, r; + pl = new PathList ();+ size = path.is_open () ? path.points.size - 1 : path.points.size;+ side1 = new Path (); side2 = new Path (); - return_val_if_fail (path.points.size > 1, pl);+ if (path.points.size < 2) {+ return pl;+ } previous = new EditPoint (); previous_inside = new EditPoint ();@@ -49,9 +49,6 @@ public class TrackTool : Tool { int join_y = -1; bool join_paths = false; - /** Create a stroked path instead of filling the shape. */- double stroke_width = 0; - /** Adjust the number of samples per point by this factor. */ double samples_per_point = 1; @@ -60,15 +57,6 @@ public class TrackTool : Tool { base (name, t_("Freehand drawing")); - sw = Preferences.get ("free_hand_stroke_width");- if (sw != "") {- stroke_width = SpinButton.convert_to_double (sw);- }- - select_action.connect((self) => {- Toolbox.set_object_stroke (stroke_width);- });- press_action.connect ((self, button, x, y) => { Glyph glyph = MainWindow.get_current_glyph (); Path p;@@ -109,7 +97,6 @@ public class TrackTool : Tool { glyph.open_path (); PenTool.add_new_edit_point (x, y).point;- p.set_stroke (stroke_width); } glyph.update_view (); @@ -143,7 +130,7 @@ public class TrackTool : Tool { if (join != join_paths) { MainWindow.get_current_glyph ().update_view ();-+ PenTool.reset_stroke (); } join_paths = join;@@ -159,6 +146,7 @@ public class TrackTool : Tool { convert_on_timeout (); last_x = x; last_y = y;+ PenTool.reset_stroke (); } }); @@ -410,7 +398,7 @@ public class TrackTool : Tool { update_cycles = 0; } - if (added_points > 40 / samples_per_point) {+ if (added_points > 10 / samples_per_point) { last_update = get_current_time (); convert_points_to_line (); }@@ -537,6 +525,7 @@ public class TrackTool : Tool { added_points = 0; last_update = get_current_time (); glyph.update_view ();+ PenTool.reset_stroke (); } /** @return current time in milli seconds. */