blob: 3a58dc794f6b02d7f35f40564bd40d8c78de936a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// SPDX-License-Identifier: BSD-2-Clause
// Copyright (c) 2025 Kirill Dmitrievich
// File: mouse.hh; Created: Tue Dec 30 2025 12:33:48
// Description: Mouse and scroll wheel handling
#ifndef CLIENT_IO_MOUSE_HH
#define CLIENT_IO_MOUSE_HH
#pragma once
class CursorPosEvent final {
public:
constexpr explicit CursorPosEvent(double xpos, double ypos);
constexpr float xpos(void) const noexcept;
constexpr float ypos(void) const noexcept;
constexpr const glm::fvec2& position(void) const noexcept;
private:
glm::fvec2 m_position;
};
class MouseButtonEvent final {
public:
constexpr explicit MouseButtonEvent(int button, int action, int modbits);
constexpr int button(void) const noexcept;
constexpr int action(void) const noexcept;
constexpr int modbits(void) const noexcept;
constexpr bool is_button(int button) const noexcept;
constexpr bool is_action(int action) const noexcept;
constexpr bool has_modbits(int modbits) const noexcept;
constexpr bool is_valid(void) const noexcept;
private:
int m_button;
int m_action;
int m_modbits;
};
class ScrollEvent final {
public:
constexpr explicit ScrollEvent(double xoffset, double yoffset);
constexpr float xoffset(void) const noexcept;
constexpr float yoffset(void) const noexcept;
constexpr const glm::fvec2& offset(void) const noexcept;
private:
glm::fvec2 m_offset;
};
namespace mouse
{
void init(void);
} // namespace mouse
constexpr CursorPosEvent::CursorPosEvent(double xpos, double ypos)
{
m_position.x = static_cast<float>(xpos);
m_position.y = static_cast<float>(ypos);
}
constexpr float CursorPosEvent::xpos(void) const noexcept
{
return m_position.x;
}
constexpr float CursorPosEvent::ypos(void) const noexcept
{
return m_position.y;
}
constexpr const glm::fvec2& CursorPosEvent::position(void) const noexcept
{
return m_position;
}
constexpr MouseButtonEvent::MouseButtonEvent(int button, int action, int modbits) : m_button(button), m_action(action), m_modbits(modbits)
{
// empty
}
constexpr int MouseButtonEvent::button(void) const noexcept
{
return m_button;
}
constexpr int MouseButtonEvent::action(void) const noexcept
{
return m_action;
}
constexpr int MouseButtonEvent::modbits(void) const noexcept
{
return m_modbits;
}
constexpr bool MouseButtonEvent::is_button(int button) const noexcept
{
return m_button == button;
}
constexpr bool MouseButtonEvent::is_action(int action) const noexcept
{
return m_action == action;
}
constexpr bool MouseButtonEvent::has_modbits(int modbits) const noexcept
{
return static_cast<bool>(m_modbits & modbits);
}
constexpr bool MouseButtonEvent::is_valid(void) const noexcept
{
return m_button >= 0 && m_button <= GLFW_MOUSE_BUTTON_LAST;
}
constexpr ScrollEvent::ScrollEvent(double xoffset, double yoffset)
{
m_offset.x = static_cast<float>(xoffset);
m_offset.y = static_cast<float>(yoffset);
}
constexpr float ScrollEvent::xoffset(void) const noexcept
{
return m_offset.x;
}
constexpr float ScrollEvent::yoffset(void) const noexcept
{
return m_offset.y;
}
constexpr const glm::fvec2& ScrollEvent::offset(void) const noexcept
{
return m_offset;
}
#endif
|