Skip to content

Commit

Permalink
Show texture preview "transparent background" in editor plugin only b…
Browse files Browse the repository at this point in the history
…ehind actual texture
  • Loading branch information
arkology committed Dec 18, 2024
1 parent 19e003b commit 117011e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
37 changes: 29 additions & 8 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 @@ -61,6 +62,9 @@ void TexturePreview::_notification(int p_what) {
metadata_label->add_theme_font_override(SceneStringName(font), metadata_label_font);
}

bg_rect->set_color(get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));
borders_rect->set_border_color(get_theme_color(SNAME("extra_border_color_1"), EditorStringName(Editor)));

checkerboard->set_texture(get_editor_theme_icon(SNAME("Checkerboard")));
} break;
}
Expand Down Expand Up @@ -124,19 +128,36 @@ void TexturePreview::_update_metadata_label_text() {
}

TexturePreview::TexturePreview(Ref<Texture2D> p_texture, bool p_show_metadata) {
checkerboard = memnew(TextureRect);
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);
add_child(checkerboard);
set_custom_minimum_size(Size2(0.0, 256.0) * EDSCALE);

bg_rect = memnew(ColorRect);
bg_rect->set_anchors_preset(PRESET_FULL_RECT);
bg_rect->set_clip_contents(true);
add_child(bg_rect);

AspectRatioContainer *centering_container = memnew(AspectRatioContainer);
centering_container->set_anchors_preset(PRESET_FULL_RECT);
bg_rect->add_child(centering_container);

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);
texture_display->set_anchors_preset(PRESET_FULL_RECT);
centering_container->add_child(texture_display);

checkerboard = memnew(TextureRect);
checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
checkerboard->set_texture_repeat(CanvasItem::TEXTURE_REPEAT_ENABLED);
checkerboard->set_anchors_preset(PRESET_FULL_RECT);
checkerboard->set_draw_behind_parent(true);
texture_display->add_child(checkerboard);

borders_rect = memnew(ReferenceRect);
borders_rect->set_border_width(Math::floor(2 * EDSCALE));
borders_rect->set_anchors_preset(PRESET_FULL_RECT);
borders_rect->set_draw_behind_parent(true);
checkerboard->add_child(borders_rect);

if (p_show_metadata) {
metadata_label = memnew(Label);
Expand Down
4 changes: 4 additions & 0 deletions editor/plugins/texture_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "editor/editor_inspector.h"
#include "editor/plugins/editor_plugin.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/color_rect.h"
#include "scene/gui/reference_rect.h"
#include "scene/resources/texture.h"

class TextureRect;
Expand All @@ -44,7 +46,9 @@ class TexturePreview : public MarginContainer {
private:
TextureRect *texture_display = nullptr;

ColorRect *bg_rect = nullptr;
TextureRect *checkerboard = nullptr;
ReferenceRect *borders_rect = nullptr;
Label *metadata_label = nullptr;

void _update_metadata_label_text();
Expand Down

0 comments on commit 117011e

Please sign in to comment.