QuasarEngine
Cross-platform 3D engine and editor
Toggle main menu visibility
Loading...
Searching...
No Matches
KeyEvent.h
Go to the documentation of this file.
1
#pragma once
2
7
8
#include <
quasar/core/KeyCodes.h
>
9
#include <
quasar/events/Event.h
>
10
11
#include <spdlog/fmt/fmt.h>
12
13
#include <cstdint>
14
#include <string>
15
16
namespace
Quasar
17
{
21
class
KeyPressedEvent
final :
public
EventOf
<EventType::KeyPressed, EventCategory::Input | EventCategory::Keyboard>
22
{
23
public
:
27
explicit
KeyPressedEvent
(
Key
key,
bool
repeat =
false
) : m_Key(key), m_Repeat(repeat) {}
28
30
Key
GetKey
()
const
{
return
m_Key; }
31
33
bool
IsRepeat
()
const
{
return
m_Repeat; }
34
36
std::string
ToString
()
const override
{
return
fmt::format(
"{}: {}{}"
,
GetName
(),
static_cast<
std::uint16_t
>
(m_Key), m_Repeat ?
" (repeat)"
:
""
); }
37
38
private
:
39
Key
m_Key;
40
bool
m_Repeat =
false
;
41
};
42
44
class
KeyReleasedEvent
final :
public
EventOf
<EventType::KeyReleased, EventCategory::Input | EventCategory::Keyboard>
45
{
46
public
:
48
explicit
KeyReleasedEvent
(
Key
key) : m_Key(key) {}
49
51
Key
GetKey
()
const
{
return
m_Key; }
52
54
std::string
ToString
()
const override
{
return
fmt::format(
"{}: {}"
,
GetName
(),
static_cast<
std::uint16_t
>
(m_Key)); }
55
56
private
:
57
Key
m_Key;
58
};
59
65
class
KeyTypedEvent
final :
public
EventOf
<EventType::KeyTyped, EventCategory::Input | EventCategory::Keyboard>
66
{
67
public
:
69
explicit
KeyTypedEvent
(
char32_t
character) : m_Character(character) {}
70
72
char32_t
GetCharacter
()
const
{
return
m_Character; }
73
77
std::string
ToString
()
const override
78
{
79
const
auto
codePoint =
static_cast<
std::uint32_t
>
(m_Character);
80
if
(codePoint >= 0x20 && codePoint <= 0x7E)
81
{
82
return
fmt::format(
"{}: '{}' (U+{:04X})"
,
GetName
(),
static_cast<
char
>
(codePoint), codePoint);
83
}
84
return
fmt::format(
"{}: U+{:04X}"
,
GetName
(), codePoint);
85
}
86
87
private
:
88
char32_t
m_Character;
89
};
90
}
Event.h
Base class of all events, with their types and categories.
KeyCodes.h
Codes of the keyboard keys, independent from GLFW.
Quasar::EventOf
Base class of each event class, which gives the event its type and its categories.
Definition
Event.h:148
Quasar::Event::GetName
const char * GetName() const
Returns the name of the type of the event, for example "KeyPressed".
Definition
Event.h:112
Quasar::KeyPressedEvent::KeyPressedEvent
KeyPressedEvent(Key key, bool repeat=false)
Creates the event.
Definition
KeyEvent.h:27
Quasar::KeyPressedEvent::IsRepeat
bool IsRepeat() const
Returns true if the event comes from the key being held down, false for the first press.
Definition
KeyEvent.h:33
Quasar::KeyPressedEvent::ToString
std::string ToString() const override
Returns the event with its key code, for example "KeyPressed: 87 (repeat)".
Definition
KeyEvent.h:36
Quasar::KeyPressedEvent::GetKey
Key GetKey() const
Returns the pressed key.
Definition
KeyEvent.h:30
Quasar::KeyReleasedEvent::ToString
std::string ToString() const override
Returns the event with its key code, for example "KeyReleased: 87".
Definition
KeyEvent.h:54
Quasar::KeyReleasedEvent::KeyReleasedEvent
KeyReleasedEvent(Key key)
Creates the event for the released key.
Definition
KeyEvent.h:48
Quasar::KeyReleasedEvent::GetKey
Key GetKey() const
Returns the released key.
Definition
KeyEvent.h:51
Quasar::KeyTypedEvent::KeyTypedEvent
KeyTypedEvent(char32_t character)
Creates the event for the typed character, as a Unicode code point.
Definition
KeyEvent.h:69
Quasar::KeyTypedEvent::ToString
std::string ToString() const override
Returns the event with its character, for example "KeyTyped: 'A' (U+0041)" or "KeyTyped: U+00E9".
Definition
KeyEvent.h:77
Quasar::KeyTypedEvent::GetCharacter
char32_t GetCharacter() const
Returns the typed character, as a Unicode code point.
Definition
KeyEvent.h:72
Quasar
Contains all the engine code.
Quasar::Key
Key
Physical key of the keyboard.
Definition
KeyCodes.h:22
quasar
events
KeyEvent.h
Generated by
1.18.0