Allow setting window icon with sf::Image

This commit is contained in:
metaquarx 2023-02-16 20:52:46 +00:00 committed by Chris Thrasher
parent 698b7ee49f
commit 474de4d16e
2 changed files with 22 additions and 0 deletions

View File

@ -35,6 +35,8 @@
namespace sf namespace sf
{ {
class Image;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Window that can serve as a target for 2D drawing /// \brief Window that can serve as a target for 2D drawing
/// ///
@ -112,6 +114,18 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2u getSize() const override; 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 /// \brief Tell if the window will use sRGB encoding when drawing on it

View File

@ -26,6 +26,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/GLCheck.hpp> #include <SFML/Graphics/GLCheck.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/RenderTextureImplFBO.hpp> #include <SFML/Graphics/RenderTextureImplFBO.hpp>
#include <SFML/Graphics/RenderWindow.hpp> #include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Texture.hpp> #include <SFML/Graphics/Texture.hpp>
@ -65,6 +66,13 @@ Vector2u RenderWindow::getSize() const
} }
////////////////////////////////////////////////////////////
void RenderWindow::setIcon(const Image& icon)
{
setIcon(icon.getSize(), icon.getPixelsPtr());
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool RenderWindow::isSrgb() const bool RenderWindow::isSrgb() const
{ {