PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
KeyEvent.hpp
1#pragma once
2
3#include "PixelBullet/Application/Event.hpp"
4#include "PixelBullet/Input/KeyCodes.hpp"
5
6namespace
7{
8 using KeyCode = PixelBullet::Input::KeyCode;
9}
10
11namespace PixelBullet
12{
13 class KeyEvent : public Event
14 {
15 public:
16 KeyCode GetKeyCode() const
17 {
18 return m_KeyCode;
19 }
20
21 EVENT_CLASS_CATEGORY(EventCategoryKeyboard | EventCategoryInput)
22 protected:
23 KeyEvent(const KeyCode keycode)
24 : m_KeyCode(keycode)
25 {
26 }
27
28 KeyCode m_KeyCode;
29 };
30
32 {
33 public:
34 KeyPressedEvent(const KeyCode keycode, bool isRepeat = false)
35 : KeyEvent(keycode)
36 , m_IsRepeat(isRepeat)
37 {
38 }
39
40 bool IsRepeat() const
41 {
42 return m_IsRepeat;
43 }
44
45 std::string ToString() const override
46 {
47 std::stringstream ss;
48 ss << "KeyPressedEvent: " << m_KeyCode << " (repeat = " << m_IsRepeat << ")";
49 return ss.str();
50 }
51
52 EVENT_CLASS_TYPE(KeyPressed)
53 private:
54 bool m_IsRepeat;
55 };
56
58 {
59 public:
60 KeyReleasedEvent(const KeyCode keycode)
61 : KeyEvent(keycode)
62 {
63 }
64
65 std::string ToString() const override
66 {
67 std::stringstream ss;
68 ss << "KeyReleasedEvent: " << m_KeyCode;
69 return ss.str();
70 }
71
72 EVENT_CLASS_TYPE(KeyReleased)
73 };
74
75 class KeyTypedEvent : public KeyEvent
76 {
77 public:
78 KeyTypedEvent(const KeyCode keycode)
79 : KeyEvent(keycode)
80 {
81 }
82
83 std::string ToString() const override
84 {
85 std::stringstream ss;
86 ss << "KeyTypedEvent: " << m_KeyCode;
87 return ss.str();
88 }
89
90 EVENT_CLASS_TYPE(KeyTyped)
91 };
92
93} // namespace PixelBullet
Definition Event.hpp:65
Definition KeyEvent.hpp:14
Definition KeyEvent.hpp:32
Definition KeyEvent.hpp:58
Definition KeyEvent.hpp:76