wippatern_preview: Adding patern preview

This adds a preview of the patern placement, checking out of bound
This commit is contained in:
2026-01-14 13:33:48 +01:00
parent 6f5ec1d811
commit 3c37d9aca4
9 changed files with 132 additions and 13 deletions

View File

@@ -22,6 +22,7 @@ class SelectionMenu;
class ControlMenu;
class Selection;
class PaternsMenu;
class PaternPreview;
typedef struct ctx {
std::shared_ptr<World> world = nullptr;
@@ -32,6 +33,7 @@ typedef struct ctx {
std::shared_ptr<ControlMenu> control_menu = nullptr;
std::shared_ptr<Selection> selection = nullptr;
std::shared_ptr<PaternsMenu> paterns_menu = nullptr;
std::shared_ptr<PaternPreview> patern_preview = nullptr;
nlohmann::json config_json;
std::filesystem::path program_dir;
} ctx;

View File

@@ -0,0 +1,32 @@
/*
* File name: patern_preview.hpp
* Author: lejulien
* Date created: 01-01-1970 00:59:59
// Date modified: 12-01-2026 21:30:10
* ------
*/
#pragma once
#include <memory>
#include <raylib.h>
#include <context.hpp>
namespace gol {
class PaternPreview {
public:
PaternPreview(std::shared_ptr<ctx>);
~PaternPreview() = default;
void update();
void display();
void start();
private:
bool is_started = false;
std::shared_ptr<ctx> context_;
Vector2 mouse_pos_ = {0, 0};
};
} // namespace gol

View File

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

View File

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