/* * File name: settings_menu.cpp * Author: lejulien * Date created: 01-01-1970 00:59:59 // Date modified: 12-01-2026 22:21:49 * ------ */ #include #include #include #include #include #include #include #include #include namespace gol { SettingsMenu::SettingsMenu(std::shared_ptr context): context_(context) { fps_ctrl_ = context->config_json["fps"].get(); cell_size_ctrl_ = context->config_json["cell_size"].get(); settings_window_ = false; width_ctrl_ = context->config_json["screen_width"].get(); height_ctrl_ = context->config_json["screen_height"].get(); dark_theme_ctrl_ = context->config_json["dark_theme"].get(); apply_ctrl_ = false; } void SettingsMenu::update() { if (apply_ctrl_) { bool resize_needed = false; context_->config_json["fps"] = fps_ctrl_; if (context_->config_json["screen_width"].get() != width_ctrl_ || context_->config_json["screen_height"].get() != height_ctrl_) { context_->config_json["screen_width"] = width_ctrl_; context_->config_json["screen_height"] = height_ctrl_; rlImGuiShutdown(); SetWindowSize(width_ctrl_, height_ctrl_); rlImGuiSetup(dark_theme_ctrl_); resize_needed = true; } if (cell_size_ctrl_ != context_->config_json["cell_size"].get() || resize_needed) { context_->world->resize(context_->config_json["screen_width"].get() / cell_size_ctrl_, context_->config_json["screen_height"].get() / cell_size_ctrl_); context_->render->updateCellSize(cell_size_ctrl_); context_->rules->newWorld(context_->world); context_->config_json["cell_size"] = cell_size_ctrl_; } if (dark_theme_ctrl_ != context_->config_json["dark_theme"]) { rlImGuiShutdown(); rlImGuiSetup(dark_theme_ctrl_); context_->config_json["dark_theme"] = dark_theme_ctrl_; } apply_ctrl_ = false; settings_window_ = false; } } void SettingsMenu::display() { if (settings_window_) { ImGuiWindowFlags settings_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize; ImGui::Begin("Settings", &settings_window_, settings_flags); ImGui::SliderInt("Window Width", &width_ctrl_, 800, 1920); ImGui::SliderInt("Window Height", &height_ctrl_, 600, 1200); ImGui::SliderInt("FPS", &fps_ctrl_, 0, 30); ImGui::SliderInt("Cell Size", &cell_size_ctrl_, 4, 100); ImGui::Checkbox("Dark Theme", &dark_theme_ctrl_); if (ImGui::Button("Save & Apply")) { apply_ctrl_ = true; } ImGui::End(); } } bool SettingsMenu::isOpen() { return settings_window_; } void SettingsMenu::Toogle() { settings_window_ = !settings_window_; } // Getters/Setters int SettingsMenu::getFPS() { return fps_ctrl_; } void SettingsMenu::setFPS(int new_fps) { fps_ctrl_ = new_fps; } int SettingsMenu::getCellSize() { return cell_size_ctrl_; } void SettingsMenu::setCellSize(int new_cell_size) { cell_size_ctrl_ = new_cell_size; } int SettingsMenu::getWidth() { return width_ctrl_; } void SettingsMenu::setWidth(int new_width) { width_ctrl_ = new_width; } int SettingsMenu::getHeight() { return height_ctrl_; } void SettingsMenu::setHeight(int new_height) { height_ctrl_ = new_height; } } // namespace gol