TexturePreview Update text when texture is being changed
This commit is contained in:
parent
c26547414d
commit
4eb59e8492
@ -62,6 +62,25 @@ void TexturePreview::_notification(int p_what) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TexturePreview::_update_metadata_label_text() {
|
||||||
|
Ref<Texture> texture = texture_display->get_texture();
|
||||||
|
|
||||||
|
String format;
|
||||||
|
if (Object::cast_to<ImageTexture>(*texture)) {
|
||||||
|
format = Image::get_format_name(Object::cast_to<ImageTexture>(*texture)->get_format());
|
||||||
|
} else if (Object::cast_to<StreamTexture>(*texture)) {
|
||||||
|
format = Image::get_format_name(Object::cast_to<StreamTexture>(*texture)->get_format());
|
||||||
|
} else {
|
||||||
|
format = texture->get_class();
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata_label->set_text(itos(texture->get_width()) + "x" + itos(texture->get_height()) + " " + format);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TexturePreview::_bind_methods() {
|
||||||
|
ClassDB::bind_method(D_METHOD("_update_metadata_label_text"), &TexturePreview::_update_metadata_label_text);
|
||||||
|
}
|
||||||
|
|
||||||
TexturePreview::TexturePreview(Ref<Texture> p_texture, bool p_show_metadata) {
|
TexturePreview::TexturePreview(Ref<Texture> p_texture, bool p_show_metadata) {
|
||||||
checkerboard = memnew(TextureRect);
|
checkerboard = memnew(TextureRect);
|
||||||
checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
|
checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
|
||||||
@ -78,16 +97,8 @@ TexturePreview::TexturePreview(Ref<Texture> p_texture, bool p_show_metadata) {
|
|||||||
if (p_show_metadata) {
|
if (p_show_metadata) {
|
||||||
metadata_label = memnew(Label);
|
metadata_label = memnew(Label);
|
||||||
|
|
||||||
String format;
|
_update_metadata_label_text();
|
||||||
if (Object::cast_to<ImageTexture>(*p_texture)) {
|
p_texture->connect("changed", this, "_update_metadata_label_text");
|
||||||
format = Image::get_format_name(Object::cast_to<ImageTexture>(*p_texture)->get_format());
|
|
||||||
} else if (Object::cast_to<StreamTexture>(*p_texture)) {
|
|
||||||
format = Image::get_format_name(Object::cast_to<StreamTexture>(*p_texture)->get_format());
|
|
||||||
} else {
|
|
||||||
format = p_texture->get_class();
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata_label->set_text(itos(p_texture->get_width()) + "x" + itos(p_texture->get_height()) + " " + format);
|
|
||||||
|
|
||||||
// It's okay that these colors are static since the grid color is static too.
|
// It's okay that these colors are static since the grid color is static too.
|
||||||
metadata_label->add_color_override("font_color", Color::named("white"));
|
metadata_label->add_color_override("font_color", Color::named("white"));
|
||||||
|
@ -44,8 +44,11 @@ private:
|
|||||||
TextureRect *checkerboard = nullptr;
|
TextureRect *checkerboard = nullptr;
|
||||||
Label *metadata_label = nullptr;
|
Label *metadata_label = nullptr;
|
||||||
|
|
||||||
|
void _update_metadata_label_text();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextureRect *get_texture_display();
|
TextureRect *get_texture_display();
|
||||||
|
Loading…
Reference in New Issue
Block a user