Commit 7111e6b
Add a box for short help texts
Changed files (17)
modifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/Expander.valaaddedlibbirdfont/Help.valamodifiedlibbirdfont/KerningDisplay.valamodifiedlibbirdfont/LabelTool.valamodifiedlibbirdfont/LayerLabel.valamodifiedlibbirdfont/LicenseDialog.valamodifiedlibbirdfont/MainWindow.valamodifiedlibbirdfont/Menu.valamodifiedlibbirdfont/MenuItem.valamodifiedlibbirdfont/QuestionDialog.valamodifiedlibbirdfont/TabContent.valamodifiedlibbirdfont/TextRendering/Text.valamodifiedlibbirdfont/TextRendering/TextArea.valamodifiedlibbirdfont/Tool.valamodifiedlibbirdfont/ToolItem.valamodifiedresources/icons.bf
Diff
@@ -191,7 +191,9 @@ public class DrawingTools : ToolCollection { }); draw_tools.add_tool (move_background); - move_canvas = new Tool ("move_canvas", t_("Move canvas"));+ move_canvas = new Tool ("move_canvas",+ t_("Move canvas"),+ t_("Press space and click to move the canvas.")); move_canvas.select_action.connect ((self) => { update_drawing_and_background_tools (self); }); @@ -238,7 +240,10 @@ public class DrawingTools : ToolCollection { key_tools.add_tool (insert_point_on_path_tool); // quadratic Bézier points- quadratic_points = new Tool ("quadratic_points", t_("Create quadratic Bézier curves"));+ quadratic_points = new Tool ("quadratic_points", + t_("Create quadratic Bézier curves"),+ t_("All control points will be converted to quadratic points in the TTF format."));+ quadratic_points.select_action.connect ((self) => { point_type = PointType.QUADRATIC; Preferences.set ("point_type", "quadratic_points");@@ -61,6 +61,10 @@ public class Expander : GLib.Object { public void clear_cache () { cached = null;+ + foreach (Tool t in tool) {+ t.clear_cache ();+ } } public void set_headline (Text h) {new file mode 100644@@ -0,0 +1,123 @@+/*+ Copyright (C) 2016 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 Cairo;++namespace BirdFont {++public class Help {++ bool visible;+ TextArea help_text;+ Text close;+ const int box_margin = 7;+ + public Help () {+ string v = Preferences.get ("help_visible");+ visible = v == "true";+ help_text = create_help_text (t_("BirdFont is a font editor."));+ + Color color = Theme.get_color ("Menu Foreground");+ close = new Text ("close", 30, 0, color);+ close.load_font ("icons.bf");+ }++ public static TextArea create_help_text (string lines) {+ Color color = Theme.get_color ("Menu Foreground");+ TextArea text = new TextArea (17, color);+ text.min_width = 200;+ text.min_height = 100;+ text.width = 200;+ text.height = 100;+ text.allocation = new WidgetAllocation.for_area (0, 0, (int)text.min_width, (int)text.min_height);+ text.set_text (lines);+ text.layout ();+ text.set_editable (false);+ text.draw_border = false;+ return text;+ }++ public void set_help_text (TextArea text) {+ if (text != help_text && is_visible ()) {+ help_text = text;+ GlyphCanvas.redraw ();+ }+ }++ public void set_visible (bool v) {+ visible = v;+ Preferences.set ("help_visible", @"$v");+ }+ + public bool is_visible () {+ return visible;+ }++ public void draw (Context cr, WidgetAllocation allocation) {+ int margin_x = 10;+ int margin_y = 15;++ help_text.allocation = allocation;+ help_text.widget_x = allocation.width - help_text.width - margin_x;+ help_text.widget_y = allocation.height - help_text.height - margin_y;+ + draw_box (cr, allocation);+ + help_text.draw (cr);++ double close_x = allocation.width;+ close_x -= close.get_sidebearing_extent ();+ close_x -= margin_x;+ close_x -= box_margin;+ + double close_y = allocation.height;+ close_y -= help_text.height;+ close_y -= margin_y;+ close_y -= 2 * box_margin;+ + close.widget_x = close_x;+ close.widget_y = close_y;+ close.draw (cr);+ }++ public bool button_press (uint button, double x, double y) {+ if (close.widget_x < x < close.widget_x + close.get_sidebearing_extent ()+ && close.widget_y < y < close.widget_y + close.font_size) {+ + set_visible (false);+ GlyphCanvas.redraw ();+ return true;+ }+ + return false;+ }++ public void draw_box (Context cr, WidgetAllocation allocation) {+ cr.save();++ Theme.color (cr, "Menu Background");+ double x, y, w, h;+ x = help_text.widget_x - 2 * box_margin;+ y = help_text.widget_y - 2 * box_margin; + w = help_text.width + 2 * box_margin;+ h = help_text.height + 2 * box_margin;+ Widget.draw_rounded_rectangle (cr, x, y, w, h, 7);+ cr.fill ();++ cr.restore();+ }++}++}@@ -1,5 +1,5 @@ /*- Copyright (C) 2012 2014 2015 Johan Mattsson+ Copyright (C) 2012 2014 2015 2016 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 @@ -46,6 +46,8 @@ public class KerningDisplay : FontDisplay { public bool adjust_side_bearings = false; public bool right_side_bearing = true; + TextArea description; + public KerningDisplay () { GlyphSequence w = new GlyphSequence (); rows = new Gee.ArrayList <GlyphSequence> ();@@ -54,6 +56,8 @@ public class KerningDisplay : FontDisplay { redo_items = new Gee.ArrayList <UndoItem> (); w.set_otf_tags (KerningTools.get_otf_tags ()); first_row.add (w);+ + description = Help.create_help_text (t_("Kerning is the process of adjusting the space between two letters. You can cahnge the space between one letter and all other letters in the spacing tab.")); } public GlyphSequence get_first_row () {@@ -487,7 +491,8 @@ public class KerningDisplay : FontDisplay { } public override void selected_canvas () {- KeyBindings.set_require_modifier (true); + KeyBindings.set_require_modifier (true);+ MainWindow.get_help ().set_help_text (description); } public void add_kerning_class (int index) {@@ -79,7 +79,8 @@ public class LabelTool : Tool { }); } - void clear_cache () {+ public override void clear_cache () {+ base.clear_cache (); selected_cache = null; deselected_cache = null; }@@ -27,9 +27,15 @@ public class LayerLabel : Tool { /** Add margin when layer is moves. */ bool active_layer = false; + static TextArea? help_text_hide = null;+ public LayerLabel (Layer layer) { base (); + if (help_text_hide == null) {+ update_description ();+ }+ this.layer = layer; this.label = layer.name; @@ -39,10 +45,10 @@ public class LayerLabel : Tool { panel_press_action.connect ((selected, button, tx, ty) => { if (y <= ty <= y + h) {- if (tx >= w - 30 * Toolbox.get_scale ()) {+ if (tx >= w - 30) { DrawingTools.deselect_layers (); remove_layer ();- } if (tx < 25 * Toolbox.get_scale ()) {+ } else if (tx < 25) { layer.visible = !layer.visible; GlyphCanvas.redraw (); BirdFont.get_current_font ().touch ();@@ -76,6 +82,13 @@ public class LayerLabel : Tool { redraw (); } + if (y <= ty <= y + h) {+ if (tx < 25 && help_text_hide != null) {+ Help help = MainWindow.get_help ();+ help.set_help_text ((!) help_text_hide);+ }+ }+ return false; }); @@ -83,7 +96,16 @@ public class LayerLabel : Tool { active_layer = false; }); }- ++ void update_description () {+ help_text_hide = Help.create_help_text (t_("Hide the layer.")); + }++ public override void clear_cache () {+ base.clear_cache ();+ update_description ();+ }+ void move_layer_up () { int i; Glyph g = MainWindow.get_current_glyph ();@@ -28,11 +28,11 @@ public class LicenseDialog : Dialog { static const double margin = 20; public LicenseDialog () {- agreement = new TextArea (font_size);+ Color color = Theme.get_color ("Text Tool Box");+ agreement = new TextArea (font_size, color); agreement.min_width = 300; agreement.set_editable (false); agreement.draw_border = false;- agreement.text_color = Theme.get_color ("Text Tool Box"); agreement.set_text ("BirdFont is developed with donations, please consider donating to the project.\n\nThis is the freeware version of BirdFont. You may use it for creating fonts under the SIL Open Font License.\n\nWhich license do you want to use for your font?"); decline = new Button ("Commercial License");@@ -1,5 +1,5 @@ /* - Copyright (C) 2012 2014 Johan Mattsson + Copyright (C) 2012 2014 2016 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 @@ -32,6 +32,7 @@ public class MainWindow : GLib.Object { public static Dialog dialog; public static SpacingTab spacing_tab; public static Task blocking_background_task; + public static Help help; /** Number of pixels per mm */ public static double units = 1; @@ -55,9 +56,14 @@ public class MainWindow : GLib.Object { dialog = new Dialog (); spacing_tab = new SpacingTab (); blocking_background_task = new Task (null); + help = new Help (); tools.select_tool (DrawingTools.bezier_tool); } + + public static Help get_help () { + return help; + } public static void abort_task () { blocking_background_task.cancel (); @@ -1,5 +1,5 @@ /*- Copyright (C) 2014 2015 Johan Mattsson+ Copyright (C) 2014 - 2016 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 @@ -509,7 +509,16 @@ public class Menu : AbstractMenu { show_menu = false; }); menu.items.add (version);- ++ MenuItem help = add_menu_item (t_("Help"), "help");+ help.action.connect (() => {+ Help help_box = MainWindow.get_help ();+ help_box.set_visible (!help_box.is_visible ());+ GlyphCanvas.redraw ();+ show_menu = false;+ });+ menu.items.add (help);+ set_current_menu (menu); top_menu = menu; @@ -23,8 +23,8 @@ public class MenuItem : GLib.Object { public double y; // key bindings- public uint modifiers = NONE;- public unichar key = '\0';+ public virtual uint modifiers { get; set; default = NONE; }+ public virtual unichar key { get; set; default = '\0'; } public Gee.ArrayList<string> displays = new Gee.ArrayList<string> (); @@ -28,12 +28,12 @@ public class QuestionDialog : Dialog { double height = 0; public QuestionDialog (string message) {- question = new TextArea (font_size);+ Color color = Theme.get_color ("Text Tool Box");+ question = new TextArea (font_size, color); question.min_width = 300; question.min_height = font_size; question.set_editable (false); question.draw_border = false;- question.text_color = Theme.get_color ("Text Tool Box"); question.set_text (message); buttons = new Gee.ArrayList<Button> (); }@@ -1,5 +1,5 @@ /*- Copyright (C) 2014 2015 Johan Mattsson+ Copyright (C) 2014 - 2016 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@@ -72,7 +72,7 @@ public class TabContent : GLib.Object { public static void draw (WidgetAllocation allocation, Context cr) { AbstractMenu menu; Dialog dialog;-+ if (unlikely (MenuTab.has_suppress_event ())) { cr.save (); Theme.color (cr, "Background 1");@@ -111,6 +111,12 @@ public class TabContent : GLib.Object { draw_text_input (allocation, cr); } }++ Help help = MainWindow.get_help ();+ + if (help.is_visible ()) {+ help.draw (cr, allocation);+ } } public static void create_pause_surface () {@@ -213,6 +219,12 @@ public class TabContent : GLib.Object { last_press_time = GLib.get_real_time (); + Help help = MainWindow.get_help ();+ + if (help.button_press (button, x, y)) {+ return; // event consumed by help text+ }+ if (MainWindow.get_dialog ().visible) { MainWindow.get_dialog ().button_press (button, x, y); } else if (!MainWindow.get_menu ().show_menu) {@@ -53,10 +53,18 @@ public class Text : Widget { double margin_left = 0; - public Text (string text = "", double size = 17, double margin_bottom = 0) {+ public Text (string text = "", double size = 17, double margin_bottom = 0, Color? color = null) { this.margin_bottom = margin_bottom; font_cache = FontCache.get_default_cache (); cached_font = font_cache.get_fallback ();++ if (color != null) {+ Color c = (!) color;+ r = c.r;+ g = c.g;+ b = c.b;+ a = c.a;+ } set_text (text); set_font_size (size);@@ -24,7 +24,8 @@ public class TextArea : Widget { public double font_size; public double padding = 3.3; public bool single_line = false;- public Color text_color = Color.black ();+ + protected Color text_color = Color.black (); public bool draw_carret { get { return carret_is_visible; }@@ -896,7 +897,6 @@ public class TextArea : Widget { for (i = paragraphs.size - 1; i >= 0 && paragraphs.size > 1; i--) { if (unlikely (paragraphs.get (i).is_empty ())) {- warning ("Empty paragraph."); paragraphs.remove_at (i); update_paragraph_index (); }@@ -1553,13 +1553,7 @@ public class TextArea : Widget { break; } - word = new Text (w, font_size);- - word.r = text_color.r;- word.g = text_color.g;- word.b = text_color.b;- word.a = text_color.a;- + word = new Text (w, font_size, 0, text_color); words_in_paragraph.add (word); } }@@ -1,5 +1,5 @@ /*- Copyright (C) 2012, 2014 Johan Mattsson+ Copyright (C) 2012 2014 2016 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 @@ -66,6 +66,8 @@ public class Tool : Widget { bool show_bg = true; public string tip = "";+ string extented_description = "";+ TextArea? help = null; public bool persistent = false; public bool editor_events = false;@@ -82,8 +84,9 @@ public class Tool : Widget { public signal void redraw_tool (); /** Create tool with a certain name and load icon "name".png */- public Tool (string? name = null, string tip = "") {+ public Tool (string? name = null, string tip = "", string extended_description = "") { this.tip = tip;+ this.extented_description = extended_description; icon_font = new Text (); @@ -122,12 +125,39 @@ public class Tool : Widget { panel_move_action.connect ((self, x, y) => { if (is_active ()) { wait_for_tooltip ();+ + Help help_box = MainWindow.get_help ();+ + if (help == null) {+ help = update_help ();+ }+ + help_box.set_help_text ((!) help); redraw (); } return false; }); } + public virtual void clear_cache () {+ help = null;+ }+ + public TextArea? update_help () {+ string t = get_tip ();+ string description = t;+ + if (t != "" && extented_description != "") {+ description += "\n\n";+ }+ + if (extented_description != "") {+ description += extented_description;+ }+ + return Help.create_help_text (description);+ }+ public virtual string get_tip () { return tip; }@@ -221,6 +251,10 @@ public class Tool : Widget { } public string get_key_binding () {+ if (is_null (MainWindow.get_menu ())) {+ return "";+ }+ ToolItem? ti = MainWindow.get_menu ().get_item_for_tool (this); ToolItem t; @@ -18,6 +18,28 @@ public class ToolItem : MenuItem { public Tool tool; + public override uint modifiers { + get {+ return base.modifiers;+ } + + set {+ base.modifiers = value;+ tool.update_help ();+ }+ }+ + public override unichar key { + get {+ return base.key;+ } + + set {+ base.key = value;+ tool.update_help ();+ }+ }+ public ToolItem (Tool tool) { base (tool.tip, tool.name); @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8" standalone="yes"?> <font>-<format>2.1</format>+<format>2.2</format> <postscript_name>BirdfontIcons</postscript_name> <name>Birdfont Icons</name>@@ -503,6 +503,18 @@ GNU Lesser General Public License</copyright> </glyph> </collection> +<collection name="close">+ <selected id="0"/>+ <glyph id="0" left="-28" right="28.419182948490214">+ <layer name= "Layer" visible="true">+ <path data="B 28.0212870839,35.2058976055 C 28.0212870839,24.7263578602 19.4616696252,16.1667539275 8.9821366429,16.1667539275 C -1.4973902527,16.1667539275 -9.9805477504,24.7263578602 -9.9805477504,35.2058976055 C -9.9805477504,45.6854373507 -1.4973902527,54.1685522418 8.9821366429,54.1685522418 C 19.4616696252,54.1685522418 28.0212870839,45.6854373507 28.0212870839,35.2058976055" />+ <path data="B -7.5337498733,35.2058976055 C -7.5337498733,26.0487188078 -0.1750401258,18.6135240765 8.9821366429,18.6135240765 C 18.1393154406,18.6135240765 25.5744898830,26.0487188078 25.5744898830,35.2058976055 C 25.5744898830,44.3630764031 18.1393154406,51.7217820928 8.9821366429,51.7217820928 C -0.1750401258,51.7217820928 -7.5337498733,44.3630764031 -7.5337498733,35.2058976055" />+ <path data="B 1.5364891996,45.0349793170 M 19.5360480338,27.3782692224 M 17.2353252034,25.0328721622 M -0.7642336309,42.6895822568 M 1.5364891996,45.0349793170" />+ <path data="B -1.2533789606,26.9501777496 M 16.4033311340,44.9497365840 M 18.7487281942,42.6490137535 M 1.0920180996,24.6494549192 M -1.2533789606,26.9501777496" />+ </layer>+ </glyph>+</collection>+ <collection name="close_path"> <selected id="1"/> <glyph id="1" left="-28" right="28.419182948490214">@@ -1860,6 +1872,7 @@ GNU Lesser General Public License</copyright> <ligature sequence="c i r c l e" replacement="circle"/> <ligature sequence="r e s i z e" replacement="resize"/> <ligature sequence="h e i g h t" replacement="height"/>+<ligature sequence="c l o s e" replacement="close"/> <ligature sequence="t r a c k" replacement="track"/> <ligature sequence="w i d t h" replacement="width"/> <ligature sequence="t h e m e" replacement="theme"/>