2025-07-05 13:28:41 +03:30
|
|
|
#include <engine/events/event.hpp>
|
|
|
|
#include <engine/events/keyboard.hpp>
|
|
|
|
#include <engine/events/mouse.hpp>
|
|
|
|
#include <engine/events/window.hpp>
|
|
|
|
#include <engine/layer/layer.hpp>
|
|
|
|
#include <engine/layer/layer_stack.hpp>
|
2021-05-27 10:41:32 +04:30
|
|
|
|
2021-05-23 18:10:11 +04:30
|
|
|
namespace Light {
|
|
|
|
|
2025-07-05 13:28:41 +03:30
|
|
|
LayerStack *LayerStack::s_Context = nullptr;
|
2022-03-07 21:57:00 +03:30
|
|
|
|
|
|
|
Scope<LayerStack> LayerStack::Create()
|
|
|
|
{
|
|
|
|
return MakeScope<LayerStack>(new LayerStack());
|
|
|
|
}
|
|
|
|
|
2025-07-05 14:23:01 +03:30
|
|
|
LayerStack::LayerStack(): m_layers {}, m_begin(), m_end()
|
2022-03-07 21:57:00 +03:30
|
|
|
{
|
|
|
|
ASSERT(!s_Context, "An instance of 'LayerStack' already exists, do not construct this class!")
|
|
|
|
s_Context = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerStack::~LayerStack()
|
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
for (Layer *layer : m_layers)
|
2022-03-07 21:57:00 +03:30
|
|
|
delete layer;
|
|
|
|
}
|
|
|
|
|
2025-07-05 13:28:41 +03:30
|
|
|
void LayerStack::AttachLayerImpl(Layer *layer)
|
2022-03-07 21:57:00 +03:30
|
|
|
{
|
|
|
|
// #todo: handle attaching layer inside a for loop
|
2025-07-05 14:23:01 +03:30
|
|
|
m_layers.push_back(layer);
|
|
|
|
m_begin = m_layers.begin();
|
|
|
|
m_end = m_layers.end();
|
2022-03-07 21:57:00 +03:30
|
|
|
|
|
|
|
LOG(trace, "Attached [{}]", layer->GetName());
|
|
|
|
}
|
|
|
|
|
2025-07-05 13:28:41 +03:30
|
|
|
void LayerStack::DetachLayerImpl(Layer *layer)
|
2022-03-07 21:57:00 +03:30
|
|
|
{
|
|
|
|
// #todo: handle detaching layer inside a for loop
|
2025-07-05 14:23:01 +03:30
|
|
|
m_layers.erase(std::find(m_layers.begin(), m_layers.end(), layer));
|
|
|
|
m_begin = m_layers.begin();
|
|
|
|
m_end = m_layers.end();
|
2022-03-07 21:57:00 +03:30
|
|
|
|
|
|
|
LOG(trace, "Detached [{}]", layer->GetName());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Light
|