diff --git a/FL/Fl_Image.H b/FL/Fl_Image.H index aafd39742a66496e5c62402cfc0010d1106fa4b0..decc5bdebc5a1f92267079d48aef4a32a972a32a 100644 --- a/FL/Fl_Image.H +++ b/FL/Fl_Image.H @@ -273,6 +273,7 @@ public: static bool register_images_done; }; +class Fl_SVG_Image; /** The Fl_RGB_Image class supports caching and drawing @@ -291,6 +292,7 @@ class FL_EXPORT Fl_RGB_Image : public Fl_Image { public: /** Points to the start of the object's data array + \see class Fl_SVG_Image which delays initialization of this member variable. */ const uchar *array; /** If non-zero, the object's data array is delete[]'d when deleting the object. @@ -332,6 +334,12 @@ public: \sa void Fl_RGB_Image::max_size(size_t) */ static size_t max_size() {return max_size_;} + /** Returns whether an image is an Fl_SVG_Image or not. + This virtual method returns a pointer to the Fl_SVG_Image if this object is an instance of Fl_SVG_Image or NULL if not. */ + virtual Fl_SVG_Image *as_svg_image() { return NULL; } + /** Makes sure the object is fully initialized. + In particular, makes sure member variable \ref array is non-null. */ + virtual void normalize() {} }; #endif // !Fl_Image_H diff --git a/FL/Fl_SVG_Image.H b/FL/Fl_SVG_Image.H index 3b9648e3ac7f670c513c4b2874a6e99e66a4d743..4940ffb8cc09a668204de90b1ec8597f5a119269 100644 --- a/FL/Fl_SVG_Image.H +++ b/FL/Fl_SVG_Image.H @@ -31,7 +31,7 @@ struct NSVGimage; if the file could not be opened or read, and ERR_FORMAT if the SVG format could not be decoded. If the image has loaded correctly, w(), h(), and d() should return values greater than zero. - Rasterization is not done until the image is first drawn or resize() is called. Therefore, + Rasterization is not done until the image is first drawn or resize() or normalize() is called. Therefore, \ref array is NULL until then. The delayed rasterization ensures an Fl_SVG_Image is always rasterized to the exact screen resolution at which it is drawn. @@ -161,6 +161,8 @@ public: virtual void color_average(Fl_Color c, float i); virtual void draw(int X, int Y, int W, int H, int cx = 0, int cy = 0); void draw(int X, int Y) { draw(X, Y, w(), h(), 0, 0); } + virtual Fl_SVG_Image *as_svg_image() { return this; }; + virtual void normalize(); }; #endif // FL_SVG_IMAGE_H diff --git a/src/Fl_SVG_Image.cxx b/src/Fl_SVG_Image.cxx index c4c593d0a99ce99781b8170317b29813977a7e1c..c76bc962b9ff1636ea94b3e49b1aca0fa94cb148 100644 --- a/src/Fl_SVG_Image.cxx +++ b/src/Fl_SVG_Image.cxx @@ -266,6 +266,12 @@ void Fl_SVG_Image::color_average(Fl_Color c, float i) { Fl_RGB_Image::color_average(c, i); } +/** Makes sure the object is fully initialized. + This function rasterizes the SVG image if that was not done before. */ +void Fl_SVG_Image::normalize() { + if (!array) resize(w(), h()); +} + #endif // FLTK_USE_NANOSVG // diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 31f5bd08edfec5848982e31fed93a292a028e5d6..8d09c875931063ef6780568048c58c3efa281478 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -4516,6 +4516,7 @@ void Fl_Cocoa_Window_Driver::icons(const Fl_RGB_Image *icons[], int count) { [icon_image release]; icon_image = nil; if (count >= 1 && pWindow->border() && pWindow->label() && strlen(pWindow->label())) { + ((Fl_RGB_Image*)icons[0])->normalize(); icon_image = rgb_to_nsimage(icons[0]); } } diff --git a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx index fb449754e62fc176644493e441ff6564ac496691..09b677fff6c59de5faa4f87f461cc00856098400 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx @@ -379,8 +379,10 @@ void Fl_WinAPI_Window_Driver::icons(const Fl_RGB_Image *icons[], int count) { icon_->icons = new Fl_RGB_Image*[count]; icon_->count = count; // FIXME: Fl_RGB_Image lacks const modifiers on methods - for (int i = 0;i < count;i++) + for (int i = 0;i < count;i++) { icon_->icons[i] = (Fl_RGB_Image*)((Fl_RGB_Image*)icons[i])->copy(); + icon_->icons[i]->normalize(); + } } if (Fl_X::i(pWindow)) diff --git a/src/drivers/X11/Fl_X11_Window_Driver.cxx b/src/drivers/X11/Fl_X11_Window_Driver.cxx index 4996b3e0f4c13bc1fd5796e01c015a21ea8f8653..50a013ba6348de52dc87a0d4fb41c2a087babf73 100644 --- a/src/drivers/X11/Fl_X11_Window_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Window_Driver.cxx @@ -356,8 +356,10 @@ void Fl_X11_Window_Driver::icons(const Fl_RGB_Image *icons[], int count) { icon_->icons = new Fl_RGB_Image*[count]; icon_->count = count; // FIXME: Fl_RGB_Image lacks const modifiers on methods - for (int i = 0;i < count;i++) + for (int i = 0;i < count;i++) { icon_->icons[i] = (Fl_RGB_Image*)((Fl_RGB_Image*)icons[i])->copy(); + icon_->icons[i]->normalize(); + } } if (Fl_X::i(pWindow))