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

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] eb314f5 - Allow use of Fl_Window::default_icon() with a scaled image - Part 2. "ManoloFLTK" 00:17 Sep 17 top right image
 
commit eb314f565340ff69922710d281d02b709ca77548
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Sat Sep 17 09:03:34 2022 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Sat Sep 17 09:03:34 2022 +0200

    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.

 src/Fl_win32.cxx | 26 +++++++++++++++++++++-----
 src/Fl_x.cxx     |  6 ++++++
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git src/Fl_win32.cxx src/Fl_win32.cxx
index 47bf8d4..4b633c1 100644
--- src/Fl_win32.cxx
+++ src/Fl_win32.cxx
@@ -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.
diff --git src/Fl_x.cxx src/Fl_x.cxx
index e5c970b..5b7e2a7 100644
--- src/Fl_x.cxx
+++ src/Fl_x.cxx
@@ -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;
   }
 }
 
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2022 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.