Commit 28fe3a1
flip control point handles when drawing direction changes
Changed files (4)
modifiedlibbirdfont/EditPoint.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/PenTool.valamodifiedlibbirdfont/RectangleTool.vala
Diff
@@ -296,6 +296,7 @@ public class EditPoint { new_point.type = type; new_point.deleted = deleted;+ new_point.selected = selected; new_point.tie_handles = tie_handles; @@ -448,15 +448,32 @@ public class Path { } private void reverse_points () {- points.reverse ();- EditPointHandle t;- foreach (var e in points) {- t = e.right_handle;- e.right_handle = e.left_handle;- e.left_handle = t;+ Path p = copy ();+ unowned List<EditPoint> e;++ create_list (); + + while (points.length () > 0) {+ points.remove_link (points.first ()); } + e = p.points.last ();+ while (!is_null (e) && !is_null (e.data)) {+ t = e.data.right_handle;+ e.data.right_handle = e.data.left_handle;+ e.data.left_handle = t;+ e.data.set_selected (false);+ + add_point (e.data);+ + if (is_null (e.prev)) {+ break;+ } else {+ e = e.prev;+ }+ }+ create_list (); } @@ -1664,6 +1681,7 @@ public class Path { if (points.length () == 1) { points.delete_link (points.first ());+ return path_list; } // set start position to the point that will be removed @@ -1708,7 +1726,12 @@ public class Path { foreach (EditPoint point in remaining_points.points) { current_path.add_point (point.copy ()); }- path_list.paths.append (current_path);+ + if (current_path.points.length () > 0) {+ current_path.points.first ().data.set_tie_handle (false);+ current_path.points.first ().data.set_reflective_handles (false);+ path_list.paths.append (current_path);+ } } else { if (current_path.points.length () > 0) { current_path.points.first ().data.set_tie_handle (false);@@ -1734,7 +1757,7 @@ public class Path { unowned List<EditPoint> iter = points.first (); unowned List<EditPoint>? ni = null; bool found = false;- + foreach (EditPoint it in points) { if (it == ep) { found = true;@@ -130,12 +130,14 @@ public class PenTool : Tool { foreach (Path p in clockwise) { if (!p.is_open () && !p.is_clockwise ()) { p.reverse ();+ update_selection (); } } foreach (Path p in counter_clockwise) { if (!p.is_open () && p.is_clockwise ()) { p.reverse ();+ update_selection (); } } });@@ -186,7 +188,7 @@ public class PenTool : Tool { while (selected_points.length () > 0) { selected_points.remove_link (selected_points.first ()); }-+ active_handle = new EditPointHandle.empty (); selected_handle = new EditPointHandle.empty (); @@ -194,6 +196,21 @@ public class PenTool : Tool { selected_point = new EditPoint (); } + /** Retain selected points even if path is copied after running reverse. */+ static void update_selection () {+ Glyph g = MainWindow.get_current_glyph ();+ + remove_all_selected_points ();+ + foreach (Path p in g.path_list) {+ foreach (EditPoint e in p.points) {+ if (e.is_selected ()) {+ selected_points.append (e);+ }+ }+ }+ }+ static void process_deleted () { Glyph g = MainWindow.get_current_glyph (); while (g.process_deleted ());@@ -431,10 +448,12 @@ public class PenTool : Tool { ((!)active_edit_point).set_selected (false); remove_from_selected ((!)active_edit_point); selected_point = new EditPoint ();+ last_selected_is_handle = false; } else { ((!)active_edit_point).set_selected (true); selected_point = (!)active_edit_point; add_selected_point (selected_point);+ last_selected_is_handle = false; } } else { selected_point = (!)active_edit_point;@@ -444,6 +463,7 @@ public class PenTool : Tool { ((!)active_edit_point).set_selected (true); selected_point = (!)active_edit_point; add_selected_point (selected_point);+ last_selected_is_handle = false; } } }@@ -453,6 +473,7 @@ public class PenTool : Tool { foreach (Path p in glyph.active_paths) { if (p.is_open () && p.points.length () > 0 && active_edit_point == p.points.first ().data) { p.reverse ();+ update_selection (); reverse = true; } }@@ -501,7 +522,8 @@ public class PenTool : Tool { Path? p; Path path; bool direction_changed = false;-+ Path union;+ if (glyph.path_list.length () < 1) { return; }@@ -511,9 +533,11 @@ public class PenTool : Tool { return; } path = (!) p;- - if (active_edit_point == path.points.first ().data) {++ if (path.is_open () && active_edit_point == path.points.first ().data) { path.reverse ();+ update_selection ();+ path.recalculate_linear_handles (); direction_changed = !direction_changed; } @@ -544,10 +568,19 @@ public class PenTool : Tool { if (direction_changed) { path.reverse ();+ update_selection (); }+ + remove_all_selected_points ();+ return; } + union = new Path ();+ foreach (EditPoint ep in path.points) {+ union.add_point (ep.copy ());+ }+ foreach (Path merge in glyph.path_list) { // don't join path with it self here if (path == merge) {@@ -561,6 +594,7 @@ public class PenTool : Tool { if (is_close_to_point (merge.points.last ().data, x, y)) { merge.reverse ();+ update_selection (); direction_changed = !direction_changed; } @@ -578,21 +612,29 @@ public class PenTool : Tool { path.points.first ().data.set_tie_handle (false); path.points.first ().data.set_reflective_handles (false);-- path.append_path (merge);- path.reopen ();+ + union.append_path (merge.copy ());+ glyph.add_path (union);+ + glyph.delete_path (path);+ glyph.delete_path (merge);+ + union.reopen (); force_direction (); if (direction_changed) { path.reverse ();+ update_selection (); }+ return; } } if (direction_changed) { path.reverse ();+ update_selection (); } } @@ -83,7 +83,6 @@ public class RectangleTool : Tool { } void press (int button, double x, double y) {- Glyph glyph = MainWindow.get_current_glyph (); press_x = x; press_y = y; resize = true;