summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/editor/editor_node.cpp1
-rw-r--r--tools/editor/plugins/editor_preview_plugins.cpp76
-rw-r--r--tools/editor/plugins/editor_preview_plugins.h11
3 files changed, 88 insertions, 0 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 9151e63df6..2d9decaaf9 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -5953,6 +5953,7 @@ EditorNode::EditorNode() {
resource_preview->add_preview_generator( Ref<EditorScriptPreviewPlugin>( memnew(EditorScriptPreviewPlugin )));
resource_preview->add_preview_generator( Ref<EditorSamplePreviewPlugin>( memnew(EditorSamplePreviewPlugin )));
resource_preview->add_preview_generator( Ref<EditorMeshPreviewPlugin>( memnew(EditorMeshPreviewPlugin )));
+ resource_preview->add_preview_generator( Ref<EditorBitmapPreviewPlugin>( memnew(EditorBitmapPreviewPlugin )));
circle_step_msec=OS::get_singleton()->get_ticks_msec();
circle_step_frame=OS::get_singleton()->get_frames_drawn();
diff --git a/tools/editor/plugins/editor_preview_plugins.cpp b/tools/editor/plugins/editor_preview_plugins.cpp
index 5f52d4c3e7..a0ce294219 100644
--- a/tools/editor/plugins/editor_preview_plugins.cpp
+++ b/tools/editor/plugins/editor_preview_plugins.cpp
@@ -6,6 +6,7 @@
#include "scene/resources/material.h"
#include "scene/resources/sample.h"
#include "scene/resources/mesh.h"
+#include "scene/resources/bit_mask.h"
bool EditorTexturePreviewPlugin::handles(const String& p_type) const {
@@ -58,6 +59,81 @@ EditorTexturePreviewPlugin::EditorTexturePreviewPlugin() {
}
+////////////////////////////////////////////////////////////////////////////
+
+bool EditorBitmapPreviewPlugin::handles(const String& p_type) const {
+
+ return ObjectTypeDB::is_type(p_type,"BitMap");
+}
+
+Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES& p_from) {
+
+ Ref<BitMap> bm =p_from;
+
+ if (bm->get_size()==Size2()) {
+ return Ref<Texture>();
+ }
+
+ DVector<uint8_t> data;
+
+ data.resize(bm->get_size().width*bm->get_size().height);
+
+ {
+ DVector<uint8_t>::Write w=data.write();
+
+ for(int i=0;i<bm->get_size().width;i++) {
+ for(int j=0;j<bm->get_size().height;j++) {
+ if (bm->get_bit(Point2i(i,j))) {
+ w[j*bm->get_size().width+i]=255;
+ } else {
+ w[j*bm->get_size().width+i]=0;
+
+ }
+ }
+
+ }
+ }
+
+
+ Image img(bm->get_size().width,bm->get_size().height,0,Image::FORMAT_GRAYSCALE,data);
+
+ int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
+ if (img.is_compressed()) {
+ if (img.decompress()!=OK)
+ return Ref<Texture>();
+ } else if (img.get_format()!=Image::FORMAT_RGB && img.get_format()!=Image::FORMAT_RGBA) {
+ img.convert(Image::FORMAT_RGBA);
+ }
+
+ int width,height;
+ if (img.get_width() > thumbnail_size && img.get_width() >= img.get_height()) {
+
+ width=thumbnail_size;
+ height = img.get_height() * thumbnail_size / img.get_width();
+ } else if (img.get_height() > thumbnail_size && img.get_height() >= img.get_width()) {
+
+ height=thumbnail_size;
+ width = img.get_width() * thumbnail_size / img.get_height();
+ } else {
+
+ width=img.get_width();
+ height=img.get_height();
+ }
+
+ img.resize(width,height);
+
+ Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture ));
+
+ ptex->create_from_image(img,0);
+ return ptex;
+
+}
+
+EditorBitmapPreviewPlugin::EditorBitmapPreviewPlugin() {
+
+
+}
+
///////////////////////////////////////////////////////////////////////////
diff --git a/tools/editor/plugins/editor_preview_plugins.h b/tools/editor/plugins/editor_preview_plugins.h
index 98071e2a0e..b3bfda8045 100644
--- a/tools/editor/plugins/editor_preview_plugins.h
+++ b/tools/editor/plugins/editor_preview_plugins.h
@@ -13,6 +13,17 @@ public:
};
+class EditorBitmapPreviewPlugin : public EditorResourcePreviewGenerator {
+public:
+
+ virtual bool handles(const String& p_type) const;
+ virtual Ref<Texture> generate(const RES& p_from);
+
+ EditorBitmapPreviewPlugin();
+};
+
+
+
class EditorPackedScenePreviewPlugin : public EditorResourcePreviewGenerator {
Ref<Texture> _gen_from_imd(Ref<ResourceImportMetadata> p_imd);