paterns_menu: Move it to it's own class
This commit is contained in:
@@ -74,6 +74,7 @@ set(SRC_CXX_FILES "./src/main.cpp"
|
|||||||
"./src/settings_menu.cpp"
|
"./src/settings_menu.cpp"
|
||||||
"./src/selection_menu.cpp"
|
"./src/selection_menu.cpp"
|
||||||
"./src/selection.cpp"
|
"./src/selection.cpp"
|
||||||
|
"./src/paterns_menu.cpp"
|
||||||
"${rlImGui_SOURCE_DIR}/rlImGui.cpp"
|
"${rlImGui_SOURCE_DIR}/rlImGui.cpp"
|
||||||
"${imgui_SOURCE_DIR}/imgui.cpp"
|
"${imgui_SOURCE_DIR}/imgui.cpp"
|
||||||
"${imgui_SOURCE_DIR}/imgui_draw.cpp"
|
"${imgui_SOURCE_DIR}/imgui_draw.cpp"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class SettingsMenu;
|
|||||||
class SelectionMenu;
|
class SelectionMenu;
|
||||||
class ControlMenu;
|
class ControlMenu;
|
||||||
class Selection;
|
class Selection;
|
||||||
|
class PaternsMenu;
|
||||||
|
|
||||||
typedef struct ctx {
|
typedef struct ctx {
|
||||||
std::shared_ptr<World> world = nullptr;
|
std::shared_ptr<World> world = nullptr;
|
||||||
@@ -30,6 +31,7 @@ typedef struct ctx {
|
|||||||
std::shared_ptr<SelectionMenu> selection_menu = nullptr;
|
std::shared_ptr<SelectionMenu> selection_menu = nullptr;
|
||||||
std::shared_ptr<ControlMenu> control_menu = nullptr;
|
std::shared_ptr<ControlMenu> control_menu = nullptr;
|
||||||
std::shared_ptr<Selection> selection = nullptr;
|
std::shared_ptr<Selection> selection = nullptr;
|
||||||
|
std::shared_ptr<PaternsMenu> paterns_menu = nullptr;
|
||||||
nlohmann::json config_json;
|
nlohmann::json config_json;
|
||||||
} ctx;
|
} ctx;
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public: // Keep those public for easy access
|
|||||||
bool rand_ctrl_ = false;
|
bool rand_ctrl_ = false;
|
||||||
bool edit_ctrl_ = false;
|
bool edit_ctrl_ = false;
|
||||||
bool clear_ctrl_ = false;
|
bool clear_ctrl_ = false;
|
||||||
bool paterns_ctrl_ = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gol
|
} // namespace gol
|
||||||
|
|||||||
24
includes/paterns_menu.hpp
Normal file
24
includes/paterns_menu.hpp
Normal file
@@ -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
|
||||||
@@ -12,19 +12,13 @@
|
|||||||
|
|
||||||
#include <control_menu.hpp>
|
#include <control_menu.hpp>
|
||||||
#include <settings_menu.hpp>
|
#include <settings_menu.hpp>
|
||||||
|
#include <paterns_menu.hpp>
|
||||||
#include <world.hpp>
|
#include <world.hpp>
|
||||||
#include <rules.hpp>
|
#include <rules.hpp>
|
||||||
|
|
||||||
namespace gol {
|
namespace gol {
|
||||||
|
|
||||||
ControlMenu::ControlMenu(std::shared_ptr<ctx> context):context_(context) {
|
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() {
|
void ControlMenu::update() {
|
||||||
@@ -82,8 +76,8 @@ void ControlMenu::display() {
|
|||||||
ImGui::Checkbox("Edit", &edit_ctrl_);
|
ImGui::Checkbox("Edit", &edit_ctrl_);
|
||||||
ImGui::Checkbox("Clear", &clear_ctrl_);
|
ImGui::Checkbox("Clear", &clear_ctrl_);
|
||||||
ImGui::Checkbox("Randomize", &rand_ctrl_);
|
ImGui::Checkbox("Randomize", &rand_ctrl_);
|
||||||
if (ImGui::Button((paterns_ctrl_) ? "Hide paterns" : "Show paterns")) {
|
if (ImGui::Button((context_->paterns_menu->isOpen()) ? "Hide paterns" : "Show paterns")) {
|
||||||
paterns_ctrl_ = !paterns_ctrl_;
|
context_->paterns_menu->Toogle();
|
||||||
}
|
}
|
||||||
if (ImGui::Button((context_->settings_menu->isOpen()) ? "Hide settings" : "Show settings")) {
|
if (ImGui::Button((context_->settings_menu->isOpen()) ? "Hide settings" : "Show settings")) {
|
||||||
context_->settings_menu->Toogle();
|
context_->settings_menu->Toogle();
|
||||||
|
|||||||
11
src/main.cpp
11
src/main.cpp
@@ -24,6 +24,7 @@
|
|||||||
#include <settings_menu.hpp>
|
#include <settings_menu.hpp>
|
||||||
#include <selection_menu.hpp>
|
#include <selection_menu.hpp>
|
||||||
#include <selection.hpp>
|
#include <selection.hpp>
|
||||||
|
#include <paterns_menu.hpp>
|
||||||
|
|
||||||
int main(int ac, char **av) {
|
int main(int ac, char **av) {
|
||||||
std::shared_ptr<gol::ctx> context = std::make_shared<gol::ctx>();
|
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->render = std::make_shared<Render>(context->settings_menu->getCellSize());
|
||||||
context->selection_menu = std::make_shared<gol::SelectionMenu>(context);
|
context->selection_menu = std::make_shared<gol::SelectionMenu>(context);
|
||||||
context->selection = std::make_shared<gol::Selection>(context);
|
context->selection = std::make_shared<gol::Selection>(context);
|
||||||
|
context->paterns_menu = std::make_shared<gol::PaternsMenu>();
|
||||||
|
|
||||||
// Speed handling values
|
// Speed handling values
|
||||||
float sim_speed = 1.0f;
|
float sim_speed = 1.0f;
|
||||||
@@ -145,14 +147,7 @@ int main(int ac, char **av) {
|
|||||||
// Start ImGui frame
|
// Start ImGui frame
|
||||||
rlImGuiBegin();
|
rlImGuiBegin();
|
||||||
context->control_menu->display();
|
context->control_menu->display();
|
||||||
if (context->control_menu->paterns_ctrl_) {
|
context->paterns_menu->display();
|
||||||
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->settings_menu->display();
|
context->settings_menu->display();
|
||||||
context->selection_menu->display();
|
context->selection_menu->display();
|
||||||
// End ImGui frame
|
// End ImGui frame
|
||||||
|
|||||||
35
src/paterns_menu.cpp
Normal file
35
src/paterns_menu.cpp
Normal 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
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <selection_menu.hpp>
|
#include <selection_menu.hpp>
|
||||||
#include <control_menu.hpp>
|
#include <control_menu.hpp>
|
||||||
#include <settings_menu.hpp>
|
#include <settings_menu.hpp>
|
||||||
|
#include <paterns_menu.hpp>
|
||||||
#include <world.hpp>
|
#include <world.hpp>
|
||||||
#include <snapping.hpp>
|
#include <snapping.hpp>
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ Selection::Selection(std::shared_ptr<ctx> context): context_(context) {
|
|||||||
void Selection::update() {
|
void Selection::update() {
|
||||||
auto gesture = GetGestureDetected();
|
auto gesture = GetGestureDetected();
|
||||||
mouse_pos_ = GetMousePosition();
|
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)) {
|
if (gesture == GESTURE_TAP && !ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)) {
|
||||||
sel_pos_ = snapToGrid(mouse_pos_, context_->settings_menu->getCellSize());
|
sel_pos_ = snapToGrid(mouse_pos_, context_->settings_menu->getCellSize());
|
||||||
selecting_ = true;
|
selecting_ = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user