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

134 lines
2.7 KiB
C++
Raw Normal View History

2022-03-08 21:19:19 +03:30
#pragma once
#include <input/events/event.hpp>
#include <math/vec2.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 WindowClosedEvent: public Event
{
public:
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
{
return "WindowClosedEvent";
}
2025-07-05 16:07:51 +03:30
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::WindowClosed;
}
2025-07-05 16:07:51 +03:30
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
2022-03-08 21:19:19 +03:30
};
class WindowMovedEvent: public Event
{
public:
WindowMovedEvent(int x, int y): m_position(x, y)
2022-03-08 21:19:19 +03:30
{
}
[[nodiscard]] auto get_position() const -> const math::ivec2 &
2025-07-05 13:28:41 +03:30
{
return m_position;
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 << "WindwoMoved: " << m_position.x << ", " << m_position.y;
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::WindowMoved;
}
2025-07-05 16:07:51 +03:30
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
2025-07-05 16:07:51 +03:30
private:
const math::ivec2 m_position;
2022-03-08 21:19:19 +03:30
};
class WindowResizedEvent: public Event
{
public:
WindowResizedEvent(unsigned int width, unsigned int height): m_size(width, height)
2022-03-08 21:19:19 +03:30
{
}
[[nodiscard]] auto get_size() const -> const math::uvec2 &
2025-07-05 13:28:41 +03:30
{
return m_size;
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 << "WindowResized: " << m_size.x << ", " << m_size.y;
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::WindowResized;
}
2025-07-05 16:07:51 +03:30
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
2025-07-05 16:07:51 +03:30
private:
const math::uvec2 m_size;
2022-03-08 21:19:19 +03:30
};
class WindowLostFocusEvent: public Event
{
public:
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
{
return "WindowLostFocus";
}
2025-07-05 16:07:51 +03:30
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::WindowLostFocus;
}
2025-07-06 14:02:50 +03:30
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
2022-03-08 21:19:19 +03:30
};
class WindowGainFocusEvent: public Event
{
public:
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
{
return "WindowGainFocus";
}
2025-07-05 16:07:51 +03:30
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::WindowGainFocus;
}
2025-07-06 14:02:50 +03:30
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
2022-03-08 21:19:19 +03:30
};
2025-07-11 00:05:48 +03:30
} // namespace lt