Added SetIcon function to RenderWindow

This commit is contained in:
Robert 2020-05-18 16:27:03 +02:00
parent cea768fce1
commit 85ab65737a
3 changed files with 67 additions and 0 deletions

View file

@ -198,4 +198,33 @@ namespace sdlu
{
SDL_SetWindowGrab(m_pWindow, grabbed ? SDL_TRUE : SDL_FALSE);
}
void RenderWindow::SetIcon(Uint32 width, Uint32 height, const Uint8* pixels)
{
size_t size = static_cast<size_t>(width) * static_cast<size_t>(height) * 4;
void* _pixels = malloc(size);
memcpy(_pixels, pixels, size);
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
width, height, 32, 32 * width,
SDL_PIXELFORMAT_RGBA8888);
SDL_SetWindowIcon(m_pWindow, surface);
}
void RenderWindow::SetIcon(Uint32 width, Uint32 height, const Uint32* pixels)
{
size_t size = static_cast<size_t>(width) * static_cast<size_t>(height) * 4;
void* _pixels = malloc(size);
memcpy(_pixels, pixels, size);
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
width, height, 32, 4 * width,
SDL_PIXELFORMAT_RGBA8888);
SDL_SetWindowIcon(m_pWindow, surface);
}
void RenderWindow::SetIcon(SDL_Surface* icon)
{
SDL_SetWindowIcon(m_pWindow, icon);
}
}

View file

@ -198,6 +198,31 @@ namespace sdlu
*/
void SetMouseCursorGrabbed(bool grabbed);
/**
* @brief Sets the window icon to an array of RGBA values
*
* @param[in] width Width of the icon (in px)
* @param[in] height Height of the icon (in px)
* @param[in] pixels Array of color data (RGBA as seperate 8-Bit integer values)
*/
void SetIcon(Uint32 width, Uint32 height, const Uint8* pixels);
/**
* @brief Sets the window icon to an array of RGBA values
*
* @param[in] width Width of the icon (in px)
* @param[in] height Height of the icon (in px)
* @param[in] pixels Array of color data (RGBA as one 32-Bit integer value)
*/
void SetIcon(Uint32 width, Uint32 height, const Uint32* pixels);
/**
* @brief Sets the window icon to a SDL_Surface
*
* @param[in] icon A SDL_Surface* holding the icon data
*/
void SetIcon(SDL_Surface* icon);
protected:
SDL_Window* m_pWindow; ///< A pointer to the window object
SDL_Renderer* m_pRenderer; ///< A pointer to the renderer object