From cba5ed0291476afbff23b84223828e5fba8e3967 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Tue, 8 Aug 2023 06:44:10 +0200 Subject: [PATCH 01/15] expose setWindowIcon() on all platforms --- libs/openFrameworks/app/ofAppGLFWWindow.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.h b/libs/openFrameworks/app/ofAppGLFWWindow.h index 54d5bb4c0e4..c9d25671467 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.h +++ b/libs/openFrameworks/app/ofAppGLFWWindow.h @@ -151,14 +151,22 @@ class ofAppGLFWWindow : public ofAppBaseGLWindow { OF_DEPRECATED_MSG("use ofGLFWWindowSettings to create the window instead", void setDepthBits(int depth)); OF_DEPRECATED_MSG("use ofGLFWWindowSettings to create the window instead", void setStencilBits(int stencil)); OF_DEPRECATED_MSG("use ofGLFWWindowSettings to create the window instead", void setMultiDisplayFullscreen(bool bMultiFullscreen)); //note this just enables the mode, you have to toggle fullscreen to activate it. + + /// \brief Set current window icon. + /// + /// \param path file to load icon from + void setWindowIcon(const std::string & path); + + /// \brief Set current window icon. + /// + /// \param iconPixels pixel definition of the icon + void setWindowIcon(const ofPixels & iconPixels); + #if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY) Display* getX11Display(); Window getX11Window(); XIC getX11XIC(); - - void setWindowIcon(const std::string & path); - void setWindowIcon(const ofPixels & iconPixels); #endif #if defined(TARGET_LINUX) && !defined(TARGET_OPENGLES) From e63ec3d58dfc08ccc1a6d9054b868bedfd56b7e3 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Tue, 8 Aug 2023 06:47:03 +0200 Subject: [PATCH 02/15] remove #ifdef TARGET_LINUX --- libs/openFrameworks/app/ofAppGLFWWindow.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index 268dc4392a1..c4022bf9770 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -6,9 +6,11 @@ #define GLFW_INCLUDE_NONE #include "GLFW/glfw3.h" +#include "ofIcon.h" +#include "ofImage.h" #ifdef TARGET_LINUX - #include "ofIcon.h" - #include "ofImage.h" + + #define GLFW_EXPOSE_NATIVE_X11 #ifndef TARGET_OPENGLES #define GLFW_EXPOSE_NATIVE_GLX @@ -294,7 +296,7 @@ void ofAppGLFWWindow::setup(const ofGLFWWindowSettings & _settings){ } glfwGetWindowSize( windowP, ¤tW, ¤tH ); } - #ifdef TARGET_LINUX + if(!iconSet){ ofPixels iconPixels; #ifdef DEBUG @@ -306,8 +308,7 @@ void ofAppGLFWWindow::setup(const ofGLFWWindowSettings & _settings){ #endif setWindowIcon(iconPixels); } - #endif - if(settings.iconified){ + if(settings.iconified){ iconify(true); } } @@ -401,7 +402,6 @@ void ofAppGLFWWindow::setup(const ofGLFWWindowSettings & _settings){ #endif } -#ifdef TARGET_LINUX //------------------------------------------------------------ void ofAppGLFWWindow::setWindowIcon(const std::string & path){ ofPixels iconPixels; @@ -427,7 +427,6 @@ void ofAppGLFWWindow::setWindowIcon(const ofPixels & iconPixels){ PropModeReplace, (const unsigned char*)buffer.data(), length); XFlush(getX11Display()); } -#endif //-------------------------------------------- ofCoreEvents & ofAppGLFWWindow::events(){ From 82f0e259791db859e553977f1c0f445c63e51fe3 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Tue, 8 Aug 2023 07:19:21 +0200 Subject: [PATCH 03/15] use glfwSetWindowIcon() build RGBA icon list and use it as icon for GLFW --- libs/openFrameworks/app/ofAppGLFWWindow.cpp | 40 ++++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index c4022bf9770..bd1880b842c 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -412,20 +412,34 @@ void ofAppGLFWWindow::setWindowIcon(const std::string & path){ //------------------------------------------------------------ void ofAppGLFWWindow::setWindowIcon(const ofPixels & iconPixels){ iconSet = true; - int length = 2+iconPixels.getWidth()*iconPixels.getHeight(); - vector buffer(length); - buffer[0]=iconPixels.getWidth(); - buffer[1]=iconPixels.getHeight(); - for(size_t i=0;i iconSizes{16,32,48,256}; + std::vector iconList; + for(auto iconSize : iconSizes){ + iconList.emplace_back(ofPixels(rgbaIcon)); + iconList.back().resize(iconSize,iconSize,OF_INTERPOLATE_BICUBIC); + } + // convert iconlist to GLFWimage array + std::vector glfwIcons; + for(auto resizedIcon : iconList){ + int w=resizedIcon.getWidth(); + int h=resizedIcon.getHeight(); + glfwIcons.emplace_back(GLFWimage{w,h,static_cast(malloc(w*h*4))}); + std::memcpy(glfwIcons.back().pixels, resizedIcon.getData(), w*h*4); + } + // set icon(s) on window + glfwSetWindowIcon(windowP, iconSizes.size(), glfwIcons.data()); + // cleanup + for(auto icon : glfwIcons){ + free(icon.pixels); } - - XChangeProperty(getX11Display(), getX11Window(), XInternAtom(getX11Display(), "_NET_WM_ICON", False), XA_CARDINAL, 32, - PropModeReplace, (const unsigned char*)buffer.data(), length); - XFlush(getX11Display()); } //-------------------------------------------- From 954eef08e09113f6f780355a37c808d469e9d3a7 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Sat, 19 Aug 2023 09:55:27 +0200 Subject: [PATCH 04/15] moving OF icon definition to cpp file --- .../app/{ofIcon.h => ofIcon.cpp} | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) rename libs/openFrameworks/app/{ofIcon.h => ofIcon.cpp} (99%) diff --git a/libs/openFrameworks/app/ofIcon.h b/libs/openFrameworks/app/ofIcon.cpp similarity index 99% rename from libs/openFrameworks/app/ofIcon.h rename to libs/openFrameworks/app/ofIcon.cpp index 3b984d2d356..82eecb574db 100644 --- a/libs/openFrameworks/app/ofIcon.h +++ b/libs/openFrameworks/app/ofIcon.cpp @@ -1,5 +1,5 @@ /* GIMP RGBA C-Source image dump 1-byte-run-length-encoded (icon.c) */ -#pragma once +#include "app/ofIcon.h" #define GIMP_IMAGE_RUN_LENGTH_DECODE(image_buf, rle_data, size, bpp) do \ { unsigned int __bpp; unsigned char *__ip; const unsigned char *__il, *__rd; \ @@ -5733,3 +5733,20 @@ static const struct { "\377[af\377!$&\377\37!\"\377*.1\377\26\31\32\377\35\36\40\377\36!#\377\16" "\17\17\377" }; + + +const ofPixels getIcon(){ + return getOfIcon(); +} + +const ofPixels getOfIcon(){ + ofPixels iconPixels; + #ifdef DEBUG + iconPixels.allocate(ofIconDebug.width,ofIconDebug.height,ofIconDebug.bytes_per_pixel); + GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(),ofIconDebug.rle_pixel_data,iconPixels.getWidth()*iconPixels.getHeight(),ofIconDebug.bytes_per_pixel); + #else + iconPixels.allocate(ofIcon.width,ofIcon.height,ofIcon.bytes_per_pixel); + GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(),ofIcon.rle_pixel_data,iconPixels.getWidth()*iconPixels.getHeight(),ofIcon.bytes_per_pixel); + #endif + return iconPixels; +} \ No newline at end of file From d7f763dcf2fe8feeb240f9cb8af9c9ad7412888d Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Sat, 19 Aug 2023 10:03:59 +0200 Subject: [PATCH 05/15] recreate header for ofIcon --- libs/openFrameworks/app/ofIcon.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 libs/openFrameworks/app/ofIcon.h diff --git a/libs/openFrameworks/app/ofIcon.h b/libs/openFrameworks/app/ofIcon.h new file mode 100644 index 00000000000..d3fd32cfc4e --- /dev/null +++ b/libs/openFrameworks/app/ofIcon.h @@ -0,0 +1,19 @@ +#pragma once +#include "graphics/ofPixels.h" + +/** + * @brief Get the application icon. Default to OF icon if not set/found + * + * + * @return const ofPixels& + */ +const ofPixels getIcon(); + +/** + * @brief Get the OF icon. + * + * @note if openFrameworks is compiled with DEBUG, it will be the OF-debug icon. + * + * @return const ofPixels& + */ +const ofPixels getOfIcon(); From 474ce245ff8ba20c6b61b66ab3b3bd4cb098bb56 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Sat, 19 Aug 2023 10:05:13 +0200 Subject: [PATCH 06/15] set icon in GLFW app --- libs/openFrameworks/app/ofAppGLFWWindow.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index bd1880b842c..d4398aa6314 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -298,15 +298,7 @@ void ofAppGLFWWindow::setup(const ofGLFWWindowSettings & _settings){ } if(!iconSet){ - ofPixels iconPixels; - #ifdef DEBUG - iconPixels.allocate(ofIconDebug.width,ofIconDebug.height,ofIconDebug.bytes_per_pixel); - GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(),ofIconDebug.rle_pixel_data,iconPixels.getWidth()*iconPixels.getHeight(),ofIconDebug.bytes_per_pixel); - #else - iconPixels.allocate(ofIcon.width,ofIcon.height,ofIcon.bytes_per_pixel); - GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(),ofIcon.rle_pixel_data,iconPixels.getWidth()*iconPixels.getHeight(),ofIcon.bytes_per_pixel); - #endif - setWindowIcon(iconPixels); + setWindowIcon(getIcon()); } if(settings.iconified){ iconify(true); From c6252a5df6fc605409b17ca9e984089e4c7b5660 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Sat, 19 Aug 2023 10:09:26 +0200 Subject: [PATCH 07/15] implementing retrieval of application embedded icon on windows --- libs/openFrameworks/app/ofIcon.cpp | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libs/openFrameworks/app/ofIcon.cpp b/libs/openFrameworks/app/ofIcon.cpp index 82eecb574db..50fc8e285e3 100644 --- a/libs/openFrameworks/app/ofIcon.cpp +++ b/libs/openFrameworks/app/ofIcon.cpp @@ -5736,6 +5736,38 @@ static const struct { const ofPixels getIcon(){ + // On Windows, try to retrieve the embedded icon + #ifdef TARGET_WIN32 + auto hIcon = (HICON) LoadImage(GetModuleHandle(nullptr), TEXT("MAINICON"), IMAGE_ICON, 128, 128, LR_DEFAULTSIZE | LR_CREATEDIBSECTION); + if(hIcon){ + ICONINFO iconinfo; + GetIconInfo(hIcon, &iconinfo); + if(iconinfo.fIcon==true){ + if(iconinfo.hbmColor){ + //Copy color icon in bitmap + auto hBmp = (HBITMAP)CopyImage(iconinfo.hbmColor, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); + DeleteObject(iconinfo.hbmColor); + DeleteObject(iconinfo.hbmMask); + DestroyIcon(hIcon); + + BITMAP bgraBmp; + GetObject(hBmp, sizeof(BITMAP), &bgraBmp); + ofPixels icon; + icon.setFromPixels((unsigned char*)bgraBmp.bmBits,bgraBmp.bmWidth,bgraBmp.bmHeight,OF_PIXELS_BGRA); + DeleteObject(hBmp); + icon.mirror(true,false); // flip vertically + return icon; + }else{ + /// TODO + ofLogWarning()<<"Monochrome icons not supported yet"; + } + } + DeleteObject(iconinfo.hbmColor); + DeleteObject(iconinfo.hbmMask); + DestroyIcon(hIcon); + } + ofLogWarning() << "Cannot retrieve application icon - using default OF icon"; + #endif return getOfIcon(); } From 3c61da4f8f2598032ba5a304bdf44820866d28c6 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Sat, 19 Aug 2023 11:14:56 +0200 Subject: [PATCH 08/15] add ofIcon.* to VS project --- .../project/vs/openframeworksLib.vcxproj | 2 ++ .../project/vs/openframeworksLib.vcxproj.filters | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/libs/openFrameworksCompiled/project/vs/openframeworksLib.vcxproj b/libs/openFrameworksCompiled/project/vs/openframeworksLib.vcxproj index 62bf767ca82..253657d67be 100644 --- a/libs/openFrameworksCompiled/project/vs/openframeworksLib.vcxproj +++ b/libs/openFrameworksCompiled/project/vs/openframeworksLib.vcxproj @@ -90,6 +90,7 @@ + @@ -180,6 +181,7 @@ + diff --git a/libs/openFrameworksCompiled/project/vs/openframeworksLib.vcxproj.filters b/libs/openFrameworksCompiled/project/vs/openframeworksLib.vcxproj.filters index e9e8c8d5261..aa303534110 100644 --- a/libs/openFrameworksCompiled/project/vs/openframeworksLib.vcxproj.filters +++ b/libs/openFrameworksCompiled/project/vs/openframeworksLib.vcxproj.filters @@ -309,6 +309,9 @@ libs\openFrameworks\video + + libs\openFrameworks\app + @@ -521,6 +524,9 @@ libs\openFrameworks\app + + libs\openFrameworks\app + From 2244737b0219ca4b97247b48e4be7bd82c42c612 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Sat, 19 Aug 2023 11:20:56 +0200 Subject: [PATCH 09/15] fix warning in VS --- libs/openFrameworks/app/ofIcon.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/app/ofIcon.cpp b/libs/openFrameworks/app/ofIcon.cpp index 50fc8e285e3..a1cf34894c9 100644 --- a/libs/openFrameworks/app/ofIcon.cpp +++ b/libs/openFrameworks/app/ofIcon.cpp @@ -5742,7 +5742,7 @@ const ofPixels getIcon(){ if(hIcon){ ICONINFO iconinfo; GetIconInfo(hIcon, &iconinfo); - if(iconinfo.fIcon==true){ + if(!(iconinfo.fIcon)){ if(iconinfo.hbmColor){ //Copy color icon in bitmap auto hBmp = (HBITMAP)CopyImage(iconinfo.hbmColor, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); @@ -5762,7 +5762,7 @@ const ofPixels getIcon(){ ofLogWarning()<<"Monochrome icons not supported yet"; } } - DeleteObject(iconinfo.hbmColor); + if(iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor); DeleteObject(iconinfo.hbmMask); DestroyIcon(hIcon); } From 04061c377dfd21688dbf234b80bad6ab1cc41e1a Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Sat, 19 Aug 2023 11:29:27 +0200 Subject: [PATCH 10/15] fix indentation issue --- libs/openFrameworks/app/ofAppGLFWWindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index c2da0a6b0ce..f18acb67eaa 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -297,9 +297,9 @@ void ofAppGLFWWindow::setup(const ofGLFWWindowSettings & _settings){ glfwGetWindowSize( windowP, ¤tW, ¤tH ); } - if(!iconSet){ - setWindowIcon(getIcon()); - } + if(!iconSet){ + setWindowIcon(getIcon()); + } if(settings.iconified){ iconify(true); } From 2a3c111da9796ab373e76ff751acdce6af4c22fb Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Sat, 19 Aug 2023 11:30:53 +0200 Subject: [PATCH 11/15] need to use getIcon() for GLUT app on Linux. --- libs/openFrameworks/app/ofAppGlutWindow.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/libs/openFrameworks/app/ofAppGlutWindow.cpp b/libs/openFrameworks/app/ofAppGlutWindow.cpp index fa19c6702dc..a29035a35de 100644 --- a/libs/openFrameworks/app/ofAppGlutWindow.cpp +++ b/libs/openFrameworks/app/ofAppGlutWindow.cpp @@ -310,17 +310,9 @@ void ofAppGlutWindow::setup(const ofGLWindowSettings & settings){ #endif #ifdef TARGET_LINUX - if(!iconSet){ - ofPixels iconPixels; - #ifdef DEBUG - iconPixels.allocate(ofIconDebug.width,ofIconDebug.height,ofIconDebug.bytes_per_pixel); - GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(),ofIconDebug.rle_pixel_data,iconPixels.getWidth()*iconPixels.getHeight(),ofIconDebug.bytes_per_pixel); - #else - iconPixels.allocate(ofIcon.width,ofIcon.height,ofIcon.bytes_per_pixel); - GIMP_IMAGE_RUN_LENGTH_DECODE(iconPixels.getData(),ofIcon.rle_pixel_data,iconPixels.getWidth()*iconPixels.getHeight(),ofIcon.bytes_per_pixel); - #endif - setWindowIcon(iconPixels); - } + if(!iconSet){ + setWindowIcon(getIcon()); + } #endif if (settings.isPositionSet()) { setWindowPosition(settings.getPosition().x,settings.getPosition().y); From 4bd8446bcaa18a299dd9834ec534d9a6456ad162 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Mon, 21 Aug 2023 10:54:30 +0200 Subject: [PATCH 12/15] get first icon of app previous method depended on name specifed by the user in .rc file. The new method is independant of it. --- libs/openFrameworks/app/ofIcon.cpp | 34 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/libs/openFrameworks/app/ofIcon.cpp b/libs/openFrameworks/app/ofIcon.cpp index a1cf34894c9..6fe8f89b0ea 100644 --- a/libs/openFrameworks/app/ofIcon.cpp +++ b/libs/openFrameworks/app/ofIcon.cpp @@ -1,6 +1,11 @@ -/* GIMP RGBA C-Source image dump 1-byte-run-length-encoded (icon.c) */ #include "app/ofIcon.h" +#ifdef TARGET_WIN32 + //#include "utils/ofFileUtils.h" + #include "shellapi.h" +#endif + +/* GIMP RGBA C-Source image dump 1-byte-run-length-encoded (icon.c) */ #define GIMP_IMAGE_RUN_LENGTH_DECODE(image_buf, rle_data, size, bpp) do \ { unsigned int __bpp; unsigned char *__ip; const unsigned char *__il, *__rd; \ __bpp = (bpp); __ip = (image_buf); __il = __ip + (size) * __bpp; \ @@ -5736,27 +5741,31 @@ static const struct { const ofPixels getIcon(){ - // On Windows, try to retrieve the embedded icon + // On Windows, try to retrieve the embedded icon from application file #ifdef TARGET_WIN32 - auto hIcon = (HICON) LoadImage(GetModuleHandle(nullptr), TEXT("MAINICON"), IMAGE_ICON, 128, 128, LR_DEFAULTSIZE | LR_CREATEDIBSECTION); - if(hIcon){ + bool gotIcon = false; + + // Get the application file name + TCHAR exeName[MAX_PATH]; + GetModuleFileName(NULL, exeName, MAX_PATH); + //auto exeName = ofFilePath::getCurrentExePath(); // ExtractIconEx espects WCHAR... + + // extract the first (index 0) large icon from the application + HICON hIcon; + if(ExtractIconEx(exeName,0,&hIcon,NULL,1)==1){ ICONINFO iconinfo; GetIconInfo(hIcon, &iconinfo); - if(!(iconinfo.fIcon)){ - if(iconinfo.hbmColor){ + ofPixels icon; + if(iconinfo.fIcon){ + if(iconinfo.hbmColor){ // We have a color icon //Copy color icon in bitmap auto hBmp = (HBITMAP)CopyImage(iconinfo.hbmColor, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); - DeleteObject(iconinfo.hbmColor); - DeleteObject(iconinfo.hbmMask); - DestroyIcon(hIcon); - BITMAP bgraBmp; GetObject(hBmp, sizeof(BITMAP), &bgraBmp); - ofPixels icon; icon.setFromPixels((unsigned char*)bgraBmp.bmBits,bgraBmp.bmWidth,bgraBmp.bmHeight,OF_PIXELS_BGRA); DeleteObject(hBmp); icon.mirror(true,false); // flip vertically - return icon; + gotIcon = true; }else{ /// TODO ofLogWarning()<<"Monochrome icons not supported yet"; @@ -5765,6 +5774,7 @@ const ofPixels getIcon(){ if(iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor); DeleteObject(iconinfo.hbmMask); DestroyIcon(hIcon); + if(gotIcon) return icon; } ofLogWarning() << "Cannot retrieve application icon - using default OF icon"; #endif From f535b7314bb9cda2fc82ecbccc5907c3bd743e34 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Wed, 23 Aug 2023 06:51:55 +0200 Subject: [PATCH 13/15] adding some classical icon sizes --- libs/openFrameworks/app/ofAppGLFWWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index f18acb67eaa..6eb96e83860 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -412,7 +412,7 @@ void ofAppGLFWWindow::setWindowIcon(const ofPixels & iconPixels){ rgbaIcon.swapRgb(); } // build a list of icon with different sizes - const std::vector iconSizes{16,32,48,256}; + const std::vector iconSizes{16,32,48,96,128,256}; std::vector iconList; for(auto iconSize : iconSizes){ iconList.emplace_back(ofPixels(rgbaIcon)); From 2541ce144a898e4b750a33a47f48adf95eacc0ea Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Wed, 23 Aug 2023 11:25:15 +0200 Subject: [PATCH 14/15] define TARGET_HAS_WINDOW_ICON setting icon will only work on targets that have it defined. Does nothing on targets that do not define it. Defined for TARGET_WIN32 or TARGET_LINUX --- libs/openFrameworks/app/ofAppGLFWWindow.cpp | 15 ++++++++++----- libs/openFrameworks/app/ofIcon.h | 7 +++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index 6eb96e83860..7464959d546 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -296,11 +296,13 @@ void ofAppGLFWWindow::setup(const ofGLFWWindowSettings & _settings){ } glfwGetWindowSize( windowP, ¤tW, ¤tH ); } - - if(!iconSet){ - setWindowIcon(getIcon()); - } - if(settings.iconified){ + + #ifdef TARGET_HAS_WINDOW_ICON + if(!iconSet){ + setWindowIcon(getIcon()); + } + #endif + if(settings.iconified){ iconify(true); } } @@ -403,6 +405,9 @@ void ofAppGLFWWindow::setWindowIcon(const std::string & path){ //------------------------------------------------------------ void ofAppGLFWWindow::setWindowIcon(const ofPixels & iconPixels){ + #ifndef TARGET_HAS_WINDOW_ICON + return; + #endif iconSet = true; // make sure we have a RGBA image diff --git a/libs/openFrameworks/app/ofIcon.h b/libs/openFrameworks/app/ofIcon.h index d3fd32cfc4e..ffb72ebea24 100644 --- a/libs/openFrameworks/app/ofIcon.h +++ b/libs/openFrameworks/app/ofIcon.h @@ -1,4 +1,11 @@ #pragma once +#include "utils/ofConstants.h" + +#if defined(TARGET_WIN32) || defined(TARGET_LINUX) + #define TARGET_HAS_WINDOW_ICON +#endif + + #include "graphics/ofPixels.h" /** From 92fc907c589da46a81a9b449116c20bb58fd13c2 Mon Sep 17 00:00:00 2001 From: Olivier XILLO Date: Wed, 23 Aug 2023 11:28:12 +0200 Subject: [PATCH 15/15] remove GLFWimage array for icon Avoid rescaling as done internally by OS. Use original image size. --- libs/openFrameworks/app/ofAppGLFWWindow.cpp | 28 +++++++-------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index 7464959d546..647d72ebe05 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -416,27 +416,17 @@ void ofAppGLFWWindow::setWindowIcon(const ofPixels & iconPixels){ if(rgbaIcon.getPixelFormat()==OF_PIXELS_BGRA){ rgbaIcon.swapRgb(); } - // build a list of icon with different sizes - const std::vector iconSizes{16,32,48,96,128,256}; - std::vector iconList; - for(auto iconSize : iconSizes){ - iconList.emplace_back(ofPixels(rgbaIcon)); - iconList.back().resize(iconSize,iconSize,OF_INTERPOLATE_BICUBIC); - } - // convert iconlist to GLFWimage array - std::vector glfwIcons; - for(auto resizedIcon : iconList){ - int w=resizedIcon.getWidth(); - int h=resizedIcon.getHeight(); - glfwIcons.emplace_back(GLFWimage{w,h,static_cast(malloc(w*h*4))}); - std::memcpy(glfwIcons.back().pixels, resizedIcon.getData(), w*h*4); - } + // convert to a GLFW image + GLFWimage glfwIcon; + glfwIcon.width = rgbaIcon.getWidth(); + glfwIcon.height = rgbaIcon.getHeight(); + size_t iconByteSize = glfwIcon.width*glfwIcon.height*4; + glfwIcon.pixels = static_cast(malloc(iconByteSize)); + std::memcpy(glfwIcon.pixels, rgbaIcon.getData(), iconByteSize); // set icon(s) on window - glfwSetWindowIcon(windowP, iconSizes.size(), glfwIcons.data()); + glfwSetWindowIcon(windowP, 1, &glfwIcon); // cleanup - for(auto icon : glfwIcons){ - free(icon.pixels); - } + free(glfwIcon.pixels); } //--------------------------------------------