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