Allow use of Fl_Window::default_icon() with a scaled image - Part 2.

Default icons are handled according to their scaled size, if there scaled.
This commit is contained in:
ManoloFLTK 2022-09-17 09:03:34 +02:00
parent 166a5bf785
commit eb314f5653
2 changed files with 27 additions and 5 deletions

View File

@ -2397,11 +2397,11 @@ static const Fl_RGB_Image *find_best_icon(int ideal_width, const Fl_RGB_Image *i
if (best == NULL)
best = icons[i];
else {
if (best->data_w() < ideal_width) {
if (icons[i]->data_w() > best->data_w())
if (best->w() < ideal_width) {
if (icons[i]->w() > best->w())
best = icons[i];
} else {
if ((icons[i]->data_w() >= ideal_width) && (icons[i]->data_w() < best->data_w()))
if ((icons[i]->w() >= ideal_width) && (icons[i]->w() < best->w()))
best = icons[i];
}
}
@ -2424,11 +2424,27 @@ void Fl_WinAPI_Screen_Driver::default_icons(const Fl_RGB_Image *icons[], int cou
best_big = find_best_icon(GetSystemMetrics(SM_CXICON), icons, count);
best_small = find_best_icon(GetSystemMetrics(SM_CXSMICON), icons, count);
if (best_big != NULL)
bool need_delete;
if (best_big != NULL) {
need_delete = false;
if (best_big->w() != best_big->data_w() || best_big->h() != best_big->data_h()) {
best_big = (Fl_RGB_Image *)best_big->copy();
need_delete = true;
}
default_big_icon = image_to_icon(best_big, true, 0, 0);
if (need_delete) delete best_big;
}
if (best_small != NULL)
if (best_small != NULL) {
need_delete = false;
if (best_small->w() != best_small->data_w() ||
best_small->h() != best_small->data_h()) {
best_small = (Fl_RGB_Image *)best_small->copy();
need_delete = true;
}
default_small_icon = image_to_icon(best_small, true, 0, 0);
if (need_delete) delete best_small;
}
}
/** Sets the window icons using Windows' native HICON icon handles.

View File

@ -2707,6 +2707,11 @@ static void icons_to_property(const Fl_RGB_Image *icons[], int count,
const Fl_RGB_Image *image;
image = icons[i];
bool need_delete = false;
if (image->w() != image->data_w() || image->h() != image->data_h()) {
image = (Fl_RGB_Image*)image->copy();
need_delete = true;
}
data[0] = image->data_w();
data[1] = image->data_h();
@ -2736,6 +2741,7 @@ static void icons_to_property(const Fl_RGB_Image *icons[], int count,
}
in += extra_data;
}
if (need_delete) delete image;
}
}