CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
InputEvent.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
12#include "Input.hpp"
13
16
18
20
21namespace CeresEngine {
22
24 enum class InputEventType {
26 Key,
27
29 Mouse,
30
32 Text
33 };
34
36 struct InputEvent {
38 double timestamp = 0.0;
39
43 };
44
46 enum class KeyEventType {
48 Down,
49
51 Up
52 };
53
78
80 enum class MouseEventType {
82 Down,
83
85 Up,
86
88 Move,
89
91 Drag,
92
94 Scroll
95 };
96
122
124 struct TextEvent final : public InputEvent {
128
139 };
140
143 private:
146
149
150 public:
153
156
159
162
163 AnyInputEvent(const AnyInputEvent&) = default;
165
168
170
171 public: // Common Data
174
175 public: // Casting
179
182
185
187 template<typename T> [[nodiscard]] bool is() const noexcept { return getEventType() == T::structType; }
188
190 template<typename T> [[nodiscard]] const T& as() const noexcept {
191 assert(getEventType() == T::structType);
192 return mData.as<T>();
193 }
194
196 template<typename T> [[nodiscard]] T& as() noexcept {
197 assert(getEventType() == T::structType);
198 return mData.as<T>();
199 }
200
201 public: // KeyEvent
204
207
210
211 public: // MouseEvent
214
217
220
221 public: // TextEvent
224
227
230 };
231
232} // namespace CeresEngine
#define CE_EXPLICIT(EXPR)
Definition Macros.hpp:413
A type that describes any possible event type.
Definition InputEvent.hpp:142
const MouseEvent & asMouseEvent() const noexcept
Gets the event as a concrete event of type MouseEvent.
Definition InputEvent.hpp:216
Variant< std::monostate, KeyEvent, MouseEvent, TextEvent > Variant
The variant type used to store the event types.
Definition InputEvent.hpp:145
bool isTextEvent() const noexcept
Checks if the event is of type TextEvent.
Definition InputEvent.hpp:223
MouseEvent & asMouseEvent() noexcept
Gets the event as a concrete event of type MouseEvent.
Definition InputEvent.hpp:219
T & as() noexcept
Gets the event as a concrete event of type T.
Definition InputEvent.hpp:196
bool isValid() const noexcept
Checks if the event is valid.
const TextEvent & asTextEvent() const noexcept
Gets the event as a concrete event of type TextEvent.
Definition InputEvent.hpp:226
AnyInputEvent(const AnyInputEvent &)=default
InputEventType getEventType() const noexcept
Returns the type of the event represented by this AnyEvent structure.
const KeyEvent & asKeyEvent() const noexcept
Gets the event as a concrete event of type KeyEvent.
Definition InputEvent.hpp:206
AnyInputEvent(AnyInputEvent &&) noexcept=default
bool isMouseEvent() const noexcept
Checks if the event is of type MouseEvent.
Definition InputEvent.hpp:213
const T & as() const noexcept
Gets the event as a concrete event of type T.
Definition InputEvent.hpp:190
KeyEvent & asKeyEvent() noexcept
Gets the event as a concrete event of type KeyEvent.
Definition InputEvent.hpp:209
bool is() const noexcept
Checks if the event is of type T.
Definition InputEvent.hpp:187
bool isKeyEvent() const noexcept
Checks if the event is of type KeyEvent.
Definition InputEvent.hpp:203
Variant mData
The variant type used to store the event types.
Definition InputEvent.hpp:148
AnyInputEvent & operator=(const AnyInputEvent &)=default
AnyInputEvent() noexcept=default
Creates a new empty event.
PlatformWindow * getWindow() const noexcept
The platform window that triggered the input event, if any.
TextEvent & asTextEvent() noexcept
Gets the event as a concrete event of type TextEvent.
Definition InputEvent.hpp:229
Definition PlatformWindow.hpp:44
Definition Text.hpp:14
Definition Application.hpp:19
ModifierButton
A enumeration of possible modifier buttons.
Definition Input.hpp:298
@ None
A special modifier button constant that only returns true if no modifier key is pressed.
Button
A enumeration of known buttons.
Definition Input.hpp:25
MouseEventType
A enumeration that defines the type of mouse events.
Definition InputEvent.hpp:80
@ Scroll
The mouse event represents a mouse scroll wheel.
@ Move
The mouse event represents a mouse movement.
@ Drag
The mouse event represents a mouse drag.
KeyEventType
A enumeration that defines the type of key events.
Definition InputEvent.hpp:46
InputEventType
A structure that describes the type of an event.
Definition InputEvent.hpp:24
@ Key
The event is of type KeyEvent.
@ Text
The event is of type TextEvent.
@ Mouse
The event is of type MouseEvent.
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
A base structure that forms the base of all input events.
Definition InputEvent.hpp:36
PlatformWindow * window
The platform window that triggered the input event, if any.
Definition InputEvent.hpp:42
double timestamp
The time when the event occurred in seconds since system startup.
Definition InputEvent.hpp:38
A structure that describes a key press event.
Definition InputEvent.hpp:55
KeyEventType type
The type of key event represented by the event structure.
Definition InputEvent.hpp:61
bool isRepeat
If set, indicates that the key is a repeat of a previous press.
Definition InputEvent.hpp:70
UInt32 scanCode
The system-specific scancode of the key.
Definition InputEvent.hpp:76
Button button
The button that has triggered the event.
Definition InputEvent.hpp:64
UInt32 repeatCount
Defines the number of times the key press is repeating.
Definition InputEvent.hpp:73
ModifierButton modifiers
The set of modifier keys pressed alongside this button.
Definition InputEvent.hpp:67
static constexpr InputEventType structType
A value that determines the type of event represented by this event struct.
Definition InputEvent.hpp:58
A structure that describes a mouse event.
Definition InputEvent.hpp:98
ModifierButton modifiers
The set of modifier keys pressed alongside this mouse button.
Definition InputEvent.hpp:110
Vector2 delta
TODO: Write docs.
Definition InputEvent.hpp:116
static constexpr InputEventType structType
A value that determines the type of event represented by this event struct.
Definition InputEvent.hpp:101
Vector2 position
The position the mouse cursor was when the even got triggered.
Definition InputEvent.hpp:113
Button button
The mouse button that has triggered the event.
Definition InputEvent.hpp:107
Vector2 scrollAmount
If the event sub-type is of type scroll this field contains the amount the scroll wheel has moved.
Definition InputEvent.hpp:120
MouseEventType type
The type of mouse event represented by the event structure.
Definition InputEvent.hpp:104
A structure that describes a text input event.
Definition InputEvent.hpp:124
static constexpr InputEventType structType
A value that determines the type of event represented by this event struct.
Definition InputEvent.hpp:127
String characters
The characters associated with a key-up or key-down event.
Definition InputEvent.hpp:138