Added SetIcon function to RenderWindow
This commit is contained in:
parent
cea768fce1
commit
85ab65737a
|
@ -198,4 +198,33 @@ namespace sdlu
|
||||||
{
|
{
|
||||||
SDL_SetWindowGrab(m_pWindow, grabbed ? SDL_TRUE : SDL_FALSE);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -198,6 +198,31 @@ namespace sdlu
|
||||||
*/
|
*/
|
||||||
void SetMouseCursorGrabbed(bool grabbed);
|
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:
|
protected:
|
||||||
SDL_Window* m_pWindow; ///< A pointer to the window object
|
SDL_Window* m_pWindow; ///< A pointer to the window object
|
||||||
SDL_Renderer* m_pRenderer; ///< A pointer to the renderer object
|
SDL_Renderer* m_pRenderer; ///< A pointer to the renderer object
|
||||||
|
|
|
@ -4,9 +4,22 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
|
Uint32* icon_data = new Uint32[64 * 64];
|
||||||
|
for (int y = 0; y < 64; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < 64; x++)
|
||||||
|
{
|
||||||
|
icon_data[64 * y + x] = 0x004400FF;
|
||||||
|
icon_data[64 * y + x] |= (((Uint32)((y / 64.f) * 255) << 24));
|
||||||
|
icon_data[64 * y + x] |= (((Uint32)((x / 64.f) * 255) << 8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MyWindow window(800, 800, "Test");
|
MyWindow window(800, 800, "Test");
|
||||||
SDL_SetWindowTitle(window.GetWindow(), "New Title");
|
SDL_SetWindowTitle(window.GetWindow(), "New Title");
|
||||||
|
|
||||||
|
window.SetIcon(64, 64, icon_data);
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
float t = 0.f;
|
float t = 0.f;
|
||||||
while (window.IsOpen())
|
while (window.IsOpen())
|
||||||
|
|
Loading…
Reference in a new issue