added layer and layerstack class
This commit is contained in:
6
SakuraVNE/src/Layer.cpp
Normal file
6
SakuraVNE/src/Layer.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "Layer.h"
|
||||
#include <string>
|
||||
|
||||
namespace SakuraVNE {
|
||||
Layer::Layer(const std::string &name) : m_LayerName(name) {}
|
||||
} // namespace SakuraVNE
|
||||
23
SakuraVNE/src/Layer.h
Normal file
23
SakuraVNE/src/Layer.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace SakuraVNE {
|
||||
class Layer {
|
||||
public:
|
||||
Layer(const std::string &name = "Layer");
|
||||
virtual ~Layer() = default;
|
||||
|
||||
virtual void OnStart() {}
|
||||
virtual void OnFrame(float timestamp) {}
|
||||
virtual void OnEnd() {}
|
||||
virtual void OnEvent() {}
|
||||
virtual void OnAttach() {}
|
||||
virtual void OnDetach() {}
|
||||
|
||||
const std::string &GetName() const { return m_LayerName; }
|
||||
|
||||
protected:
|
||||
std::string m_LayerName;
|
||||
};
|
||||
} // namespace SakuraVNE
|
||||
30
SakuraVNE/src/LayerStack.cpp
Normal file
30
SakuraVNE/src/LayerStack.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "LayerStack.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace SakuraVNE {
|
||||
void LayerStack::PushLayer(Layer *layer) {
|
||||
m_LayerStack.emplace(m_LayerStack.begin() + m_LayerIndex, layer);
|
||||
m_LayerIndex++;
|
||||
}
|
||||
|
||||
void LayerStack::PopLayer(Layer *layer) {
|
||||
auto match = std::find(m_LayerStack.begin(), m_LayerStack.begin() + m_LayerIndex, layer);
|
||||
if (match != m_LayerStack.begin() + m_LayerIndex) {
|
||||
layer->OnDetach();
|
||||
m_LayerStack.erase(match);
|
||||
m_LayerIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
void LayerStack::PushOverLay(Layer *layer) { m_LayerStack.emplace_back(layer); }
|
||||
|
||||
void LayerStack::PopOverlay(Layer *layer) {
|
||||
auto match = std::find(m_LayerStack.begin() + m_LayerIndex, m_LayerStack.end(), layer);
|
||||
|
||||
if (match != m_LayerStack.end()) {
|
||||
layer->OnDetach();
|
||||
m_LayerStack.erase(match);
|
||||
}
|
||||
}
|
||||
} // namespace SakuraVNE
|
||||
21
SakuraVNE/src/LayerStack.h
Normal file
21
SakuraVNE/src/LayerStack.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Layer.h"
|
||||
#include <vector>
|
||||
|
||||
namespace SakuraVNE {
|
||||
class LayerStack {
|
||||
public:
|
||||
LayerStack() = default;
|
||||
~LayerStack();
|
||||
|
||||
void PushLayer(Layer *layer);
|
||||
void PopLayer(Layer *layer);
|
||||
void PushOverLay(Layer *layer);
|
||||
void PopOverlay(Layer *layer);
|
||||
|
||||
private:
|
||||
std::vector<Layer *> m_LayerStack;
|
||||
unsigned int m_LayerIndex = 0;
|
||||
};
|
||||
} // namespace SakuraVNE
|
||||
Reference in New Issue
Block a user