light/modules/input/public/events/keyboard.hpp

108 lines
1.9 KiB
C++
Raw Normal View History

2022-03-08 21:19:19 +03:30
#pragma once
#include <input/events/event.hpp>
2022-03-08 21:19:19 +03:30
#include <sstream>
2025-07-11 00:05:48 +03:30
namespace lt {
2022-03-08 21:19:19 +03:30
class KeyPressedEvent: public Event
{
public:
KeyPressedEvent(int key): m_key(key)
2022-03-08 21:19:19 +03:30
{
}
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto get_key() const -> int
2025-07-05 13:28:41 +03:30
{
return m_key;
2025-07-05 13:28:41 +03:30
}
2022-03-08 21:19:19 +03:30
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto get_info_lt_log() const -> std::string override
2022-03-08 21:19:19 +03:30
{
std::stringstream ss;
ss << "KeyPressed: " << m_key;
2022-03-08 21:19:19 +03:30
return ss.str();
}
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::KeyPressed;
}
2025-07-05 16:07:51 +03:30
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | KeyboardEventCategory) & category;
}
2025-07-05 16:07:51 +03:30
2022-03-08 21:19:19 +03:30
private:
const int m_key;
2025-07-05 16:07:51 +03:30
};
2022-03-08 21:19:19 +03:30
2025-07-05 16:07:51 +03:30
class KeyRepeatEvent: public Event
{
2022-03-08 21:19:19 +03:30
public:
KeyRepeatEvent(int key): m_key(key)
2022-03-08 21:19:19 +03:30
{
}
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto get_key() const -> int
2025-07-05 13:28:41 +03:30
{
return m_key;
2025-07-05 13:28:41 +03:30
}
2022-03-08 21:19:19 +03:30
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto get_info_lt_log() const -> std::string override
2022-03-08 21:19:19 +03:30
{
std::stringstream ss;
ss << "KeyRepeated: " << m_key;
2022-03-08 21:19:19 +03:30
return ss.str();
}
2025-07-06 14:02:50 +03:30
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::KeyRepeated;
}
2025-07-06 14:02:50 +03:30
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | KeyboardEventCategory) & category;
}
2022-03-08 21:19:19 +03:30
private:
const int m_key;
2025-07-05 16:07:51 +03:30
};
2022-03-08 21:19:19 +03:30
2025-07-05 16:07:51 +03:30
class KeyReleasedEvent: public Event
{
2022-03-08 21:19:19 +03:30
public:
KeyReleasedEvent(int key): m_key(key)
2022-03-08 21:19:19 +03:30
{
}
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto get_key() const -> int
2025-07-05 13:28:41 +03:30
{
return m_key;
2025-07-05 13:28:41 +03:30
}
2022-03-08 21:19:19 +03:30
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto get_info_lt_log() const -> std::string override
2022-03-08 21:19:19 +03:30
{
std::stringstream ss;
ss << "KeyReleased: " << m_key;
2022-03-08 21:19:19 +03:30
return ss.str();
}
2025-07-05 16:07:51 +03:30
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::KeyReleased;
}
2025-07-06 14:02:50 +03:30
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | KeyboardEventCategory) & category;
}
2025-07-05 16:07:51 +03:30
private:
const int m_key;
2022-03-08 21:19:19 +03:30
};
2025-07-11 00:05:48 +03:30
} // namespace lt