control_menu: Move processing and display code into it's correspondind methods
This commit is contained in:
@@ -6,7 +6,12 @@
|
||||
* ------
|
||||
*/
|
||||
|
||||
#include <imgui.h>
|
||||
#include <raylib.h>
|
||||
#include <rlImGui.h>
|
||||
|
||||
#include <control_menu.hpp>
|
||||
#include <world.hpp>
|
||||
|
||||
namespace gol {
|
||||
|
||||
@@ -27,4 +32,59 @@ ControlMenu::ControlMenu(ctx context):context_(context) {
|
||||
apply_ctrl_ = false;
|
||||
}
|
||||
|
||||
void ControlMenu::update() {
|
||||
if (menu_state_ == MenuState::PLAY || menu_state_ == MenuState::EDIT) {
|
||||
if (!play_ctrl_ && !edit_ctrl_) {
|
||||
menu_state_ = MenuState::NONE;
|
||||
}
|
||||
}
|
||||
if (rand_ctrl_) {
|
||||
context_.world->randomize();
|
||||
rand_ctrl_ = false;
|
||||
}
|
||||
if (clear_ctrl_) {
|
||||
context_.world->clear();
|
||||
clear_ctrl_ = false;
|
||||
}
|
||||
if (edit_ctrl_ && play_ctrl_) {
|
||||
if (menu_state_ == MenuState::PLAY) {
|
||||
menu_state_ = MenuState::EDIT;
|
||||
play_ctrl_ = false;
|
||||
} else if (menu_state_ == MenuState::EDIT) {
|
||||
menu_state_ = MenuState::PLAY;
|
||||
edit_ctrl_ = false;
|
||||
}
|
||||
} else if (play_ctrl_) {
|
||||
menu_state_ = MenuState::PLAY;
|
||||
} else if (edit_ctrl_) {
|
||||
menu_state_ = MenuState::EDIT;
|
||||
}
|
||||
}
|
||||
|
||||
void ControlMenu::display() {
|
||||
bool control_panel_open = true;
|
||||
ImGuiWindowFlags control_panel_flags = ImGuiWindowFlags_AlwaysAutoResize |
|
||||
ImGuiWindowFlags_NoResize;
|
||||
ImVec2 menu_pos(3, 3);
|
||||
ImGui::SetNextWindowPos(menu_pos, ImGuiCond_Always);
|
||||
ImGui::Begin("Control Panel", &control_panel_open, control_panel_flags);
|
||||
ImGui::Checkbox("Play", &play_ctrl_);
|
||||
if (ImGui::Button("Step")) {
|
||||
step_ctrl_ = true;
|
||||
}
|
||||
if (ImGui::Button("Step Back")) {
|
||||
step_back_ctrl_ = true;
|
||||
}
|
||||
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((settings_window_) ? "Hide settings" : "Show settings")) {
|
||||
settings_window_ = !settings_window_;
|
||||
}
|
||||
ImGui::Text("Generation: %zu", context_.world->getCycle());
|
||||
ImGui::End();}
|
||||
|
||||
} // namespace gol
|
||||
|
||||
Reference in New Issue
Block a user