settings_menu: Create a dedicated class for the settings
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* File name: context.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 20:31:50
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
* ------
|
||||
*/
|
||||
|
||||
@@ -14,12 +14,16 @@
|
||||
|
||||
class World;
|
||||
class Rules;
|
||||
class Render;
|
||||
|
||||
namespace gol {
|
||||
class SettingsMenu;
|
||||
|
||||
typedef struct ctx {
|
||||
std::shared_ptr<World> world = nullptr;
|
||||
std::shared_ptr<Rules> rules = nullptr;
|
||||
std::shared_ptr<Render> render = nullptr;
|
||||
std::shared_ptr<SettingsMenu> settings_menu = nullptr;
|
||||
nlohmann::json config_json;
|
||||
} ctx;
|
||||
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
* File name: control_menu.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 10-01-2026 22:00:33
|
||||
// Date modified: 10-01-2026 22:45:10
|
||||
// Date modified: 12-01-2026 22:18:26
|
||||
* ------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <context.hpp>
|
||||
#include <types.hpp>
|
||||
|
||||
@@ -15,28 +17,21 @@ namespace gol {
|
||||
|
||||
class ControlMenu {
|
||||
public:
|
||||
ControlMenu(ctx context);
|
||||
ControlMenu(std::shared_ptr<ctx> context);
|
||||
~ControlMenu() = default;
|
||||
void update();
|
||||
void display();
|
||||
private:
|
||||
ctx context_;
|
||||
std::shared_ptr<ctx> context_;
|
||||
public: // Keep those public for easy access
|
||||
MenuState menu_state_ = MenuState::NONE;
|
||||
int fps_ctrl_ = false;
|
||||
int cell_size_ctrl_ = false;
|
||||
bool play_ctrl_ = true;
|
||||
bool step_ctrl_ = false;
|
||||
bool step_back_ctrl_ = false;
|
||||
bool rand_ctrl_ = false;
|
||||
bool edit_ctrl_ = false;
|
||||
bool clear_ctrl_ = false;
|
||||
bool settings_window_ = false;
|
||||
bool paterns_ctrl_ = false;
|
||||
int width_ctrl_ = false;
|
||||
int height_ctrl_ = false;
|
||||
bool dark_theme_ctrl_ = false;
|
||||
bool apply_ctrl_ = false;
|
||||
};
|
||||
|
||||
} // namespace gol
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
* File name: render.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 10-01-2026 21:54:12
|
||||
// Date modified: 10-01-2026 22:00:37
|
||||
// Date modified: 12-01-2026 21:56:03
|
||||
* ------
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "world.hpp"
|
||||
|
||||
#pragma once
|
||||
@@ -16,7 +18,7 @@ public:
|
||||
Render(int cell_size);
|
||||
|
||||
// Member function
|
||||
void display(World *world);
|
||||
void display(std::shared_ptr<World> world);
|
||||
void updateCellSize(int new_size);
|
||||
|
||||
private:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* File name: rules.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 09-01-2026 23:59:55
|
||||
* Date modified: 10-01-2026 21:49:44
|
||||
// Date modified: 12-01-2026 21:58:17
|
||||
* ------
|
||||
*/
|
||||
|
||||
@@ -19,12 +19,12 @@ private:
|
||||
|
||||
public:
|
||||
Rules();
|
||||
void setup(World *world);
|
||||
void newWorld(World *world);
|
||||
void setup(std::shared_ptr<World> world);
|
||||
void newWorld(std::shared_ptr<World> world);
|
||||
void update();
|
||||
|
||||
private:
|
||||
World *_world;
|
||||
std::shared_ptr<World> _world;
|
||||
std::vector<bool> _buffer;
|
||||
int _width;
|
||||
int _height;
|
||||
|
||||
46
includes/settings_menu.hpp
Normal file
46
includes/settings_menu.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* File name: settings_menu.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 22:16:29
|
||||
* ------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <context.hpp>
|
||||
|
||||
namespace gol {
|
||||
|
||||
class SettingsMenu {
|
||||
public:
|
||||
SettingsMenu(std::shared_ptr<ctx> context);
|
||||
~SettingsMenu() = default;
|
||||
void update();
|
||||
void display();
|
||||
bool isOpen();
|
||||
void Toogle();
|
||||
// Getter/Setters
|
||||
int getFPS();
|
||||
void setFPS(int);
|
||||
int getCellSize();
|
||||
void setCellSize(int);
|
||||
int getWidth();
|
||||
void setWidth(int);
|
||||
int getHeight();
|
||||
void setHeight(int);
|
||||
private:
|
||||
std::shared_ptr<ctx> context_ = nullptr;
|
||||
int fps_ctrl_ = false;
|
||||
int cell_size_ctrl_ = false;
|
||||
bool settings_window_ = false;
|
||||
int width_ctrl_ = false;
|
||||
int height_ctrl_ = false;
|
||||
bool dark_theme_ctrl_ = false;
|
||||
bool apply_ctrl_ = false;
|
||||
};
|
||||
|
||||
|
||||
} // namespace gol
|
||||
@@ -2,14 +2,14 @@
|
||||
* File name: world.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 09-01-2026 23:59:55
|
||||
* Date modified: 10-01-2026 21:49:31
|
||||
// Date modified: 12-01-2026 22:20:26
|
||||
* ------
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
class World {
|
||||
|
||||
public:
|
||||
World(gol::ctx &ctx);
|
||||
World(std::shared_ptr<gol::ctx> ctx);
|
||||
~World();
|
||||
|
||||
std::vector<bool> *getWorldData();
|
||||
|
||||
Reference in New Issue
Block a user