Cursor is now changeable

This commit is contained in:
Robert 2020-05-18 18:29:37 +02:00
parent 7d178b36cb
commit 2c934fd5a3
3 changed files with 80 additions and 2 deletions

View file

@ -245,4 +245,41 @@ namespace sdlu
{
m_oFramerate = max;
}
void RenderWindow::SetMouseCursor(SDL_Cursor* cursor)
{
SDL_SetCursor(cursor);
}
void RenderWindow::SetMouseCursor(SDL_SystemCursor cursor)
{
SDL_Cursor* _cursor = SDL_CreateSystemCursor(cursor);
SDL_SetCursor(_cursor);
}
void RenderWindow::SetMouseCursor(SDL_Surface* surface, Vector2u clickspot)
{
SDL_Cursor* _cursor = SDL_CreateColorCursor(surface, clickspot.x, clickspot.y);
SDL_SetCursor(_cursor);
}
void RenderWindow::SetMouseCursor(const Uint8* pixels, Vector2u size, Vector2u clickspot)
{
size_t _size = static_cast<size_t>(size.x) * static_cast<size_t>(size.y) * 4;
void* _pixels = malloc(_size);
memcpy(_pixels, pixels, _size);
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
size.x, size.y, 32, 8 * size.x, SDL_PIXELFORMAT_RGBA8888);
this->SetMouseCursor(surface, clickspot);
}
void RenderWindow::SetMouseCursor(const Uint32* pixels, Vector2u size, Vector2u clickspot)
{
size_t _size = static_cast<size_t>(size.x) * static_cast<size_t>(size.y) * 4;
void* _pixels = malloc(_size);
memcpy(_pixels, pixels, _size);
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(_pixels,
size.x, size.y, 32, 8 * size.x, SDL_PIXELFORMAT_RGBA32);
this->SetMouseCursor(surface, clickspot);
}
}

View file

@ -233,7 +233,47 @@ namespace sdlu
*
* @param[in] max The new maximum framerate
*/
void SetMaxFramerate(Uint32 max);
void SetMaxFramerate(Uint32 max);
/**
* @brief Changes the mouse cursor
*
* @param[in] cursor A pointer to a SDL_Cursor containing cursor data
*/
void SetMouseCursor(SDL_Cursor* cursor);
/**
* @brief Changes the mouse cursor
*
* @param[in] cursor An enum for a system cursor
*/
void SetMouseCursor(SDL_SystemCursor cursor);
/**
* @brief Changes the mouse cursor
*
* @param[in] surface A pointer to a SDL_Surface containing sprite data
* @param[in] clickspot The effective position of the cursor relative to the top left of the sprite
*/
void SetMouseCursor(SDL_Surface* surface, Vector2u clickspot);
/**
* @brief Changes the mouse cursor
*
* @param[in] pixels An array of color data (RGBA as seperate 8-bit values)
* @param[in] size Size of the cursor
* @param[in] clickspot The effective position of the cursor relative to the top left of the sprite
*/
void SetMouseCursor(const Uint8* pixels, Vector2u size, Vector2u clickspot);
/**
* @brief Changes the mouse cursor
*
* @param[in] pixels An array of color data (RGBA as one 32-bit value)
* @param[in] size Size of the cursor
* @param[in] clickspot The effective position of the cursor relative to the top left of the sprite
*/
void SetMouseCursor(const Uint32* pixels, Vector2u size, Vector2u clickspot);
protected:
SDL_Window* m_pWindow; ///< A pointer to the window object