Cursor is now changeable
This commit is contained in:
parent
7d178b36cb
commit
2c934fd5a3
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -22,6 +22,7 @@ int main(int argc, char** argv)
|
|||
SDL_SetWindowTitle(window.GetWindow(), "New Title");
|
||||
|
||||
window.SetIcon(64, 64, icon_data);
|
||||
window.SetMouseCursor(SDL_SYSTEM_CURSOR_CROSSHAIR);
|
||||
window.SetMaxFramerate(144);
|
||||
|
||||
SDL_Event event;
|
||||
|
@ -45,7 +46,7 @@ int main(int argc, char** argv)
|
|||
window.Clear(sdlu::Color::FromHSV(floor(t), 100, 100));
|
||||
|
||||
window.Display();
|
||||
t += 0.01;
|
||||
t += 0.08;
|
||||
|
||||
diff = std::chrono::duration_cast<std::chrono::microseconds>
|
||||
(std::chrono::steady_clock::now() - start).count();
|
||||
|
|
Loading…
Reference in a new issue