OpenShaderDesigner 0.0.1
Loading...
Searching...
No Matches
EditorSystem.h
1// =====================================================================================================================
2// OpenShaderDesigner, an open source software utility to create materials and shaders.
3// Copyright (C) 2024 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
19#ifndef EDITORSYSTEM_H
20#define EDITORSYSTEM_H
21
22#include <SDL_events.h>
23#include <open-cpp-utils/unique_id.h>
24#include <unordered_map>
25
26#include <Editor/EditorWindow.h>
27#include <Editor/MainMenuBar.h>
28
29#define MAX_EDITORS 256
30
31namespace OpenShaderDesigner
32{
33
35{
36public:
37 using WindowID = uint64_t;
38
39 template<typename T>
40 static WindowID ID() { return open_cpp_utils::unique_id<WindowID, T>(); }
41
42 template<typename T>
43 static T* Open() { T* window; (window = Get<T>())->Open(); return window; }
44
45 template<typename T>
46 static T* Close() { T* window; (window = Get<T>())->Close(); return window; }
47
48 template<typename T>
49 static T* Get()
50 {
51 T* window = reinterpret_cast<T*>(Windows_[ID<T>()]);
52 if(window == nullptr) Windows_[ID<T>()] = window = new T();
53 return window;
54 }
55
56 template<typename T>
57 static T* SetMainMenuBar() { delete MainMenuBar_; T* bar = new T(); MainMenuBar_ = bar; return bar; }
58
59 template<typename T>
60 static T* GetMainMenuBar() { return static_cast<T*>(MainMenuBar_); }
61
62 static void Initialize();
63 static void Draw();
64 static void Shutdown();
65 static void HandleEvents(SDL_Event* event);
66
67private:
68 inline static EditorWindow* Windows_[MAX_EDITORS] { nullptr };
69 inline static MainMenuBar* MainMenuBar_ = nullptr;
70};
71
72}
73
74
75
76#endif //EDITORSYSTEM_H
Definition EditorSystem.h:35
EditorWindow class for wrapping ImGui window functionality.
Definition EditorWindow.h:32
Definition MainMenuBar.h:14