Commit 9b156fa
Show curve orientation with an arrow
Changed files (6)
modifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/Glyph.valaaddedlibbirdfont/OrientationTool.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/Theme.valamodifiedresources/icons.bf
Diff
@@ -85,7 +85,7 @@ public class DrawingTools : ToolCollection { Tool undo_tool; Tool select_all_button; - Tool reverse_path_tool;+ OrientationTool reverse_path_tool; Tool move_layer; Tool flip_vertical; Tool flip_horizontal;@@ -579,16 +579,7 @@ public class DrawingTools : ToolCollection { }); draw_tool_modifiers.add_tool (create_line); - reverse_path_tool = new Tool ("reverse_path", t_("Create counter from outline"));- reverse_path_tool.select_action.connect ((self) => {- Glyph g = MainWindow.get_current_glyph ();- - foreach (Path p in g.active_paths) {- p.reverse ();- }- - g.redraw_area (0, 0, g.allocation.width, g.allocation.height);- });+ reverse_path_tool = new OrientationTool ("reverse_path", t_("Create counter from outline")); draw_tool_modifiers.add_tool (reverse_path_tool); move_layer = new Tool ("move_layer", t_("Move to path to the bottom layer"));@@ -106,6 +106,8 @@ public class Glyph : FontDisplay { public const double CANVAS_MIN = -10000; public const double CANVAS_MAX = 10000; + public bool show_orientation_arrow = false;+ public Glyph (string name, unichar unichar_code = 0) { this.name = name; this.unichar_code = unichar_code;@@ -1437,7 +1439,7 @@ public class Glyph : FontDisplay { /** Draw filled paths. */ public void draw_paths (Context cr) { PathList stroke;- + cr.save (); cr.new_path (); foreach (Path p in path_list) {@@ -1453,12 +1455,14 @@ public class Glyph : FontDisplay { } public void draw_path (Context cr) {+ PathList stroke; if (is_open () && Path.fill_open_path) { cr.save (); cr.new_path (); foreach (Path p in path_list) { if (p.stroke > 0) {- draw_path_list (StrokeTool.get_stroke (p, p.stroke), cr, get_path_fill_color ());+ stroke = StrokeTool.get_stroke (p, p.stroke);+ draw_path_list (stroke, cr, get_path_fill_color ()); } p.draw_path (cr, this, get_path_fill_color ());@@ -1471,27 +1475,29 @@ public class Glyph : FontDisplay { cr.save (); cr.new_path (); foreach (Path p in path_list) {- if (p.stroke > 0) { - draw_outline_for_paths (StrokeTool.get_stroke (p, p.stroke), cr);+ if (p.stroke > 0) {+ stroke = StrokeTool.get_stroke (p, p.stroke);+ draw_outline_for_paths (stroke, cr); } p.draw_outline (cr);- p.draw_edit_points (cr); + p.draw_edit_points (cr); } cr.restore (); }-+ if (!is_open ()) { // This was good for testing but it is way too slow: // Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () - baseline);- + cr.save (); cr.new_path (); foreach (Path p in path_list) { if (p.stroke == 0) { p.draw_path (cr, this, Color.black ()); } else {- draw_path_list (StrokeTool.get_stroke (p, p.stroke), cr, Color.black ());+ stroke = StrokeTool.get_stroke (p, p.stroke);+ draw_path_list (stroke, cr, Color.black ()); } } cr.close_path ();@@ -1511,6 +1517,19 @@ public class Glyph : FontDisplay { cr.restore (); } }+ + if (show_orientation_arrow) {+ foreach (Path p in path_list) {+ if (p.stroke > 0) {+ stroke = StrokeTool.get_stroke (p, p.stroke);+ foreach (Path ps in stroke.paths) {+ ps.draw_orientation_arrow (cr);+ } + } else {+ p.draw_orientation_arrow (cr);+ }+ }+ } } private Color get_path_fill_color () {new file mode 100644@@ -0,0 +1,65 @@+/*+ Copyright (C) 2015 Johan Mattsson++ This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version.++ This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details.+*/++using Math;+using Cairo;++namespace BirdFont {++public class OrientationTool : Tool {++ public OrientationTool (string n, string tip) {+ base (n, tip);++ select_action.connect ((self) => {+ Glyph g = MainWindow.get_current_glyph ();+ + foreach (Path p in g.active_paths) {+ p.reverse ();+ }+ + GlyphCanvas.redraw ();+ });++ panel_move_action.connect ((t, x, y) => {+ Glyph g = MainWindow.get_current_glyph ();+ + if (!g.show_orientation_arrow && is_active ()) {+ g.show_orientation_arrow = true;+ GlyphCanvas.redraw ();+ }+ + return false;+ });+ + move_out_action.connect ((t) => {+ Glyph g = MainWindow.get_current_glyph ();+ + if (g.show_orientation_arrow) {+ g.show_orientation_arrow = false;+ GlyphCanvas.redraw ();+ }+ });+ + draw_action.connect ((self, cr, glyph) => {+ draw_actions (cr);+ });+ }+ + public static void draw_actions (Context cr) {++ }+}++}@@ -280,12 +280,42 @@ public class Path { c = (!) color; cr.set_source_rgba (c.r, c.g, c.b, c.a); } else {- if (is_clockwise ()) {- cr.set_source_rgba (80/255.0, 95/255.0, 137/255.0, 0.5);- } else {- cr.set_source_rgba (144/255.0, 145/255.0, 236/255.0, 0.5);+ Theme.color (cr, "Selected Objects");+ }+ }++ public void draw_orientation_arrow (Context cr) {+ EditPoint top = new EditPoint ();+ double max = Glyph.CANVAS_MIN;+ Text arrow;+ double x, y, angle;+ double size = 50 * Glyph.ivz ();+ + foreach (EditPoint e in points) {+ if (e.y > max) {+ max = e.y;+ top = e; } }+ + arrow = new Text ("orientation_arrow", size);+ arrow.load_font ("icons.bf");+ arrow.use_cache (false);+ + Theme.text_color (arrow, "Highlighted 1");++ angle = top.get_right_handle ().angle;+ x = Glyph.xc () + top.x + cos (angle + PI / 2) * 10 * Glyph.ivz (); + y = Glyph.yc () - top.y - sin (angle + PI / 2) * 10 * Glyph.ivz ();+ + cr.save ();+ cr.translate (x, y);+ cr.rotate (-angle);+ cr.translate (-x, -y); + + arrow.draw_at_baseline (cr, x, y);+ + cr.restore (); } private void draw_next (EditPoint e, EditPoint en, Context cr, bool highlighted = false) {@@ -100,6 +100,7 @@ public class Theme : GLib.Object { Theme.set_default_color ("Stroke Color", 0, 0, 0, 1); Theme.set_default_color ("Handle Color", 0, 0, 0, 1); Theme.set_default_color ("Fill Color", 0.5, 0.5, 0.5, 1);+ Theme.set_default_color ("Selected Objects", 0.5, 0.5, 0.5, 1); Theme.set_default_color ("Background 1", 1, 1, 1, 1); Theme.set_default_color ("Background 2", 101 / 255.0, 108 / 255.0, 116 / 255.0, 1);@@ -576,6 +576,12 @@ GNU Lesser General Public License</copyright> <glyph id="1" left="-28" right="28"> </glyph> </collection>+<collection name="orientation_arrow">+ <selected id="1"/>+ <glyph id="1" left="-28" right="28">+ <path stroke="0" skew="0" data="S -41.4110032362,2.3559870550 L -21.4110032362,2.3559870550 L -21.4110032362,6.3559870550 L -13.1715210356,0.0809061489 L -21.4110032362,-5.6440129450 L -21.4110032362,-5.6440129450 L -21.4110032362,-1.6440129450 L -41.4110032362,-1.6440129450 L -41.4110032362,2.3559870550" />+ </glyph>+</collection> <collection unicode="U+70"> <selected id="1"/> <glyph id="1" left="-28" right="28">@@ -971,6 +977,7 @@ GNU Lesser General Public License</copyright> <ligature sequence="n e x t _ k e r n i n g _ s t r i n g" replacement="next_kerning_string"/> <ligature sequence="k e r n i n g _ t e x t _ i n p u t" replacement="kerning_text_input"/> <ligature sequence="c o n t r a s t _ t h r e s h o l d" replacement="contrast_threshold"/>+<ligature sequence="o r i e n t a t i o n _ a r r o w" replacement="orientation_arrow"/> <ligature sequence="d e l e t e _ b a c k g r o u n d" replacement="delete_background"/> <ligature sequence="n e w _ p o i n t _ o n _ p a t h" replacement="new_point_on_path"/> <ligature sequence="i n s e r t _ b a c k g r o u n d" replacement="insert_background"/>