Skip to content

Commit 88b2953

Browse files
committed
Fix AtlasTexture::draw_rect flipping for non-zero margin
1 parent 446e7a7 commit 88b2953

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

scene/gui/texture_rect.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include "texture_rect.h"
3232

33-
#include "scene/resources/atlas_texture.h"
3433
#include "servers/rendering_server.h"
3534

3635
void TextureRect::_notification(int p_what) {
@@ -92,15 +91,6 @@ void TextureRect::_notification(int p_what) {
9291
} break;
9392
}
9493

95-
Ref<AtlasTexture> p_atlas = texture;
96-
97-
if (p_atlas.is_valid() && !region.has_area()) {
98-
Size2 scale_size(size.width / texture->get_width(), size.height / texture->get_height());
99-
100-
offset.width += hflip ? p_atlas->get_margin().get_position().width * scale_size.width * 2 : 0;
101-
offset.height += vflip ? p_atlas->get_margin().get_position().height * scale_size.height * 2 : 0;
102-
}
103-
10494
size.width *= hflip ? -1.0f : 1.0f;
10595
size.height *= vflip ? -1.0f : 1.0f;
10696

scene/resources/atlas_texture.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,13 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
164164
return;
165165
}
166166

167-
Rect2 rc = region;
167+
Rect2 src_rect = Rect2(0, 0, get_width(), get_height());
168168

169-
if (rc.size.width == 0) {
170-
rc.size.width = atlas->get_width();
171-
}
172-
173-
if (rc.size.height == 0) {
174-
rc.size.height = atlas->get_height();
169+
Rect2 dr;
170+
Rect2 src_c;
171+
if (get_rect_region(p_rect, src_rect, dr, src_c)) {
172+
atlas->draw_rect_region(p_canvas_item, dr, src_c, p_modulate, p_transpose, filter_clip);
175173
}
176-
177-
Vector2 scale = p_rect.size / (region.size + margin.size);
178-
Rect2 dr(p_rect.position + margin.position * scale, rc.size * scale);
179-
180-
atlas->draw_rect_region(p_canvas_item, dr, rc, p_modulate, p_transpose, filter_clip);
181174
}
182175

183176
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 {
@@ -188,9 +181,9 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons
188181

189182
Rect2 dr;
190183
Rect2 src_c;
191-
get_rect_region(p_rect, p_src_rect, dr, src_c);
192-
193-
atlas->draw_rect_region(p_canvas_item, dr, src_c, p_modulate, p_transpose, filter_clip);
184+
if (get_rect_region(p_rect, p_src_rect, dr, src_c)) {
185+
atlas->draw_rect_region(p_canvas_item, dr, src_c, p_modulate, p_transpose, filter_clip);
186+
}
194187
}
195188

196189
bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {

0 commit comments

Comments
 (0)