Compare commits
1 Commits
lju/window
...
568c292ed4
| Author | SHA1 | Date | |
|---|---|---|---|
| 568c292ed4 |
@@ -8,17 +8,25 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <context.hpp>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace gol {
|
namespace gol {
|
||||||
|
|
||||||
class PaternsMenu {
|
class PaternsMenu {
|
||||||
public:
|
public:
|
||||||
PaternsMenu() = default;
|
PaternsMenu(std::shared_ptr<ctx>);
|
||||||
~PaternsMenu() = default;
|
~PaternsMenu() = default;
|
||||||
void Toogle();
|
void Toogle();
|
||||||
bool isOpen();
|
bool isOpen();
|
||||||
void display();
|
void display();
|
||||||
|
void refresh();
|
||||||
private:
|
private:
|
||||||
bool is_open_ = false;
|
bool is_open_ = false;
|
||||||
|
std::shared_ptr<ctx> context_ = nullptr;
|
||||||
|
std::vector<std::string> paterns_list_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gol
|
} // namespace gol
|
||||||
|
|||||||
@@ -106,7 +106,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>();
|
context->paterns_menu = std::make_shared<gol::PaternsMenu>(context);
|
||||||
|
|
||||||
// Speed handling values
|
// Speed handling values
|
||||||
float sim_speed = 1.0f;
|
float sim_speed = 1.0f;
|
||||||
@@ -115,6 +115,7 @@ int main(int ac, char **av) {
|
|||||||
|
|
||||||
// Setups
|
// Setups
|
||||||
context->rules->setup(context->world);
|
context->rules->setup(context->world);
|
||||||
|
context->paterns_menu->refresh();
|
||||||
// Diplay generations
|
// Diplay generations
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
// Frames shinenigans
|
// Frames shinenigans
|
||||||
|
|||||||
@@ -8,12 +8,16 @@
|
|||||||
|
|
||||||
#include <paterns_menu.hpp>
|
#include <paterns_menu.hpp>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <rlImGui.h>
|
#include <rlImGui.h>
|
||||||
|
|
||||||
namespace gol {
|
namespace gol {
|
||||||
|
|
||||||
|
PaternsMenu::PaternsMenu(std::shared_ptr<ctx> ctx): context_(ctx) {}
|
||||||
|
|
||||||
void PaternsMenu::Toogle() {
|
void PaternsMenu::Toogle() {
|
||||||
is_open_ = !is_open_;
|
is_open_ = !is_open_;
|
||||||
}
|
}
|
||||||
@@ -22,12 +26,27 @@ bool PaternsMenu::isOpen() {
|
|||||||
return is_open_;
|
return is_open_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaternsMenu::refresh() {
|
||||||
|
paterns_list_.clear();
|
||||||
|
auto paterns_path = context_->program_dir / "paterns";
|
||||||
|
if (std::filesystem::exists(paterns_path) && std::filesystem::is_directory(paterns_path)) {
|
||||||
|
for (const auto& entry : std::filesystem::directory_iterator(paterns_path)) {
|
||||||
|
paterns_list_.push_back(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PaternsMenu::display() {
|
void PaternsMenu::display() {
|
||||||
if (is_open_) {
|
if (is_open_) {
|
||||||
ImGuiWindowFlags paterns_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize;
|
ImGuiWindowFlags paterns_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize;
|
||||||
ImGui::SetNextWindowSize(ImVec2(150, 200), ImGuiCond_Always);
|
ImGui::SetNextWindowSize(ImVec2(150, 200), ImGuiCond_Always);
|
||||||
ImGui::Begin("paterns", &is_open_, paterns_flags);
|
ImGui::Begin("paterns", &is_open_, paterns_flags);
|
||||||
ImGui::Button("refresh");
|
if (ImGui::Button("refresh")) {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
for (auto patern_name: paterns_list_) {
|
||||||
|
ImGui::Button(patern_name.c_str());
|
||||||
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user