patern_preview/world: Place selection into the world
This commit is contained in:
@@ -30,24 +30,28 @@ void PaternPreview::update() {
|
||||
is_started = false;
|
||||
return;
|
||||
}
|
||||
// if right click stop the preview
|
||||
// if left click, apply patern to current world
|
||||
if (ImGui::IsMouseClicked(0) && !is_unplacable_) {
|
||||
auto selection_pos =
|
||||
screenToGrid(mouse_pos_, context_->settings_menu->getCellSize());
|
||||
Vector2i size = {context_->paterns_menu->patern_width_,
|
||||
context_->paterns_menu->patern_height_};
|
||||
context_->world->setSelection(selection_pos, size,
|
||||
context_->paterns_menu->loaded_patern_);
|
||||
is_started = false;
|
||||
}
|
||||
// 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 =
|
||||
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 =
|
||||
@@ -56,7 +60,7 @@ void PaternPreview::display() {
|
||||
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);
|
||||
(is_unplacable_) ? RED : BLUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user