Commit 40b867c
Platform independent tool tip
Changed files (6)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/NativeWindow.valamodifiedlibbirdfont/Renderer/TextArea.valamodifiedlibbirdfont/Tool.valamodifiedlibbirdfont/Toolbox.valamodifiedlibbirdfont/Widget.vala
Diff
@@ -521,52 +521,6 @@ public class GtkWindow : Gtk.Window, NativeWindow { 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; @@ -39,12 +39,6 @@ public interface NativeWindow : GLib.Object { /** 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 ();@@ -832,6 +832,10 @@ public class TextArea : Widget { 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 ())) { warning ("Empty paragraph.");@@ -100,7 +100,7 @@ public class Tool : Widget { }); 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 class Tool : Widget { 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 @@ public class Tool : Widget { } 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) {@@ -46,8 +46,12 @@ public class Toolbox : GLib.Object { 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,9 +469,45 @@ public class Toolbox : GLib.Object { 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 { public ImageSurface? background;@@ -29,7 +29,7 @@ public abstract class Widget : GLib.Object { 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));