Repository: godotengine/godot
File: editor/scene/texture/texture_editor_plugin.cpp (C++)

Code before:
	if (p_show_metadata) {
		metadata_label = memnew(Label);
		metadata_label->set_focus_mode(FOCUS_ACCESSIBILITY);

		if (p_texture.is_valid()) {
			_update_metadata_label_text();
			p_texture->connect_changed(callable_mp(this, &TexturePreview::_update_metadata_label_text));
		}

		// It's okay that these colors are static since the grid color is static too.
		metadata_label->add_theme_color_override(SceneStringName(font_color), Color(1, 1, 1));
		metadata_label->add_theme_color_override("font_shadow_color", Color(0, 0, 0));

		metadata_label->add_theme_font_size_override(SceneStringName(font_size), 14 * EDSCALE);
		metadata_label->add_theme_color_override("font_outline_color", Color(0, 0, 0));
		metadata_label->add_theme_constant_override("outline_size", 8 * EDSCALE);

		metadata_label->set_h_size_flags(Control::SIZE_SHRINK_END);
		metadata_label->set_v_size_flags(Control::SIZE_SHRINK_END);

		add_child(metadata_label);
	}
}

bool EditorInspectorPluginTexture::can_handle(Object *p_object) {
	if (p_object->get_class().begins_with("GradientTexture")) {
		return false;
	}

	if (Object::cast_to<Image>(p_object) != nullptr ||
			Object::cast_to<ImageTexture>(p_object) != nullptr ||
			Object::cast_to<AtlasTexture>(p_object) != nullptr ||
			Object::cast_to<CompressedTexture2D>(p_object) != nullptr ||
			Object::cast_to<PortableCompressedTexture2D>(p_object) != nullptr ||
			Object::cast_to<AnimatedTexture>(p_object) != nullptr ||
			Object::cast_to<Texture2DRD>(p_object) != nullptr) {
		return true;
	}

	Ref<Texture2D> texture_2d(Object::cast_to<Texture2D>(p_object));
	if (texture_2d.is_valid()) {
		this_image = texture_2d->get_image();
		return this_image.is_valid();
	}
	return false;
}

void EditorInspectorPluginTexture::parse_begin(Object *p_object) {
	Ref<Texture> texture(Object::cast_to<Texture>(p_object));
	if (texture.is_null()) {
		Ref<Image> image(Object::cast_to<Image>(p_object));

Review comment (suggestion):
```suggestion
	if (Object::cast_to<GradientTexture1D>(p_object) || Object::cast_to<GradientTexture2D>(p_object)) {
```
It's better to avoid string checks.

Code after:
		// It's okay that these colors are static since the grid color is static too.
		metadata_label->add_theme_color_override(SceneStringName(font_color), Color(1, 1, 1));
		metadata_label->add_theme_color_override("font_shadow_color", Color(0, 0, 0));

		metadata_label->add_theme_font_size_override(SceneStringName(font_size), 14 * EDSCALE);
		metadata_label->add_theme_color_override("font_outline_color", Color(0, 0, 0));
		metadata_label->add_theme_constant_override("outline_size", 8 * EDSCALE);

		metadata_label->set_h_size_flags(Control::SIZE_SHRINK_END);
		metadata_label->set_v_size_flags(Control::SIZE_SHRINK_END);

		add_child(metadata_label);
	}
}

bool EditorInspectorPluginTexture::can_handle(Object *p_object) {
	if (Object::cast_to<GradientTexture1D>(p_object) || Object::cast_to<GradientTexture2D>(p_object)) {
		return false;
	}

	if (Object::cast_to<Image>(p_object) != nullptr ||
			Object::cast_to<ImageTexture>(p_object) != nullptr ||
			Object::cast_to<AtlasTexture>(p_object) != nullptr ||
			Object::cast_to<CompressedTexture2D>(p_object) != nullptr ||
			Object::cast_to<PortableCompressedTexture2D>(p_object) != nullptr ||
			Object::cast_to<AnimatedTexture>(p_object) != nullptr ||
			Object::cast_to<DPITexture>(p_object) != nullptr ||
			Object::cast_to<Texture2DRD>(p_object) != nullptr) {
		return true;
	}

	Ref<Texture2D> texture_2d(Object::cast_to<Texture2D>(p_object));
	if (texture_2d.is_valid()) {
		this_image = texture_2d->get_image();
		return this_image.is_valid();
	}
	return false;
}

void EditorInspectorPluginTexture::parse_begin(Object *p_object) {
	Ref<Texture> texture(Object::cast_to<Texture>(p_object));
	if (texture.is_null()) {
		Ref<Image> image(Object::cast_to<Image>(p_object));
		texture = ImageTexture::create_from_image(image);

		ERR_FAIL_COND_MSG(texture.is_null(), "Failed to create the texture from an invalid image.");
	}

	add_custom_control(memnew(TexturePreview(texture, true)));
}