work on layers
This commit is contained in:
@@ -1,3 +1,30 @@
|
||||
#ifndef EVENT_H
|
||||
#define EVENT_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
class Event {};
|
||||
namespace Archimedes {
|
||||
|
||||
class Event {
|
||||
|
||||
public:
|
||||
|
||||
enum class Type : unsigned int {
|
||||
None = 0,
|
||||
WindowEvent = 1 << 0,
|
||||
KeyEvent = 1 << 1,
|
||||
MouseMoveEvent = 1 << 2,
|
||||
MouseScrollEvent = 1 << 3,
|
||||
MouseButtonEvent = 1 << 4,
|
||||
PressedEvent = 1 << 5,
|
||||
ReleasedEvent = 1 << 6,
|
||||
WindowCloseEvent = 1 << 7,
|
||||
WindowResizeEvent = 1 << 8,
|
||||
};
|
||||
|
||||
unsigned int type;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "modules/WindowModule/src/WindowModule.h"
|
||||
|
||||
#include "utils/Layers/Layer.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class GuiModule : public Module {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -9,7 +9,6 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
int w, h;
|
||||
typedef void renderCmd();
|
||||
|
||||
~Renderer() {}
|
||||
|
||||
@@ -19,12 +18,12 @@ namespace Archimedes {
|
||||
r.render(rc, w, h);
|
||||
}
|
||||
|
||||
std::list<renderCmd*>& getCmdList() {
|
||||
std::list<std::function<void()>>& getCmdList() {
|
||||
return rc;
|
||||
}
|
||||
|
||||
private:
|
||||
std::list<renderCmd*> rc;
|
||||
std::list<std::function<void()>> rc;
|
||||
RendererImpl r;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
Window() { renderer = new Renderer(); }
|
||||
Window() {}
|
||||
|
||||
~Window() { delete renderer; }
|
||||
~Window() {}
|
||||
|
||||
bool shouldClose() { return window.shouldClose(); }
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Archimedes {
|
||||
}
|
||||
|
||||
Renderer* getRenderer() { return renderer; }
|
||||
//void setRenderer(Renderer* r) { renderer = r; }
|
||||
void setRenderer(Renderer* r) { renderer = r; }
|
||||
|
||||
WindowImpl& getWindowImpl() { return window; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user