light/modules/surface/events.cppm
light7734 2fd6a199aa
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone Build was killed
wip: fix: renderer
2025-12-08 16:41:41 +03:30

257 lines
3.9 KiB
C++

export module surface.events;
import input.codes;
import math.vec2;
import std;
export namespace lt::surface {
class KeyPressedEvent
{
public:
KeyPressedEvent(Key key): m_key(key)
{
}
[[nodiscard]] auto get_key() const -> Key
{
return m_key;
}
[[nodiscard]] auto to_string() const -> std::string
{
return std::format("KeyPressed: {}", std::to_underlying(m_key));
}
private:
Key m_key;
};
class KeyRepeatEvent
{
public:
KeyRepeatEvent(Key key): m_key(key)
{
}
[[nodiscard]] auto get_key() const -> Key
{
return m_key;
}
[[nodiscard]] auto to_string() const -> std::string
{
return std::format("KeyRepeated: {}", std::to_underlying(m_key));
}
private:
Key m_key;
};
class KeyReleasedEvent
{
public:
KeyReleasedEvent(Key key): m_key(key)
{
}
[[nodiscard]] auto get_key() const -> Key
{
return m_key;
}
[[nodiscard]] auto to_string() const -> std::string
{
return std::format("KeyReleased: {}", std::to_underlying(m_key));
}
private:
Key m_key;
};
class KeySetCharEvent
{
public:
KeySetCharEvent(Key character): m_character(character)
{
}
[[nodiscard]] auto get_character() const -> Key
{
return m_character;
}
[[nodiscard]] auto to_string() const -> std::string
{
return std::format("KeyCharSet: {}", std::to_underlying(m_character));
}
private:
Key m_character;
};
class MouseMovedEvent
{
public:
MouseMovedEvent(float x, float y): m_position(x, y)
{
}
[[nodiscard]] auto get_position() const -> const math::vec2 &
{
return m_position;
}
[[nodiscard]] auto get_x() const -> float
{
return m_position.x;
}
[[nodiscard]] auto get_y() const -> float
{
return m_position.y;
}
[[nodiscard]] auto to_string() const -> std::string
{
return std::format("MouseMoved: {}, {}", m_position.x, m_position.y);
}
private:
math::vec2 m_position;
};
class WheelScrolledEvent
{
public:
WheelScrolledEvent(float offset): m_offset(offset)
{
}
[[nodiscard]] auto get_offset() const -> float
{
return m_offset;
}
[[nodiscard]] auto to_string() const -> std::string
{
std::stringstream ss;
ss << "WheelScrolled: " << m_offset;
return ss.str();
}
private:
float m_offset;
};
class ButtonPressedEvent
{
public:
ButtonPressedEvent(Key button): m_button(button)
{
}
[[nodiscard]] auto get_button() const -> Key
{
return m_button;
}
[[nodiscard]] auto to_string() const -> std::string
{
return std::format("ButtonPressed: {}", std::to_underlying(m_button));
}
private:
Key m_button;
};
class ButtonReleasedEvent
{
public:
ButtonReleasedEvent(Key button): m_button(button)
{
}
[[nodiscard]] auto get_button() const -> Key
{
return m_button;
}
[[nodiscard]] auto to_string() const -> std::string
{
return std::format("ButtonReleased: {}", std::to_underlying(m_button));
}
private:
Key m_button;
};
class ClosedEvent
{
public:
[[nodiscard]] auto to_string() const -> std::string_view
{
return "SurfaceClosedEvent";
}
};
class MovedEvent
{
public:
MovedEvent(std::int32_t x, std::int32_t y): m_position(x, y)
{
}
[[nodiscard]] auto get_position() const -> const math::ivec2 &
{
return m_position;
}
[[nodiscard]] auto to_string() const -> std::string
{
return std::format("WindowMoved: {}, {}", m_position.x, m_position.y);
}
private:
math::ivec2 m_position;
};
class ResizedEvent
{
public:
ResizedEvent(std::uint32_t width, std::uint32_t height): m_size(width, height)
{
}
[[nodiscard]] auto get_size() const -> const math::uvec2 &
{
return m_size;
}
[[nodiscard]] auto to_string() const -> std::string
{
return std::format("SurfaceResized: {}, {}", m_size.x, m_size.y);
}
private:
math::uvec2 m_size;
};
class LostFocusEvent
{
public:
[[nodiscard]] auto to_string() const -> std::string_view
{
return "SurfaceLostFocus";
}
};
class GainFocusEvent
{
public:
[[nodiscard]] auto to_string() const -> std::string_view
{
return "SurfaceGainFocus";
}
};
} // namespace lt::surface