Commit e147293
Fix tool selection
Changed files (9)
modifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/ColorPicker.valamodifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/Expander.valamodifiedlibbirdfont/Gradient.valamodifiedlibbirdfont/MoveTool.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/Stop.valamodifiedlibbirdfont/Toolbox.vala
Diff
@@ -653,12 +653,12 @@ public class BirdFont { 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); }@@ -25,6 +25,7 @@ public class ColorPicker : Tool { 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;@@ -37,11 +38,17 @@ public class ColorPicker : Tool { 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 @@ public class ColorPicker : Tool { }); 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);@@ -69,6 +76,14 @@ public class ColorPicker : Tool { }); } + 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) { c.to_hsva (out hue, out s, out b, out a); }@@ -90,7 +105,7 @@ public class ColorPicker : Tool { 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; @@ -100,14 +115,25 @@ public class ColorPicker : Tool { 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 @@ public class ColorPicker : Tool { 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);@@ -201,7 +230,28 @@ public class ColorPicker : Tool { } } }+ } 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) {@@ -1385,7 +1385,10 @@ public class DrawingTools : ToolCollection { 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 @@ public class DrawingTools : ToolCollection { 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 ();@@ -249,6 +249,8 @@ public class Expander : GLib.Object { } } + // FIXME: delete+ /* if (!is_persistent () && !selected.persistent) { var time = new TimeoutSource(200); time.set_callback(() => {@@ -257,7 +259,7 @@ public class Expander : GLib.Object { return false; }); time.attach(null);- }+ }*/ selected.new_selection = false; });@@ -23,7 +23,7 @@ public class Gradient : GLib.Object { 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 () { }@@ -51,8 +51,6 @@ public class MoveTool : Tool { }); select_action.connect((self) => {- Glyph glyph = MainWindow.get_current_glyph ();- glyph.close_path (); }); deselect_action.connect((self) => {@@ -473,7 +471,6 @@ public class MoveTool : Tool { 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);@@ -83,6 +83,8 @@ public class Path : GLib.Object { public Color? color = null; public Color? stroke_color = null; + public Gradient? gradient = null;+ public Path () { string width; @@ -1013,6 +1015,14 @@ public class Path : GLib.Object { 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 (); } @@ -19,7 +19,7 @@ namespace BirdFont { public class Stop : GLib.Object { public Color color = Color.black ();- double offset = 0;+ public double offset = 0; public Stop () { }@@ -88,6 +88,10 @@ public class Toolbox : GLib.Object { update_expanders (); } + public static DrawingTools get_drawing_tools () {+ return drawing_tools;+ }+ public static void set_toolbox_from_tab (string tab_name, Tab? t = null) { if (tab_name == "Spacing") { current_set = (ToolCollection) spacing_tools;