Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tile resizing towards atlas boundary #76152

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions editor/plugins/tiles/tile_atlas_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,16 @@ Vector2i TileAtlasView::get_atlas_tile_coords_at_pos(const Vector2 p_pos, bool p
Vector2i separation = tile_set_atlas_source->get_separation();
Vector2i texture_region_size = tile_set_atlas_source->get_texture_region_size();

// Compute index in atlas
// Compute index in atlas.
Vector2 pos = p_pos - margins;
Vector2i ret = (pos / (texture_region_size + separation)).floor();

// Return invalid value (without clamp).
Rect2i rect = Rect2(Vector2i(), tile_set_atlas_source->get_atlas_grid_size());
if (!p_clamp && !rect.has_point(ret)) {
return TileSetSource::INVALID_ATLAS_COORDS;
}

// Clamp.
ret.x = CLAMP(ret.x, 0, rect.size.x - 1);
ret.y = CLAMP(ret.y, 0, rect.size.y - 1);
if (p_clamp) {
Vector2i size = tile_set_atlas_source->get_atlas_grid_size();
ret.x = CLAMP(ret.x, 0, size.x - 1);
ret.y = CLAMP(ret.y, 0, size.y - 1);
}

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/tiles/tile_set_atlas_source_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
if (mm.is_valid()) {
Vector2i start_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_mouse_pos, true);
Vector2i last_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_last_mouse_pos, true);
Vector2i new_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position(), true);
Vector2i new_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position());

Vector2i grid_size = tile_set_atlas_source->get_atlas_grid_size();

Expand Down