Loading...
Searching...
No Matches
Event.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
32#include <SFML/Window/Mouse.hpp>
34
36
37#include <variant>
38
39
40namespace sf
41{
46class Event
47{
48public:
53 struct Closed
54 {
55 };
56
61 struct Resized
62 {
64 };
65
70 struct FocusLost
71 {
72 };
73
79 {
80 };
81
87 {
88 char32_t unicode{};
89 };
90
96 {
99 bool alt{};
100 bool control{};
101 bool shift{};
102 bool system{};
103 };
104
118
129
139
149
155 {
157 };
158
188 {
190 };
191
197 {
198 };
199
205 {
206 };
207
213 {
214 unsigned int joystickId{};
215 unsigned int button{};
216 };
217
223 {
224 unsigned int joystickId{};
225 unsigned int button{};
226 };
227
233 {
234 unsigned int joystickId{};
236 float position{};
237 };
238
244 {
245 unsigned int joystickId{};
246 };
247
253 {
254 unsigned int joystickId{};
255 };
256
262 {
263 unsigned int finger{};
265 };
266
272 {
273 unsigned int finger{};
275 };
276
282 {
283 unsigned int finger{};
285 };
286
296
305 template <typename TEventSubtype>
306 Event(const TEventSubtype& eventSubtype);
307
316 template <typename TEventSubtype>
317 [[nodiscard]] bool is() const;
318
327 template <typename TEventSubtype>
328 [[nodiscard]] const TEventSubtype* getIf() const;
329
338 template <typename T>
339 decltype(auto) visit(T&& visitor) const;
340
341private:
343 // Member data
345 std::variant<Closed,
346 Resized,
347 FocusLost,
358 MouseLeft,
368 m_data;
369
371 // Helper functions
373 template <typename T, typename... Ts>
374 [[nodiscard]] static constexpr bool isInParameterPack(const std::variant<Ts...>*)
375 {
376 return (std::is_same_v<T, Ts> || ...);
377 }
378
379 template <typename T>
380 static constexpr bool isEventSubtype = isInParameterPack<T>(decltype (&m_data)(nullptr));
381};
382
383} // namespace sf
384
385#include <SFML/Window/Event.inl>
386
387
Defines a system event and its parameters.
Definition Event.hpp:47
const TEventSubtype * getIf() const
Attempt to get specified event subtype.
bool is() const
Check current event subtype.
Event(const TEventSubtype &eventSubtype)
Construct from a given sf::Event subtype.
decltype(auto) visit(T &&visitor) const
Apply a visitor to the event.
Axis
Axes supported by SFML joysticks.
Definition Joystick.hpp:55
Key
Key codes.
Definition Keyboard.hpp:52
Scan
Scancodes.
Definition Keyboard.hpp:173
Button
Mouse buttons.
Definition Mouse.hpp:50
Wheel
Mouse wheels.
Definition Mouse.hpp:66
Type
Sensor type.
Definition Sensor.hpp:45
Closed event subtype.
Definition Event.hpp:54
Gained focus event subtype.
Definition Event.hpp:79
Lost focus event subtype.
Definition Event.hpp:71
Joystick button pressed event subtype.
Definition Event.hpp:213
unsigned int button
Index of the button that has been pressed (in range [0 .. Joystick::ButtonCount - 1])
Definition Event.hpp:215
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:214
Joystick button released event subtype.
Definition Event.hpp:223
unsigned int button
Index of the button that has been released (in range [0 .. Joystick::ButtonCount - 1])
Definition Event.hpp:225
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:224
Joystick connected event subtype.
Definition Event.hpp:244
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:245
Joystick disconnected event subtype.
Definition Event.hpp:253
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:254
Joystick axis move event subtype.
Definition Event.hpp:233
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:234
Joystick::Axis axis
Axis on which the joystick moved.
Definition Event.hpp:235
float position
New position on the axis (in range [-100 .. 100])
Definition Event.hpp:236
Key pressed event subtype.
Definition Event.hpp:96
bool system
Is the System key pressed?
Definition Event.hpp:102
bool control
Is the Control key pressed?
Definition Event.hpp:100
bool shift
Is the Shift key pressed?
Definition Event.hpp:101
bool alt
Is the Alt key pressed?
Definition Event.hpp:99
Keyboard::Key code
Code of the key that has been pressed.
Definition Event.hpp:97
Keyboard::Scancode scancode
Physical code of the key that has been pressed.
Definition Event.hpp:98
Key released event subtype.
Definition Event.hpp:110
bool alt
Is the Alt key pressed?
Definition Event.hpp:113
bool control
Is the Control key pressed?
Definition Event.hpp:114
bool shift
Is the Shift key pressed?
Definition Event.hpp:115
bool system
Is the System key pressed?
Definition Event.hpp:116
Keyboard::Key code
Code of the key that has been released.
Definition Event.hpp:111
Keyboard::Scancode scancode
Physical code of the key that has been released.
Definition Event.hpp:112
Mouse button pressed event subtype.
Definition Event.hpp:135
Vector2i position
Position of the mouse pointer, relative to the top left of the owner window.
Definition Event.hpp:137
Mouse::Button button
Code of the button that has been pressed.
Definition Event.hpp:136
Mouse button released event subtype.
Definition Event.hpp:145
Vector2i position
Position of the mouse pointer, relative to the top left of the owner window.
Definition Event.hpp:147
Mouse::Button button
Code of the button that has been released.
Definition Event.hpp:146
Mouse entered event subtype.
Definition Event.hpp:197
Mouse left event subtype.
Definition Event.hpp:205
Mouse move raw event subtype.
Definition Event.hpp:188
Vector2i delta
Delta movement of the mouse since the last event.
Definition Event.hpp:189
Mouse move event subtype.
Definition Event.hpp:155
Vector2i position
Position of the mouse pointer, relative to the top left of the owner window.
Definition Event.hpp:156
Mouse wheel scrolled event subtype.
Definition Event.hpp:124
Mouse::Wheel wheel
Which wheel (for mice with multiple ones)
Definition Event.hpp:125
Vector2i position
Position of the mouse pointer, relative to the top left of the owner window.
Definition Event.hpp:127
float delta
Wheel offset (positive is up/left, negative is down/right). High-precision mice may use non-integral ...
Definition Event.hpp:126
Resized event subtype.
Definition Event.hpp:62
Vector2u size
New size, in pixels.
Definition Event.hpp:63
Sensor event subtype.
Definition Event.hpp:292
Sensor::Type type
Type of the sensor.
Definition Event.hpp:293
Vector3f value
Current value of the sensor on the X, Y, and Z axes.
Definition Event.hpp:294
Text event subtype.
Definition Event.hpp:87
char32_t unicode
UTF-32 Unicode value of the character.
Definition Event.hpp:88
Touch began event subtype.
Definition Event.hpp:262
Vector2i position
Start position of the touch, relative to the top left of the owner window.
Definition Event.hpp:264
unsigned int finger
Index of the finger in case of multi-touch events.
Definition Event.hpp:263
Touch ended event subtype.
Definition Event.hpp:282
Vector2i position
Final position of the touch, relative to the top left of the owner window.
Definition Event.hpp:284
unsigned int finger
Index of the finger in case of multi-touch events.
Definition Event.hpp:283
Touch moved event subtype.
Definition Event.hpp:272
Vector2i position
Current position of the touch, relative to the top left of the owner window.
Definition Event.hpp:274
unsigned int finger
Index of the finger in case of multi-touch events.
Definition Event.hpp:273