Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_mouse.hpp
1#pragma once
2
3#include <array>
4#include <ostream>
5#include <string>
6
7#include "structure/math/spk_vector2.hpp"
8#include "type/spk_input_state.hpp"
9
10namespace spk
11{
16 struct Mouse
17 {
21 enum Button
22 {
23 Right,
24 Middle,
25 Left
26 };
27
30 static inline const size_t NbButton = 3;
31
35 std::array<InputState, NbButton> buttons;
39 spk::Vector2Int position = {0, 0};
43 spk::Vector2Int deltaPosition = {0, 0};
47 float wheel = 0;
48
49 Mouse()
50 {
51 for (auto &state : buttons)
52 {
53 state = InputState::Up;
54 }
55 }
56
62 InputState &operator[](const Button p_button)
63 {
64 return buttons[static_cast<size_t>(p_button)];
65 }
66
72 const InputState &operator[](const Button p_button) const
73 {
74 return buttons[static_cast<size_t>(p_button)];
75 }
76 };
77
78 std::string toString(const Mouse::Button &p_button);
79 std::wstring toWstring(const Mouse::Button &p_button);
80
81 std::ostream &operator<<(std::ostream &p_stream, const Mouse::Button &p_button);
82 std::wostream &operator<<(std::wostream &p_stream, const Mouse::Button &p_button);
83}
InputState & operator[](const Button p_button)
Accesses the state of a mouse button.
Definition spk_mouse.hpp:62
const InputState & operator[](const Button p_button) const
Accesses the state of a mouse button.
Definition spk_mouse.hpp:72
Button
Mouse buttons tracked by the input system.
Definition spk_mouse.hpp:22
static const size_t NbButton
Number of mouse buttons supported.
Definition spk_mouse.hpp:30
spk::Vector2Int deltaPosition
Current delta position between current frame and the previous one.
Definition spk_mouse.hpp:43
float wheel
Wheel delta.
Definition spk_mouse.hpp:47
spk::Vector2Int position
Current cursor position.
Definition spk_mouse.hpp:39
std::array< InputState, NbButton > buttons
Button states ordered as Right, Middle, Left.
Definition spk_mouse.hpp:35