The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Draw paths with quadratic control points using the new Beziér tool

These changes was commited to the Birdfont repository Wed, 15 Oct 2014 18:42:24 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Wed, 15 Oct 2014 18:42:24 +0000]

Updated Files

libbirdfont/EditPoint.vala
libbirdfont/ForesightTool.vala
--- a/libbirdfont/EditPoint.vala +++ b/libbirdfont/EditPoint.vala @@ -485,8 +485,8 @@ set_position (tx, ty); - left_handle.move_to_coordinate_internal (lx, ly); - right_handle.move_to_coordinate_internal (rx, ry); + left_handle.move_to_coordinate (lx, ly); + right_handle.move_to_coordinate (rx, ry); } public void set_position (double tx, double ty) {
--- a/libbirdfont/ForesightTool.vala +++ b/libbirdfont/ForesightTool.vala @@ -43,18 +43,21 @@ PenTool p = (PenTool) PointTool.pen (); PointSelection ps; EditPoint first_point; + bool clockwise; if (state == NONE) { + p.press_action (p, 3, x, y); + p.release_action (p, 3, x, y); + add_new_point (x, y); - move_action (this, x, y); + // FIXME: DELETE move_action (this, x, y); + state = MOVE_HANDLES; - PenTool.active_path.hide_end_handle = false; } - if (state == MOVE_POINT) { + if (state == MOVE_POINT) { state = MOVE_HANDLES; - PenTool.active_path.hide_end_handle = false; - + if (p.has_join_icon ()) { return_if_fail (PenTool.active_path.points.size != 0); ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path); @@ -66,6 +69,7 @@ ps.point.convert_to_curve (); first_point = PenTool.active_path.points.get (0); + clockwise = PenTool.active_path.is_clockwise (); p.release_action (p, 3, x, y); p.press_action (p, 3, x, y); @@ -73,8 +77,13 @@ if (ps.path.has_point (first_point)) { ps.path.reverse (); } - - ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path); + + 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; @@ -99,10 +108,7 @@ if (state == MOVE_HANDLES) { state = MOVE_POINT; add_new_point (x, y); - PenTool.active_path.hide_end_handle = true; - } - - if (state == MOVE_LAST_HANDLE) { + } else if (state == MOVE_LAST_HANDLE) { state = NONE; return_if_fail (PenTool.selected_points.size != 0); last = PenTool.selected_points.get (PenTool.selected_points.size - 1); @@ -112,12 +118,16 @@ last.path.direction_is_set = false; PenTool.force_direction (); + } else { + warning (@"Unknown state $state."); } }); move_action.connect ((self, x, y) => { Tool p = PointTool.pen (); PointSelection last; + + PenTool.active_path.hide_end_handle = (state == MOVE_POINT); if (state == MOVE_HANDLES || state == MOVE_LAST_HANDLE) { return_if_fail (PenTool.selected_points.size != 0); @@ -133,10 +143,11 @@ last.point.set_reflective_handles (false); PenTool.move_selected_handle = false; last.path.highlight_last_segment = true; - + last.point.set_tie_handle (true); - } else { + p.move_action (p, x, y); + } else { if (DrawingTools.get_selected_point_type () != PointType.QUADRATIC) { p.move_action (p, x, y); } else { @@ -166,17 +177,36 @@ void add_new_point (int x, int y) { PointSelection last; + double handle_x, handle_y; PenTool p = (PenTool) PointTool.pen (); - - PenTool.selected_points.clear (); - PenTool.selected_handle = new EditPointHandle.empty (); - p.release_action (p, 3, x, y); - - last = p.new_point_action (x, y); + if (PenTool.active_path.points.size == 0) { + last = p.new_point_action (x, y); + } else { + return_if_fail (PenTool.selected_points.size != 0); + last = PenTool.selected_points.get (PenTool.selected_points.size - 1); + + PenTool.selected_points.clear (); + PenTool.selected_handle = new EditPointHandle.empty (); + + p.release_action (p, 3, x, y); + + if (DrawingTools.get_selected_point_type () != PointType.QUADRATIC) { + last = p.new_point_action (x, y); + } else { + last.point.get_right_handle ().length *= 0.999999; + handle_x = last.point.get_right_handle ().x; + handle_y = last.point.get_right_handle ().y; + + last = p.new_point_action (x, y); + + last.point.get_left_handle ().x = handle_x; + last.point.get_left_handle ().y = handle_y; + } - p.press_action (p, 3, x, y); + p.press_action (p, 3, x, y); + } PenTool.selected_points.clear (); PenTool.selected_points.add (last); @@ -186,8 +216,10 @@ PenTool.move_selected_handle = false; PenTool.move_selected = true; + + PenTool.active_path.hide_end_handle = (state == MOVE_POINT); } } }