From 81f1bc5e72c46b4165bbe9eb48d6ebf86215132f Mon Sep 17 00:00:00 2001 From: lejulien Date: Tue, 13 Jan 2026 14:49:12 +0100 Subject: [PATCH] paterns_menu: Move it to it's own class --- CMakeLists.txt | 1 + includes/context.hpp | 2 ++ includes/control_menu.hpp | 1 - includes/paterns_menu.hpp | 24 ++++++++++++++++++++++++ src/control_menu.cpp | 12 +++--------- src/main.cpp | 11 +++-------- src/paterns_menu.cpp | 35 +++++++++++++++++++++++++++++++++++ src/selection.cpp | 3 ++- 8 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 includes/paterns_menu.hpp create mode 100644 src/paterns_menu.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 811c3d8..f03cca0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ set(SRC_CXX_FILES "./src/main.cpp" "./src/settings_menu.cpp" "./src/selection_menu.cpp" "./src/selection.cpp" + "./src/paterns_menu.cpp" "${rlImGui_SOURCE_DIR}/rlImGui.cpp" "${imgui_SOURCE_DIR}/imgui.cpp" "${imgui_SOURCE_DIR}/imgui_draw.cpp" diff --git a/includes/context.hpp b/includes/context.hpp index 9ad954e..40f8704 100644 --- a/includes/context.hpp +++ b/includes/context.hpp @@ -21,6 +21,7 @@ class SettingsMenu; class SelectionMenu; class ControlMenu; class Selection; +class PaternsMenu; typedef struct ctx { std::shared_ptr world = nullptr; @@ -30,6 +31,7 @@ typedef struct ctx { std::shared_ptr selection_menu = nullptr; std::shared_ptr control_menu = nullptr; std::shared_ptr selection = nullptr; + std::shared_ptr paterns_menu = nullptr; nlohmann::json config_json; } ctx; diff --git a/includes/control_menu.hpp b/includes/control_menu.hpp index 7c20a7d..c9c71b5 100644 --- a/includes/control_menu.hpp +++ b/includes/control_menu.hpp @@ -31,7 +31,6 @@ public: // Keep those public for easy access bool rand_ctrl_ = false; bool edit_ctrl_ = false; bool clear_ctrl_ = false; - bool paterns_ctrl_ = false; }; } // namespace gol diff --git a/includes/paterns_menu.hpp b/includes/paterns_menu.hpp new file mode 100644 index 0000000..9af513a --- /dev/null +++ b/includes/paterns_menu.hpp @@ -0,0 +1,24 @@ +/* +* File name: paterns_menu.hpp +* Author: lejulien +* Date created: 01-01-1970 00:59:59 +// Date modified: 12-01-2026 21:30:10 +* ------ +*/ + +#pragma once + +namespace gol { + +class PaternsMenu { +public: + PaternsMenu() = default; + ~PaternsMenu() = default; + void Toogle(); + bool isOpen(); + void display(); +private: + bool is_open_ = false; +}; + +} // namespace gol diff --git a/src/control_menu.cpp b/src/control_menu.cpp index d91d3ff..2ec86cf 100644 --- a/src/control_menu.cpp +++ b/src/control_menu.cpp @@ -12,19 +12,13 @@ #include #include +#include #include #include namespace gol { ControlMenu::ControlMenu(std::shared_ptr context):context_(context) { - play_ctrl_ = true; - step_ctrl_ = false; - step_back_ctrl_ = false; - rand_ctrl_ = false; - edit_ctrl_ = false; - clear_ctrl_ = false; - paterns_ctrl_ = false; } void ControlMenu::update() { @@ -82,8 +76,8 @@ void ControlMenu::display() { ImGui::Checkbox("Edit", &edit_ctrl_); ImGui::Checkbox("Clear", &clear_ctrl_); ImGui::Checkbox("Randomize", &rand_ctrl_); - if (ImGui::Button((paterns_ctrl_) ? "Hide paterns" : "Show paterns")) { - paterns_ctrl_ = !paterns_ctrl_; + if (ImGui::Button((context_->paterns_menu->isOpen()) ? "Hide paterns" : "Show paterns")) { + context_->paterns_menu->Toogle(); } if (ImGui::Button((context_->settings_menu->isOpen()) ? "Hide settings" : "Show settings")) { context_->settings_menu->Toogle(); diff --git a/src/main.cpp b/src/main.cpp index 25482dc..6f7ebb2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,7 @@ #include #include #include +#include int main(int ac, char **av) { std::shared_ptr context = std::make_shared(); @@ -96,6 +97,7 @@ int main(int ac, char **av) { context->render = std::make_shared(context->settings_menu->getCellSize()); context->selection_menu = std::make_shared(context); context->selection = std::make_shared(context); + context->paterns_menu = std::make_shared(); // Speed handling values float sim_speed = 1.0f; @@ -145,14 +147,7 @@ int main(int ac, char **av) { // Start ImGui frame rlImGuiBegin(); context->control_menu->display(); - if (context->control_menu->paterns_ctrl_) { - ImGuiWindowFlags paterns_flags = - ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize; - ImGui::SetNextWindowSize(ImVec2(150, 200), ImGuiCond_Always); - ImGui::Begin("paterns", &context->control_menu->paterns_ctrl_, paterns_flags); - ImGui::Button("refresh"); - ImGui::End(); - } + context->paterns_menu->display(); context->settings_menu->display(); context->selection_menu->display(); // End ImGui frame diff --git a/src/paterns_menu.cpp b/src/paterns_menu.cpp new file mode 100644 index 0000000..ad450fa --- /dev/null +++ b/src/paterns_menu.cpp @@ -0,0 +1,35 @@ +/* +* File name: paterns_menu.cpp +* Author: lejulien +* Date created: 01-01-1970 00:59:59 +// Date modified: 12-01-2026 21:30:10 +* ------ +*/ + +#include + +#include +#include +#include + +namespace gol { + +void PaternsMenu::Toogle() { + is_open_ = !is_open_; +} + +bool PaternsMenu::isOpen() { + return is_open_; +} + +void PaternsMenu::display() { + if (is_open_) { + ImGuiWindowFlags paterns_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize; + ImGui::SetNextWindowSize(ImVec2(150, 200), ImGuiCond_Always); + ImGui::Begin("paterns", &is_open_, paterns_flags); + ImGui::Button("refresh"); + ImGui::End(); + } +} + +} // namespace gol diff --git a/src/selection.cpp b/src/selection.cpp index c36cfd7..fac32b7 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -24,7 +25,7 @@ Selection::Selection(std::shared_ptr context): context_(context) { void Selection::update() { auto gesture = GetGestureDetected(); mouse_pos_ = GetMousePosition(); - if (!context_->control_menu->edit_ctrl_ && !context_->control_menu->play_ctrl_ && !context_->control_menu->paterns_ctrl_ && !context_->settings_menu->isOpen()) { + if (!context_->control_menu->edit_ctrl_ && !context_->control_menu->play_ctrl_ && !context_->paterns_menu->isOpen() && !context_->settings_menu->isOpen()) { if (gesture == GESTURE_TAP && !ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)) { sel_pos_ = snapToGrid(mouse_pos_, context_->settings_menu->getCellSize()); selecting_ = true;