Skip to content

Commit

Permalink
Add texture borders to TextureEditorPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
arkology committed Dec 14, 2024
1 parent 19e003b commit ce723c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 16 additions & 3 deletions editor/plugins/texture_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -128,15 +131,25 @@ TexturePreview::TexturePreview(Ref<Texture2D> 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);
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/texture_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit ce723c4

Please sign in to comment.