mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-26 21:57:16 +01:00
Add Gradient resource preview generator
Co-Authored-By: Haoyu Qiu <timothyqiu32@gmail.com>
This commit is contained in:
parent
cfc4f0f050
commit
b85a3cbce3
@ -6971,6 +6971,7 @@ EditorNode::EditorNode() {
|
|||||||
resource_preview->add_preview_generator(Ref<EditorMeshPreviewPlugin>(memnew(EditorMeshPreviewPlugin)));
|
resource_preview->add_preview_generator(Ref<EditorMeshPreviewPlugin>(memnew(EditorMeshPreviewPlugin)));
|
||||||
resource_preview->add_preview_generator(Ref<EditorBitmapPreviewPlugin>(memnew(EditorBitmapPreviewPlugin)));
|
resource_preview->add_preview_generator(Ref<EditorBitmapPreviewPlugin>(memnew(EditorBitmapPreviewPlugin)));
|
||||||
resource_preview->add_preview_generator(Ref<EditorFontPreviewPlugin>(memnew(EditorFontPreviewPlugin)));
|
resource_preview->add_preview_generator(Ref<EditorFontPreviewPlugin>(memnew(EditorFontPreviewPlugin)));
|
||||||
|
resource_preview->add_preview_generator(Ref<EditorGradientPreviewPlugin>(memnew(EditorGradientPreviewPlugin)));
|
||||||
|
|
||||||
{
|
{
|
||||||
Ref<SpatialMaterialConversionPlugin> spatial_mat_convert;
|
Ref<SpatialMaterialConversionPlugin> spatial_mat_convert;
|
||||||
|
@ -118,7 +118,7 @@ void EditorResourcePicker::_update_resource_preview(const String &p_path, const
|
|||||||
if (p_preview.is_valid()) {
|
if (p_preview.is_valid()) {
|
||||||
preview_rect->set_margin(MARGIN_LEFT, assign_button->get_icon()->get_width() + assign_button->get_theme_stylebox("normal")->get_default_margin(MARGIN_LEFT) + get_theme_constant("hseparation", "Button"));
|
preview_rect->set_margin(MARGIN_LEFT, assign_button->get_icon()->get_width() + assign_button->get_theme_stylebox("normal")->get_default_margin(MARGIN_LEFT) + get_theme_constant("hseparation", "Button"));
|
||||||
|
|
||||||
if (type == "GradientTexture") {
|
if (type == "GradientTexture" || type == "Gradient") {
|
||||||
preview_rect->set_stretch_mode(TextureRect::STRETCH_SCALE);
|
preview_rect->set_stretch_mode(TextureRect::STRETCH_SCALE);
|
||||||
assign_button->set_custom_minimum_size(Size2(1, 1));
|
assign_button->set_custom_minimum_size(Size2(1, 1));
|
||||||
} else {
|
} else {
|
||||||
|
@ -956,3 +956,32 @@ EditorFontPreviewPlugin::~EditorFontPreviewPlugin() {
|
|||||||
RS::get_singleton()->free(canvas);
|
RS::get_singleton()->free(canvas);
|
||||||
RS::get_singleton()->free(viewport);
|
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<Texture> EditorGradientPreviewPlugin::generate(const Ref<Resource> &p_from, const Size2 &p_size) const {
|
||||||
|
Ref<Gradient> gradient = p_from;
|
||||||
|
if (gradient.is_valid()) {
|
||||||
|
Ref<GradientTexture> ptex = Ref<GradientTexture>(memnew(GradientTexture));
|
||||||
|
ptex->set_width(p_size.width * GRADIENT_PREVIEW_TEXTURE_SCALE_FACTOR * EDSCALE);
|
||||||
|
ptex->set_gradient(gradient);
|
||||||
|
|
||||||
|
Ref<ImageTexture> image = Ref<ImageTexture>(memnew(ImageTexture));
|
||||||
|
image->create_from_image(ptex->get_data());
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
return Ref<Texture>();
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGradientPreviewPlugin::EditorGradientPreviewPlugin() {
|
||||||
|
}
|
||||||
|
@ -183,3 +183,14 @@ public:
|
|||||||
~EditorFontPreviewPlugin();
|
~EditorFontPreviewPlugin();
|
||||||
};
|
};
|
||||||
#endif // EDITORPREVIEWPLUGINS_H
|
#endif // EDITORPREVIEWPLUGINS_H
|
||||||
|
class EditorGradientPreviewPlugin : public EditorResourcePreviewGenerator {
|
||||||
|
GDCLASS(EditorGradientPreviewPlugin, EditorResourcePreviewGenerator);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual bool handles(const String &p_type) const;
|
||||||
|
virtual bool generate_small_preview_automatically() const;
|
||||||
|
virtual Ref<Texture> generate(const Ref<Resource> &p_from, const Size2 &p_size) const;
|
||||||
|
|
||||||
|
EditorGradientPreviewPlugin();
|
||||||
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user