Merge pull request #60395 from Geometror/editor-gradient-preview-plugin
This commit is contained in:
commit
e8cca501fe
4 changed files with 45 additions and 1 deletions
|
@ -7086,6 +7086,7 @@ EditorNode::EditorNode() {
|
|||
resource_preview->add_preview_generator(Ref<EditorMeshPreviewPlugin>(memnew(EditorMeshPreviewPlugin)));
|
||||
resource_preview->add_preview_generator(Ref<EditorBitmapPreviewPlugin>(memnew(EditorBitmapPreviewPlugin)));
|
||||
resource_preview->add_preview_generator(Ref<EditorFontPreviewPlugin>(memnew(EditorFontPreviewPlugin)));
|
||||
resource_preview->add_preview_generator(Ref<EditorGradientPreviewPlugin>(memnew(EditorGradientPreviewPlugin)));
|
||||
|
||||
{
|
||||
Ref<StandardMaterial3DConversionPlugin> spatial_mat_convert;
|
||||
|
|
|
@ -90,7 +90,8 @@ void EditorResourcePicker::_update_resource_preview(const String &p_path, const
|
|||
if (p_preview.is_valid()) {
|
||||
preview_rect->set_offset(SIDE_LEFT, assign_button->get_icon()->get_width() + assign_button->get_theme_stylebox(SNAME("normal"))->get_default_margin(SIDE_LEFT) + get_theme_constant(SNAME("h_separation"), SNAME("Button")));
|
||||
|
||||
if (Ref<GradientTexture1D>(edited_resource).is_valid()) {
|
||||
// Resource-specific stretching.
|
||||
if (Ref<GradientTexture1D>(edited_resource).is_valid() || Ref<Gradient>(edited_resource).is_valid()) {
|
||||
preview_rect->set_stretch_mode(TextureRect::STRETCH_SCALE);
|
||||
assign_button->set_custom_minimum_size(Size2(1, 1));
|
||||
} else {
|
||||
|
|
|
@ -904,3 +904,34 @@ EditorFontPreviewPlugin::~EditorFontPreviewPlugin() {
|
|||
RS::get_singleton()->free(canvas);
|
||||
RS::get_singleton()->free(viewport);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const real_t GRADIENT_PREVIEW_TEXTURE_SCALE_FACTOR = 4.0;
|
||||
|
||||
bool EditorGradientPreviewPlugin::handles(const String &p_type) const {
|
||||
return ClassDB::is_parent_class(p_type, "Gradient");
|
||||
}
|
||||
|
||||
bool EditorGradientPreviewPlugin::generate_small_preview_automatically() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
Ref<Texture2D> EditorGradientPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const {
|
||||
Ref<Gradient> gradient = p_from;
|
||||
if (gradient.is_valid()) {
|
||||
Ref<GradientTexture1D> ptex;
|
||||
ptex.instantiate();
|
||||
ptex->set_width(p_size.width * GRADIENT_PREVIEW_TEXTURE_SCALE_FACTOR * EDSCALE);
|
||||
ptex->set_gradient(gradient);
|
||||
|
||||
Ref<ImageTexture> itex;
|
||||
itex.instantiate();
|
||||
itex->create_from_image(ptex->get_image());
|
||||
return itex;
|
||||
}
|
||||
return Ref<Texture2D>();
|
||||
}
|
||||
|
||||
EditorGradientPreviewPlugin::EditorGradientPreviewPlugin() {
|
||||
}
|
||||
|
|
|
@ -182,4 +182,15 @@ public:
|
|||
EditorTileMapPatternPreviewPlugin();
|
||||
~EditorTileMapPatternPreviewPlugin();
|
||||
};
|
||||
|
||||
class EditorGradientPreviewPlugin : public EditorResourcePreviewGenerator {
|
||||
GDCLASS(EditorGradientPreviewPlugin, EditorResourcePreviewGenerator);
|
||||
|
||||
public:
|
||||
virtual bool handles(const String &p_type) const override;
|
||||
virtual bool generate_small_preview_automatically() const override;
|
||||
virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const override;
|
||||
|
||||
EditorGradientPreviewPlugin();
|
||||
};
|
||||
#endif // EDITORPREVIEWPLUGINS_H
|
||||
|
|
Loading…
Reference in a new issue