CoriEngine
Loading...
Searching...
No Matches
KeyEvent.hpp
Go to the documentation of this file.
1#pragma once
2#include "Event.hpp"
4
5namespace Cori {
6 namespace Core {
7 class KeyEvent : public Event {
8 public:
9 [[nodiscard]] CoriKeycode GetKeyCode() const { return m_KeyCode; }
11 protected:
12 explicit KeyEvent(const CoriKeycode keycode)
13 : m_KeyCode(keycode) {
14 }
16 };
17
18 class KeyPressedEvent final : public KeyEvent {
19 public:
20 KeyPressedEvent(const CoriKeycode keycode, const bool repeat)
21 : KeyEvent(keycode), m_Repeat(repeat) {
22 }
23
24 [[nodiscard]] bool IsRepeated() const { return m_Repeat; }
25
26 [[nodiscard]] std::string ToString() const override {
27 return std::string("KeyPressedEvent: ") + CoriGetKeyName(m_KeyCode) + std::string(" ( Repeated: ") + Logger::BoolAlpha(m_Repeat) + std::string(" )");
28 }
30 private:
31 bool m_Repeat{ false };
32 };
33
34 class KeyReleasedEvent final : public KeyEvent {
35 public:
36 explicit KeyReleasedEvent(const CoriKeycode keycode)
37 : KeyEvent(keycode) {
38 }
39
40 [[nodiscard]] std::string ToString() const override {
41 return std::string("KeyReleasedEvent: ") + CoriGetKeyName(m_KeyCode);
42 }
44 };
45 }
46}
#define EVENT_CLASS_TYPE(type)
Assigns an EventType to the custom event type derived from the Event class. Use it in the public fiel...
Definition Event.hpp:124
#define EVENT_CLASS_CATEGORY(category)
Assigns an EventCategory to the custom event type derived from the Event class. Use it in the public ...
Definition Event.hpp:132
An abstract class that is ment to be used as a template for defining events.
Definition Event.hpp:18
KeyEvent(const CoriKeycode keycode)
Definition KeyEvent.hpp:12
CoriKeycode GetKeyCode() const
Definition KeyEvent.hpp:9
CoriKeycode m_KeyCode
Definition KeyEvent.hpp:15
KeyPressedEvent(const CoriKeycode keycode, const bool repeat)
Definition KeyEvent.hpp:20
std::string ToString() const override
Returns the name of the Event.
Definition KeyEvent.hpp:26
std::string ToString() const override
Returns the name of the Event.
Definition KeyEvent.hpp:40
KeyReleasedEvent(const CoriKeycode keycode)
Definition KeyEvent.hpp:36
static std::string BoolAlpha(const bool b)
Definition Logger.hpp:181
Core systems of the engine are here.
static std::string CoriGetKeyName(const CoriKeycode code)
@ EventCategoryKeyboard
Definition Event.hpp:10
@ EventCategoryInput
Definition Event.hpp:9
CoriKeycode
This is a adaptation of SDL3 scancodes. Taken from 'SDL_scancode.h'.
Global engine namespace.