-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasyappbase.hpp
147 lines (118 loc) · 4.48 KB
/
easyappbase.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#pragma once
#define EASY_APP_LICENSE \
"Copyright (c) 2024 James Baker" \
"\n" \
"Permission is hereby granted, free of charge, to any person obtaining a copy " \
"of this software and associated documentation files (the \"Software\"), to dea l" \
"in the Software without restriction, including without limitation the rights " \
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell " \
"copies of the Software, and to permit persons to whom the Software is " \
"furnished to do so, subject to the following conditions:\n" \
"\n" \
"The above copyright notice and this permission notice shall be included in " \
"all copies or substantial portions of the Software.\n" \
"\n" \
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR " \
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, " \
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " \
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER " \
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, " \
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN " \
"THE SOFTWARE.\n" \
"\n" \
"The official repository for this library is at https://github.com/VA7ODR/EasyAppBase"
#include "app_logger.hpp"
#include "utils.hpp"
#include "data.hpp"
#include "eventhandler.hpp"
#include "network.hpp"
#include "thread.hpp"
#include "shared_recursive_mutex.hpp"
#include "imgui.h"
#include <SDL.h>
#define EASY_APP_VERSION_MAJOR 1
#define EASY_APP_VERSION_MINOR 0
#define EASY_APP_VERSION_PATCH 0
#define EASY_APP_VERSION_STRING "1.0.0"
#define EASY_APP_BUILD_DATE __DATE__
class EasyAppBase
{
public:
class SettingsTreeEntry
{
public:
SettingsTreeEntry() = default;
~SettingsTreeEntry() = default;
std::string sName;
std::set<SettingsTreeEntry> children;
bool operator<(const SettingsTreeEntry & rhs) const;
};
EasyAppBase(const std::string & sNameIn, const std::string & sTitleIn);
EasyAppBase(std::string && sNameIn, std::string && sTitleIn);
virtual ~EasyAppBase() = default;
virtual void Start() {};
virtual void Render(bool * bShow) = 0;
virtual void Stop() {};
virtual bool BuildsOwnWindow() { return false; }
[[nodiscard]] const std::string & Name() const { return sName; }
[[nodiscard]] const std::string & Title() const { return sTitle; }
static void DisableDemo(bool bDisable);
static void DisableDocking(bool bDisable);
static void DisableViewports(bool bDisable);
static void DisableGUI(bool bDisable);
static void SetNetworkThreads(int iSetTo);
static int Run(const std::string & sAppName, const std::string & sTitle = "");
static void SetMainRenderer(std::function<void ()> render);
[[nodiscard]] refTSEx<json::value> ExclusiveSettings() const;
[[nodiscard]] refTSEx<json::value> SharedSettings() const;
[[nodiscard]] static refTSEx<json::value> ExclusiveGlobalSettings();
[[nodiscard]] static refTSEx<json::value> SharedGlobalSettings();
template <typename T>
static std::shared_ptr<EasyAppBase> GenerateWindow()
requires(std::derived_from<T, EasyAppBase>)
{
auto ret = std::make_shared<T>();
auto registry = EasyAppBase::Registry();
auto it = (*registry).find(ret->Name());
if (it == (*registry).end()) {
return (*registry)[ret->Name()] = ret;
}
return it->second;
}
static void ExitAll();
protected:
static refTSEx<std::map<std::string, std::shared_ptr<EasyAppBase>>> Registry() { return {registry, mtx}; }
private:
static void StartAll();
static void Render();
static void Menu();
static void StopAll();
static refTSEx<json::value> ExclusiveSettings(const std::string & sName);
static refTSSh<json::value> SharedSettings(const std::string & sName);
static EventHandler::Event eQuit;
static bool bShowEasyAbout;
static bool bDisableDemo;
static bool bDisableDocking;
static bool bDisableViewports;
static bool bDisableGUI;
static int iNetworkThreads;
static SharedRecursiveMutex mtx;
static json::document jSaveData;
static SDL_Window* window;
static std::map<std::string, std::shared_ptr<EasyAppBase>> registry;
std::string sName;
std::string sTitle;
static std::function<void()> mainRenderer;
};
class DemoWindow : public EasyAppBase
{
public:
DemoWindow() : EasyAppBase("demo_window", "ImGui Demo Window") {}
bool BuildsOwnWindow() override { return true; }
void Render(bool * bShow) override
{
if (*bShow) {
ImGui::ShowDemoWindow(bShow);
}
}
};