Преглед изворни кода

Merge pull request #93857 from kleonc/atlas-texture-fix-draw-rect-flipping-3x

[3.x] Fix `AtlasTexture::draw_rect` flipping for non-zero margin
lawnjelly пре 1 година
родитељ
комит
d500046684
2 измењених фајлова са 5 додато и 21 уклоњено
  1. 0 9
      scene/gui/texture_rect.cpp
  2. 5 12
      scene/resources/texture.cpp

+ 0 - 9
scene/gui/texture_rect.cpp

@@ -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;
 

+ 5 - 12
scene/resources/texture.cpp

@@ -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 {