feat: updated engine

This commit is contained in:
Sara Gerretsen 2026-07-10 17:04:34 +02:00
parent cbe99774ff
commit f4cf6b3999
6607 changed files with 910135 additions and 430025 deletions

View file

@ -30,6 +30,11 @@
#include "texture_rect.h"
#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "scene/resources/atlas_texture.h"
#include "servers/rendering/rendering_server.h"
void TextureRect::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
@ -95,7 +100,23 @@ void TextureRect::_notification(int p_what) {
if (region.has_area()) {
draw_texture_rect_region(texture, Rect2(offset, size), region);
} else {
draw_texture_rect(texture, Rect2(offset, size), tile);
// `draw_texture_rect` doesn't support tiling an AtlasTexture.
// Workaround using nine patch. Doesn't work properly for non-zero margin, nesting AtlasTextures is fine otherwise.
if (tile && Object::cast_to<AtlasTexture>(*texture)) {
Rect2 src_rect(Vector2(), texture->get_size());
Rect2 dst_rect(offset, size);
Ref<AtlasTexture> at = texture;
bool anything_to_draw = true;
while (anything_to_draw && at.is_valid()) {
anything_to_draw = at->get_rect_region(dst_rect, src_rect, dst_rect, src_rect);
at = at->get_atlas();
}
if (anything_to_draw) {
RS::get_singleton()->canvas_item_add_nine_patch(get_canvas_item(), dst_rect, src_rect, texture->get_scaled_rid(), Vector2(), Vector2(), RSE::NINE_PATCH_TILE, RSE::NINE_PATCH_TILE, true);
}
} else {
draw_texture_rect(texture, Rect2(offset, size), tile);
}
}
} break;
case NOTIFICATION_RESIZED: {
@ -132,6 +153,23 @@ Size2 TextureRect::get_minimum_size() const {
return Size2();
}
PackedStringArray TextureRect::get_configuration_warnings() const {
PackedStringArray warnings = Control::get_configuration_warnings();
if (stretch_mode == STRETCH_TILE) {
Ref<AtlasTexture> at = texture;
while (at.is_valid()) {
if (at->get_margin() != Rect2()) {
warnings.push_back(vformat(RTR("STRETCH_TILE mode is not supported for an AtlasTexture with non-zero margin.")));
break;
}
at = at->get_atlas();
}
}
return warnings;
}
void TextureRect::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TextureRect::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &TextureRect::get_texture);
@ -144,7 +182,7 @@ void TextureRect::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_stretch_mode", "stretch_mode"), &TextureRect::set_stretch_mode);
ClassDB::bind_method(D_METHOD("get_stretch_mode"), &TextureRect::get_stretch_mode);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, Texture2D::get_class_static()), "set_texture", "get_texture");
ADD_PROPERTY(PropertyInfo(Variant::INT, "expand_mode", PROPERTY_HINT_ENUM, "Keep Size,Ignore Size,Fit Width,Fit Width Proportional,Fit Height,Fit Height Proportional"), "set_expand_mode", "get_expand_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "is_flipped_h");
@ -179,6 +217,7 @@ bool TextureRect::_set(const StringName &p_name, const Variant &p_value) {
void TextureRect::_texture_changed() {
queue_redraw();
update_minimum_size();
update_configuration_warnings();
}
void TextureRect::set_texture(const Ref<Texture2D> &p_tex) {
@ -196,8 +235,7 @@ void TextureRect::set_texture(const Ref<Texture2D> &p_tex) {
texture->connect_changed(callable_mp(this, &TextureRect::_texture_changed));
}
queue_redraw();
update_minimum_size();
_texture_changed();
}
Ref<Texture2D> TextureRect::get_texture() const {
@ -225,6 +263,7 @@ void TextureRect::set_stretch_mode(StretchMode p_mode) {
stretch_mode = p_mode;
queue_redraw();
update_configuration_warnings();
}
TextureRect::StretchMode TextureRect::get_stretch_mode() const {