1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Improve cursor_set_custom_image() method

This commit is contained in:
kobewi
2024-02-28 18:38:15 +01:00
parent df78c0636d
commit 3aeb4a5542
10 changed files with 63 additions and 171 deletions

View File

@@ -990,36 +990,9 @@ void DisplayServerWayland::cursor_set_custom_image(const Ref<Resource> &p_cursor
wayland_thread.cursor_shape_clear_custom_image(p_shape);
}
Ref<Texture2D> texture = p_cursor;
ERR_FAIL_COND(!texture.is_valid());
Size2i texture_size;
Ref<AtlasTexture> atlas_texture = texture;
if (atlas_texture.is_valid()) {
texture_size.width = atlas_texture->get_region().size.x;
texture_size.height = atlas_texture->get_region().size.y;
} else {
texture_size.width = texture->get_width();
texture_size.height = texture->get_height();
}
ERR_FAIL_COND(p_hotspot.x < 0 || p_hotspot.y < 0);
// NOTE: The Wayland protocol says nothing about cursor size limits, yet if
// the texture is larger than 256x256 it won't show at least on sway.
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
ERR_FAIL_COND(texture_size.height == 0 || texture_size.width == 0);
Ref<Image> image = texture->get_image();
ERR_FAIL_COND(!image.is_valid());
if (image->is_compressed()) {
image = image->duplicate(true);
Error err = image->decompress();
ERR_FAIL_COND_MSG(err != OK, "Couldn't decompress VRAM-compressed custom mouse cursor image. Switch to a lossless compression mode in the Import dock.");
}
Rect2 atlas_rect;
Ref<Image> image = _get_cursor_image_from_resource(p_cursor, p_hotspot, atlas_rect);
ERR_FAIL_COND(image.is_null());
CustomCursor &cursor = custom_cursors[p_shape];