Commit 31dec45d authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

gui: add application class to move static variables

parent e35da6e7
Pipeline #27843 passed with stage
in 1 minute and 40 seconds
...@@ -120,31 +120,39 @@ get_executable_directory() ...@@ -120,31 +120,39 @@ get_executable_directory()
} }
#endif #endif
path_manager::path_manager(window_logger& logger) application::settings_manager::settings_manager() noexcept
{ {
if (auto home = get_home_directory(); home) { try {
home_dir = home.value(); if (auto home = get_home_directory(); home) {
home_dir /= "irritator"; home_dir = home.value();
} else { home_dir /= "irritator";
logger.log( } else {
3, "Fail to retrieve home directory. Use current directory instead"); log_w.log(
home_dir = std::filesystem::current_path(); 3,
} "Fail to retrieve home directory. Use current directory instead");
home_dir = std::filesystem::current_path();
}
if (auto install = get_executable_directory(); install) { if (auto install = get_executable_directory(); install) {
install_dir = install.value(); executable_dir = install.value();
} else { } else {
logger.log( log_w.log(
3, 3,
"Fail to retrieve executable directory. Use current directory " "Fail to retrieve executable directory. Use current directory "
"instead"); "instead");
install_dir = std::filesystem::current_path(); executable_dir = std::filesystem::current_path();
} }
logger.log(5, log_w.log(5,
"home: %s\ninstall: %s\n", "home: %s\ninstall: %s\n",
home_dir.u8string().c_str(), home_dir.u8string().c_str(),
install_dir.u8string().c_str()); executable_dir.u8string().c_str());
// TODO Fill the libraries vectors with users and systems directory.
} catch (const std::exception& /*e*/) {
log_w.log(2, "Fail to initialize application");
}
} }
struct file_dialog struct file_dialog
......
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
namespace irt { namespace irt {
void void
node_editor_initialize(); application_initialize();
bool bool
node_editor_show(); application_show();
void void
node_editor_shutdown(); application_shutdown();
/* Move into internal API */ /* Move into internal API */
......
...@@ -120,7 +120,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) ...@@ -120,7 +120,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version); ImGui_ImplOpenGL3_Init(glsl_version);
imnodes::Initialize(); imnodes::Initialize();
irt::node_editor_initialize(); irt::application_initialize();
// Load Fonts // Load Fonts
// - If no fonts are loaded, dear imgui will use the default font. You can // - If no fonts are loaded, dear imgui will use the default font. You can
...@@ -169,7 +169,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) ...@@ -169,7 +169,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
if (!irt::node_editor_show()) if (!irt::application_show())
glfwSetWindowShouldClose(window, GLFW_TRUE); glfwSetWindowShouldClose(window, GLFW_TRUE);
// Rendering // Rendering
...@@ -189,7 +189,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) ...@@ -189,7 +189,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
// Cleanup // Cleanup
irt::node_editor_shutdown(); irt::application_shutdown();
imnodes::Shutdown(); imnodes::Shutdown();
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
......
...@@ -97,7 +97,7 @@ int main(int, char**) ...@@ -97,7 +97,7 @@ int main(int, char**)
g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart());
imnodes::Initialize(); imnodes::Initialize();
irt::node_editor_initialize(); irt::application_initialize();
// Load Fonts // Load Fonts
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
...@@ -141,7 +141,7 @@ int main(int, char**) ...@@ -141,7 +141,7 @@ int main(int, char**)
ImGui_ImplWin32_NewFrame(); ImGui_ImplWin32_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
if (!irt::node_editor_show()) if (!irt::application_show())
::PostMessage(hwnd, WM_CLOSE, 0, 0); ::PostMessage(hwnd, WM_CLOSE, 0, 0);
// Rendering // Rendering
...@@ -180,7 +180,7 @@ int main(int, char**) ...@@ -180,7 +180,7 @@ int main(int, char**)
frameCtxt->FenceValue = fenceValue; frameCtxt->FenceValue = fenceValue;
} }
irt::node_editor_shutdown(); irt::application_shutdown();
imnodes::Shutdown(); imnodes::Shutdown();
......
This diff is collapsed.
...@@ -214,16 +214,7 @@ struct window_logger ...@@ -214,16 +214,7 @@ struct window_logger
void show(bool* is_show); void show(bool* is_show);
}; };
struct path_manager static inline window_logger log_w;
{
path_manager(window_logger& log);
std::filesystem::path home_dir;
std::filesystem::path install_dir;
std::vector<std::filesystem::path> libraries;
};
struct plot_output struct plot_output
{ {
...@@ -363,6 +354,36 @@ struct editor ...@@ -363,6 +354,36 @@ struct editor
bool show_load_file_dialog = false; bool show_load_file_dialog = false;
bool show_save_file_dialog = false; bool show_save_file_dialog = false;
bool show_select_directory_dialog = false; bool show_select_directory_dialog = false;
bool show_settings = false;
struct settings_manager
{
int kernel_model_cache = 1024;
int kernel_message_cache = 32768;
int gui_node_cache = 1024;
ImVec4 gui_model_color{ .27f, .27f, .54f, 1.f };
ImVec4 gui_model_transition_color{ .27f, .54f, .54f, 1.f };
ImVec4 gui_cluster_color{ .27f, .54f, .27f, 1.f };
ImU32 gui_hovered_model_color;
ImU32 gui_selected_model_color;
ImU32 gui_hovered_model_transition_color;
ImU32 gui_selected_model_transition_color;
ImU32 gui_hovered_cluster_color;
ImU32 gui_selected_cluster_color;
int automatic_layout_iteration_limit = 200;
float automatic_layout_x_distance = 350.f;
float automatic_layout_y_distance = 350.f;
float grid_layout_x_distance = 250.f;
float grid_layout_y_distance = 250.f;
bool show_dynamics_inputs_in_editor = false;
void compute_colors() noexcept;
void show(bool* is_open);
} settings;
status initialize(u32 id) noexcept; status initialize(u32 id) noexcept;
void clear() noexcept; void clear() noexcept;
...@@ -444,11 +465,38 @@ struct editor ...@@ -444,11 +465,38 @@ struct editor
bool show_editor() noexcept; bool show_editor() noexcept;
}; };
editor*
make_combo_editor_name(editor_id& current) noexcept;
void void
show_simulation_box(editor& ed, window_logger& log_w, bool* show_simulation); show_simulation_box(editor& ed, bool* show_simulation);
struct application
{
data_array<editor, editor_id> editors;
struct settings_manager
{
settings_manager() noexcept;
std::filesystem::path home_dir;
std::filesystem::path executable_dir;
std::vector<std::string> libraries_dir;
void show(bool *is_open);
} settings;
bool show_log = true;
bool show_simulation = true;
bool show_demo = false;
bool show_plot = true;
bool show_settings = false;
editor* alloc_editor();
void free_editor(editor& ed);
};
static inline application app;
editor*
make_combo_editor_name(application& app, editor_id& current) noexcept;
} // namespace irt } // namespace irt
......
...@@ -431,7 +431,7 @@ show_simulation_run_debug(window_logger& log_w, editor& ed) ...@@ -431,7 +431,7 @@ show_simulation_run_debug(window_logger& log_w, editor& ed)
} }
void void
show_simulation_box(editor& ed, window_logger& log_w, bool* show_simulation) show_simulation_box(editor& ed, bool* show_simulation)
{ {
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver); ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(250, 350), ImGuiCond_Once); ImGui::SetNextWindowSize(ImVec2(250, 350), ImGuiCond_Once);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment