Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AtlasTexture::draw_rect flipping for non-zero margin #93828

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions scene/gui/texture_rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include "texture_rect.h"

#include "scene/resources/atlas_texture.h"
#include "servers/rendering_server.h"

void TextureRect::_notification(int p_what) {
Expand Down Expand Up @@ -92,15 +91,6 @@ void TextureRect::_notification(int p_what) {
} break;
}

Ref<AtlasTexture> p_atlas = texture;

if (p_atlas.is_valid() && !region.has_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
23 changes: 8 additions & 15 deletions scene/resources/atlas_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,13 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
return;
}

Rect2 rc = region;
Rect2 src_rect = Rect2(0, 0, get_width(), get_height());

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

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

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, filter_clip);
}

void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, bool p_clip_uv) const {
Expand All @@ -188,9 +181,9 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons

Rect2 dr;
Rect2 src_c;
get_rect_region(p_rect, p_src_rect, dr, src_c);

atlas->draw_rect_region(p_canvas_item, dr, src_c, p_modulate, p_transpose, filter_clip);
if (get_rect_region(p_rect, p_src_rect, dr, src_c)) {
atlas->draw_rect_region(p_canvas_item, dr, src_c, p_modulate, p_transpose, filter_clip);
}
}

bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
Expand Down
Loading