Hana
Loading...
Searching...
No Matches
KeyEvent.h
1#pragma once
2
3#include "Hana/Events/Event.h"
4
5namespace Hana
6{
7 class KeyEvent : public Event
8 {
9 public:
10 inline int GetKeyCode() const { return m_KeyCode; }
11
12 EVENT_CLASS_CATEGORY(EventCategoryKeyboard | EventCategoryInput)
13 protected:
14 KeyEvent(int keycode)
15 : m_KeyCode(keycode) {}
16
17 int m_KeyCode;
18 };
19
20 class KeyPressedEvent : public KeyEvent
21 {
22 public:
23 KeyPressedEvent(int keycode, int repeatCount)
24 : KeyEvent(keycode), m_RepeatCount(repeatCount) {}
25
26 inline int GetRepeatCount() const { return m_RepeatCount; }
27
28 std::string ToString() const override
29 {
30 std::stringstream ss;
31 ss << "KeyPressedEvent: " << m_KeyCode << " (" << m_RepeatCount << " repeats)";
32 return ss.str();
33 }
34
35 EVENT_CLASS_TYPE(KeyPressed)
36 private:
37 int m_RepeatCount;
38 };
39
40 class KeyReleasedEvent : public KeyEvent
41 {
42 public:
43 KeyReleasedEvent(int keycode)
44 : KeyEvent(keycode) {}
45
46 std::string ToString() const override
47 {
48 std::stringstream ss;
49 ss << "KeyReleasedEvent: " << m_KeyCode;
50 return ss.str();
51 }
52
53 EVENT_CLASS_TYPE(KeyReleased)
54 };
55
56 class KeyTypedEvent : public KeyEvent
57 {
58 public:
59 KeyTypedEvent(int keycode)
60 : KeyEvent(keycode) {}
61
62 std::string ToString() const override
63 {
64 std::stringstream ss;
65 ss << "KeyTypedEvent: " << m_KeyCode;
66 return ss.str();
67 }
68
69 EVENT_CLASS_TYPE(KeyTyped)
70 };
71}
Definition Event.h:39