Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
mouse.hpp
Go to the documentation of this file.
1
3#pragma once
4
6#include <aegis2d/platform/export.hpp>
7
8#include <bitset>
9#include <cstddef>
10#include <cstdint>
11
12namespace aegis2d::platform {
13
15enum class MouseButton : std::uint8_t {
17 Left,
19 Middle,
21 Right,
23 X1,
25 X2,
26};
27
29inline constexpr std::size_t mouse_button_count = static_cast<std::size_t>(MouseButton::X2) + 1;
30
38class AEGIS2D_PLATFORM_EXPORT Mouse {
39public:
41 void begin_frame() noexcept;
42
45 void move_to(Vec2 position) noexcept;
46
49 void press(MouseButton button) noexcept;
50
53 void release(MouseButton button) noexcept;
54
56 void release_all() noexcept;
57
61 void scroll(Vec2 delta) noexcept;
62
65 [[nodiscard]] Vec2 position() const noexcept;
66
69 [[nodiscard]] bool moved() const noexcept;
70
74 [[nodiscard]] bool held(MouseButton button) const noexcept;
75
79 [[nodiscard]] bool pressed(MouseButton button) const noexcept;
80
84 [[nodiscard]] bool released(MouseButton button) const noexcept;
85
88 [[nodiscard]] Vec2 wheel() const noexcept;
89
92 [[nodiscard]] std::uint64_t frame() const noexcept;
93
94private:
95 std::bitset<mouse_button_count> held_;
96 std::bitset<mouse_button_count> pressed_;
97 std::bitset<mouse_button_count> released_;
98 Vec2 position_{0.0F, 0.0F};
99 Vec2 wheel_{0.0F, 0.0F};
100 bool moved_ = false;
101 std::uint64_t frame_ = 0;
102};
103
104} // namespace aegis2d::platform
Position of the mouse, buttons held, and those pressed or released and the wheel turned since the sta...
Definition mouse.hpp:38
void begin_frame() noexcept
Starts a frame: forgets the presses, releases and wheel of the previous one.
Vector and matrix types of the engine (GLM behind engine names).
Window and input on top of SDL3, independent of the graphics API (client only).
Definition actions.hpp:19
constexpr std::size_t mouse_button_count
Number of MouseButton values.
Definition mouse.hpp:29
MouseButton
Buttons of a mouse.
Definition mouse.hpp:15
@ X2
Second side button (forward in a browser).
@ X1
First side button (back in a browser).
glm::vec2 Vec2
2D vector of floats: positions, velocities, sizes (glm::vec2).
Definition math.hpp:19
Definition endpoint.hpp:85