summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuri Sizov <yuris@humnom.net>2023-07-26 18:40:38 +0200
committerYuri Sizov <yuris@humnom.net>2023-07-26 18:40:38 +0200
commit7fe88c771017cbd1cf17701ce5d149dce6f111f2 (patch)
tree5c7ac152791080af9a0bb1fa660b53d9b94425bc
parentd894a2ff574cfbb32cc9bce72f72b6492c254038 (diff)
parent965847b6e945e15c1ffb43ab55ba98b0f4b08da0 (diff)
downloadredot-engine-7fe88c771017cbd1cf17701ce5d149dce6f111f2.tar.gz
Merge pull request #79899 from KoBeWi/snapped_in_half
Improve atlas tile size dragging
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.cpp12
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.h1
2 files changed, 11 insertions, 2 deletions
diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
index e0df73596e..eaec4cebb3 100644
--- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
+++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
@@ -1141,24 +1141,26 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
}
} else if (drag_type >= DRAG_TYPE_RESIZE_TOP_LEFT && drag_type <= DRAG_TYPE_RESIZE_LEFT) {
// Resizing a tile.
- new_base_tiles_coords = new_base_tiles_coords.max(Vector2i(-1, -1)).min(grid_size);
-
Rect2i old_rect = Rect2i(drag_current_tile, tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile));
Rect2i new_rect = old_rect;
if (drag_type == DRAG_TYPE_RESIZE_LEFT || drag_type == DRAG_TYPE_RESIZE_TOP_LEFT || drag_type == DRAG_TYPE_RESIZE_BOTTOM_LEFT) {
+ new_base_tiles_coords = _get_drag_offset_tile_coords(Vector2i(-1, 0));
new_rect.position.x = MIN(new_base_tiles_coords.x + 1, old_rect.get_end().x - 1);
new_rect.size.x = old_rect.get_end().x - new_rect.position.x;
}
if (drag_type == DRAG_TYPE_RESIZE_TOP || drag_type == DRAG_TYPE_RESIZE_TOP_LEFT || drag_type == DRAG_TYPE_RESIZE_TOP_RIGHT) {
+ new_base_tiles_coords = _get_drag_offset_tile_coords(Vector2i(0, -1));
new_rect.position.y = MIN(new_base_tiles_coords.y + 1, old_rect.get_end().y - 1);
new_rect.size.y = old_rect.get_end().y - new_rect.position.y;
}
if (drag_type == DRAG_TYPE_RESIZE_RIGHT || drag_type == DRAG_TYPE_RESIZE_TOP_RIGHT || drag_type == DRAG_TYPE_RESIZE_BOTTOM_RIGHT) {
+ new_base_tiles_coords = _get_drag_offset_tile_coords(Vector2i(1, 0));
new_rect.set_end(Vector2i(MAX(new_base_tiles_coords.x, old_rect.position.x + 1), new_rect.get_end().y));
}
if (drag_type == DRAG_TYPE_RESIZE_BOTTOM || drag_type == DRAG_TYPE_RESIZE_BOTTOM_LEFT || drag_type == DRAG_TYPE_RESIZE_BOTTOM_RIGHT) {
+ new_base_tiles_coords = _get_drag_offset_tile_coords(Vector2i(0, 1));
new_rect.set_end(Vector2i(new_rect.get_end().x, MAX(new_base_tiles_coords.y, old_rect.position.y + 1)));
}
@@ -2173,6 +2175,12 @@ void TileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo
#undef ADD_UNDO
}
+Vector2i TileSetAtlasSourceEditor::_get_drag_offset_tile_coords(const Vector2i &p_offset) const {
+ Vector2i half_tile_size = tile_set->get_tile_size() / 2;
+ Vector2i new_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position() + half_tile_size * p_offset);
+ return new_base_tiles_coords.max(Vector2i(-1, -1)).min(tile_set_atlas_source->get_atlas_grid_size());
+}
+
void TileSetAtlasSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource *p_tile_set_atlas_source, int p_source_id) {
ERR_FAIL_COND(!p_tile_set.is_valid());
ERR_FAIL_COND(!p_tile_set_atlas_source);
diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.h b/editor/plugins/tiles/tile_set_atlas_source_editor.h
index 6bbede520f..d9584c0955 100644
--- a/editor/plugins/tiles/tile_set_atlas_source_editor.h
+++ b/editor/plugins/tiles/tile_set_atlas_source_editor.h
@@ -270,6 +270,7 @@ private:
void _auto_create_tiles();
void _auto_remove_tiles();
AcceptDialog *confirm_auto_create_tiles = nullptr;
+ Vector2i _get_drag_offset_tile_coords(const Vector2i &p_offset) const;
void _tile_set_changed();
void _tile_proxy_object_changed(String p_what);