-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only `Color` is supported for now. Made sure to initialize via `EditorNode::add_init_callback`, else would crash.
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "variant_resource_preview.h" | ||
|
||
bool VariantResourcePreviewGenerator::handles(const String &p_type) const { | ||
return p_type == "VariantResource"; | ||
} | ||
|
||
Ref<Texture> VariantResourcePreviewGenerator::generate(const Ref<Resource> &p_from, const Size2 &p_size) const { | ||
Ref<VariantResource> var = p_from; | ||
ERR_FAIL_COND_V_MSG(var.is_null(), Ref<VariantResource>(), "Invalid reference to a VariantResource object."); | ||
|
||
const Variant &value = var->get(var->get_property_name()); | ||
|
||
if (value.get_type() == Variant::NIL) { | ||
return Ref<Texture>(); | ||
} | ||
Ref<Image> image; | ||
image.instance(); | ||
image->create(p_size.x, p_size.y, false, Image::FORMAT_RGBA8); | ||
|
||
switch (value.get_type()) { | ||
case Variant::COLOR: { | ||
Color color = value; | ||
image->fill(color); | ||
} break; | ||
default: { | ||
return Ref<Texture>(); | ||
}; | ||
} | ||
Ref<ImageTexture> tex; | ||
tex.instance(); | ||
tex->create_from_image(image, 0); | ||
|
||
return tex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef VARIANT_RESOURCE_PREVIEW_H | ||
#define VARIANT_RESOURCE_PREVIEW_H | ||
|
||
#include "editor/editor_resource_preview.h" | ||
#include "../variant_resource.h" | ||
|
||
class VariantResourcePreviewGenerator : public EditorResourcePreviewGenerator { | ||
GDCLASS(VariantResourcePreviewGenerator, EditorResourcePreviewGenerator); | ||
|
||
public: | ||
virtual bool handles(const String &p_type) const; | ||
virtual Ref<Texture> generate(const RES &p_from, const Size2 &p_size) const; | ||
|
||
virtual bool generate_small_preview_automatically() const { return true; }; | ||
virtual bool can_generate_small_preview() const { return true; }; | ||
}; | ||
|
||
#endif // VARIANT_RESOURCE_PREVIEW_H |