13#include <SDL_stbimage.h>
25 , m_cursor_bitmap {
nullptr}
42 return SDL_HasMouse();
47 SDL_SetWindowMouseGrab(
m_window, grabbed);
52 SDL_WarpMouseInWindow(
m_window, x, y);
57 const auto sdlrect = rect.to_sdl();
58 return SDL_SetWindowMouseRect(
m_window, &sdlrect);
75 m_cursor = SDL_CreateSystemCursor(cursor);
92 auto& fs = entt::locator<VirtualFileSystem>::value();
94 auto data = fs.read_binary(cursor);
97 auto surface = STBIMG_LoadFromMemory(data.data(),
static_cast<int>(data.size()));
113 SDL_DestroySurface(surface);
125 SDL_SetCursor(SDL_GetDefaultCursor());
139 const auto buttons = SDL_GetMouseState(
nullptr,
nullptr);
140 return buttons & SDL_BUTTON_MASK(
static_cast<SDL_MouseButtonFlags
>(btn));
145 return sl::mouse_x();
150 return sl::mouse_y();
155 return sl::set_mouse_mapping(x, y, scale_x, scale_y);
160 sl::clear_mouse_mapping();
165 sl::set_relative_mouse_mode(
m_window, enabled);
170 return sl::relative_mouse_mode(
m_window);
176 sl::mouse_delta(&vec2.x, &vec2.y);
#define GALAXY_LOG(level, msg,...)
bool set_window_mouse_rect(iRect &rect) noexcept
Confines the cursor to the specified area of a window.
glm::ivec2 mouse_delta(int *dx, int *dy) noexcept
Retrieve relative mouse movement (delta) since the last call.
sl::Bitmap * m_cursor_bitmap
Mouse custom bitmap.
void set_mouse_mapping(const int x, const int y, const float scale_x, const float scale_y) const noexcept
Set mouse relative mapping to another coord space.
bool is_mouse_down(const MouseButton btn) const noexcept
Check if a mouse button was pressed.
void set_cursor_system(const SDL_SystemCursor cursor) noexcept
Set cursor to a system cursor.
Mouse() noexcept
Constructor.
~Mouse() noexcept
Destructor.
void clear_mouse_mapping() const noexcept
Return mouse_x()/mouse_y() to plain screen coordinates.
void destroy_cursor() noexcept
Destroy any existing cursor.
bool relative_mouse_mode() const noexcept
Return whether relative mouse mode is currently enabled.
void hide_cursor() const noexcept
Hide cursor.
void set_relative_mouse_mode(const bool enabled) const noexcept
Enable or disable relative mouse mode (locks cursor to window, hides it, and reports relative motion)...
void restore_cursor() noexcept
Set the cursor back to default.
void set_mouse_grab(const bool grabbed) const noexcept
Toggle mouse grab.
int mouse_y() const noexcept
Get current cursor y position.
void show_cursor() const noexcept
Show cursor.
SDL_Cursor * m_cursor
Holds data for a custom cursor.
int mouse_x() const noexcept
Get current cursor x position.
bool mouse_connected() const noexcept
Check if there is a mouse connected.
void warp_mouse(const float x, const float y) const noexcept
Move the mouse cursor to the given position within the window.
void use_custom_mouse(const std::string &cursor, const glm::ivec2 &offset=glm::ivec2(0, 0))
Replaces the system cursor with a bitmap.
WindowBindable() noexcept
Constructor.
SDL_Window * m_window
Pointer to SDL_Window handle.
Rect< int > iRect
Type definition for an int rectangle.
MouseButton
Enum class representing mouse buttons.