work on layers

This commit is contained in:
2025-04-08 11:47:24 -05:00
parent fbfa13a742
commit 3a797fb19a
10 changed files with 183 additions and 87 deletions

View File

@@ -1,15 +1,25 @@
#ifndef LAYER_H
#define LAYER_H
#include "pch.hpp"
#include "utils/Events/Event.h"
class Layer {
namespace Archimedes {
class Layer {
virtual ~Layer() {}
public:
virtual void onRender() = 0;
virtual ~Layer() {}
virtual void onAttach() = 0;
virtual void onRender() = 0;
virtual void onDetach() = 0;
virtual void onAttach() = 0;
virtual bool onEvent(const Event&) = 0;
};
virtual void onDetach() = 0;
virtual bool onEvent(const Event&) = 0;
};
}
#endif

View File

@@ -1,31 +1,49 @@
#ifndef LAYERSTACK_H
#define LAYERSTACK_H
#include "pch.hpp"
#include "Layer.h"
class Layerstack {
namespace Archimedes {
class Layerstack {
public:
Layerstack() {}
public:
Layerstack() {}
~Layerstack() {
while(!lstack.empty()) {
pop();
~Layerstack() {
while(!lstack.empty()) {
pop();
}
}
}
void push(Layer* l) { lstack.push_front(l); }
void push(Layer* l) {
lstack.push_front(l);
l->onAttach();
}
void pop() {
Layer* l = lstack.front();
lstack.pop_front();
delete l;
}
void pop() {
Layer* l = lstack.front();
lstack.pop_front();
l->onDetach();
}
void renderAll() {
for(Layer* l : lstack)
l->onRender();
}
void renderAll() {
for(Layer* l : lstack)
l->onRender();
}
private:
void sendEvent(const Event& e) {
for(Layer* l : lstack) {
if(l->onEvent(e)) {
break;
}
}
}
std::list<Layer*> lstack;
};
private:
std::list<Layer*> lstack;
};
}
#endif