Commit 673f7af
Fix preview bug
Changed files (8)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/NativeWindow.valamodifiedlibbirdfont/Preview.valamodifiedlibbirdfont/SvgFontFormatWriter.valamodifiedlibbirdfont/Tool.valamodifiedlibbirdfont/Toolbox.valamodifiedlibbirdfont/TrackTool.vala
Diff
@@ -852,7 +852,11 @@ public class GtkWindow : Gtk.Window, NativeWindow { } // TODO: add tooltip- public void tooltip (string tooltip, int x, int y) {+ public void show_tooltip (string tooltip, int x, int y) {+ + }++ public void hide_tooltip () { } }@@ -131,6 +131,7 @@ public static int run_export (string[] arg) { ExportTool.export_ttf_font_path (File.new_for_path (output_directory), false); } + Toolbox.redraw_tool_box (); return 0; } @@ -53,7 +53,10 @@ public interface NativeWindow : GLib.Object { public abstract bool convert_to_png (string from, string to); /** Show help text. */- public abstract void tooltip (string tooltip, int x, int y);+ public abstract void show_tooltip (string tooltip, int x, int y);+ + /** Hide help text. */+ public abstract void hide_tooltip (); } }@@ -57,7 +57,7 @@ public class Preview : FontDisplay { public static string get_windows_uri () { Font font = BirdFont.get_current_font ();- string html = @"$(font.get_name ()).html";+ string html = @"$(font.get_full_name ()).html"; File dir = font.get_folder (); File file = dir.get_child (html); return "file:///" + (!) file.get_path ();@@ -76,15 +76,18 @@ public class Preview : FontDisplay { File f_ttf; File f_eot; File f_svg;- + File r_ttf;+ File r_svg;+ + try { dis = new DataInputStream (get_file ().read ()); preview_directory = BirdFont.get_preview_directory (); - f_ttf = font.get_folder ().get_child (@"$(font.get_name ()).ttf");- f_eot = font.get_folder ().get_child (@"$(font.get_name ()).eot");- f_svg = font.get_folder ().get_child (@"$(font.get_name ()).svg");+ f_ttf = font.get_folder ().get_child (@"$(font.get_full_name ()).ttf");+ f_eot = font.get_folder ().get_child (@"$(font.get_full_name ()).eot");+ f_svg = font.get_folder ().get_child (@"$(font.get_full_name ()).svg"); if (!f_ttf.query_exists ()) { warning ("TTF file does not exist.");@@ -94,26 +97,34 @@ public class Preview : FontDisplay { warning ("SVG file does not exist."); } - File r_ttf = preview_directory.get_child (@"$(font.get_name ())$rid.ttf");- File r_svg = preview_directory.get_child (@"$(font.get_name ())$rid.svg");+ r_ttf = preview_directory.get_child (@"$(font.get_full_name ())$rid.ttf");+ r_svg = preview_directory.get_child (@"$(font.get_full_name ())$rid.svg"); - if (BirdFont.win32) {- f_ttf.copy (r_ttf, FileCopyFlags.NONE);+ try {+ if (BirdFont.win32) {+ f_ttf.copy (r_ttf, FileCopyFlags.NONE);+ }+ } catch (Error e) {+ warning (e.message);+ warning ("Failed to copy ttf file."); }- - f_svg.copy (r_svg, FileCopyFlags.NONE); + try {+ f_svg.copy (r_svg, FileCopyFlags.NONE);+ } catch (Error e) {+ warning (e.message);+ warning ("Failed to copy svg file.");+ } while ((line = dis.read_line (null)) != null) {- line = ((!) line).replace (@"$(font.get_name ()).ttf", @"$(FontDisplay.path_to_uri ((!) f_ttf.get_path ()))?$rid");- line = ((!) line).replace (@"$(font.get_name ()).eot", @"$(FontDisplay.path_to_uri ((!) f_eot.get_path ()))?$rid");- line = ((!) line).replace (@"$(font.get_name ()).svg", @"$(FontDisplay.path_to_uri ((!) f_svg.get_path ()))?$rid");+ line = ((!) line).replace (@"$(font.get_full_name ()).ttf", @"$(FontDisplay.path_to_uri ((!) f_ttf.get_path ()))?$rid");+ line = ((!) line).replace (@"$(font.get_full_name ()).eot", @"$(FontDisplay.path_to_uri ((!) f_eot.get_path ()))?$rid");+ line = ((!) line).replace (@"$(font.get_full_name ()).svg", @"$(FontDisplay.path_to_uri ((!) f_svg.get_path ()))?$rid"); sb.append ((!) line); } } catch (Error e) { warning (e.message); warning ("Failed to load html into canvas."); }- return sb.str; } }@@ -34,7 +34,7 @@ class SvgFontFormatWriter : Object { } public void write_font_file (Font font) throws Error {- string font_name = font.get_name ();+ string font_name = font.get_full_name (); int units_per_em = 100; @@ -90,6 +90,9 @@ public class Tool : GLib.Object { public bool persistent = false; public bool editor_events = false; + bool showing_tooltip = false;+ bool waiting_for_tooltip = false;+ /** Create tool with a certain name and load icon "name".png */ public Tool (string? name = null, string tip = "", unichar key = '\0', uint modifier_flag = 0) { this.tip = tip;@@ -116,6 +119,44 @@ public class Tool : GLib.Object { MainWindow.get_tool_tip ().set_text_from_tool (); }); + panel_move_action.connect ((self, x, y) => {+ bool show_tooltip = false;+ int tooltip_cycles = 0;+ TimeoutSource timer;+ + if (show_tooltip) {+ MainWindow.native_window.show_tooltip (tip, (int)x, (int)y);+ }+ + if (!waiting_for_tooltip) {+ waiting_for_tooltip = true;+ timer = new TimeoutSource (600);+ timer.set_callback (() => {+ if (is_active () && !showing_tooltip) {+ MainWindow.native_window.show_tooltip (tip, (int)x, (int)y);+ showing_tooltip = true;+ return true;+ }+ + if (!is_active () && showing_tooltip) { + MainWindow.native_window.hide_tooltip ();+ showing_tooltip = false;+ waiting_for_tooltip = false;+ return false;+ }+ + if (!is_active () && !showing_tooltip) {+ waiting_for_tooltip = false;+ return false;+ }+ + return true;+ });+ timer.attach (null);+ }+ return false;+ });+ r = r_default; g = g_default; b = b_default;@@ -72,8 +72,11 @@ public class Toolbox : GLib.Object { } public static void set_allocation (int w, int h) {- allocation_width = w;- allocation_height = h;+ if (w != allocation_width || allocation_height != h) {+ allocation_width = w;+ allocation_height = h;+ Toolbox.redraw_tool_box ();+ } } public void key_press (uint keyval) {@@ -58,7 +58,7 @@ public class TrackTool : Tool { public TrackTool (string name) { string sw; - base (name, t_("Free hand drawing"));+ base (name, t_("Freehand drawing")); sw = Preferences.get ("free_hand_stroke_width"); if (sw != "") {