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
Mouse.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_INPUT_MOUSE_HPP_
9#define GALAXY_INPUT_MOUSE_HPP_
10
11#include <glm/vec2.hpp>
12#include <SDL3/SDL_mouse.h>
13
15#include "galaxy/math/Rect.hpp"
17
18namespace sl
19{
20 struct Bitmap;
21}
22
23namespace galaxy
24{
28 class Mouse final : public WindowBindable
29 {
30 public:
34 Mouse() noexcept;
35
39 ~Mouse() noexcept;
40
46 [[nodiscard]]
47 bool mouse_connected() const noexcept;
48
54 void set_mouse_grab(const bool grabbed) const noexcept;
55
65 void warp_mouse(const float x, const float y) const noexcept;
66
77 [[nodiscard]]
78 bool set_window_mouse_rect(iRect& rect) noexcept;
79
83 void show_cursor() const noexcept;
84
88 void hide_cursor() const noexcept;
89
95 void set_cursor_system(const SDL_SystemCursor cursor) noexcept;
96
105 void use_custom_mouse(const std::string& cursor, const glm::ivec2& offset = glm::ivec2(0, 0));
106
110 void restore_cursor() noexcept;
111
119 [[nodiscard]]
120 bool is_mouse_down(const MouseButton btn) const noexcept;
121
127 [[nodiscard]]
128 int mouse_x() const noexcept;
129
135 [[nodiscard]]
136 int mouse_y() const noexcept;
137
150 void set_mouse_mapping(const int x, const int y, const float scale_x, const float scale_y) const noexcept;
151
155 void clear_mouse_mapping() const noexcept;
156
162 void set_relative_mouse_mode(const bool enabled) const noexcept;
163
169 [[nodiscard]]
170 bool relative_mouse_mode() const noexcept;
171
177 [[nodiscard]]
178 glm::ivec2 mouse_delta(int* dx, int* dy) noexcept;
179
180 private:
184 Mouse(Mouse&&) = delete;
185
189 Mouse& operator=(Mouse&&) = delete;
190
194 Mouse(const Mouse&) = delete;
195
199 Mouse& operator=(const Mouse&) = delete;
200
204 void destroy_cursor() noexcept;
205
206 private:
210 SDL_Cursor* m_cursor;
211
216 };
217} // namespace galaxy
218
219#endif
bool set_window_mouse_rect(iRect &rect) noexcept
Confines the cursor to the specified area of a window.
Definition Mouse.cpp:55
glm::ivec2 mouse_delta(int *dx, int *dy) noexcept
Retrieve relative mouse movement (delta) since the last call.
Definition Mouse.cpp:173
sl::Bitmap * m_cursor_bitmap
Mouse custom bitmap.
Definition Mouse.hpp:215
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.
Definition Mouse.cpp:153
bool is_mouse_down(const MouseButton btn) const noexcept
Check if a mouse button was pressed.
Definition Mouse.cpp:137
void set_cursor_system(const SDL_SystemCursor cursor) noexcept
Set cursor to a system cursor.
Definition Mouse.cpp:71
Mouse() noexcept
Constructor.
Definition Mouse.cpp:22
Mouse & operator=(Mouse &&)=delete
Move assignment operator.
void clear_mouse_mapping() const noexcept
Return mouse_x()/mouse_y() to plain screen coordinates.
Definition Mouse.cpp:158
void destroy_cursor() noexcept
Destroy any existing cursor.
Definition Mouse.cpp:128
bool relative_mouse_mode() const noexcept
Return whether relative mouse mode is currently enabled.
Definition Mouse.cpp:168
void hide_cursor() const noexcept
Hide cursor.
Definition Mouse.cpp:66
Mouse & operator=(const Mouse &)=delete
Copy assignment operator.
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)...
Definition Mouse.cpp:163
Mouse(Mouse &&)=delete
Move constructor.
void restore_cursor() noexcept
Set the cursor back to default.
Definition Mouse.cpp:122
void set_mouse_grab(const bool grabbed) const noexcept
Toggle mouse grab.
Definition Mouse.cpp:45
int mouse_y() const noexcept
Get current cursor y position.
Definition Mouse.cpp:148
void show_cursor() const noexcept
Show cursor.
Definition Mouse.cpp:61
SDL_Cursor * m_cursor
Holds data for a custom cursor.
Definition Mouse.hpp:210
int mouse_x() const noexcept
Get current cursor x position.
Definition Mouse.cpp:143
Mouse(const Mouse &)=delete
Copy constructor.
bool mouse_connected() const noexcept
Check if there is a mouse connected.
Definition Mouse.cpp:40
void warp_mouse(const float x, const float y) const noexcept
Move the mouse cursor to the given position within the window.
Definition Mouse.cpp:50
void use_custom_mouse(const std::string &cursor, const glm::ivec2 &offset=glm::ivec2(0, 0))
Replaces the system cursor with a bitmap.
Definition Mouse.cpp:86
WindowBindable() noexcept
Constructor.
Tag.cpp galaxy.
Definition Tag.cpp:13
Rect< int > iRect
Type definition for an int rectangle.
Definition Rect.hpp:190
MouseButton
Enum class representing mouse buttons.
Mouse.hpp galaxy.
Definition Mouse.hpp:19