From a5adbd99ca073ecb9d6153b089543b23a673c9b5 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 10 Dec 2022 23:22:24 +0100 Subject: Add option to bind images to a widget (#589) Adding image binding to FLUID as well --- src/Fl_Widget.cxx | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src') diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx index 2289dcf0b..1d1b71dc4 100644 --- a/src/Fl_Widget.cxx +++ b/src/Fl_Widget.cxx @@ -165,6 +165,8 @@ Fl_Widget::~Fl_Widget() { Fl::clear_widget_pointer(this); if (flags() & COPIED_LABEL) free((void *)(label_.value)); if (flags() & COPIED_TOOLTIP) free((void *)(tooltip_)); + image(NULL); + deimage(NULL); // remove from parent group if (parent_) parent_->remove(this); #ifdef DEBUG_DELETE @@ -323,6 +325,44 @@ void Fl_Widget::copy_label(const char *a) { } } +void Fl_Widget::image(Fl_Image* img) { + if (image_bound()) { + if (label_.image && (label_.image != img)) { + label_.image->release(); + } + bind_image(0); + } + label_.image = img; +} + +void Fl_Widget::image(Fl_Image& img) { + image(&img); +} + +void Fl_Widget::bind_image(Fl_Image* img) { + image(img); + bind_image( (img != NULL) ); +} + +void Fl_Widget::deimage(Fl_Image* img) { + if (deimage_bound()) { + if (label_.deimage && (label_.deimage != img)) { + label_.deimage->release(); + } + bind_deimage(0); + } + label_.deimage = img; +} + +void Fl_Widget::deimage(Fl_Image& img) { + deimage(&img); +} + +void Fl_Widget::bind_deimage(Fl_Image* img) { + deimage(img); + bind_deimage( (img != NULL) ); +} + /** Calls the widget callback function with arbitrary arguments. All overloads of do_callback() call this method. -- cgit v1.2.3