The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

New selection box

These changes was commited to the Birdfont repository Sun, 17 Jan 2016 22:12:30 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 17 Jan 2016 22:12:30 +0000 (23:12 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 17 Jan 2016 22:12:30 +0000 (23:12 +0100)
commit 3b04821b9fbcecdb72e57b6ae64d9644e901bbba
tree 84fd1ea3bd37112a2719fb6316d526d76911809a
parent 26e337be389f1befdddf0dcc0cf56cb818a52013
New selection box

libbirdfont/Glyph.vala
libbirdfont/PathObject.vala
libbirdfont/Theme.vala
resources/dark.theme
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -142,6 +142,11 @@ public Surface? overview_thumbnail = null; + public double selection_box_width = 0; + public double selection_box_height = 0; + public double selection_box_x = 0; + public double selection_box_y = 0; + public Glyph (string name, unichar unichar_code = 0) { this.name = name; this.unichar_code = unichar_code; @@ -1609,10 +1614,12 @@ bool has_path = false; foreach (SvgBird.Object object in get_visible_objects ()) { - if (object is PathObject && object.stroke > 0) { + if (object is PathObject + && object.stroke > 0) { + has_path = true; PathObject object_path = (PathObject) object; - object_path.draw_path (cr); + object_path.draw_outline (cr); } } @@ -1624,16 +1631,18 @@ has_path = false; foreach (SvgBird.Object object in get_visible_objects ()) { - if (object is PathObject && object.stroke == 0) { + if (object is PathObject + && object.stroke == 0) { + has_path = true; PathObject object_path = (PathObject) object; - object_path.draw_path (cr); + object_path.draw_outline (cr); } } if (has_path) { cr.set_fill_rule (FillRule.EVEN_ODD); - cr.set_source_rgba (0, 0, 0, 1); + Theme.color (cr, "Objects"); cr.fill (); } @@ -1645,6 +1654,14 @@ cr.set_line_width (CanvasSettings.stroke_width / g.view_zoom); object_path.path.draw_outline (cr); object_path.path.draw_control_points (cr); + } + } + } + + if (show_orientation_arrow) { + foreach (Path p in get_visible_paths ()) { + if (p.stroke == 0) { + p.draw_orientation_arrow (cr, orientation_arrow_opacity); } } } @@ -1708,17 +1725,26 @@ cmp.save (); cmp.scale (view_zoom, view_zoom); cmp.translate (-view_offset_x, -view_offset_y); - draw_layers (cmp); + draw_layers (cmp); cmp.restore (); - + + Tool selected_tool = MainWindow.get_toolbox ().get_current_tool (); + bool draw_selection = active_paths.size > 0 + && (selected_tool is MoveTool || selected_tool is ResizeTool); + + if (draw_selection) { + update_selection_boundaries (); + draw_selection_box (cmp); + } + cmp.save (); tool = MainWindow.get_toolbox ().get_current_tool (); tool.draw_action (tool, cmp, this); cmp.restore (); } - private void zoom_in_at_point (double x, double y, double amount = 15) { - int n = (int) (-amount); + private void zoom_in_at_point (double x, double y, double zoom = 15) { + int n = (int) (-zoom); zoom_at_point (x, y, n); } @@ -2397,8 +2423,111 @@ cr.stroke (); cr.restore (); + } + + void draw_selection_box (Context cr) { + double x, y, w, h; + double hook_width; + + x = reverse_path_coordinate_x (selection_box_x); + y = reverse_path_coordinate_y (selection_box_y); + w = selection_box_width / ivz (); + h = selection_box_height / ivz (); + + hook_width = w > 20 ? 10 : w * 0.2; + + update_selection_boundaries (); + cr.save (); + + // FIXME: use color theme + cr.set_source_rgba (0, 0, 0, 1); + + cr.set_line_width (1); + cr.move_to (x, y + hook_width); + cr.line_to (x, y); + cr.line_to (x + hook_width, y); + cr.stroke (); + + cr.move_to (x + w - hook_width, y); + cr.line_to (x + w, y); + cr.line_to (x + w, y + hook_width); + cr.stroke (); + + cr.move_to (x + w, y + h - hook_width); + cr.line_to (x + w, y + h); + cr.line_to (x + w - hook_width, y + h); + + cr.move_to (x + hook_width, y + h); + cr.line_to (x, y + h); + cr.line_to (x, y + h - hook_width); + + cr.stroke (); + cr.restore (); + + cr.save (); + cr.set_source_rgba (1, 1, 1, 1); + + cr.set_line_width (1); + cr.move_to (x + 1, y + hook_width); + cr.line_to (x + 1, y + 1); + cr.line_to (x + hook_width, y + 1); + cr.stroke (); + + cr.move_to (x + w - hook_width, y + 1); + cr.line_to (x + w - 1, y + 1); + cr.line_to (x + w - 1, y + hook_width); + cr.stroke (); + + cr.move_to (x + w - 1, y + h - hook_width); + cr.line_to (x + w - 1, y + h - 1); + cr.line_to (x + w - hook_width, y + h - 1); + + cr.move_to (x + hook_width, y + h - 1); + cr.line_to (x + 1, y + h - 1); + cr.line_to (x + 1, y + h - hook_width); + + cr.stroke (); + cr.restore (); + } + + public void update_selection_boundaries () { + get_selection_box_boundaries (out selection_box_x, + out selection_box_y, out selection_box_width, + out selection_box_height); + } + + public void get_selection_box_boundaries (out double x, out double y, out double w, out double h) { + double px, py, px2, py2; + + px = CANVAS_MAX; + py = CANVAS_MAX; + px2 = CANVAS_MIN; + py2 = CANVAS_MIN; + + foreach (Path p in get_active_paths ()) { + if (px > p.xmin) { + px = p.xmin; + } + + if (py > p.ymin) { + py = p.ymin; + } + + if (px2 < p.xmax) { + px2 = p.xmax; + } + + if (py2 < p.ymax) { + py2 = p.ymax; + } + } + + w = px2 - px; + h = py2 - py; + x = px; + y = py2; } } }
--- a/libbirdfont/PathObject.vala +++ b/libbirdfont/PathObject.vala @@ -102,37 +102,9 @@ } public override void draw_outline (Context cr) { - draw_path (cr); - } - - private SvgBird.Color get_path_fill_color () { - Color c = Theme.get_color ("Fill Color"); - return new SvgBird.Color (c.r, c.g, c.b, c.a); - } - - public void draw_path (Context cr) { // FIXME: delete - PathList path_stroke; - bool open; - - if (path.stroke > 0) { - cr.set_fill_rule (FillRule.WINDING); - path_stroke = path.get_stroke_fast (); - draw_path_list (path_stroke, cr); - } else { - cr.set_fill_rule (FillRule.EVEN_ODD); - open = path.is_open (); - - if (open) { - path.close (); - path.recalculate_linear_handles (); - } - - path.draw_path (cr); - - if (open) { - path.reopen (); - } - } + PathList pl = new PathList (); + pl.add (path); + draw_path_list (pl, cr); } public static void draw_path_list (PathList pl, Context cr) {
--- a/libbirdfont/Theme.vala +++ b/libbirdfont/Theme.vala @@ -103,8 +103,8 @@ Theme.set_default_color ("Stroke Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); Theme.set_default_color ("Handle Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); Theme.set_default_color ("Fill Color", 0.5, 0.5, 0.5, 1); - Theme.set_default_color ("Selected Objects", 35 / 255.0, 131 / 255.0, 194 / 255.0, 1); - + Theme.set_default_color ("Objects", 0, 0, 0, 1); + Theme.set_default_color ("Background 1", 1, 1, 1, 1); Theme.set_default_color ("Dialog Background", 238 / 255.0, 239 / 255.0, 243 / 255.0, 1); Theme.set_default_color ("Menu Background", 222 / 255.0, 221 / 255.0, 226 / 255.0, 1); @@ -210,7 +210,7 @@ Theme.set_default_color ("Stroke Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); Theme.set_default_color ("Handle Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); Theme.set_default_color ("Fill Color", 0.5, 0.5, 0.5, 1); - Theme.set_default_color ("Selected Objects", 35 / 255.0, 131 / 255.0, 194 / 255.0, 1); + Theme.set_default_color ("Objects", 0, 0, 0, 1); Theme.set_default_color ("Background 1", 1, 1, 1, 1); Theme.set_default_color ("Dialog Background", 55 / 255.0, 56 / 255.0, 62 / 255.0, 1); @@ -315,7 +315,7 @@ Theme.set_default_color ("Stroke Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); Theme.set_default_color ("Handle Color", 141 / 255.0, 141 / 255.0, 141 / 255.0, 1); Theme.set_default_color ("Fill Color", 0, 0, 0, 1); - Theme.set_default_color ("Selected Objects", 0, 0, 0, 1); + Theme.set_default_color ("Objects", 0, 0, 0, 1); Theme.set_default_color ("Background 1", 1, 1, 1, 1); Theme.set_default_color ("Dialog Background", 1, 1, 1, 1); @@ -424,6 +424,7 @@ t_("Handle Color"); t_("Fill Color"); t_("Selected Objects"); + t_("Objects"); t_("Background 1"); t_("Dialog Background");
--- a/resources/dark.theme +++ b/resources/dark.theme @@ -8,6 +8,7 @@ <color name="Guide 2" red="0.69999999999999996" green="0" blue="0" alpha="0.5"/> <color name="Guide 3" red="0.47058823529411764" green="0.26666666666666666" blue="0.47058823529411764" alpha="0.47058823529411764"/> <color name="Tab Separator" red="0.4823529411764706" green="0.49803921568627452" blue="0.51764705882352946" alpha="1"/> + <color name="Objects" red="0" green="0" blue="0" alpha="1"/> <color name="Overview Glyph" red="0.85882352941176465" green="0.8666666666666667" blue="0.9137254901960784" alpha="1"/> <color name="Dialog Shadow" red="0" green="0" blue="0" alpha="0.29999999999999999"/> <color name="Selected Active Cubic Control Point" red="0.91764705882352937" green="0.30196078431372547" blue="0.10196078431372549" alpha="1"/> @@ -57,7 +58,6 @@ <color name="Spin Button" red="0.41960784313725491" green="0.4392156862745098" blue="0.47843137254901963" alpha="1"/> <color name="Text Tool Box" red="0.50196078431372548" green="0.50980392156862742" blue="0.53333333333333333" alpha="1"/> <color name="Overview Foreground" red="0.17647058823529413" green="0.17647058823529413" blue="0.17647058823529413" alpha="1"/> - <color name="Selected Objects" red="0.13725490196078433" green="0.51372549019607838" blue="0.76078431372549016" alpha="1"/> <color name="Tool Foreground" red="0.4823529411764706" green="0.49803921568627452" blue="0.51764705882352946" alpha="1"/> <color name="Selected Quadratic Control Point" red="0.91764705882352937" green="0.30196078431372547" blue="0.10196078431372549" alpha="1"/> <color name="Checkbox Background" red="0.396078431372549" green="0.42352941176470588" blue="0.45490196078431372" alpha="1"/>