Added Window Manager
This commit is contained in:
parent
70835b8593
commit
2e5a07c847
|
@ -1,7 +1,7 @@
|
|||
|
||||
add_executable(ComplexPlotting
|
||||
"main.cpp"
|
||||
"PlotWindow.hpp" "PlotWindow.cpp")
|
||||
"PlotWindow.hpp" "PlotWindow.cpp" "PlotManager.hpp" "PlotManager.cpp")
|
||||
|
||||
file(GLOB vendor_SRC
|
||||
${CMAKE_SOURCE_DIR}/vendor/src/*.c
|
||||
|
|
35
src/PlotManager.cpp
Normal file
35
src/PlotManager.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "PlotManager.hpp"
|
||||
|
||||
void PlotManager::NewPlot()
|
||||
{
|
||||
currentID++;
|
||||
OpenWindows.emplace_back(400, 400, currentID);
|
||||
}
|
||||
|
||||
WList::iterator PlotManager::Remove(WList::iterator it)
|
||||
{
|
||||
return OpenWindows.erase(it);
|
||||
}
|
||||
|
||||
void PlotManager::Loop()
|
||||
{
|
||||
for (WList::iterator it = OpenWindows.begin(); it != OpenWindows.end();)
|
||||
{
|
||||
if (it->ShouldClose())
|
||||
{
|
||||
it->Destroy();
|
||||
it = OpenWindows.erase(it);
|
||||
|
||||
if (OpenWindows.empty())
|
||||
isOpen = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
it->GiveContext();
|
||||
|
||||
it->Clear();
|
||||
it->Display();
|
||||
it++;
|
||||
}
|
||||
}
|
23
src/PlotManager.hpp
Normal file
23
src/PlotManager.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "PlotWindow.hpp"
|
||||
|
||||
typedef std::vector<PlotWindow> WList;
|
||||
|
||||
class PlotManager
|
||||
{
|
||||
public:
|
||||
static void NewPlot();
|
||||
static WList::iterator Remove(WList::iterator it);
|
||||
|
||||
static void Loop();
|
||||
|
||||
public:
|
||||
inline static bool isOpen = true;
|
||||
|
||||
private:
|
||||
inline static WList OpenWindows;
|
||||
inline static int currentID = 0;
|
||||
};
|
|
@ -39,11 +39,14 @@ void PlotWindow::GiveContext()
|
|||
glfwMakeContextCurrent(window);
|
||||
}
|
||||
|
||||
void PlotWindow::Display()
|
||||
void PlotWindow::Clear()
|
||||
{
|
||||
glClearColor(0.6f, 0.1f, 0.4f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void PlotWindow::Display()
|
||||
{
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <glad/glad.h>
|
||||
#include <glfw/glfw3.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
class PlotWindow
|
||||
{
|
||||
public:
|
||||
|
@ -12,7 +14,8 @@ public:
|
|||
void Destroy();
|
||||
|
||||
void GiveContext();
|
||||
void Display();
|
||||
virtual void Clear();
|
||||
virtual void Display();
|
||||
|
||||
private:
|
||||
int id;
|
||||
|
|
27
src/main.cpp
27
src/main.cpp
|
@ -5,7 +5,7 @@
|
|||
#include <glad/glad.h>
|
||||
#include <glfw/glfw3.h>
|
||||
|
||||
#include "PlotWindow.hpp"
|
||||
#include "PlotManager.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -21,27 +21,14 @@ int main(int argc, char** argv)
|
|||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
std::vector<PlotWindow> windows;
|
||||
windows.emplace_back(500, 500, 1);
|
||||
windows.emplace_back(500, 500, 2);
|
||||
windows.emplace_back(500, 500, 3);
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
PlotManager::NewPlot();
|
||||
}
|
||||
|
||||
while (!windows.empty())
|
||||
while (PlotManager::isOpen)
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
for (std::vector<PlotWindow>::iterator it = windows.begin(); it != windows.end();)
|
||||
{
|
||||
if (it->ShouldClose())
|
||||
{
|
||||
it->Destroy();
|
||||
it = windows.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
it->GiveContext();
|
||||
it->Display();
|
||||
it++;
|
||||
}
|
||||
PlotManager::Loop();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue