From 42eb92d19afb489a71d8c87b1230946f80c99366 Mon Sep 17 00:00:00 2001 From: Dashcell Date: Thu, 17 Sep 2020 20:03:52 -0300 Subject: [PATCH] Fixes the resize of tile shapes when a vertex is outside of the tilesheet. Fix #34970 (cherry picked from commit 5355169d3c3e911d0f1d3691858bf78f6195947f) --- editor/plugins/tile_set_editor_plugin.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 8440e50edee..75a2c26a0d3 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -3095,6 +3095,7 @@ Vector2 TileSetEditor::snap_point(const Vector2 &point) { anchor += tileset->tile_get_region(get_current_tile()).position; anchor += WORKSPACE_MARGIN; Rect2 region(anchor, tile_size); + Rect2 tile_region(tileset->tile_get_region(get_current_tile()).position + WORKSPACE_MARGIN, tileset->tile_get_region(get_current_tile()).size); if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) { region.position = tileset->tile_get_region(get_current_tile()).position + WORKSPACE_MARGIN; region.size = tileset->tile_get_region(get_current_tile()).size; @@ -3104,6 +3105,7 @@ Vector2 TileSetEditor::snap_point(const Vector2 &point) { p.x = Math::snap_scalar_separation(snap_offset.x, snap_step.x, p.x, snap_separation.x); p.y = Math::snap_scalar_separation(snap_offset.y, snap_step.y, p.y, snap_separation.y); } + if (tools[SHAPE_KEEP_INSIDE_TILE]->is_pressed()) { if (p.x < region.position.x) p.x = region.position.x; @@ -3114,6 +3116,20 @@ Vector2 TileSetEditor::snap_point(const Vector2 &point) { if (p.y > region.position.y + region.size.y) p.y = region.position.y + region.size.y; } + + if (p.x < tile_region.position.x) { + p.x = tile_region.position.x; + } + if (p.y < tile_region.position.y) { + p.y = tile_region.position.y; + } + if (p.x > (tile_region.position.x + tile_region.size.x)) { + p.x = (tile_region.position.x + tile_region.size.x); + } + if (p.y > (tile_region.position.y + tile_region.size.y)) { + p.y = (tile_region.position.y + tile_region.size.y); + } + return p; }