@@ -968,33 +968,12 @@ void TileMapLayerEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p
968968 continue ;
969969 }
970970
971- // Compute the offset
972971 Rect2i source_rect = atlas_source->get_tile_texture_region (E.value .get_atlas_coords ());
973- Vector2i tile_offset = tile_data->get_texture_origin ();
974972
975973 // Compute the destination rectangle in the CanvasItem.
976974 Rect2 dest_rect;
977- dest_rect.size = source_rect.size ;
978-
979- bool transpose = tile_data->get_transpose () ^ bool (E.value .alternative_tile & TileSetAtlasSource::TRANSFORM_TRANSPOSE);
980- if (transpose) {
981- dest_rect.position = (tile_set->map_to_local (E.key ) - Vector2 (dest_rect.size .y , dest_rect.size .x ) / 2 );
982- SWAP (tile_offset.x , tile_offset.y );
983- } else {
984- dest_rect.position = (tile_set->map_to_local (E.key ) - dest_rect.size / 2 );
985- }
986-
987- if (tile_data->get_flip_h () ^ bool (E.value .alternative_tile & TileSetAtlasSource::TRANSFORM_FLIP_H)) {
988- dest_rect.size .x = -dest_rect.size .x ;
989- tile_offset.x = -tile_offset.x ;
990- }
991-
992- if (tile_data->get_flip_v () ^ bool (E.value .alternative_tile & TileSetAtlasSource::TRANSFORM_FLIP_V)) {
993- dest_rect.size .y = -dest_rect.size .y ;
994- tile_offset.y = -tile_offset.y ;
995- }
996-
997- dest_rect.position -= tile_offset;
975+ bool transpose;
976+ TileMapLayer::compute_transformed_tile_dest_rect (dest_rect, transpose, tile_set->map_to_local (E.key ), source_rect.size , tile_data, E.value .alternative_tile );
998977
999978 // Get the tile modulation.
1000979 Color modulate = tile_data->get_modulate () * edited_layer->get_modulate_in_tree () * edited_layer->get_self_modulate ();
@@ -1501,14 +1480,13 @@ void TileMapLayerEditorTilesPlugin::_stop_dragging() {
15011480 drag_type = DRAG_TYPE_NONE;
15021481}
15031482
1504- void TileMapLayerEditorTilesPlugin::_apply_transform (int p_type) {
1483+ void TileMapLayerEditorTilesPlugin::_apply_transform (TileTransformType p_type) {
15051484 if (selection_pattern.is_null () || selection_pattern->is_empty ()) {
15061485 return ;
15071486 }
15081487
15091488 Ref<TileMapPattern> transformed_pattern;
15101489 transformed_pattern.instantiate ();
1511- bool keep_shape = selection_pattern->get_size () == Vector2i (1 , 1 );
15121490
15131491 Vector2i size = selection_pattern->get_size ();
15141492 for (int y = 0 ; y < size.y ; y++) {
@@ -1520,9 +1498,7 @@ void TileMapLayerEditorTilesPlugin::_apply_transform(int p_type) {
15201498
15211499 Vector2i dst_coords;
15221500
1523- if (keep_shape) {
1524- dst_coords = src_coords;
1525- } else if (p_type == TRANSFORM_ROTATE_LEFT) {
1501+ if (p_type == TRANSFORM_ROTATE_LEFT) {
15261502 dst_coords = Vector2i (y, size.x - x - 1 );
15271503 } else if (p_type == TRANSFORM_ROTATE_RIGHT) {
15281504 dst_coords = Vector2i (size.y - y - 1 , x);
@@ -1541,46 +1517,28 @@ void TileMapLayerEditorTilesPlugin::_apply_transform(int p_type) {
15411517 CanvasItemEditor::get_singleton ()->update_viewport ();
15421518}
15431519
1544- int TileMapLayerEditorTilesPlugin::_get_transformed_alternative (int p_alternative_id, int p_transform) {
1520+ int TileMapLayerEditorTilesPlugin::_get_transformed_alternative (int p_alternative_id, TileTransformType p_transform) {
15451521 bool transform_flip_h = p_alternative_id & TileSetAtlasSource::TRANSFORM_FLIP_H;
15461522 bool transform_flip_v = p_alternative_id & TileSetAtlasSource::TRANSFORM_FLIP_V;
15471523 bool transform_transpose = p_alternative_id & TileSetAtlasSource::TRANSFORM_TRANSPOSE;
15481524
15491525 switch (p_transform) {
1550- case TRANSFORM_ROTATE_LEFT:
1551- case TRANSFORM_ROTATE_RIGHT: {
1552- // A matrix with every possible flip/transpose combination, sorted by what comes next when you rotate.
1553- const LocalVector<bool > rotation_matrix = {
1554- // NOLINTBEGIN(modernize-use-bool-literals)
1555- 0 , 0 , 0 ,
1556- 0 , 1 , 1 ,
1557- 1 , 1 , 0 ,
1558- 1 , 0 , 1 ,
1559- 1 , 0 , 0 ,
1560- 0 , 0 , 1 ,
1561- 0 , 1 , 0 ,
1562- 1 , 1 , 1
1563- // NOLINTEND(modernize-use-bool-literals)
1564- };
1565-
1566- for (int i = 0 ; i < 8 ; i++) {
1567- if (transform_flip_h == rotation_matrix[i * 3 ] && transform_flip_v == rotation_matrix[i * 3 + 1 ] && transform_transpose == rotation_matrix[i * 3 + 2 ]) {
1568- if (p_transform == TRANSFORM_ROTATE_LEFT) {
1569- i = i / 4 * 4 + (i + 1 ) % 4 ;
1570- } else {
1571- i = i / 4 * 4 + Math::posmod (i - 1 , 4 );
1572- }
1573- transform_flip_h = rotation_matrix[i * 3 ];
1574- transform_flip_v = rotation_matrix[i * 3 + 1 ];
1575- transform_transpose = rotation_matrix[i * 3 + 2 ];
1576- break ;
1577- }
1578- }
1526+ case TRANSFORM_ROTATE_LEFT: { // (h, v, t) -> (v, !h, !t)
1527+ bool negated_flip_h = !transform_flip_h;
1528+ transform_flip_h = transform_flip_v;
1529+ transform_flip_v = negated_flip_h;
1530+ transform_transpose = !transform_transpose;
1531+ } break ;
1532+ case TRANSFORM_ROTATE_RIGHT: { // (h, v, t) -> (!v, h, !t)
1533+ bool negated_flip_v = !transform_flip_v;
1534+ transform_flip_v = transform_flip_h;
1535+ transform_flip_h = negated_flip_v;
1536+ transform_transpose = !transform_transpose;
15791537 } break ;
1580- case TRANSFORM_FLIP_H: {
1538+ case TRANSFORM_FLIP_H: { // (h, v, t) -> (!h, v, t)
15811539 transform_flip_h = !transform_flip_h;
15821540 } break ;
1583- case TRANSFORM_FLIP_V: {
1541+ case TRANSFORM_FLIP_V: { // (h, v, t) -> (h, !v, t)
15841542 transform_flip_v = !transform_flip_v;
15851543 } break ;
15861544 }
0 commit comments