From 474de4d16e570b9cb4258d85d5f9142a26e22202 Mon Sep 17 00:00:00 2001 From: metaquarx Date: Thu, 16 Feb 2023 20:52:46 +0000 Subject: [PATCH] Allow setting window icon with `sf::Image` --- include/SFML/Graphics/RenderWindow.hpp | 14 ++++++++++++++ src/SFML/Graphics/RenderWindow.cpp | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/include/SFML/Graphics/RenderWindow.hpp b/include/SFML/Graphics/RenderWindow.hpp index 3ca516a0..1466f2d0 100644 --- a/include/SFML/Graphics/RenderWindow.hpp +++ b/include/SFML/Graphics/RenderWindow.hpp @@ -35,6 +35,8 @@ namespace sf { +class Image; + //////////////////////////////////////////////////////////// /// \brief Window that can serve as a target for 2D drawing /// @@ -112,6 +114,18 @@ public: //////////////////////////////////////////////////////////// Vector2u getSize() const override; + //////////////////////////////////////////////////////////// + /// \brief Change the window's icon + /// + /// The OS default icon is used by default. + /// + /// \param icon Image to use as the icon. The image is copied, + /// so you need not keep the source alive after + /// calling this function. + /// + //////////////////////////////////////////////////////////// + void setIcon(const Image& icon); + using Window::setIcon; //////////////////////////////////////////////////////////// /// \brief Tell if the window will use sRGB encoding when drawing on it diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index 045cd114..ef7d457c 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -26,6 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -65,6 +66,13 @@ Vector2u RenderWindow::getSize() const } +//////////////////////////////////////////////////////////// +void RenderWindow::setIcon(const Image& icon) +{ + setIcon(icon.getSize(), icon.getPixelsPtr()); +} + + //////////////////////////////////////////////////////////// bool RenderWindow::isSrgb() const {