Skip to content

Commit

Permalink
[3.x] Fix AtlasTexture::draw_rect flipping for non-zero margin
Browse files Browse the repository at this point in the history
  • Loading branch information
kleonc committed Jul 2, 2024
1 parent 98e2483 commit 66d1ab0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
9 changes: 0 additions & 9 deletions scene/gui/texture_rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ void TextureRect::_notification(int p_what) {
} break;
}

Ref<AtlasTexture> p_atlas = texture;

if (p_atlas.is_valid() && region.has_no_area()) {
Size2 scale_size(size.width / texture->get_width(), size.height / texture->get_height());

offset.width += hflip ? p_atlas->get_margin().get_position().width * scale_size.width * 2 : 0;
offset.height += vflip ? p_atlas->get_margin().get_position().height * scale_size.height * 2 : 0;
}

size.width *= hflip ? -1.0f : 1.0f;
size.height *= vflip ? -1.0f : 1.0f;

Expand Down
17 changes: 5 additions & 12 deletions scene/resources/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,20 +1013,13 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
return;
}

Rect2 rc = region;

if (rc.size.width == 0) {
rc.size.width = atlas->get_width();
}
Rect2 src_rect = Rect2(0, 0, get_width(), get_height());

if (rc.size.height == 0) {
rc.size.height = atlas->get_height();
Rect2 dst;
Rect2 src;
if (get_rect_region(p_rect, src_rect, dst, src)) {
atlas->draw_rect_region(p_canvas_item, dst, src, p_modulate, p_transpose, p_normal_map);
}

Vector2 scale = p_rect.size / (region.size + margin.size);
Rect2 dr(p_rect.position + margin.position * scale, rc.size * scale);

atlas->draw_rect_region(p_canvas_item, dr, rc, p_modulate, p_transpose, p_normal_map);
}

Texture::RefineRectResult AtlasTexture::refine_rect_region(Rect2 &r_dst_rect, Rect2 &r_src_rect) const {
Expand Down

0 comments on commit 66d1ab0

Please sign in to comment.