From b7189192e2e31ce5ca1f2eaac2a303f9b8216ded Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 29 Mar 2025 22:40:13 +0100 Subject: Adds a new event FL_TOOLTIP_EVENT... ... and Fl_Tootip::override_text() to allow users to dynamically generate tooltips. --- test/color_chooser.cxx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/color_chooser.cxx b/test/color_chooser.cxx index 61fbc4caf..a9a7a5ca1 100644 --- a/test/color_chooser.cxx +++ b/test/color_chooser.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,22 @@ void cb2(Fl_Widget *, void *v) { bx->parent()->redraw(); } +class Image_Box: public Fl_Box { +public: + Image_Box(int x, int y, int w, int h, const char *label = nullptr) + : Fl_Box(x, y, w, h, label) { } + int handle(int event) { + if (event == FL_TOOLTIP_EVENT) { + const char *color_name_lut[] = { "blue", "green", "black", "red" }; + int quadrant = (Fl::event_x() < x()+w()/2) + 2*(Fl::event_y() < y()+h()/2); + char buf[80]; + ::snprintf(buf, 79, "Color %s at x=%d, y=%d", color_name_lut[quadrant], Fl::event_x(), Fl::event_y()); + return Fl_Tooltip::override_text(buf); + } + return Fl_Box::handle(event); + } +}; + int main(int argc, char ** argv) { Fl::set_color(fullcolor_cell,145,159,170); Fl_Window window(400,400); @@ -98,7 +115,8 @@ int main(int argc, char ** argv) { b1.callback(cb1,&box); Fl_Button b2(120,120,180,30,"fl_color_chooser()"); b2.callback(cb2,&box); - Fl_Box image_box(160,190,width,height,0); + Image_Box image_box(160,190,width,height,0); + image_box.tooltip("Image Box"); make_image(); (new Fl_RGB_Image(image, width, height))->label(&image_box); Fl_Box b(160,310,120,30,"Example of fl_draw_image()"); -- cgit v1.2.3