2025-07-11 02:35:28 +03:30
|
|
|
#include <app/application.hpp>
|
|
|
|
#include <app/entrypoint.hpp>
|
2025-07-26 18:01:27 +03:30
|
|
|
#include <app/system.hpp>
|
2025-07-17 10:44:00 +03:30
|
|
|
#include <math/vec2.hpp>
|
2025-07-26 18:01:27 +03:30
|
|
|
#include <surface/system.hpp>
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-11 00:05:48 +03:30
|
|
|
namespace lt {
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-26 18:01:27 +03:30
|
|
|
template<class... Ts>
|
|
|
|
struct overloads: Ts...
|
|
|
|
{
|
|
|
|
using Ts::operator()...;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Mirror: public app::Application
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
|
|
|
public:
|
|
|
|
Mirror()
|
|
|
|
{
|
2025-07-26 18:01:27 +03:30
|
|
|
m_editor_registry = create_ref<ecs::Registry>();
|
|
|
|
|
|
|
|
setup_window_system();
|
|
|
|
register_systems();
|
|
|
|
|
2025-07-28 20:45:24 +03:30
|
|
|
m_window_system->add_event_listener(
|
|
|
|
m_window,
|
|
|
|
[&](const surface::SurfaceComponent::Event &event) {
|
|
|
|
const auto visitor = overloads {
|
|
|
|
[&](const lt::surface::KeyPressedEvent &event) {
|
|
|
|
std::cout << "key pressed: " << event.to_string() << std::endl;
|
2025-07-26 18:01:27 +03:30
|
|
|
|
2025-07-28 20:45:24 +03:30
|
|
|
if (event.get_key() == 81)
|
|
|
|
{
|
|
|
|
unregister_system(m_window_system);
|
|
|
|
log_inf("Quitting...");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
[](const auto &) { return false; },
|
|
|
|
};
|
2025-07-26 18:01:27 +03:30
|
|
|
|
2025-07-28 20:45:24 +03:30
|
|
|
return std::visit(visitor, event);
|
|
|
|
}
|
|
|
|
);
|
2025-07-05 13:28:41 +03:30
|
|
|
}
|
2025-07-26 18:01:27 +03:30
|
|
|
|
|
|
|
void setup_window_system()
|
|
|
|
{
|
|
|
|
using lt::surface::SurfaceComponent;
|
|
|
|
m_window_system = create_ref<lt::surface::System>(m_editor_registry);
|
|
|
|
|
|
|
|
m_window = m_editor_registry->create_entity("Editor Window");
|
|
|
|
m_window.add_component<SurfaceComponent>(SurfaceComponent::CreateInfo {
|
|
|
|
.title = "Editor Window",
|
|
|
|
.size = { 800u, 600u },
|
|
|
|
.vsync = true,
|
|
|
|
.visible = true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void register_systems()
|
|
|
|
{
|
|
|
|
register_system(m_window_system);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Ref<ecs::Registry> m_editor_registry;
|
|
|
|
|
|
|
|
Ref<lt::surface::System> m_window_system;
|
|
|
|
|
|
|
|
lt::ecs::Entity m_window;
|
2025-07-05 13:28:41 +03:30
|
|
|
};
|
|
|
|
|
2025-07-26 18:01:27 +03:30
|
|
|
auto app::create_application() -> Scope<app::Application>
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
2025-07-07 15:13:05 +03:30
|
|
|
return create_scope<Mirror>();
|
2025-07-05 13:28:41 +03:30
|
|
|
}
|
|
|
|
|
2025-07-11 00:05:48 +03:30
|
|
|
} // namespace lt
|