patern_preview: Adding patern preview
This adds a preview of the patern placement, checking out of bound
This commit is contained in:
65
src/patern_preview.cpp
Normal file
65
src/patern_preview.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* File name: patern_preview.cpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
* ------
|
||||
*/
|
||||
|
||||
#include <imgui.h>
|
||||
#include <raylib.h>
|
||||
#include <rlImGui.h>
|
||||
|
||||
#include <patern_preview.hpp>
|
||||
#include <paterns_menu.hpp>
|
||||
#include <settings_menu.hpp>
|
||||
#include <snapping.hpp>
|
||||
#include <world.hpp>
|
||||
|
||||
namespace gol {
|
||||
|
||||
PaternPreview::PaternPreview(std::shared_ptr<ctx> context)
|
||||
: context_(context) {}
|
||||
|
||||
void PaternPreview::start() { is_started = true; }
|
||||
|
||||
void PaternPreview::update() {
|
||||
if (!is_started) return;
|
||||
mouse_pos_ = GetMousePosition();
|
||||
if (ImGui::IsMouseClicked(1)) {
|
||||
is_started = false;
|
||||
return;
|
||||
}
|
||||
// if right click stop the preview
|
||||
// if left click, apply patern to current world
|
||||
// mouse should pass through any present windows
|
||||
}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user