Backport fix for issue #185 "Shared Image reload() loses initial dimensions" from branch 1.4

This commit is contained in:
ManoloFLTK 2021-02-17 09:30:08 +01:00
parent 02e4b8f980
commit eda03f0f88

View File

@ -291,7 +291,11 @@ void Fl_Shared_Image::reload() {
if (alloc_image_) delete image_; if (alloc_image_) delete image_;
alloc_image_ = 1; alloc_image_ = 1;
#if FLTK_ABI_VERSION >= 10304
image_ = img;
int W = w();
int H = h();
#else
if ((img->w() != w() && w()) || (img->h() != h() && h())) { if ((img->w() != w() && w()) || (img->h() != h() && h())) {
// Make sure the reloaded image is the same size as the existing one. // Make sure the reloaded image is the same size as the existing one.
Fl_Image *temp = img->copy(w(), h()); Fl_Image *temp = img->copy(w(), h());
@ -300,8 +304,13 @@ void Fl_Shared_Image::reload() {
} else { } else {
image_ = img; image_ = img;
} }
#endif
update(); update();
#if FLTK_ABI_VERSION >= 10304
// Make sure the reloaded image gets the same drawing size as the existing one.
if (W)
scale(W, H, 0, 1);
#endif
} }
} }