mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Added Layer system
This commit is contained in:
parent
58a0d46009
commit
afe2053151
|
@ -1,6 +1,21 @@
|
|||
#ifndef NAVIGATOR_H
|
||||
#define NAVIGATOR_H
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "Navigator/Logger.h"
|
||||
#include "Navigator/Application.h"
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ namespace Navigator {
|
|||
m_runFlag(true)
|
||||
{
|
||||
s_instance = this;
|
||||
|
||||
PushLayer(new Layer());
|
||||
}
|
||||
|
||||
Application::~Application() {}
|
||||
|
@ -26,15 +28,25 @@ namespace Navigator {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Application::PushLayer() {}
|
||||
void Application::PushLayer(Layer* layer)
|
||||
{
|
||||
m_stack.PushLayer(layer);
|
||||
layer->OnAttach();
|
||||
}
|
||||
|
||||
void Application::PushOverlay() {}
|
||||
void Application::PushOverlay(Layer* layer)
|
||||
{
|
||||
m_stack.PushOverlay(layer);
|
||||
layer->OnAttach();
|
||||
}
|
||||
|
||||
void Application::Run()
|
||||
{
|
||||
while(m_runFlag)
|
||||
{
|
||||
NAV_TRACE("Doing a run.");
|
||||
for(auto layer : m_stack)
|
||||
NAV_TRACE("Layer with name {0} found!", layer->GetName());
|
||||
WindowCloseEvent event;
|
||||
OnEvent(event);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "NavCore.h"
|
||||
#include "Events/Event.h"
|
||||
#include "Events/AppEvent.h"
|
||||
#include "LayerStack.h"
|
||||
#include "Layer.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
|
@ -16,8 +18,8 @@ namespace Navigator {
|
|||
void Run();
|
||||
|
||||
void OnEvent(Event& event);
|
||||
void PushLayer();
|
||||
void PushOverlay();
|
||||
void PushLayer(Layer* layer);
|
||||
void PushOverlay(Layer* layer);
|
||||
|
||||
inline static Application& Get() { return *s_instance; }
|
||||
|
||||
|
@ -26,6 +28,7 @@ namespace Navigator {
|
|||
private:
|
||||
bool OnWindowCloseEvent(WindowCloseEvent& event);
|
||||
|
||||
LayerStack m_stack;
|
||||
bool m_runFlag;
|
||||
|
||||
static Application* s_instance;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define EVENT_H
|
||||
|
||||
#include "NavCore.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
|
|
11
Navigator/src/Navigator/Layer.cpp
Normal file
11
Navigator/src/Navigator/Layer.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "Layer.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
Layer::Layer(const std::string& name) :
|
||||
m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
Layer::~Layer() {}
|
||||
}
|
27
Navigator/src/Navigator/Layer.h
Normal file
27
Navigator/src/Navigator/Layer.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef LAYER_H
|
||||
#define LAYER_H
|
||||
|
||||
#include "Events/Event.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
class Layer
|
||||
{
|
||||
public:
|
||||
Layer(const std::string& name="Layer");
|
||||
virtual ~Layer();
|
||||
|
||||
virtual void OnAttach() {}
|
||||
virtual void OnDetach() {}
|
||||
virtual void OnImGuiRender() {}
|
||||
virtual void OnEvent(Event& event) {}
|
||||
|
||||
inline const std::string& GetName() { return m_name; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
40
Navigator/src/Navigator/LayerStack.cpp
Normal file
40
Navigator/src/Navigator/LayerStack.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include "LayerStack.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
LayerStack::LayerStack() {}
|
||||
|
||||
LayerStack::~LayerStack()
|
||||
{
|
||||
for(Layer* layer : m_stack)
|
||||
delete layer;
|
||||
}
|
||||
|
||||
void LayerStack::PushLayer(Layer* layer)
|
||||
{
|
||||
m_stack.emplace(m_stack.begin() + m_insertIndex, layer);
|
||||
m_insertIndex++;
|
||||
}
|
||||
|
||||
void LayerStack::PushOverlay(Layer* layer)
|
||||
{
|
||||
m_stack.emplace_back(layer);
|
||||
}
|
||||
|
||||
void LayerStack::PopLayer(Layer* layer)
|
||||
{
|
||||
auto iter = std::find(m_stack.begin(), m_stack.end(), layer);
|
||||
if(iter != m_stack.end())
|
||||
{
|
||||
m_stack.erase(iter);
|
||||
m_insertIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
void LayerStack::PopOverlay(Layer* layer)
|
||||
{
|
||||
auto iter = std::find(m_stack.begin(), m_stack.end(), layer);
|
||||
if(iter != m_stack.end())
|
||||
m_stack.erase(iter);
|
||||
}
|
||||
}
|
29
Navigator/src/Navigator/LayerStack.h
Normal file
29
Navigator/src/Navigator/LayerStack.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef LAYER_STACK_H
|
||||
#define LAYER_STACK_H
|
||||
|
||||
#include "NavCore.h"
|
||||
#include "Layer.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
class LayerStack
|
||||
{
|
||||
public:
|
||||
LayerStack();
|
||||
~LayerStack();
|
||||
|
||||
void PushLayer(Layer* layer);
|
||||
void PopLayer(Layer* layer);
|
||||
void PushOverlay(Layer* layer);
|
||||
void PopOverlay(Layer* layer);
|
||||
|
||||
std::vector<Layer*>::iterator begin() { return m_stack.begin(); }
|
||||
std::vector<Layer*>::iterator end() { return m_stack.end(); }
|
||||
private:
|
||||
std::vector<Layer*> m_stack; //These layers are owned by the LayerStack!
|
||||
unsigned int m_insertIndex=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user