Added mouse position setters

This commit is contained in:
Robert 2020-05-19 15:24:47 +02:00
parent c4c81f35f6
commit 235b8f4ac3
4 changed files with 29 additions and 4 deletions

View file

@ -151,12 +151,12 @@ namespace sdlu
SDL_SetWindowTitle(m_pWindow, title.c_str());
}
SDL_Window* const RenderWindow::GetWindow()
SDL_Window* const RenderWindow::GetWindow() const
{
return m_pWindow;
}
SDL_Renderer* const RenderWindow::GetRenderer()
SDL_Renderer* const RenderWindow::GetRenderer() const
{
return m_pRenderer;
}

View file

@ -154,14 +154,14 @@ namespace sdlu
*
* @return A constant pointer to SDL_Window
*/
SDL_Window* const GetWindow();
SDL_Window* const GetWindow() const;
/**
* @brief Returns a constant pointer to the SDL_Renderer
*
* @return A constant pointer to SDL_Renderer
*/
SDL_Renderer* const GetRenderer();
SDL_Renderer* const GetRenderer() const;
/**
* @brief Clears the display

View file

@ -25,4 +25,14 @@ namespace sdlu
{
return GetPosition() - relativeTo.GetPosition();
}
void Mouse::SetPosition(const Vector2i& position)
{
SDL_WarpMouseGlobal(position.x, position.y);
}
void Mouse::SetPosition(const Vector2i& position, const RenderWindow& relativeTo)
{
SDL_WarpMouseInWindow(relativeTo.GetWindow(), position.x, position.y);
}
}

View file

@ -58,5 +58,20 @@ namespace sdlu
* @return The position of the mouse relative to the top left of the passed window object
*/
static Vector2i GetPosition(const RenderWindow& relativeTo);
/**
* @brief Sets the absolute position of the mouse
*
* @param[in] position A 2D vector of the new position
*/
static void SetPosition(const Vector2i& position);
/**
* @brief Sets current relative position of the mouse
*
* @param[in] position A 2D vector of the new position
* @param[in] relativeTo The window the mouse position should be relative to
*/
static void SetPosition(const Vector2i& position, const RenderWindow& relativeTo);
};
}