Commit fd432a8
color and line width
Changed files (14)
modifiedbirdfont/GtkWindow.valamodifiedicons/active_edit_point.pngmodifiedicons/active_edit_point_handle.pngmodifiedicons/active_selected_edit_point.pngmodifiedicons/edit_point.pngmodifiedicons/edit_point_handle.pngmodifiedicons/selected_edit_point.pngmodifiedlibbirdfont/Birdfont.valaaddedlibbirdfont/ColorTool.valamodifiedlibbirdfont/NativeWindow.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/Supplement.valamodifiedlibbirdfont/Tool.valamodifiedlibbirdfont/Toolbox.vala
Diff
@@ -235,6 +235,29 @@ public class GtkWindow : Gtk.Window, NativeWindow { show_all (); } + public void color_selection (ColorTool color_tool) {+ ColorWindow c = new ColorWindow (color_tool);+ }+ + class ColorWindow : Gtk.Window {+ ColorSelection color_selection = new ColorSelection ();++ public ColorWindow (ColorTool color_tool) { + color_selection.color_changed.connect (() => {+ Color c;+ color_selection.get_current_color (out c);+ color_tool.color_r = (double) c.red / uint16.MAX;+ color_tool.color_g = (double) c.green / uint16.MAX;+ color_tool.color_b = (double) c.blue / uint16.MAX;+ color_tool.color_a = (double) color_selection.get_current_alpha () / uint16.MAX; + color_tool.color_updated ();+ });+ + add (color_selection);+ show_all ();+ } + }+ public string get_clipboard () { SelectionData selection_data; Atom target;Binary files a/icons/active_edit_point.png and b/icons/active_edit_point.png differBinary files a/icons/active_edit_point_handle.png and b/icons/active_edit_point_handle.png differBinary files a/icons/active_selected_edit_point.png and b/icons/active_selected_edit_point.png differBinary files a/icons/edit_point.png and b/icons/edit_point.png differBinary files a/icons/edit_point_handle.png and b/icons/edit_point_handle.png differBinary files a/icons/selected_edit_point.png and b/icons/selected_edit_point.png differ@@ -94,10 +94,10 @@ public static int run_export (string[] arg) { LogLevelFlags levels = LogLevelFlags.LEVEL_ERROR | LogLevelFlags.LEVEL_CRITICAL | LogLevelFlags.LEVEL_WARNING; Log.set_handler (null, levels, supplement.fatal_warning); }-+ Preferences preferences = new Preferences (); preferences.load ();- + supplement.args = new Argument (""); supplement.current_font = new Font (); supplement.current_glyph = new Glyph ("");new file mode 100644@@ -0,0 +1,74 @@+/*+ Copyright (C) 2012 Johan Mattsson++ This program is free software: you can redistribute it and/or modify+ it under the terms of the GNU General Public License as published by+ the Free Software Foundation, either version 3 of the License, or+ (at your option) any later version.++ This program 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 General Public License for more details.++ You should have received a copy of the GNU General Public License+ along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++using Cairo;++namespace Supplement {++public class ColorTool : Tool {+ + public double color_r = 0;+ public double color_g = 0;+ public double color_b = 0;+ public double color_a = 0;+ + public signal void color_updated ();+ + public ColorTool (string tool_tip) {+ base ("color_selection", tool_tip);++ select_action.connect((self) => {+ MainWindow.native_window.color_selection (this);+ });+ + color_updated.connect (() => {+ MainWindow.get_toolbox ().redraw ((int)x, (int)y, (int)x + 20, (int)y + 20);+ });+ }+ + public override void draw (Context cr) {+ double xt = x + 4 + w;+ double yt = y + h + 16;+ + base.draw (cr);+ + cr.save ();+ cr.set_source_rgba (color_r, color_g, color_b, 1);+ cr.rectangle (xt, yt, 16, 16);+ cr.fill ();+ cr.restore ();+ }+ + public void set_r (double c) {+ color_r = c;+ }++ public void set_g (double c) {+ color_g = c;+ }++ public void set_b (double c) {+ color_b = c;+ }++ public void set_a (double c) {+ color_a = c;+ }++}++}@@ -30,6 +30,8 @@ public interface NativeWindow : GLib.Object { public abstract void set_clipboard (string data); public abstract void set_inkscape_clipboard (string data); + public abstract void color_selection (ColorTool color_tool);+ protected void webkit_callback (string s) { FontDisplay fd = MainWindow.get_current_display (); fd.process_property (s);@@ -60,7 +60,16 @@ public class Path { Path quadratic_path; // quadratic points for TrueType export + public static double line_color_r = 0;+ public static double line_color_g = 0;+ public static double line_color_b = 0;+ public static double line_color_a = 1;+ + public static double stroke_width = 1;+ public Path () {+ string width;+ if (edit_point_image == null) { edit_point_image = Icons.get_icon ("edit_point.png"); active_edit_point_image = Icons.get_icon ("active_edit_point.png");@@ -68,6 +77,16 @@ public class Path { active_edit_point_handle_image = Icons.get_icon ("active_edit_point_handle.png"); selected_edit_point_image = Icons.get_icon ("selected_edit_point.png"); active_selected_edit_point_image = Icons.get_icon ("active_selected_edit_point.png");+ + width = Preferences.get ("stroke_width");+ if (width != "") {+ stroke_width = double.parse (width);++ line_color_r = double.parse (Preferences.get ("line_color_r"));+ line_color_g = double.parse (Preferences.get ("line_color_g"));+ line_color_b = double.parse (Preferences.get ("line_color_b"));+ line_color_a = double.parse (Preferences.get ("line_color_a"));+ } } } @@ -178,8 +197,8 @@ public class Path { get_bezier_points (e, en, out xa, out ya, out xb, out yb, out xc, out yc, out xd, out yd); - cr.set_source_rgba (0, 0, 0, alpha);- cr.set_line_width (1 / g.view_zoom);+ cr.set_source_rgba (line_color_r, line_color_g, line_color_b, line_color_a);+ cr.set_line_width (stroke_width / g.view_zoom); cr.line_to (xa, ya); // this point makes sense only if it is the first or last position, the other points are meaning less don't export them @@ -241,8 +260,8 @@ public class Path { get_line_points (e, en, out ax, out ay, out bx, out by); - cr.set_source_rgba (0/255.0, 0/255.0, 0/255.0, 1);- cr.set_line_width (1.7 * (1/g.view_zoom));+ cr.set_source_rgba (line_color_r, line_color_g, line_color_b, line_color_a);+ cr.set_line_width (1.7 * (stroke_width / g.view_zoom)); cr.line_to (ax, ay); cr.line_to (bx, by);@@ -294,22 +313,24 @@ public class Path { public static void draw_img_center (Context cr, ImageSurface img, double x, double y) { Glyph g = MainWindow.get_current_glyph ();+ double r = 1.0 / 10.0;+ + double width = Math.sqrt (stroke_width); double ivz = 1 / g.view_zoom;+ double ivs = 1 / width; double xc = g.allocation.width / 2.0; double yc = g.allocation.height / 2.0; cr.save ();-- cr.scale (ivz, ivz);+ cr.scale (ivz * width * r, ivz * width * r); - x = xc + x - (img.get_width () / 2.0) * ivz; - y = yc - y - (img.get_height () / 2.0) * ivz;+ x = xc + x - (width * r * img.get_width () / 2.0) * ivz; + y = yc - y - (width * r * img.get_height () / 2.0) * ivz; - cr.set_source_surface (img, x * g.view_zoom, y * g.view_zoom);+ cr.set_source_surface (img, x * g.view_zoom * ivs * 1/r, y * g.view_zoom * ivs * 1/r); cr.paint ();- cr.restore (); } @@ -59,6 +59,9 @@ public class Supplement { Process.exit (0); } + Preferences preferences = new Preferences (); + preferences.load (); + current_font = new Font (); current_glyph = new Glyph (""); @@ -80,10 +83,7 @@ public class Supplement { } else { exec_path = "./"; } - - Preferences preferences = new Preferences (); - preferences.load (); - + if (args.get_file () != "") { font_file = File.new_for_path (args.get_file ()); @@ -140,7 +140,7 @@ public class Tool : GLib.Object { } public bool is_selected () {- return selected;+ return selected; } public virtual void set_properties (double tx, double ty, double tw, double th) {@@ -68,6 +68,7 @@ public class Toolbox : GLib.Object { Expander view_tools = new Expander (); Expander grid = new Expander (); Expander background_tools = new Expander ();+ Expander style_tools = new Expander (); grid_expander = grid; @@ -172,7 +173,7 @@ public class Toolbox : GLib.Object { precision.set_max (1); draw_tool_modifiers.add_tool (precision);- + // path tools Tool union_paths_tool = new MergeTool ("union_paths"); path_tool_modifiers.add_tool (union_paths_tool);@@ -243,7 +244,7 @@ public class Toolbox : GLib.Object { MainWindow.get_tab_bar ().select_tab_name ("Overview"); }); characterset_tools.add_tool (delete_glyph);- + if (Supplement.has_argument ("--test")) { Tool test_case = new Tool ("test_case"); test_case.select_action.connect((self) => {@@ -472,9 +473,49 @@ public class Toolbox : GLib.Object { b.set_contrast (background_contrast.get_value ()); } });++ // color and style+ ColorTool stroke_color = new ColorTool (_("Stroke color"));+ stroke_color.color_updated.connect (() => {+ Path.line_color_r = stroke_color.color_r;+ Path.line_color_g = stroke_color.color_g;+ Path.line_color_b = stroke_color.color_b;+ Path.line_color_a = stroke_color.color_a;++ Preferences.set ("line_color_r", @"$(Path.line_color_r)");+ Preferences.set ("line_color_g", @"$(Path.line_color_g)");+ Preferences.set ("line_color_b", @"$(Path.line_color_b)");+ Preferences.set ("line_color_a", @"$(Path.line_color_a)");++ Glyph g = MainWindow.get_current_glyph ();+ g.redraw_area (0, 0, g.allocation.width, g.allocation.height);+ }); - // Fixa: background_tools.add_tool (background_contrast);+ stroke_color.set_r (double.parse (Preferences.get ("line_color_r")));+ stroke_color.set_g (double.parse (Preferences.get ("line_color_g")));+ stroke_color.set_b (double.parse (Preferences.get ("line_color_b")));+ stroke_color.set_a (double.parse (Preferences.get ("line_color_a"))); + style_tools.add_tool (stroke_color);+ + SpinButton stroke_width;+ stroke_width = new SpinButton ("stroke_width", _("Stroke width"));+ + if (Preferences.get ("stroke_width") == "") {+ stroke_width.set_value_round (1);+ } else {+ stroke_width.set_value (Preferences.get ("stroke_width"));+ }+ + stroke_width.new_value_action.connect((self) => {+ Glyph g = MainWindow.get_current_glyph ();+ Path.stroke_width = stroke_width.get_value ();+ g.redraw_area (0, 0, g.allocation.width, g.allocation.height);+ Preferences.set ("stroke_width", @"$(Path.stroke_width)");+ redraw ((int) stroke_width.x, (int) stroke_width.y, 70, 70);+ });+ style_tools.add_tool (stroke_width);+ draw_tools.set_open (true); draw_tool_modifiers.set_open (true); path_tool_modifiers.set_open (true);@@ -484,6 +525,7 @@ public class Toolbox : GLib.Object { test_tools.set_open (true); guideline_tools.set_open (true); background_tools.set_open (true);+ style_tools.set_open (true); add_expander (draw_tools); add_expander (draw_tool_modifiers);@@ -494,6 +536,7 @@ public class Toolbox : GLib.Object { add_expander (grid); add_expander (view_tools); add_expander (background_tools);+ add_expander (style_tools); // Fixa: add_expander (trace);