paterns_menu: Move it to it's own class

This commit is contained in:
2026-01-13 14:49:12 +01:00
parent 55341973b3
commit 81f1bc5e72
8 changed files with 70 additions and 19 deletions

View File

@@ -12,19 +12,13 @@
#include <control_menu.hpp>
#include <settings_menu.hpp>
#include <paterns_menu.hpp>
#include <world.hpp>
#include <rules.hpp>
namespace gol {
ControlMenu::ControlMenu(std::shared_ptr<ctx> 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();

View File

@@ -24,6 +24,7 @@
#include <settings_menu.hpp>
#include <selection_menu.hpp>
#include <selection.hpp>
#include <paterns_menu.hpp>
int main(int ac, char **av) {
std::shared_ptr<gol::ctx> context = std::make_shared<gol::ctx>();
@@ -96,6 +97,7 @@ int main(int ac, char **av) {
context->render = std::make_shared<Render>(context->settings_menu->getCellSize());
context->selection_menu = std::make_shared<gol::SelectionMenu>(context);
context->selection = std::make_shared<gol::Selection>(context);
context->paterns_menu = std::make_shared<gol::PaternsMenu>();
// 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

35
src/paterns_menu.cpp Normal file
View File

@@ -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 <paterns_menu.hpp>
#include <imgui.h>
#include <raylib.h>
#include <rlImGui.h>
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

View File

@@ -12,6 +12,7 @@
#include <selection_menu.hpp>
#include <control_menu.hpp>
#include <settings_menu.hpp>
#include <paterns_menu.hpp>
#include <world.hpp>
#include <snapping.hpp>
@@ -24,7 +25,7 @@ Selection::Selection(std::shared_ptr<ctx> 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;