SFML 3.0.0

- Main Page
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

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
30#include <SFML/Window/Joystick.hpp>
31#include <SFML/Window/Keyboard.hpp>
32#include <SFML/Window/Mouse.hpp>
33#include <SFML/Window/Sensor.hpp>
34
35#include <SFML/System/Vector2.hpp>
36
37#include <variant>
38
39
40 namespace sf
41{
46 class Event
47{
48 public:
53 struct Closed
54 {
55 };
56
61 struct Resized
62 {
63 Vector2u size;
64 };
65
70 struct FocusLost
71 {
72 };
73
78 struct FocusGained
79 {
80 };
81
86 struct TextEntered
87 {
88 char32_t unicode{};
89 };
90
95 struct KeyPressed
96 {
97 Keyboard::Key code{};
98 Keyboard::Scancode scancode{};
99 bool alt{};
100 bool control{};
101 bool shift{};
102 bool system{};
103 };
104
109 struct KeyReleased
110 {
111 Keyboard::Key code{};
112 Keyboard::Scancode scancode{};
113 bool alt{};
114 bool control{};
115 bool shift{};
116 bool system{};
117 };
118
123 struct MouseWheelScrolled
124 {
125 Mouse::Wheel wheel{};
126 float delta{};
127 Vector2i position;
128 };
129
134 struct MouseButtonPressed
135 {
136 Mouse::Button button{};
137 Vector2i position;
138 };
139
144 struct MouseButtonReleased
145 {
146 Mouse::Button button{};
147 Vector2i position;
148 };
149
154 struct MouseMoved
155 {
156 Vector2i position;
157 };
158
187 struct MouseMovedRaw
188 {
189 Vector2i delta;
190 };
191
196 struct MouseEntered
197 {
198 };
199
204 struct MouseLeft
205 {
206 };
207
212 struct JoystickButtonPressed
213 {
214 unsigned int joystickId{};
215 unsigned int button{};
216 };
217
222 struct JoystickButtonReleased
223 {
224 unsigned int joystickId{};
225 unsigned int button{};
226 };
227
232 struct JoystickMoved
233 {
234 unsigned int joystickId{};
235 Joystick::Axis axis{};
236 float position{};
237 };
238
243 struct JoystickConnected
244 {
245 unsigned int joystickId{};
246 };
247
252 struct JoystickDisconnected
253 {
254 unsigned int joystickId{};
255 };
256
261 struct TouchBegan
262 {
263 unsigned int finger{};
264 Vector2i position;
265 };
266
271 struct TouchMoved
272 {
273 unsigned int finger{};
274 Vector2i position;
275 };
276
281 struct TouchEnded
282 {
283 unsigned int finger{};
284 Vector2i position;
285 };
286
291 struct SensorChanged
292 {
293 Sensor::Type type{};
294 Vector3f value;
295 };
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
341 private:
343 // Member data
345 std::variant<Closed,
346 Resized,
347 FocusLost,
348 FocusGained,
349 TextEntered,
350 KeyPressed,
351 KeyReleased,
352 MouseWheelScrolled,
353 MouseButtonPressed,
354 MouseButtonReleased,
355 MouseMoved,
356 MouseMovedRaw,
357 MouseEntered,
358 MouseLeft,
359 JoystickButtonPressed,
360 JoystickButtonReleased,
361 JoystickMoved,
362 JoystickConnected,
363 JoystickDisconnected,
364 TouchBegan,
365 TouchMoved,
366 TouchEnded,
367 SensorChanged>
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
Joystick.hpp
Keyboard.hpp
Mouse.hpp
Sensor.hpp
Vector2.hpp
sf::Event
Defines a system event and its parameters.
Definition Event.hpp:47
sf::Event::getIf
const TEventSubtype * getIf() const
Attempt to get specified event subtype.
sf::Event::is
bool is() const
Check current event subtype.
sf::Event::Event
Event(const TEventSubtype &eventSubtype)
Construct from a given sf::Event subtype.
sf::Event::visit
decltype(auto) visit(T &&visitor) const
Apply a visitor to the event.
sf::Vector2< unsigned int >
sf::Vector3< float >
sf::Joystick::Axis
Axis
Axes supported by SFML joysticks.
Definition Joystick.hpp:55
sf::Keyboard::Key
Key
Key codes.
Definition Keyboard.hpp:52
sf::Keyboard::Scan
Scan
Scancodes.
Definition Keyboard.hpp:173
sf::Mouse::Button
Button
Mouse buttons.
Definition Mouse.hpp:50
sf::Mouse::Wheel
Wheel
Mouse wheels.
Definition Mouse.hpp:66
sf::Sensor::Type
Type
Sensor type.
Definition Sensor.hpp:45
sf
Definition AudioResource.hpp:36
sf::Event::Closed
Closed event subtype.
Definition Event.hpp:54
sf::Event::FocusGained
Gained focus event subtype.
Definition Event.hpp:79
sf::Event::FocusLost
Lost focus event subtype.
Definition Event.hpp:71
sf::Event::JoystickButtonPressed
Joystick button pressed event subtype.
Definition Event.hpp:213
sf::Event::JoystickButtonPressed::button
unsigned int button
Index of the button that has been pressed (in range [0 .. Joystick::ButtonCount - 1])
Definition Event.hpp:215
sf::Event::JoystickButtonPressed::joystickId
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:214
sf::Event::JoystickButtonReleased
Joystick button released event subtype.
Definition Event.hpp:223
sf::Event::JoystickButtonReleased::button
unsigned int button
Index of the button that has been released (in range [0 .. Joystick::ButtonCount - 1])
Definition Event.hpp:225
sf::Event::JoystickButtonReleased::joystickId
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:224
sf::Event::JoystickConnected
Joystick connected event subtype.
Definition Event.hpp:244
sf::Event::JoystickConnected::joystickId
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:245
sf::Event::JoystickDisconnected
Joystick disconnected event subtype.
Definition Event.hpp:253
sf::Event::JoystickDisconnected::joystickId
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:254
sf::Event::JoystickMoved
Joystick axis move event subtype.
Definition Event.hpp:233
sf::Event::JoystickMoved::joystickId
unsigned int joystickId
Index of the joystick (in range [0 .. Joystick::Count - 1])
Definition Event.hpp:234
sf::Event::JoystickMoved::axis
Joystick::Axis axis
Axis on which the joystick moved.
Definition Event.hpp:235
sf::Event::JoystickMoved::position
float position
New position on the axis (in range [-100 .. 100])
Definition Event.hpp:236
sf::Event::KeyPressed
Key pressed event subtype.
Definition Event.hpp:96
sf::Event::KeyPressed::system
bool system
Is the System key pressed?
Definition Event.hpp:102
sf::Event::KeyPressed::control
bool control
Is the Control key pressed?
Definition Event.hpp:100
sf::Event::KeyPressed::shift
bool shift
Is the Shift key pressed?
Definition Event.hpp:101
sf::Event::KeyPressed::alt
bool alt
Is the Alt key pressed?
Definition Event.hpp:99
sf::Event::KeyPressed::code
Keyboard::Key code
Code of the key that has been pressed.
Definition Event.hpp:97
sf::Event::KeyPressed::scancode
Keyboard::Scancode scancode
Physical code of the key that has been pressed.
Definition Event.hpp:98
sf::Event::KeyReleased
Key released event subtype.
Definition Event.hpp:110
sf::Event::KeyReleased::alt
bool alt
Is the Alt key pressed?
Definition Event.hpp:113
sf::Event::KeyReleased::control
bool control
Is the Control key pressed?
Definition Event.hpp:114
sf::Event::KeyReleased::shift
bool shift
Is the Shift key pressed?
Definition Event.hpp:115
sf::Event::KeyReleased::system
bool system
Is the System key pressed?
Definition Event.hpp:116
sf::Event::KeyReleased::code
Keyboard::Key code
Code of the key that has been released.
Definition Event.hpp:111
sf::Event::KeyReleased::scancode
Keyboard::Scancode scancode
Physical code of the key that has been released.
Definition Event.hpp:112
sf::Event::MouseButtonPressed
Mouse button pressed event subtype.
Definition Event.hpp:135
sf::Event::MouseButtonPressed::position
Vector2i position
Position of the mouse pointer, relative to the top left of the owner window.
Definition Event.hpp:137
sf::Event::MouseButtonPressed::button
Mouse::Button button
Code of the button that has been pressed.
Definition Event.hpp:136
sf::Event::MouseButtonReleased
Mouse button released event subtype.
Definition Event.hpp:145
sf::Event::MouseButtonReleased::position
Vector2i position
Position of the mouse pointer, relative to the top left of the owner window.
Definition Event.hpp:147
sf::Event::MouseButtonReleased::button
Mouse::Button button
Code of the button that has been released.
Definition Event.hpp:146
sf::Event::MouseEntered
Mouse entered event subtype.
Definition Event.hpp:197
sf::Event::MouseLeft
Mouse left event subtype.
Definition Event.hpp:205
sf::Event::MouseMovedRaw
Mouse move raw event subtype.
Definition Event.hpp:188
sf::Event::MouseMovedRaw::delta
Vector2i delta
Delta movement of the mouse since the last event.
Definition Event.hpp:189
sf::Event::MouseMoved
Mouse move event subtype.
Definition Event.hpp:155
sf::Event::MouseMoved::position
Vector2i position
Position of the mouse pointer, relative to the top left of the owner window.
Definition Event.hpp:156
sf::Event::MouseWheelScrolled
Mouse wheel scrolled event subtype.
Definition Event.hpp:124
sf::Event::MouseWheelScrolled::wheel
Mouse::Wheel wheel
Which wheel (for mice with multiple ones)
Definition Event.hpp:125
sf::Event::MouseWheelScrolled::position
Vector2i position
Position of the mouse pointer, relative to the top left of the owner window.
Definition Event.hpp:127
sf::Event::MouseWheelScrolled::delta
float delta
Wheel offset (positive is up/left, negative is down/right). High-precision mice may use non-integral ...
Definition Event.hpp:126
sf::Event::Resized
Resized event subtype.
Definition Event.hpp:62
sf::Event::Resized::size
Vector2u size
New size, in pixels.
Definition Event.hpp:63
sf::Event::SensorChanged
Sensor event subtype.
Definition Event.hpp:292
sf::Event::SensorChanged::type
Sensor::Type type
Type of the sensor.
Definition Event.hpp:293
sf::Event::SensorChanged::value
Vector3f value
Current value of the sensor on the X, Y, and Z axes.
Definition Event.hpp:294
sf::Event::TextEntered
Text event subtype.
Definition Event.hpp:87
sf::Event::TextEntered::unicode
char32_t unicode
UTF-32 Unicode value of the character.
Definition Event.hpp:88
sf::Event::TouchBegan
Touch began event subtype.
Definition Event.hpp:262
sf::Event::TouchBegan::position
Vector2i position
Start position of the touch, relative to the top left of the owner window.
Definition Event.hpp:264
sf::Event::TouchBegan::finger
unsigned int finger
Index of the finger in case of multi-touch events.
Definition Event.hpp:263
sf::Event::TouchEnded
Touch ended event subtype.
Definition Event.hpp:282
sf::Event::TouchEnded::position
Vector2i position
Final position of the touch, relative to the top left of the owner window.
Definition Event.hpp:284
sf::Event::TouchEnded::finger
unsigned int finger
Index of the finger in case of multi-touch events.
Definition Event.hpp:283
sf::Event::TouchMoved
Touch moved event subtype.
Definition Event.hpp:272
sf::Event::TouchMoved::position
Vector2i position
Current position of the touch, relative to the top left of the owner window.
Definition Event.hpp:274
sf::Event::TouchMoved::finger
unsigned int finger
Index of the finger in case of multi-touch events.
Definition Event.hpp:273