The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Fix tool selection

These changes was commited to the Birdfont repository Mon, 15 Jun 2015 08:48:01 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Mon, 15 Jun 2015 08:48:01 +0000]

Updated Files

libbirdfont/BirdFont.vala
libbirdfont/ColorPicker.vala
libbirdfont/DrawingTools.vala
libbirdfont/Expander.vala
libbirdfont/Gradient.vala
libbirdfont/MoveTool.vala
libbirdfont/Path.vala
libbirdfont/Stop.vala
libbirdfont/Toolbox.vala
--- a/libbirdfont/BirdFont.vala +++ b/libbirdfont/BirdFont.vala @@ -653,12 +653,12 @@ home = File.new_for_path (home_path); #endif - if (settings_directory != null) { + if (settings_subdirectory != null) { settings = get_child(home, (!) settings_subdirectory); } else { settings = get_child(home, "birdfont"); } - + if (!settings.query_exists ()) { DirUtils.create ((!) settings.get_path (), 0755); }
--- a/libbirdfont/ColorPicker.vala +++ b/libbirdfont/ColorPicker.vala @@ -25,6 +25,7 @@ public signal void fill_color_updated (); public signal void stroke_color_updated (); + public signal void gradient_color_updated (); bool update_color = false; public double bar_height; @@ -36,12 +37,18 @@ public Color stroke_color = new Color (0, 0, 0, 1); public Color fill_color = new Color (0, 0, 0, 1); + + public Gradient gradient = new Gradient (); + bool update_gradient = false; + int bars; + Stop current_stop = new Stop (); public ColorPicker (string tooltip = "") { base (null, tooltip); bar_height = 22 * Toolbox.get_scale (); - h = 5 * bar_height; + bars = 5; + h = bars * bar_height; stroke_color_updated.connect (() => { redraw (); @@ -49,7 +56,7 @@ }); panel_press_action.connect ((selected, button, tx, ty) => { - if (y <= ty <= y + 5 * bar_height) { + if (y <= ty <= y + bars * bar_height) { update_color = true; selected_bar = (int) ((ty - y) / bar_height); set_color_from_pointer (tx); @@ -67,6 +74,14 @@ panel_release_action.connect ((selected, button, tx, ty) => { update_color = false; }); + } + + public void set_gradient (Gradient g, bool update_gradient) { + gradient = g; + this.update_gradient = update_gradient; + return_if_fail (g.stops.size > 0); + current_stop = g.stops.get (0); + redraw (); } public void set_color (Color c) { @@ -90,7 +105,7 @@ b = (double) tx / Toolbox.allocation_width; } else if (selected_bar == 3) { a = (double) tx / Toolbox.allocation_width; - } else if (selected_bar == 4) { + } else if (!update_gradient && selected_bar == 4) { if (has_stroke_color) { stroke_selected = tx > Toolbox.allocation_width / 2.0; @@ -99,15 +114,26 @@ } else { set_color (fill_color); } + } + } else if (update_gradient && selected_bar == 4) { + if (gradient.stops.size > 0) { + int g = (int) ((double) Toolbox.allocation_width / gradient.stops.size); + return_if_fail (0 <= g < gradient.stops.size); + current_stop = gradient.stops.get (g); } } - if (has_stroke_color && stroke_selected) { - stroke_color = new Color.hsba (hue, s, b, a); - stroke_color_updated (); + if (update_gradient) { + current_stop.color = new Color.hsba (hue, s, b, a); + gradient_color_updated (); } else { - fill_color = new Color.hsba (hue, s, b, a); - fill_color_updated (); + if (has_stroke_color && stroke_selected) { + stroke_color = new Color.hsba (hue, s, b, a); + stroke_color_updated (); + } else { + fill_color = new Color.hsba (hue, s, b, a); + fill_color_updated (); + } } } @@ -161,8 +187,11 @@ cr.rectangle (p * Toolbox.allocation_width, y + 3 * bar_height, scale, bar_height); cr.fill (); cr.restore (); - + } + + if (!update_gradient) { if (!has_stroke_color) { + c = fill_color; cr.save (); cr.set_source_rgba (c.r, c.g, c.b, c.a); cr.rectangle (0, y + 4 * bar_height, Toolbox.allocation_width, bar_height); @@ -199,9 +228,30 @@ cr.stroke (); cr.restore (); } + } + } + } else { // update gradient + int stop_size = (int) ((double) Toolbox.allocation_width / gradient.stops.size); + for (int i = 0; i < gradient.stops.size; i++) { + Stop s = gradient.stops.get (i); + c = s.color; + cr.save (); + cr.set_source_rgba (c.r, c.g, c.b, c.a); + cr.rectangle (i * stop_size, y + 4 * bar_height, stop_size, bar_height); + cr.fill (); + cr.restore (); + + if (s == current_stop) { + cr.save (); + Theme.color (cr, "Tool Foreground"); + cr.set_line_width (1); + cr.rectangle (i * stop_size, y + 4 * bar_height, stop_size, bar_height); + cr.stroke (); + cr.restore (); } } } + } void draw_dial (Context cr, double px, double py, int bar_index, double val) {
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -1385,7 +1385,10 @@ hide_all_modifiers (); - move_background.set_selected (false); + foreach (Tool t in draw_tools.tool) { + t.set_selected (false); + } + cut_background.set_selected (false); bezier_tool.set_selected (false); @@ -1412,6 +1415,7 @@ flip_horizontal.set_selected (false); current_tool.set_selected (true); + current_tool.select_action (current_tool); if (resize_tool.is_selected () || move_tool.is_selected ()) { show_object_tool_modifiers ();
--- a/libbirdfont/Expander.vala +++ b/libbirdfont/Expander.vala @@ -249,6 +249,8 @@ } } + // FIXME: delete + /* if (!is_persistent () && !selected.persistent) { var time = new TimeoutSource(200); time.set_callback(() => { @@ -257,7 +259,7 @@ return false; }); time.attach(null); - } + }*/ selected.new_selection = false; });
--- a/libbirdfont/Gradient.vala +++ b/libbirdfont/Gradient.vala @@ -23,7 +23,7 @@ public double x2 = 0; public double y2 = 0; - Gee.ArrayList<Stop> stops = new Gee.ArrayList<Stop> (); + public Gee.ArrayList<Stop> stops = new Gee.ArrayList<Stop> (); public Gradient () { }
--- a/libbirdfont/MoveTool.vala +++ b/libbirdfont/MoveTool.vala @@ -51,8 +51,6 @@ }); select_action.connect((self) => { - Glyph glyph = MainWindow.get_current_glyph (); - glyph.close_path (); }); deselect_action.connect((self) => { @@ -473,7 +471,6 @@ Glyph g = MainWindow.get_current_glyph (); g.clear_active_paths (); - foreach (Path p in g.get_paths_in_current_layer ()) { if (p.points.size > 0) { g.add_active_path (p);
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -82,6 +82,8 @@ public Color? color = null; public Color? stroke_color = null; + + public Gradient? gradient = null; public Path () { string width; @@ -1011,6 +1013,14 @@ foreach (EditPoint ep in points) { ep.x += delta_x; ep.y += delta_y; + } + + if (gradient != null) { + Gradient g = (!) gradient; + g.x1 += delta_x; + g.x2 += delta_x; + g.y1 += delta_y; + g.y2 += delta_y; } update_region_boundaries ();
--- a/libbirdfont/Stop.vala +++ b/libbirdfont/Stop.vala @@ -19,7 +19,7 @@ public class Stop : GLib.Object { public Color color = Color.black (); - double offset = 0; + public double offset = 0; public Stop () { }
--- a/libbirdfont/Toolbox.vala +++ b/libbirdfont/Toolbox.vala @@ -86,6 +86,10 @@ }); update_expanders (); + } + + public static DrawingTools get_drawing_tools () { + return drawing_tools; } public static void set_toolbox_from_tab (string tab_name, Tab? t = null) {