Fix TileAtlasView bounds checks for transposed tiles
This commit is contained in:
parent
c73ac74c4a
commit
6895f6f8cc
@ -372,7 +372,7 @@ void TileAtlasView::_draw_base_tiles_shape_grid() {
|
||||
for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) {
|
||||
Vector2i tile_id = tile_set_atlas_source->get_tile_id(i);
|
||||
Vector2 in_tile_base_offset = tile_set_atlas_source->get_tile_data(tile_id, 0)->get_texture_origin();
|
||||
if (tile_set_atlas_source->is_position_in_tile_texture_region(tile_id, 0, -tile_shape_size / 2) && tile_set_atlas_source->is_position_in_tile_texture_region(tile_id, 0, tile_shape_size / 2 - Vector2(1, 1))) {
|
||||
if (tile_set_atlas_source->is_rect_in_tile_texture_region(tile_id, 0, Rect2(Vector2(-tile_shape_size) / 2, tile_shape_size))) {
|
||||
for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(tile_id); frame++) {
|
||||
Color color = grid_color;
|
||||
if (frame > 0) {
|
||||
|
@ -1385,10 +1385,8 @@ void TileDataTextureOriginEditor::draw_over_tile(CanvasItem *p_canvas_item, Tran
|
||||
|
||||
TileSetSource *source = *(tile_set->get_source(p_cell.source_id));
|
||||
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
|
||||
if (atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, -tile_set_tile_size / 2) && atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, tile_set_tile_size / 2 - Vector2(1, 1))) {
|
||||
Transform2D tile_xform;
|
||||
tile_xform.set_scale(tile_set_tile_size);
|
||||
tile_set->draw_tile_shape(p_canvas_item, p_transform * tile_xform, color);
|
||||
if (atlas_source->is_rect_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, Rect2(Vector2(-tile_set_tile_size) / 2, tile_set_tile_size))) {
|
||||
tile_set->draw_tile_shape(p_canvas_item, p_transform.scaled_local(tile_set_tile_size), color);
|
||||
}
|
||||
|
||||
if (atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, Vector2())) {
|
||||
|
@ -5275,11 +5275,26 @@ Rect2i TileSetAtlasSource::get_tile_texture_region(Vector2i p_atlas_coords, int
|
||||
|
||||
bool TileSetAtlasSource::is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const {
|
||||
Size2 size = get_tile_texture_region(p_atlas_coords).size;
|
||||
Rect2 rect = Rect2(-size / 2 - get_tile_data(p_atlas_coords, p_alternative_tile)->get_texture_origin(), size);
|
||||
TileData *tile_data = get_tile_data(p_atlas_coords, p_alternative_tile);
|
||||
if (tile_data->get_transpose()) {
|
||||
size = Size2(size.y, size.x);
|
||||
}
|
||||
Rect2 rect = Rect2(-size / 2 - tile_data->get_texture_origin(), size);
|
||||
|
||||
return rect.has_point(p_position);
|
||||
}
|
||||
|
||||
bool TileSetAtlasSource::is_rect_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Rect2 p_rect) const {
|
||||
Size2 size = get_tile_texture_region(p_atlas_coords).size;
|
||||
TileData *tile_data = get_tile_data(p_atlas_coords, p_alternative_tile);
|
||||
if (tile_data->get_transpose()) {
|
||||
size = Size2(size.y, size.x);
|
||||
}
|
||||
Rect2 rect = Rect2(-size / 2 - tile_data->get_texture_origin(), size);
|
||||
|
||||
return p_rect.intersection(rect) == p_rect;
|
||||
}
|
||||
|
||||
int TileSetAtlasSource::alternative_no_transform(int p_alternative_id) {
|
||||
return p_alternative_id & ~(TRANSFORM_FLIP_H | TRANSFORM_FLIP_V | TRANSFORM_TRANSPOSE);
|
||||
}
|
||||
|
@ -763,6 +763,7 @@ public:
|
||||
Vector2i get_atlas_grid_size() const;
|
||||
Rect2i get_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const;
|
||||
bool is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const;
|
||||
bool is_rect_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Rect2 p_rect) const;
|
||||
|
||||
static int alternative_no_transform(int p_alternative_id);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user