The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Platform independent tool tip

These changes was commited to the Birdfont repository Sat, 14 Mar 2015 19:35:57 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sat, 14 Mar 2015 19:35:57 +0000]

Updated Files

birdfont/GtkWindow.vala
libbirdfont/NativeWindow.vala
libbirdfont/Renderer/TextArea.vala
libbirdfont/Tool.vala
libbirdfont/Toolbox.vala
libbirdfont/Widget.vala
--- a/birdfont/GtkWindow.vala +++ b/birdfont/GtkWindow.vala @@ -521,52 +521,6 @@ return true; } - // TODO: add the default tooltip style to the label - public void show_tooltip (string tooltip, int x, int y) { - Label tooltip_label; - int parent_x, parent_y; - int tool_box_x, tool_box_y; - int posx, posy; - Gtk.Allocation label_allocation; - Gtk.Box box; - - box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - - get_position (out parent_x, out parent_y); - toolbox.translate_coordinates (toolbox.get_toplevel (), 0, 0, out tool_box_x, out tool_box_y); - - tooltip_window.hide (); - - tooltip_window = new Gtk.Window (Gtk.WindowType.POPUP); - tooltip_label = new Label(tooltip); - tooltip_label.margin = 0; - - box.pack_start (tooltip_label, true, true, 0); - - tooltip_window.add (box); - tooltip_label.show(); - box.show (); - - posx = parent_x + tool_box_x + x; - posy = parent_y + tool_box_y + y - 7; - tooltip_window.move (posx, posy); - - tooltip_window.show(); - - label_allocation = new Gtk.Allocation (); - tooltip_label.size_allocate (label_allocation); - - // move label to the left if it is off screen - if (posx + label_allocation.width > screen.get_width () - 20) { - tooltip_window.move (screen.get_width () - label_allocation.width - 20, posy); - } - - } - - public void hide_tooltip () { - tooltip_window.hide (); - } - public void run_background_thread (Task t) { unowned Thread<void*> bg;
--- a/libbirdfont/NativeWindow.vala +++ b/libbirdfont/NativeWindow.vala @@ -39,12 +39,6 @@ /** Convert an image to PNG format. */ public abstract bool convert_to_png (string from, string to); - - /** Show help text. */ - public abstract void show_tooltip (string tooltip, int x, int y); - - /** Hide help text. */ - public abstract void hide_tooltip (); /** Export fonts in a background thread. */ public abstract void export_font ();
--- a/libbirdfont/Renderer/TextArea.vala +++ b/libbirdfont/Renderer/TextArea.vala @@ -831,6 +831,10 @@ tx = 0; ty = font_size; + + if (allocation.width <= 0 || allocation.height <= 0) { + warning ("Parent widget allocation is not set."); + } for (i = paragraphs.size - 1; i >= 0 && paragraphs.size > 1; i--) { if (unlikely (paragraphs.get (i).is_empty ())) {
--- a/libbirdfont/Tool.vala +++ b/libbirdfont/Tool.vala @@ -100,7 +100,7 @@ }); move_out_action.connect ((self) => { - MainWindow.native_window.hide_tooltip (); + MainWindow.get_toolbox ().hide_tooltip (); active_tooltip.showing_this_tooltip = false; }); @@ -158,13 +158,16 @@ public static void show_tooltip () { TimeoutSource timer_hide; + Toolbox toolbox; + + toolbox = MainWindow.get_toolbox (); // hide tooltip label later if (!active_tooltip.showing_this_tooltip) { timer_hide = new TimeoutSource (1500); timer_hide.set_callback (() => { if (!active_tooltip.is_active ()) { - MainWindow.native_window.hide_tooltip (); + toolbox.hide_tooltip (); active_tooltip.showing_this_tooltip = false; active_tooltip = new Tool (); } @@ -174,8 +177,9 @@ } active_tooltip.showing_this_tooltip = true; - MainWindow.native_window.hide_tooltip (); - MainWindow.native_window.show_tooltip (active_tooltip.tip, (int)active_tooltip.x, (int)active_tooltip.y); + + toolbox.hide_tooltip (); + toolbox.show_tooltip (active_tooltip.tip, (int) active_tooltip.x, (int) active_tooltip.y); } public void set_icon (string name) {
--- a/libbirdfont/Toolbox.vala +++ b/libbirdfont/Toolbox.vala @@ -46,8 +46,12 @@ public List<ToolCollection> tool_sets = new List<ToolCollection> (); static double scale = 1; + + string? tool_tip = null; + double tool_tip_x = 0; + double tool_tip_y = 0; - public Toolbox (GlyphCanvas glyph_canvas, TabBar tab_bar) { + public Toolbox (GlyphCanvas glyph_canvas, TabBar tab_bar) { current_tool = new Tool ("no_icon"); press_tool = new Tool (null); @@ -465,7 +469,43 @@ draw_expanders (w, h, cr); cr.restore (); + + draw_tool_tip (cr); } + } + + private void draw_tool_tip (Context cr) { + TextArea t; + + if (tool_tip != null && tool_tip != "") { + t = new TextArea (20 * get_scale ()); + t.allocation = new WidgetAllocation.for_area (0, 0, allocation_width, allocation_height); + t.set_editable (false); + t.set_text ((!) tool_tip); + t.width = allocation_width - 20 * get_scale (); + t.min_height = 17 * get_scale (); + t.height = 17 * get_scale (); + + t.layout (); + + t.widget_x = 10 * get_scale (); + t.widget_y = tool_tip_y - t.height - 5 * get_scale (); + + t.draw (cr); + } + } + + public void hide_tooltip () { + tool_tip = null; + redraw_tool_box (); + } + + public void show_tooltip (string tool_tip, double x, double y) { + this.tool_tip = tool_tip; + this.tool_tip_x = x; + this.tool_tip_y = y; + + redraw_tool_box (); } public class EmptySet : ToolCollection {
--- a/libbirdfont/Widget.vala +++ b/libbirdfont/Widget.vala @@ -29,7 +29,7 @@ public WidgetAllocation allocation = new WidgetAllocation (); - public void draw_rounded_rectangle (Context cr, double x, double y, double w, double h, double radius) { + public static void draw_rounded_rectangle (Context cr, double x, double y, double w, double h, double radius) { // fixme radius is padding not margin cr.move_to (x, y + radius); cr.arc (x + radius, y + radius, radius, 2 * (PI / 2), 3 * (PI / 2));