aboutsummaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorpoke10242018-02-28 20:23:40 +0100
committerHein-Pieter van Braam2018-04-14 20:37:54 +0200
commit2f53325beda6531eff42460bd95881bd6f8e392b (patch)
treece6d46cdeee624352ed44b2879535f7a88f7b9c5 /editor
parent7ad6a9aeea8186ef1f9fa06d194d070565f89f94 (diff)
downloadgodot-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')
-rw-r--r--editor/editor_node.cpp1
-rw-r--r--editor/plugins/editor_preview_plugins.cpp32
-rw-r--r--editor/plugins/editor_preview_plugins.h2
3 files changed, 35 insertions, 0 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 7441e322b..dcd695253 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -975,6 +975,7 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
String file = cache_base + ".png";
+ post_process_preview(img);
img->save_png(file);
}
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: