galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::Mouse Class Referencefinal

Physical mouse device and state management. More...

#include <Mouse.hpp>

Inheritance diagram for galaxy::Mouse:
Collaboration diagram for galaxy::Mouse:

Public Member Functions

 Mouse () noexcept
 Constructor.
 ~Mouse () noexcept
 Destructor.
bool mouse_connected () const noexcept
 Check if there is a mouse connected.
void set_mouse_grab (const bool grabbed) const noexcept
 Toggle mouse grab.
void warp_mouse (const float x, const float y) const noexcept
 Move the mouse cursor to the given position within the window.
bool set_window_mouse_rect (iRect &rect) noexcept
 Confines the cursor to the specified area of a window.
void show_cursor () const noexcept
 Show cursor.
void hide_cursor () const noexcept
 Hide cursor.
void set_cursor_system (const SDL_SystemCursor cursor) noexcept
 Set cursor to a system cursor.
void use_custom_mouse (const std::string &cursor, const glm::ivec2 &offset=glm::ivec2(0, 0))
 Replaces the system cursor with a bitmap.
void restore_cursor () noexcept
 Set the cursor back to default.
bool is_mouse_down (const MouseButton btn) const noexcept
 Check if a mouse button was pressed.
int mouse_x () const noexcept
 Get current cursor x position.
int mouse_y () const noexcept
 Get current cursor y position.
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.
void clear_mouse_mapping () const noexcept
 Return mouse_x()/mouse_y() to plain screen coordinates.
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).
bool relative_mouse_mode () const noexcept
 Return whether relative mouse mode is currently enabled.
glm::ivec2 mouse_delta (int *dx, int *dy) noexcept
 Retrieve relative mouse movement (delta) since the last call.
Public Member Functions inherited from galaxy::WindowBindable
virtual ~WindowBindable () noexcept
 Virtual destructor.

Private Member Functions

 Mouse (Mouse &&)=delete
 Move constructor.
Mouse & operator= (Mouse &&)=delete
 Move assignment operator.
 Mouse (const Mouse &)=delete
 Copy constructor.
Mouse & operator= (const Mouse &)=delete
 Copy assignment operator.
void destroy_cursor () noexcept
 Destroy any existing cursor.

Private Attributes

SDL_Cursor * m_cursor
 Holds data for a custom cursor.
sl::Bitmap * m_cursor_bitmap
 Mouse custom bitmap.

Additional Inherited Members

Protected Member Functions inherited from galaxy::WindowBindable
 WindowBindable () noexcept
 Constructor.
 WindowBindable (WindowBindable &&) noexcept
 Move constructor.
virtual WindowBindable & operator= (WindowBindable &&) noexcept
 Move assignment operator.
 WindowBindable (const WindowBindable &) noexcept
 Copy constructor.
virtual WindowBindable & operator= (const WindowBindable &) noexcept
 Copy assignment operator.
void bind_window () noexcept
 Bind SDL3 window to this object.
Protected Attributes inherited from galaxy::WindowBindable
SDL_Window * m_window
 Pointer to SDL_Window handle.

Detailed Description

Physical mouse device and state management.

Definition at line 28 of file Mouse.hpp.

Constructor & Destructor Documentation

◆ Mouse() [1/3]

galaxy::Mouse::Mouse ( )
noexcept

Constructor.

Definition at line 22 of file Mouse.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Mouse()

galaxy::Mouse::~Mouse ( )
noexcept

Destructor.

Definition at line 29 of file Mouse.cpp.

Here is the call graph for this function:

◆ Mouse() [2/3]

galaxy::Mouse::Mouse ( Mouse && )
privatedelete

Move constructor.

Here is the call graph for this function:

◆ Mouse() [3/3]

galaxy::Mouse::Mouse ( const Mouse & )
privatedelete

Copy constructor.

Here is the call graph for this function:

Member Function Documentation

◆ mouse_connected()

bool galaxy::Mouse::mouse_connected ( ) const
nodiscardnoexcept

Check if there is a mouse connected.

Returns
True if there is a mouse device connected.

Definition at line 40 of file Mouse.cpp.

Here is the caller graph for this function:

◆ set_mouse_grab()

void galaxy::Mouse::set_mouse_grab ( const bool grabbed) const
noexcept

Toggle mouse grab.

Parameters
grabbedThis is true to grab keyboard, and false to release.

Definition at line 45 of file Mouse.cpp.

Here is the caller graph for this function:

◆ warp_mouse()

void galaxy::Mouse::warp_mouse ( const float x,
const float y ) const
noexcept

Move the mouse cursor to the given position within the window.

This function generates a mouse motion event. Will not work correctly if mouse space is altered.

Parameters
xThe x coordinate within the window.
yThe y coordinate within the window.

Definition at line 50 of file Mouse.cpp.

Here is the caller graph for this function:

◆ set_window_mouse_rect()

bool galaxy::Mouse::set_window_mouse_rect ( iRect & rect)
nodiscardnoexcept

Confines the cursor to the specified area of a window.

Note that this does NOT grab the cursor, it only defines the area a cursor is restricted to when the window has mouse focus. Will not work correctly if mouse space is altered.

Parameters
rectA rectangle area in window-relative coordinates.
Returns
True on success.

Definition at line 55 of file Mouse.cpp.

Here is the caller graph for this function:

◆ show_cursor()

void galaxy::Mouse::show_cursor ( ) const
noexcept

Show cursor.

Definition at line 61 of file Mouse.cpp.

Here is the caller graph for this function:

◆ hide_cursor()

void galaxy::Mouse::hide_cursor ( ) const
noexcept

Hide cursor.

Definition at line 66 of file Mouse.cpp.

Here is the caller graph for this function:

◆ set_cursor_system()

void galaxy::Mouse::set_cursor_system ( const SDL_SystemCursor cursor)
noexcept

Set cursor to a system cursor.

Parameters
cursorSDL_SystemCursor enum.

Definition at line 71 of file Mouse.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ use_custom_mouse()

void galaxy::Mouse::use_custom_mouse ( const std::string & cursor,
const glm::ivec2 & offset = glm::ivec2(0, 0) )

Replaces the system cursor with a bitmap.

Use a bitmap as the mouse cursor, drawn so the pixel at (offset_x, offset_y), measured from the bitmap's top-left, sits on the mouse position; nullptr restores the OS.

Parameters
cursorTexture to draw.
offsetTop left, right of mouse cursor.

Definition at line 86 of file Mouse.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_cursor()

void galaxy::Mouse::restore_cursor ( )
noexcept

Set the cursor back to default.

Definition at line 122 of file Mouse.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_mouse_down()

bool galaxy::Mouse::is_mouse_down ( const MouseButton btn) const
nodiscardnoexcept

Check if a mouse button was pressed.

Parameters
btnMouse button keycode.
Returns
True if button was pressed.

Definition at line 137 of file Mouse.cpp.

Here is the caller graph for this function:

◆ mouse_x()

int galaxy::Mouse::mouse_x ( ) const
nodiscardnoexcept

Get current cursor x position.

Returns
Returns logical pixel pos.

Definition at line 143 of file Mouse.cpp.

Here is the caller graph for this function:

◆ mouse_y()

int galaxy::Mouse::mouse_y ( ) const
nodiscardnoexcept

Get current cursor y position.

Returns
Returns logical pixel pos.

Definition at line 148 of file Mouse.cpp.

Here is the caller graph for this function:

◆ set_mouse_mapping()

void galaxy::Mouse::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.

Make mouse_x()/mouse_y() report positions inside a scaled image drawn at (x, y) in screen coordinates with the given scale, for example a letterboxed or integer-scaled render target. See present_scaled_target(). Positions over the bars fall outside the image's coordinate range.

Parameters
xUpper X position of space.
yUpper Y position of space.
scale_xScale "width".
scale_yScale "height".

Definition at line 153 of file Mouse.cpp.

Here is the caller graph for this function:

◆ clear_mouse_mapping()

void galaxy::Mouse::clear_mouse_mapping ( ) const
noexcept

Return mouse_x()/mouse_y() to plain screen coordinates.

Definition at line 158 of file Mouse.cpp.

Here is the caller graph for this function:

◆ set_relative_mouse_mode()

void galaxy::Mouse::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).

Parameters
enabledTrue to enable, false to disable.

Definition at line 163 of file Mouse.cpp.

Here is the caller graph for this function:

◆ relative_mouse_mode()

bool galaxy::Mouse::relative_mouse_mode ( ) const
nodiscardnoexcept

Return whether relative mouse mode is currently enabled.

Returns
True if the mouse is in relative mode.

Definition at line 168 of file Mouse.cpp.

Here is the caller graph for this function:

◆ mouse_delta()

glm::ivec2 galaxy::Mouse::mouse_delta ( int * dx,
int * dy )
nodiscardnoexcept

Retrieve relative mouse movement (delta) since the last call.

Returns
vec2, x is delta x, y is delta y.

Definition at line 173 of file Mouse.cpp.

Here is the caller graph for this function:

◆ operator=() [1/2]

Mouse & galaxy::Mouse::operator= ( Mouse && )
privatedelete

Move assignment operator.

Here is the call graph for this function:

◆ operator=() [2/2]

Mouse & galaxy::Mouse::operator= ( const Mouse & )
privatedelete

Copy assignment operator.

Here is the call graph for this function:

◆ destroy_cursor()

void galaxy::Mouse::destroy_cursor ( )
privatenoexcept

Destroy any existing cursor.

Definition at line 128 of file Mouse.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ m_cursor

SDL_Cursor* galaxy::Mouse::m_cursor
private

Holds data for a custom cursor.

Definition at line 210 of file Mouse.hpp.

◆ m_cursor_bitmap

sl::Bitmap* galaxy::Mouse::m_cursor_bitmap
private

Mouse custom bitmap.

Definition at line 215 of file Mouse.hpp.


The documentation for this class was generated from the following files: