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()
}
#endif
path_manager::path_manager(window_logger& logger)
application::settings_manager::settings_manager() noexcept
{
if (auto home = get_home_directory(); home) {
home_dir = home.value();
home_dir /= "irritator";
} else {
logger.log(
3, "Fail to retrieve home directory. Use current directory instead");
home_dir = std::filesystem::current_path();
}
try {
if (auto home = get_home_directory(); home) {
home_dir = home.value();
home_dir /= "irritator";
} else {
log_w.log(
3,
"Fail to retrieve home directory. Use current directory instead");
home_dir = std::filesystem::current_path();
}
if (auto install = get_executable_directory(); install) {
install_dir = install.value();
} else {
logger.log(
3,
"Fail to retrieve executable directory. Use current directory "
"instead");
install_dir = std::filesystem::current_path();
}
if (auto install = get_executable_directory(); install) {
executable_dir = install.value();
} else {
log_w.log(
3,
"Fail to retrieve executable directory. Use current directory "
"instead");
executable_dir = std::filesystem::current_path();
}
logger.log(5,
"home: %s\ninstall: %s\n",
home_dir.u8string().c_str(),
install_dir.u8string().c_str());
log_w.log(5,
"home: %s\ninstall: %s\n",
home_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
......
......@@ -11,13 +11,13 @@
namespace irt {
void
node_editor_initialize();
application_initialize();
bool
node_editor_show();
application_show();
void
node_editor_shutdown();
application_shutdown();
/* Move into internal API */
......
......@@ -120,7 +120,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
imnodes::Initialize();
irt::node_editor_initialize();
irt::application_initialize();
// Load Fonts
// - 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[])
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
if (!irt::node_editor_show())
if (!irt::application_show())
glfwSetWindowShouldClose(window, GLFW_TRUE);
// Rendering
......@@ -189,7 +189,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
// Cleanup
irt::node_editor_shutdown();
irt::application_shutdown();
imnodes::Shutdown();
ImGui_ImplOpenGL3_Shutdown();
......
......@@ -97,7 +97,7 @@ int main(int, char**)
g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart());
imnodes::Initialize();
irt::node_editor_initialize();
irt::application_initialize();
// 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.
......@@ -141,7 +141,7 @@ int main(int, char**)
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
if (!irt::node_editor_show())
if (!irt::application_show())
::PostMessage(hwnd, WM_CLOSE, 0, 0);
// Rendering
......@@ -180,7 +180,7 @@ int main(int, char**)
frameCtxt->FenceValue = fenceValue;
}
irt::node_editor_shutdown();
irt::application_shutdown();
imnodes::Shutdown();
......
This diff is collapsed.
......@@ -214,16 +214,7 @@ struct window_logger
void show(bool* is_show);
};
struct path_manager
{
path_manager(window_logger& log);
std::filesystem::path home_dir;
std::filesystem::path install_dir;
std::vector<std::filesystem::path> libraries;
};
static inline window_logger log_w;
struct plot_output
{
......@@ -363,6 +354,36 @@ struct editor
bool show_load_file_dialog = false;
bool show_save_file_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;
void clear() noexcept;
......@@ -444,11 +465,38 @@ struct editor
bool show_editor() noexcept;
};
editor*
make_combo_editor_name(editor_id& current) noexcept;
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
......
......@@ -431,7 +431,7 @@ show_simulation_run_debug(window_logger& log_w, editor& ed)
}
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::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