diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index d93466b5ba98..c7af98cac976 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -32,6 +32,7 @@ #include "editor/editor_string_names.h" #include "editor/themes/editor_scale.h" +#include "scene/gui/aspect_ratio_container.h" #include "scene/gui/label.h" #include "scene/gui/texture_rect.h" #include "scene/resources/animated_texture.h" @@ -62,6 +63,8 @@ void TexturePreview::_notification(int p_what) { } checkerboard->set_texture(get_editor_theme_icon(SNAME("Checkerboard"))); + + texture_borders_rect->set_border_color(get_theme_color(SNAME("disabled_border_color"), EditorStringName(Editor))); } break; } } @@ -128,15 +131,25 @@ TexturePreview::TexturePreview(Ref p_texture, bool p_show_metadata) { checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE); checkerboard->set_texture_repeat(CanvasItem::TEXTURE_REPEAT_ENABLED); checkerboard->set_custom_minimum_size(Size2(0.0, 256.0) * EDSCALE); + checkerboard->set_clip_contents(true); add_child(checkerboard); + AspectRatioContainer *arc = memnew(AspectRatioContainer); + arc->set_anchors_preset(PRESET_FULL_RECT); + checkerboard->add_child(arc); + texture_display = memnew(TextureRect); texture_display->set_texture_filter(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS); texture_display->set_texture(p_texture); - texture_display->set_anchors_preset(TextureRect::PRESET_FULL_RECT); - texture_display->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); texture_display->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE); - add_child(texture_display); + arc->add_child(texture_display); + + texture_borders_rect = memnew(ReferenceRect); + texture_borders_rect->set_anchors_preset(PRESET_FULL_RECT); + texture_borders_rect->set_draw_behind_parent(true); + //texture_borders_rect->set_border_width(1); + texture_display->add_child(texture_borders_rect); + if (p_show_metadata) { metadata_label = memnew(Label); diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h index ea31429238ef..cf15a769581c 100644 --- a/editor/plugins/texture_editor_plugin.h +++ b/editor/plugins/texture_editor_plugin.h @@ -34,6 +34,7 @@ #include "editor/editor_inspector.h" #include "editor/plugins/editor_plugin.h" #include "scene/gui/margin_container.h" +#include "scene/gui/reference_rect.h" #include "scene/resources/texture.h" class TextureRect; @@ -44,6 +45,7 @@ class TexturePreview : public MarginContainer { private: TextureRect *texture_display = nullptr; + ReferenceRect *texture_borders_rect = nullptr; TextureRect *checkerboard = nullptr; Label *metadata_label = nullptr;