Compare commits

..

1 Commits

Author SHA1 Message Date
ceb83d5ab3 wip 2026-01-14 13:33:48 +01:00
9 changed files with 19 additions and 74 deletions

View File

@@ -76,7 +76,6 @@ set(SRC_CXX_FILES "./src/main.cpp"
"./src/selection.cpp" "./src/selection.cpp"
"./src/paterns_menu.cpp" "./src/paterns_menu.cpp"
"./src/patern_preview.cpp" "./src/patern_preview.cpp"
"./src/snapping.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"

View File

@@ -6,7 +6,7 @@ This is a simple Game Of Life editor written in C++ with raylib & dearImGUI
## How to compile the project ## How to compile the project
Ensure you have g++, cmake and the dependencies of raylib Ensure you have g++, cmake and the thendependencies of raylib
```shell ```shell
mkdir build mkdir build

View File

@@ -10,8 +10,6 @@
#include <memory> #include <memory>
#include <raylib.h>
#include <context.hpp> #include <context.hpp>
namespace gol { namespace gol {
@@ -26,7 +24,6 @@ public:
private: private:
bool is_started = false; bool is_started = false;
std::shared_ptr<ctx> context_; std::shared_ptr<ctx> context_;
Vector2 mouse_pos_ = {0, 0};
}; };
} // namespace gol } // namespace gol

View File

@@ -30,7 +30,6 @@ private:
std::shared_ptr<ctx> context_ = nullptr; std::shared_ptr<ctx> context_ = nullptr;
std::map<std::string,std::string> paterns_paths_list_; std::map<std::string,std::string> paterns_paths_list_;
std::vector<std::string> paterns_name_list_; std::vector<std::string> paterns_name_list_;
public:
int patern_width_ = 0; int patern_width_ = 0;
int patern_height_ = 0; int patern_height_ = 0;
std::vector<uint32_t> loaded_patern_; std::vector<uint32_t> loaded_patern_;

View File

@@ -1,5 +1,5 @@
/* /*
* File name: snapping.hpp * File name: selection.cpp
* Author: lejulien * Author: lejulien
* Date created: 01-01-1970 00:59:59 * Date created: 01-01-1970 00:59:59
// Date modified: 12-01-2026 21:30:10 // Date modified: 12-01-2026 21:30:10
@@ -13,6 +13,12 @@
#include <raylib.h> #include <raylib.h>
#include <cmath> #include <cmath>
Vector2 snapToGrid(Vector2 screen, int cell_size); Vector2 snapToGrid(Vector2 screen, int cell_size) {
return {static_cast<float>(round(screen.x / cell_size) * cell_size),
static_cast<float>(round(screen.y / cell_size) * cell_size)};
}
Vector2i screenToGrid(Vector2 screen, int cell_size); Vector2i screenToGrid(Vector2 screen, int cell_size) {
return {static_cast<int>(round(screen.x / cell_size)),
static_cast<int>(round(screen.y / cell_size))};
}

View File

@@ -25,7 +25,6 @@
#include <selection_menu.hpp> #include <selection_menu.hpp>
#include <selection.hpp> #include <selection.hpp>
#include <paterns_menu.hpp> #include <paterns_menu.hpp>
#include <patern_preview.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>();
@@ -108,7 +107,6 @@ int main(int ac, char **av) {
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); context->paterns_menu = std::make_shared<gol::PaternsMenu>(context);
context->patern_preview = std::make_shared<gol::PaternPreview>(context);
// Speed handling values // Speed handling values
float sim_speed = 1.0f; float sim_speed = 1.0f;
@@ -138,7 +136,6 @@ int main(int ac, char **av) {
// Selection behaviour // Selection behaviour
context->selection->update(); context->selection->update();
context->patern_preview->update();
context->selection_menu->update(); context->selection_menu->update();
context->settings_menu->update(); context->settings_menu->update();
@@ -157,7 +154,6 @@ int main(int ac, char **av) {
ClearBackground(BLACK); ClearBackground(BLACK);
context->render->display(context->world); context->render->display(context->world);
context->selection->display(); context->selection->display();
context->patern_preview->display();
// Start ImGui frame // Start ImGui frame
rlImGuiBegin(); rlImGuiBegin();
context->control_menu->display(); context->control_menu->display();

View File

@@ -6,60 +6,27 @@
* ------ * ------
*/ */
#include <imgui.h>
#include <raylib.h>
#include <rlImGui.h>
#include <patern_preview.hpp> #include <patern_preview.hpp>
#include <paterns_menu.hpp>
#include <settings_menu.hpp>
#include <snapping.hpp>
#include <world.hpp>
namespace gol { namespace gol {
PaternPreview::PaternPreview(std::shared_ptr<ctx> context) PaternPreview::PaternPreview(std::shared_ptr<ctx> context): context_(context) {}
: context_(context) {}
void PaternPreview::start() { is_started = true; } void PaternPreview::start() {
// TODO: load patern from pater menu
is_started = true;
}
void PaternPreview::update() { void PaternPreview::update() {
if (!is_started) return; if (!is_started) return;
mouse_pos_ = GetMousePosition(); // gather mousePos
if (ImGui::IsMouseClicked(1)) {
is_started = false;
return;
}
// if right click stop the preview // if right click stop the preview
// if left click, apply patern to current world // if left click, apply patern to current world
// mouse should pass through any present windows // mouse should pass through any present windows
} }
void PaternPreview::display() { void PaternPreview::display() {
if (!is_started) return;
std::cout << "preview display started " << std::endl;
auto cell_size = context_->settings_menu->getCellSize();
auto mouse_in_grid =
screenToGrid(mouse_pos_, context_->settings_menu->getCellSize());
bool is_unplacable =
((mouse_in_grid.x + context_->paterns_menu->patern_width_ >
context_->world->getWidth()) ||
(mouse_in_grid.y + context_->paterns_menu->patern_height_ >
context_->world->getHeight()));
std::cout << "mx:" << mouse_in_grid.x << ", my:" << mouse_in_grid.y
<< ", cs:" << context_->settings_menu->getCellSize() << std::endl;
for (int j = 0; j < context_->paterns_menu->patern_height_; j++) {
for (int i = 0; i < context_->paterns_menu->patern_width_; i++) {
auto cell =
context_->paterns_menu
->loaded_patern_[i + (j * context_->paterns_menu->patern_width_)];
if (cell) {
DrawRectangle((i + mouse_in_grid.x) * cell_size,
(j + mouse_in_grid.y) * cell_size, cell_size, cell_size,
(is_unplacable) ? RED : BLUE);
}
}
}
} }
}; // namespace gol };

View File

@@ -64,7 +64,7 @@ bool PaternsMenu::loadPatern(std::string &path) {
} }
} catch (std::exception &e) { } catch (std::exception &e) {
std::cerr << "Failure in loading patern : " << path << std::endl; std::cerr << "Failure in loading patern : " << path << std::endl;
return false; return 1;
} }
return true; return true;
} }

View File

@@ -1,19 +0,0 @@
/*
* File name: snapping.hpp
* Author: lejulien
* Date created: 01-01-1970 00:59:59
// Date modified: 12-01-2026 21:30:10
* ------
*/
#include <snapping.hpp>
Vector2 snapToGrid(Vector2 screen, int cell_size) {
return {static_cast<float>(round(screen.x / cell_size) * cell_size),
static_cast<float>(round(screen.y / cell_size) * cell_size)};
}
Vector2i screenToGrid(Vector2 screen, int cell_size) {
return {static_cast<int>(round(screen.x / cell_size)),
static_cast<int>(round(screen.y / cell_size))};
}