Skip to content

Commit

Permalink
f002_Added layer stack class
Browse files Browse the repository at this point in the history
  • Loading branch information
david-palm committed Oct 22, 2022
1 parent f426c5e commit 5ddee61
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_executable(uml-creator
uml-creator/Events/KeyEvent.h
uml-creator/Window.h
uml-creator/Platform/Windows/WindowsWindow.h
uml-creator/Platform/Windows/WindowsWindow.cpp uml-creator/Events/WindowEvent.h uml-creator/Events/MouseEvent.h uml-creator/Layer.h uml-creator/Layer.cpp)
uml-creator/Platform/Windows/WindowsWindow.cpp uml-creator/Events/WindowEvent.h uml-creator/Events/MouseEvent.h uml-creator/Layer.h uml-creator/Layer.cpp uml-creator/LayerStack.h uml-creator/LayerStack.cpp)
set(CMAKE_CXX_STANDARD 23)

# Adding subdirectory for uml creator
Expand Down
41 changes: 41 additions & 0 deletions uml-creator/LayerStack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "LayerStack.h"

LayerStack::LayerStack()
{
m_LayerInsert = m_Layers.begin();
}

LayerStack::~LayerStack()
{
for(Layer* layer : m_Layers)
delete layer;
}

void LayerStack::pushLayer(Layer* layer)
{
m_LayerInsert = m_Layers.emplace(m_LayerInsert, layer);
}

void LayerStack::popLayer(Layer* layer)
{
auto iterator = std::find(m_Layers.begin(), m_Layers.end(), layer);
if(iterator != m_Layers.end())
{
m_Layers.erase(iterator);
m_LayerInsert--;
}
}

void LayerStack::pushOverlay(Layer* overlay)
{
m_Layers.emplace_back(overlay);
}

void LayerStack::popOverlay(Layer* overlay)
{
auto iterator = std::find(m_Layers.begin(), m_Layers.end(), overlay);
if(iterator != m_Layers.end())
{
m_Layers.erase(iterator);
}
}
26 changes: 26 additions & 0 deletions uml-creator/LayerStack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <vector>

#include "Layer.h"

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_Layers.begin(); };
std::vector<Layer*>::iterator end() { return m_Layers.end(); };

private:
std::vector<Layer*> m_Layers;
std::vector<Layer*>::iterator m_LayerInsert;

};

0 comments on commit 5ddee61

Please sign in to comment.