diff options
| author | poke1024 | 2018-02-28 20:23:40 +0100 |
|---|---|---|
| committer | Hein-Pieter van Braam | 2018-04-14 20:37:54 +0200 |
| commit | 2f53325beda6531eff42460bd95881bd6f8e392b (patch) | |
| tree | ce6d46cdeee624352ed44b2879535f7a88f7b9c5 /editor/plugins | |
| parent | 7ad6a9aeea8186ef1f9fa06d194d070565f89f94 (diff) | |
| download | godot-2f53325beda6531eff42460bd95881bd6f8e392b.tar.gz godot-2f53325beda6531eff42460bd95881bd6f8e392b.tar.zst godot-2f53325beda6531eff42460bd95881bd6f8e392b.zip | |
Fix round preview getting square on "run scene" (issue 16734)
(cherry picked from commit 899f7b125e843d7187ad7c614588d635ce989f80)
Diffstat (limited to 'editor/plugins')
| -rw-r--r-- | editor/plugins/editor_preview_plugins.cpp | 32 | ||||
| -rw-r--r-- | editor/plugins/editor_preview_plugins.h | 2 |
2 files changed, 34 insertions, 0 deletions
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 215964235..e45577766 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -39,6 +39,38 @@ #include "scene/resources/material.h" #include "scene/resources/mesh.h" +void post_process_preview(Ref<Image> p_image) { + + if (p_image->get_format() != Image::FORMAT_RGBA8) + p_image->convert(Image::FORMAT_RGBA8); + + p_image->lock(); + + const int w = p_image->get_width(); + const int h = p_image->get_height(); + + const int r = MIN(w, h) / 32; + const int r2 = r * r; + Color transparent = Color(0, 0, 0, 0); + + for (int i = 0; i < r; i++) { + for (int j = 0; j < r; j++) { + int dx = i - r; + int dy = j - r; + if (dx * dx + dy * dy > r2) { + p_image->set_pixel(i, j, transparent); + p_image->set_pixel(w - 1 - i, j, transparent); + p_image->set_pixel(w - 1 - i, h - 1 - j, transparent); + p_image->set_pixel(i, h - 1 - j, transparent); + } else { + break; + } + } + } + + p_image->unlock(); +} + bool EditorTexturePreviewPlugin::handles(const String &p_type) const { return ClassDB::is_parent_class(p_type, "Texture"); diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h index 2e12515e3..35b5c3a5f 100644 --- a/editor/plugins/editor_preview_plugins.h +++ b/editor/plugins/editor_preview_plugins.h @@ -33,6 +33,8 @@ #include "editor/editor_resource_preview.h" +void post_process_preview(Ref<Image> p_image); + class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator { GDCLASS(EditorTexturePreviewPlugin, EditorResourcePreviewGenerator) public: |
