Skip to content

Commit 0e4a806

Browse files
committed
Adapt for runtime path setting for the framework
1 parent 785bb0e commit 0e4a806

File tree

12 files changed

+109
-59
lines changed

12 files changed

+109
-59
lines changed

Framework/C/CDefines.h

-30
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,6 @@ extern "C"
3232
#define X11_WINDOW_TYPE_DND "_NET_WM_WINDOW_TYPE_DND"
3333
#define X11_WINDOW_TYPE_NORMAL "_NET_WM_WINDOW_TYPE_NORMAL"
3434

35-
// Default defines for these directories. They will only be defined while compiling for production
36-
#ifndef UIMGUI_FRAMEWORK_LIBRARY_DIR
37-
#define UIMGUI_FRAMEWORK_LIBRARY_DIR "."
38-
#endif
39-
40-
#ifndef UIMGUI_APPLICATION_DIR
41-
#define UIMGUI_APPLICATION_DIR "."
42-
#endif
43-
44-
#ifndef UIMGUI_APPLICATION_LIBRARY_DIR
45-
#define UIMGUI_APPLICATION_LIBRARY_DIR "."
46-
#endif
47-
48-
#ifndef UIMGUI_CONFIG_DIR
49-
#define UIMGUI_CONFIG_DIR "../Config/"
50-
#define UIMGUI_PROJECT_DIR "../"
51-
#endif
52-
53-
#ifndef UIMGUI_CONTENT_DIR
54-
#define UIMGUI_CONTENT_DIR "../Content/"
55-
#endif
56-
57-
#ifndef UIMGUI_FRAMEWORK_INCLUDE_DIR
58-
#define UIMGUI_FRAMEWORK_INCLUDE_DIR "../Framework/"
59-
#endif
60-
61-
#ifndef UIMGUI_APPLICATION_INCLUDE_DIR
62-
#define UIMGUI_APPLICATION_INCLUDE_DIR "../Source/"
63-
#endif
64-
6535
/**
6636
* @brief The ComponentState enum defines 3 fields that represent the event state of the given component, the given
6737
* component can then check its own state(if in PAUSED or RUNNING state) and call specific components of its event

Framework/C/Components/CInstance.cpp

+45-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
#include <Instance.hpp>
33
#include <Global.hpp>
44

5+
#define INIT_INFO UImGui::internalGlobal.instance->initInfo
6+
57
void UImGui_Instance_setCInitInfo(UImGui_CInitInfo* initInfo)
68
{
7-
UImGui::internalGlobal.instance->initInfo.cInitInfo = initInfo;
9+
INIT_INFO.cInitInfo = initInfo;
810
}
911

1012
void* UImGui_Instance_getCppInitInfoGlobalData(bool* bAllocatedOnHeap)
1113
{
12-
auto& initInfo = UImGui::internalGlobal.instance->initInfo;
13-
14-
*bAllocatedOnHeap = initInfo.bGlobalAllocatedOnHeap;
15-
return initInfo.globalData;
14+
*bAllocatedOnHeap = INIT_INFO.bGlobalAllocatedOnHeap;
15+
return INIT_INFO.globalData;
1616
}
1717

1818
char** UImGui_Instance_getCLIArguments(int* argc)
@@ -21,4 +21,44 @@ char** UImGui_Instance_getCLIArguments(int* argc)
2121
*argc = instance->argc;
2222

2323
return instance->argv;
24+
}
25+
26+
UImGui_String UImGui_InitInfo_getFrameworkLibraryDir()
27+
{
28+
return INIT_INFO.frameworkLibraryDir.c_str();
29+
}
30+
31+
UImGui_String UImGui_InitInfo_getApplicationDir()
32+
{
33+
return INIT_INFO.applicationDir.c_str();
34+
}
35+
36+
UImGui_String UImGui_InitInfo_getApplicationLibraryDir()
37+
{
38+
return INIT_INFO.applicationLibraryDir.c_str();
39+
}
40+
41+
UImGui_String UImGui_InitInfo_getConfigDir()
42+
{
43+
return INIT_INFO.configDir.c_str();
44+
}
45+
46+
UImGui_String UImGui_InitInfo_getProjectDir()
47+
{
48+
return INIT_INFO.projectDir.c_str();
49+
}
50+
51+
UImGui_String UImGui_InitInfo_getContentDir()
52+
{
53+
return INIT_INFO.contentDir.c_str();
54+
}
55+
56+
UImGui_String UImGui_InitInfo_getFrameworkIncludeDir()
57+
{
58+
return INIT_INFO.frameworkIncludeDir.c_str();
59+
}
60+
61+
UImGui_String UImGui_InitInfo_getApplicationIncludeDir()
62+
{
63+
return INIT_INFO.applicationIncludeDir.c_str();
2464
}

Framework/C/Components/CInstance.h

+21
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ extern "C"
4949

5050
// Event Safety - Any time
5151
UIMGUI_PUBLIC_API char** UImGui_Instance_getCLIArguments(int* argc);
52+
53+
// Event Safety - Any time
54+
UIMGUI_PUBLIC_API UImGui_String UImGui_InitInfo_getFrameworkLibraryDir();
55+
// Event Safety - Any time
56+
UIMGUI_PUBLIC_API UImGui_String UImGui_InitInfo_getApplicationDir();
57+
// Event Safety - Any time
58+
UIMGUI_PUBLIC_API UImGui_String UImGui_InitInfo_getApplicationLibraryDir();
59+
60+
// Event Safety - Any time
61+
UIMGUI_PUBLIC_API UImGui_String UImGui_InitInfo_getConfigDir();
62+
// Event Safety - Any time
63+
UIMGUI_PUBLIC_API UImGui_String UImGui_InitInfo_getProjectDir();
64+
65+
// Event Safety - Any time
66+
UIMGUI_PUBLIC_API UImGui_String UImGui_InitInfo_getContentDir();
67+
68+
// Event Safety - Any time
69+
UIMGUI_PUBLIC_API UImGui_String UImGui_InitInfo_getFrameworkIncludeDir();
70+
// Event Safety - Any time
71+
UIMGUI_PUBLIC_API UImGui_String UImGui_InitInfo_getApplicationIncludeDir();
72+
5273
#ifdef __cplusplus
5374
};
5475
#endif

Framework/Core/Components/Instance.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ namespace UImGui
3232
bool bGlobalAllocatedOnHeap = true; // Set this to false if the global is a stack pointer
3333

3434
UImGui_CInitInfo* cInitInfo = nullptr;
35+
36+
FString frameworkLibraryDir = ".";
37+
FString applicationDir = ".";
38+
FString applicationLibraryDir = ".";
39+
40+
FString configDir = "../Config/";
41+
FString projectDir = "../";
42+
43+
FString contentDir = "../Content/";
44+
45+
FString frameworkIncludeDir = "../Framework/";
46+
FString applicationIncludeDir = "../Source/";
3547
};
3648

3749
/**

Framework/Core/Global.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,4 @@ UImGui::Global::~Global() noexcept
2424
void UImGui::Global::init() noexcept
2525
{
2626
window.createWindow();
27-
28-
modulesManagerr.init();
2927
}

Framework/Modules/Manager/ModulesManager.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
Modules::data().x = mod[#x].as<bool>(); \
1919
}
2020

21+
#include <Utilities.hpp>
22+
#include <Components/Instance.hpp>
2123

22-
void UImGui::ModulesManager::init()
24+
25+
void UImGui::ModulesManager::init(const FString& configDir)
2326
{
2427
YAML::Node node;
2528
try
2629
{
27-
node = YAML::LoadFile(UIMGUI_CONFIG_DIR"Core/Modules.yaml");
30+
node = YAML::LoadFile(configDir + "Core/Modules.yaml");
2831
}
2932
catch (YAML::BadFile&)
3033
{
@@ -35,7 +38,7 @@ void UImGui::ModulesManager::init()
3538
if (node["undo-max-transactions"])
3639
settings.maxTransactions = node["undo-max-transactions"].as<size_t>();
3740

38-
initModules();
41+
initModules(UImGui_InitInfo_getProjectDir());
3942

4043
// Put this one after we have initialized the locale module
4144
#ifdef UIMGUI_LOCALE_MODULE_ENABLED
@@ -44,7 +47,7 @@ void UImGui::ModulesManager::init()
4447
#endif
4548
}
4649

47-
void UImGui::ModulesManager::save() const noexcept
50+
void UImGui::ModulesManager::save(const FString& configDir) const noexcept
4851
{
4952
YAML::Emitter out;
5053
out << YAML::BeginMap;
@@ -55,7 +58,7 @@ void UImGui::ModulesManager::save() const noexcept
5558
#endif
5659
out << YAML::EndMap;
5760

58-
std::ofstream fout(UIMGUI_CONFIG_DIR"Core/Modules.yaml");
61+
std::ofstream fout(configDir + "Core/Modules.yaml");
5962
fout << out.c_str();
6063
}
6164

@@ -66,20 +69,20 @@ UImGui::ModuleSettings& UImGui::Modules::data() noexcept
6669

6770
void UImGui::Modules::save() noexcept
6871
{
69-
Modules::get().save();
72+
Modules::get().save(UImGui::Utility::getGlobal().instance->initInfo.configDir);
7073
}
7174

7275
UImGui::ModulesManager& UImGui::Modules::get() noexcept
7376
{
7477
return internalGlobal.modulesManagerr;
7578
}
7679

77-
void UImGui::ModulesManager::initModules()
80+
void UImGui::ModulesManager::initModules(const FString& projectDir)
7881
{
7982
YAML::Node node;
8083
try
8184
{
82-
node = YAML::LoadFile(UIMGUI_PROJECT_DIR"uvproj.yaml");
85+
node = YAML::LoadFile(projectDir + "uvproj.yaml");
8386
}
8487
catch (YAML::BadFile&)
8588
{

Framework/Modules/Manager/ModulesManager.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace UImGui
5050
private:
5151
friend class Modules;
5252
friend class Global;
53+
friend class RendererInternal;
5354

5455
friend class Locale;
5556
friend class LocaleManager;
@@ -82,9 +83,9 @@ namespace UImGui
8283
StateTracker stateTracker{};
8384
#endif
8485

85-
void init();
86-
void initModules();
87-
void save() const noexcept;
86+
void init(const FString& configDir);
87+
void initModules(const FString& projectDir);
88+
void save(const FString& configDir) const noexcept;
8889
};
8990

9091
class UIMGUI_PUBLIC_API Modules

Framework/Renderer/ImGui/ImGui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void UImGui::GUIRenderer::shutdown(const FString& ini)
5959
}
6060
}
6161

62-
ImGui::SaveIniSettingsToDisk((UIMGUI_CONFIG_DIR"Core/" + ini + ".ini").c_str());
62+
ImGui::SaveIniSettingsToDisk((UImGui::internalGlobal.instance->initInfo.configDir + "Core/" + ini + ".ini").c_str());
6363
ImGui_ImplOpenGL3_Shutdown();
6464
ImGui_ImplGlfw_Shutdown();
6565
#ifdef UIMGUI_PLOTTING_MODULE_ENABLED
@@ -84,7 +84,7 @@ void UImGui::GUIRenderer::init(GLFWwindow* glfwwindow, const FString& ini)
8484
io.ConfigViewportsNoTaskBarIcon = true;
8585
io.ConfigUseDefaultMouseCursors = true;
8686

87-
ImGui::LoadIniSettingsFromDisk((UIMGUI_CONFIG_DIR"Core/" + ini + ".ini").c_str());
87+
ImGui::LoadIniSettingsFromDisk((UImGui::internalGlobal.instance->initInfo.configDir + "Core/" + ini + ".ini").c_str());
8888
ImGui::StyleColorsDark();
8989
ImGui::StyleColorsClassic();
9090
ImGuiStyle& style = ImGui::GetStyle();

Framework/Renderer/Renderer.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
void UImGui::RendererInternal::start() noexcept
1111
{
12+
loadConfig();
13+
1214
// Normally we would just use the Renderer::get but since we assign a pointer here we need to avoid the SEGFAULT and
1315
// other madness the normal solution entails
1416
internalGlobal.renderer = this;
@@ -27,6 +29,7 @@ void UImGui::RendererInternal::start() noexcept
2729
gpuName = (char*)glGetString(GL_RENDERER);
2830

2931
GUIRenderer::init(Window::get().windowMain, Window::get().windowData.layoutLocation);
32+
UImGui::internalGlobal.modulesManagerr.init(UImGui::internalGlobal.instance->initInfo.configDir);
3033

3134
double lastTime = 0.0f;
3235
while (!glfwWindowShouldClose(Window::get().windowMain))
@@ -64,7 +67,7 @@ void UImGui::RendererInternal::loadConfig()
6467
YAML::Node node;
6568
try
6669
{
67-
node = YAML::LoadFile(UIMGUI_CONFIG_DIR"Core/Renderer.yaml");
70+
node = YAML::LoadFile(UImGui::internalGlobal.instance->initInfo.configDir + "Core/Renderer.yaml");
6871
}
6972
catch (YAML::BadFile&)
7073
{
@@ -95,7 +98,7 @@ void UImGui::RendererInternal::saveConfig() const noexcept
9598
out << YAML::Key << "sample-rate-shading" << YAML::Value << data.bSampleRateShading;
9699
out << YAML::Key << "sample-rate-shading-mult" << YAML::Value << data.sampleRateShadingMult;
97100

98-
std::ofstream fout(UIMGUI_CONFIG_DIR"Core/Renderer.yaml");
101+
std::ofstream fout(UImGui::internalGlobal.instance->initInfo.configDir + "Core/Renderer.yaml");
99102
fout << out.c_str();
100103
fout.close();
101104
}

Framework/Renderer/Renderer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace UImGui
1515
RendererInternal() = default;
1616

1717
void start() noexcept;
18-
void stop() noexcept;
18+
static void stop() noexcept;
1919
private:
2020
friend class Renderer;
2121

Framework/Renderer/Utils/Window.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <Interfaces/RendererInterface.hpp>
2222
#include <Interfaces/WindowInterface.hpp>
2323

24+
#include <Components/Instance.hpp>
25+
2426
#define _NET_WM_STATE_ADD 1
2527

2628
UImGui::WindowInternal::WindowInternal() noexcept
@@ -42,7 +44,7 @@ bool& UImGui::WindowInternal::resized() noexcept
4244

4345
void UImGui::WindowInternal::saveConfig(bool bSaveKeybindings) noexcept
4446
{
45-
std::ofstream fout(UIMGUI_CONFIG_DIR"Core/Window.yaml");
47+
std::ofstream fout(UImGui::internalGlobal.instance->initInfo.configDir + "Core/Window.yaml");
4648
{
4749
YAML::Emitter out;
4850
out << YAML::BeginMap;
@@ -86,7 +88,7 @@ void UImGui::WindowInternal::saveConfig(bool bSaveKeybindings) noexcept
8688
}
8789
out << YAML::EndSeq << YAML::EndMap;
8890

89-
fout = std::ofstream(UIMGUI_CONFIG_DIR"Core/Keybindings.yaml");
91+
fout = std::ofstream(UImGui::internalGlobal.instance->initInfo.configDir + "Core/Keybindings.yaml");
9092
fout << out.c_str();
9193
fout.close();
9294
}
@@ -299,7 +301,7 @@ void UImGui::WindowInternal::openConfig()
299301

300302
try
301303
{
302-
out = YAML::LoadFile(UIMGUI_CONFIG_DIR"Core/Window.yaml");
304+
out = YAML::LoadFile(UImGui::internalGlobal.instance->initInfo.configDir + "Core/Window.yaml");
303305
}
304306
catch (YAML::BadFile&)
305307
{
@@ -329,7 +331,7 @@ void UImGui::WindowInternal::openConfig()
329331

330332
try
331333
{
332-
out = YAML::LoadFile(UIMGUI_CONFIG_DIR"Core/Keybindings.yaml");
334+
out = YAML::LoadFile(UImGui::internalGlobal.instance->initInfo.configDir + "Core/Keybindings.yaml");
333335
}
334336
catch (YAML::BadFile&)
335337
{
@@ -373,7 +375,7 @@ finish_inner_loop:;
373375
void UImGui::WindowInternal::setIcon(UImGui::String name) noexcept
374376
{
375377
GLFWimage images[1];
376-
images[0].pixels = stbi_load((UImGui::FString(UIMGUI_CONTENT_DIR) + name).c_str(), &images[0].width, &images[0].height, nullptr, 4);
378+
images[0].pixels = stbi_load((UImGui::internalGlobal.instance->initInfo.contentDir + name).c_str(), &images[0].width, &images[0].height, nullptr, 4);
377379
glfwSetWindowIcon(windowMain, 1, images);
378380
stbi_image_free(images[0].pixels);
379381
}

0 commit comments

Comments
 (0)