summaryrefslogtreecommitdiffstats
path: root/servers/display_server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'servers/display_server.cpp')
-rw-r--r--servers/display_server.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/servers/display_server.cpp b/servers/display_server.cpp
index 6631d44f63..199152b5e8 100644
--- a/servers/display_server.cpp
+++ b/servers/display_server.cpp
@@ -31,6 +31,7 @@
#include "display_server.h"
#include "core/input/input.h"
+#include "scene/resources/atlas_texture.h"
#include "scene/resources/texture.h"
#include "servers/display_server_headless.h"
@@ -987,6 +988,43 @@ void DisplayServer::_bind_methods() {
BIND_ENUM_CONSTANT(TTS_UTTERANCE_BOUNDARY);
}
+Ref<Image> DisplayServer::_get_cursor_image_from_resource(const Ref<Resource> &p_cursor, const Vector2 &p_hotspot, Rect2 &r_atlas_rect) {
+ Ref<Image> image;
+ ERR_FAIL_COND_V_MSG(p_hotspot.x < 0 || p_hotspot.y < 0, image, "Hotspot outside cursor image.");
+
+ Size2 texture_size;
+
+ Ref<Texture2D> texture = p_cursor;
+ if (texture.is_valid()) {
+ Ref<AtlasTexture> atlas_texture = p_cursor;
+
+ if (atlas_texture.is_valid()) {
+ texture = atlas_texture->get_atlas();
+ r_atlas_rect.size = texture->get_size();
+ r_atlas_rect.position = atlas_texture->get_region().position;
+ texture_size = atlas_texture->get_region().size;
+ } else {
+ texture_size = texture->get_size();
+ }
+ image = texture->get_image();
+ } else {
+ image = p_cursor;
+ ERR_FAIL_COND_V(image.is_null(), image);
+ texture_size = image->get_size();
+ }
+
+ ERR_FAIL_COND_V_MSG(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height, image, "Hotspot outside cursor image.");
+ ERR_FAIL_COND_V_MSG(texture_size.width > 256 || texture_size.height > 256, image, "Cursor image too big. Max supported size is 256x256.");
+
+ ERR_FAIL_COND_V(image.is_null(), image);
+ if (image->is_compressed()) {
+ image = image->duplicate(true);
+ Error err = image->decompress();
+ ERR_FAIL_COND_V_MSG(err != OK, Ref<Image>(), "Couldn't decompress VRAM-compressed custom mouse cursor image. Switch to a lossless compression mode in the Import dock.");
+ }
+ return image;
+}
+
void DisplayServer::register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers) {
ERR_FAIL_COND(server_create_count == MAX_SERVERS);
// Headless display server is always last