The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Make Beziér tool work better with grid and a couple of experiments

These changes was commited to the Birdfont repository Thu, 16 Oct 2014 18:52:12 +0000.

Contributing

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

Updated Files

libbirdfont/BirdFont.vala
libbirdfont/ForesightTool.vala
libbirdfont/PenTool.vala
--- a/libbirdfont/BirdFont.vala +++ b/libbirdfont/BirdFont.vala @@ -663,6 +663,8 @@ } else { warning ("No logstream."); } + + stderr.printf (s); } catch (GLib.Error e) { warning (e.message); }
--- a/libbirdfont/ForesightTool.vala +++ b/libbirdfont/ForesightTool.vala @@ -28,9 +28,12 @@ uint state = NONE; bool move_right_handle = true; + int previous_point = 0; int last_x = 0; int last_y = 0; + + Path current_path = new Path (); public ForesightTool (string name) { base (name, t_ ("Create Beziér curves"), '.', CTRL); @@ -49,49 +52,54 @@ 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); - - state = MOVE_HANDLES; - } - - if (state == MOVE_POINT) { - state = MOVE_HANDLES; + if (previous_point > 0) { + previous_point = 0; + state = MOVE_POINT; + } else { + if (state == NONE) { + p.press_action (p, 3, x, y); + p.release_action (p, 3, x, y); - 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); - ps.point.set_tie_handle (false); - ps.point.convert_to_curve (); + add_new_point (x, y); - ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path); - ps.point.set_tie_handle (false); - ps.point.convert_to_curve (); - - first_point = PenTool.active_path.points.get (0); - clockwise = PenTool.active_path.is_clockwise (); + state = MOVE_HANDLES; + } - p.release_action (p, 3, x, y); - p.press_action (p, 3, x, y); - - if (ps.path.has_point (first_point)) { - ps.path.reverse (); - } + if (state == MOVE_POINT) { + state = MOVE_HANDLES; - if (clockwise && PenTool.active_path.is_clockwise ()) { - ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path); - } else { + 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); - } + ps.point.set_tie_handle (false); + ps.point.convert_to_curve (); + + ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path); + ps.point.set_tie_handle (false); + ps.point.convert_to_curve (); + + first_point = PenTool.active_path.points.get (0); + clockwise = PenTool.active_path.is_clockwise (); - PenTool.selected_points.clear (); - PenTool.selected_points.add (ps); - PenTool.selected_point = ps.point; - - state = MOVE_LAST_HANDLE; + p.release_action (p, 3, x, y); + p.press_action (p, 3, 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; + } } } }); @@ -124,40 +132,74 @@ } else { warning (@"Unknown state $state."); } + + current_path.hide_end_handle = true; }); move_action.connect ((self, x, y) => { Tool p = PointTool.pen (); PointSelection last; - bool rh; + bool lh; + EditPointHandle h; + PenTool.active_path = current_path; 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); - last = PenTool.selected_points.get (PenTool.selected_points.size - 1); + + if (state == MOVE_HANDLES || state == MOVE_LAST_HANDLE) { + if (previous_point > 0) { + return_if_fail (PenTool.active_path.points.size >= previous_point + 1); + last = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - (previous_point + 1)), PenTool.active_path); + } else { + return_if_fail (PenTool.selected_points.size != 0); + last = PenTool.selected_points.get (PenTool.selected_points.size - 1); + } PenTool.move_selected_handle = true; + PenTool.move_selected = false; - rh = (state == MOVE_LAST_HANDLE); + lh = (state == MOVE_LAST_HANDLE); if (!move_right_handle) { - rh = !rh; + lh = !lh; } - PenTool.selected_handle = (rh) - ? last.point.get_left_handle () : last.point.get_right_handle (); + if (previous_point > 0) { + lh = false; + } + + h = (lh) ? last.point.get_left_handle () : last.point.get_right_handle (); + PenTool.selected_handle = h; + PenTool.active_handle = h; + + if (previous_point == 0) { + last.point.set_reflective_handles (true); + } + + if (previous_point > 0) { + PenTool.retain_angle = last.point.tie_handles; + } + + if (h.is_line ()) { + last.point.convert_to_curve (); + last.point.get_right_handle ().length = 0.01; + last.point.get_left_handle ().length = 0.01; + } - last.point.set_reflective_handles (true); - last.point.convert_to_curve (); p.move_action (p, x, y); last.point.set_reflective_handles (false); + + PenTool.selected_handle = h; + PenTool.active_handle = h; + PenTool.move_selected_handle = false; last.path.highlight_last_segment = true; - last.point.set_tie_handle (true); + if (previous_point == 0) { + last.point.set_tie_handle (true); + p.move_action (p, x, y); + } - p.move_action (p, x, y); + PenTool.retain_angle = false; } else { if (DrawingTools.get_selected_point_type () != PointType.QUADRATIC) { p.move_action (p, x, y); @@ -174,16 +216,33 @@ key_press_action.connect ((self, keyval) => { Tool p = PointTool.pen (); + unichar c = ((unichar) keyval).tolower (); + EditPoint ep; - switch (keyval) { + switch (c) { case 's': switch_to_line_mode (); break; case 'r': move_right_handle = !move_right_handle; state = MOVE_HANDLES; - move_action (self, last_x, last_y); - break; + break; + case 'p': + previous_point++; + state = MOVE_HANDLES; + break; + case 'w': + if (previous_point != 0) { + return_if_fail (current_path.points.size >= (previous_point + 1)); + ep = current_path.points.get (current_path.points.size - (previous_point + 1)); + } else { + return_if_fail (current_path.points.size >= 1); + ep = current_path.points.get (current_path.points.size - 1); + } + + ep.set_tie_handle (!ep.tie_handles); + + break; } p.key_press_action (p, keyval); @@ -245,6 +304,8 @@ } p.press_action (p, 3, x, y); + + PenTool.move_selected = true; p.move_action (p, x, y); } @@ -258,8 +319,10 @@ PenTool.move_selected = true; PenTool.active_path.hide_end_handle = (state == MOVE_POINT); + + current_path = last.path; } } }
--- a/libbirdfont/PenTool.vala +++ b/libbirdfont/PenTool.vala @@ -46,8 +46,8 @@ public static EditPoint selected_point; - private static double last_point_x = 0; - private static double last_point_y = 0; + public static double last_point_x = 0; + public static double last_point_y = 0; public static bool show_selection_box = false; private static double selection_box_x = 0; @@ -76,7 +76,9 @@ public static double path_stroke_width = 0; public static double simplification_threshold = 0.5; - + + public static bool retain_angle = false; + public PenTool (string name) { base (name, t_("Add new points")); @@ -535,13 +537,19 @@ control_point_event (x, y); curve_active_corner_event (x, y); set_default_handle_positions (); - + + if (move_selected_handle && move_selected) { + warning ("move_selected_handle && move_selected"); + move_selected = false; + move_selected_handle = true; + } + // move control point handles if (move_selected_handle) { set_type_for_moving_handle (); - // don't update angle if the user is pressing shift - if (KeyBindings.modifier == SHIFT) { + // don't update angle if the user is holding down shift + if (KeyBindings.modifier == SHIFT || PenTool.retain_angle) { angle = selected_handle.angle; } @@ -549,25 +557,26 @@ coordinate_x = Glyph.path_coordinate_x (x); coordinate_y = Glyph.path_coordinate_y (y); GridTool.tie_coordinate (ref coordinate_x, ref coordinate_y); - delta_coordinate_x = coordinate_x - selected_handle.x; - delta_coordinate_y = coordinate_y - selected_handle.y; - selected_handle.move_delta_coordinate (delta_coordinate_x, delta_coordinate_y); + delta_coordinate_x = coordinate_x - last_point_x; + delta_coordinate_y = coordinate_y - last_point_y; + selected_handle.move_to_coordinate (selected_handle.x + delta_coordinate_x, selected_handle.y + delta_coordinate_y); } else if (GridTool.has_ttf_grid ()) { + // FIXME: coordinate_x = Glyph.path_coordinate_x (x); coordinate_y = Glyph.path_coordinate_y (y); GridTool.ttf_grid_coordinate (ref coordinate_x, ref coordinate_y); - delta_coordinate_x = coordinate_x - selected_handle.x; - delta_coordinate_y = coordinate_y - selected_handle.y; + delta_coordinate_x = coordinate_x - last_point_x; + delta_coordinate_y = coordinate_y - last_point_y; selected_handle.move_delta_coordinate (delta_coordinate_x, delta_coordinate_y); } else { coordinate_x = Glyph.path_coordinate_x (x); coordinate_y = Glyph.path_coordinate_y (y); - delta_coordinate_x = coordinate_x - selected_handle.x; - delta_coordinate_y = coordinate_y - selected_handle.y; + delta_coordinate_x = coordinate_x - last_point_x; + delta_coordinate_y = coordinate_y - last_point_y; selected_handle.move_delta_coordinate (delta_coordinate_x, delta_coordinate_y); } - if (KeyBindings.modifier == SHIFT) { + if (KeyBindings.modifier == SHIFT || PenTool.retain_angle) { selected_handle.angle = angle; selected_handle.process_connected_handle ();