summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2023-02-21 13:14:51 +0100
committerRay <[email protected]>2023-02-21 13:14:51 +0100
commit1347a155397621d789f23a4bd1f49e3652cb125d (patch)
tree60330db34157c9d64415b00a8b0e1f16ac7d1586
parentd26a56d4e1d8168912e3670a2ff3122b125fd94c (diff)
downloadraylib-1347a155397621d789f23a4bd1f49e3652cb125d.tar.gz
raylib-1347a155397621d789f23a4bd1f49e3652cb125d.zip
ADDED: `SetWindowIcons()` to set multiple icon image sizes
-rw-r--r--src/raylib.h3
-rw-r--r--src/rcore.c66
2 files changed, 58 insertions, 11 deletions
diff --git a/src/raylib.h b/src/raylib.h
index 73c6d224..6bc81fe7 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -941,7 +941,8 @@ RLAPI void ToggleFullscreen(void); // Toggle wind
RLAPI void MaximizeWindow(void); // Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
RLAPI void MinimizeWindow(void); // Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
RLAPI void RestoreWindow(void); // Set window state: not minimized/maximized (only PLATFORM_DESKTOP)
-RLAPI void SetWindowIcon(Image image); // Set icon for window (only PLATFORM_DESKTOP)
+RLAPI void SetWindowIcon(Image image); // Set icon for window (single image, RGBA 32bit, only PLATFORM_DESKTOP)
+RLAPI void SetWindowIcons(Image *images, int count); // Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
RLAPI void SetWindowTitle(const char *title); // Set title for window (only PLATFORM_DESKTOP)
RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP)
RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window (fullscreen mode)
diff --git a/src/rcore.c b/src/rcore.c
index 3de0f3f3..df5f193c 100644
--- a/src/rcore.c
+++ b/src/rcore.c
@@ -1554,23 +1554,69 @@ void ClearWindowState(unsigned int flags)
}
// Set icon for window (only PLATFORM_DESKTOP)
-// NOTE: Image must be in RGBA format, 8bit per channel
+// NOTE 1: Image must be in RGBA format, 8bit per channel
+// NOTE 2: Image is scaled by the OS for all required sizes
void SetWindowIcon(Image image)
{
#if defined(PLATFORM_DESKTOP)
- if (image.format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
+ if (image.data == NULL)
{
- GLFWimage icon[1] = { 0 };
+ // Revert to the default window icon, pass in an empty image array
+ glfwSetWindowIcon(CORE.Window.handle, 0, NULL);
+ }
+ else
+ {
+ if (image.format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
+ {
+ GLFWimage icon[1] = { 0 };
+
+ icon[0].width = image.width;
+ icon[0].height = image.height;
+ icon[0].pixels = (unsigned char *)image.data;
+
+ // NOTE 1: We only support one image icon
+ // NOTE 2: The specified image data is copied before this function returns
+ glfwSetWindowIcon(CORE.Window.handle, 1, icon);
+ }
+ else TRACELOG(LOG_WARNING, "GLFW: Window icon image must be in R8G8B8A8 pixel format");
+ }
+#endif
+}
- icon[0].width = image.width;
- icon[0].height = image.height;
- icon[0].pixels = (unsigned char *)image.data;
+// Set icon for window (multiple images, only PLATFORM_DESKTOP)
+// NOTE 1: Images must be in RGBA format, 8bit per channel
+// NOTE 2: The multiple images are used depending on provided sizes
+// Standard Windows icon sizes: 256, 128, 96, 64, 48, 32, 24, 16
+void SetWindowIcons(Image *images, int count)
+{
+#if defined(PLATFORM_DESKTOP)
+ if ((images == NULL) || (count <= 0))
+ {
+ // Revert to the default window icon, pass in an empty image array
+ glfwSetWindowIcon(CORE.Window.handle, 0, NULL);
+ }
+ else
+ {
+ int valid = 0;
+ GLFWimage *icons = RL_CALLOC(count, sizeof(GLFWimage));
+
+ for (int i = 0; i < count; i++)
+ {
+ if (images[i].format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
+ {
+ icons[valid].width = images[i].width;
+ icons[valid].height = images[i].height;
+ icons[valid].pixels = (unsigned char *)images[i].data;
+
+ valid++;
+ }
+ else TRACELOG(LOG_WARNING, "GLFW: Window icon image must be in R8G8B8A8 pixel format");
+ }
+ // NOTE: Images data is copied internally before this function returns
+ glfwSetWindowIcon(CORE.Window.handle, valid, icons);
- // NOTE 1: We only support one image icon
- // NOTE 2: The specified image data is copied before this function returns
- glfwSetWindowIcon(CORE.Window.handle, 1, icon);
+ RL_FREE(icons);
}
- else TRACELOG(LOG_WARNING, "GLFW: Window icon image must be in R8G8B8A8 pixel format");
#endif
}