diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp index 12d3a6fd2fc..aff83ddeee3 100644 --- a/platform/linuxbsd/wayland/display_server_wayland.cpp +++ b/platform/linuxbsd/wayland/display_server_wayland.cpp @@ -1018,8 +1018,7 @@ void DisplayServerWayland::cursor_set_custom_image(const Ref &p_cursor wayland_thread.cursor_shape_clear_custom_image(p_shape); } - Rect2 atlas_rect; - Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot, atlas_rect); + Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot); ERR_FAIL_COND(image.is_null()); CustomCursor &cursor = custom_cursors[p_shape]; diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 34b6d0219a5..4ca1b110944 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -3108,8 +3108,7 @@ void DisplayServerX11::cursor_set_custom_image(const Ref &p_cursor, Cu cursors_cache.erase(p_shape); } - Rect2 atlas_rect; - Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot, atlas_rect); + Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot); ERR_FAIL_COND(image.is_null()); Vector2i texture_size = image->get_size(); @@ -3127,13 +3126,8 @@ void DisplayServerX11::cursor_set_custom_image(const Ref &p_cursor, Cu cursor_image->pixels = (XcursorPixel *)memalloc(size); for (XcursorPixel index = 0; index < image_size; index++) { - int row_index = floor(index / texture_size.width) + atlas_rect.position.y; - int column_index = (index % int(texture_size.width)) + atlas_rect.position.x; - - if (atlas_rect.has_area()) { - column_index = MIN(column_index, atlas_rect.size.width - 1); - row_index = MIN(row_index, atlas_rect.size.height - 1); - } + int row_index = floor(index / texture_size.width); + int column_index = index % int(texture_size.width); *(cursor_image->pixels + index) = image->get_pixel(column_index, row_index).to_argb32(); } diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 50313cfe67a..4661cd57a2e 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -2845,8 +2845,7 @@ void DisplayServerMacOS::cursor_set_custom_image(const Ref &p_cursor, cursors_cache.erase(p_shape); } - Rect2 atlas_rect; - Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot, atlas_rect); + Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot); ERR_FAIL_COND(image.is_null()); Vector2i texture_size = image->get_size(); @@ -2868,13 +2867,8 @@ void DisplayServerMacOS::cursor_set_custom_image(const Ref &p_cursor, int len = int(texture_size.width * texture_size.height); for (int i = 0; i < len; i++) { - int row_index = floor(i / texture_size.width) + atlas_rect.position.y; - int column_index = (i % int(texture_size.width)) + atlas_rect.position.x; - - if (atlas_rect.has_area()) { - column_index = MIN(column_index, atlas_rect.size.width - 1); - row_index = MIN(row_index, atlas_rect.size.height - 1); - } + int row_index = floor(i / texture_size.width); + int column_index = i % int(texture_size.width); uint32_t color = image->get_pixel(column_index, row_index).to_argb32(); diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index fab92b18949..40de4e523b0 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -517,19 +517,10 @@ DisplayServer::CursorShape DisplayServerWeb::cursor_get_shape() const { void DisplayServerWeb::cursor_set_custom_image(const Ref &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { ERR_FAIL_INDEX(p_shape, CURSOR_MAX); if (p_cursor.is_valid()) { - Rect2 atlas_rect; - Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot, atlas_rect); + Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot); ERR_FAIL_COND(image.is_null()); Vector2i texture_size = image->get_size(); - if (atlas_rect.has_area()) { - image->crop_from_point( - atlas_rect.position.x, - atlas_rect.position.y, - texture_size.width, - texture_size.height); - } - if (image->get_format() != Image::FORMAT_RGBA8) { image->convert(Image::FORMAT_RGBA8); } diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 4a482f560c2..8943467e558 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -2408,8 +2408,7 @@ void DisplayServerWindows::cursor_set_custom_image(const Ref &p_cursor cursors_cache.erase(p_shape); } - Rect2 atlas_rect; - Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot, atlas_rect); + Ref image = _get_cursor_image_from_resource(p_cursor, p_hotspot); ERR_FAIL_COND(image.is_null()); Vector2i texture_size = image->get_size(); @@ -2437,13 +2436,9 @@ void DisplayServerWindows::cursor_set_custom_image(const Ref &p_cursor bool fully_transparent = true; for (UINT index = 0; index < image_size; index++) { - int row_index = floor(index / texture_size.width) + atlas_rect.position.y; - int column_index = (index % int(texture_size.width)) + atlas_rect.position.x; + int row_index = floor(index / texture_size.width); + int column_index = index % int(texture_size.width); - if (atlas_rect.has_area()) { - column_index = MIN(column_index, atlas_rect.size.width - 1); - row_index = MIN(row_index, atlas_rect.size.height - 1); - } const Color &c = image->get_pixel(column_index, row_index); fully_transparent = fully_transparent && (c.a == 0.f); diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 2150a3038ee..b6e0d58af74 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -31,7 +31,6 @@ #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" @@ -1124,35 +1123,22 @@ void DisplayServer::_bind_methods() { BIND_ENUM_CONSTANT(TTS_UTTERANCE_BOUNDARY); } -Ref DisplayServer::_get_cursor_image_from_resource(const Ref &p_cursor, const Vector2 &p_hotspot, Rect2 &r_atlas_rect) { +Ref DisplayServer::_get_cursor_image_from_resource(const Ref &p_cursor, const Vector2 &p_hotspot) { Ref image; ERR_FAIL_COND_V_MSG(p_hotspot.x < 0 || p_hotspot.y < 0, image, "Hotspot outside cursor image."); - Size2 texture_size; - Ref texture = p_cursor; if (texture.is_valid()) { - Ref 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); + + Size2 image_size = image->get_size(); + ERR_FAIL_COND_V_MSG(p_hotspot.x > image_size.width || p_hotspot.y > image_size.height, image, "Hotspot outside cursor image."); + ERR_FAIL_COND_V_MSG(image_size.width > 256 || image_size.height > 256, image, "Cursor image too big. Max supported size is 256x256."); + if (image->is_compressed()) { image = image->duplicate(true); Error err = image->decompress(); diff --git a/servers/display_server.h b/servers/display_server.h index 5224d59c04a..5d82b6c13c9 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -101,7 +101,7 @@ private: protected: static void _bind_methods(); - static Ref _get_cursor_image_from_resource(const Ref &p_cursor, const Vector2 &p_hotspot, Rect2 &r_atlas_rect); + static Ref _get_cursor_image_from_resource(const Ref &p_cursor, const Vector2 &p_hotspot); enum { MAX_SERVERS = 64 @@ -248,8 +248,8 @@ public: virtual void tts_set_utterance_callback(TTSUtteranceEvent p_event, const Callable &p_callable); virtual void tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id, int p_pos = 0); - virtual bool is_dark_mode_supported() const { return false; }; - virtual bool is_dark_mode() const { return false; }; + virtual bool is_dark_mode_supported() const { return false; } + virtual bool is_dark_mode() const { return false; } virtual Color get_accent_color() const { return Color(0, 0, 0, 0); } virtual Color get_base_color() const { return Color(0, 0, 0, 0); } virtual void set_system_theme_change_callback(const Callable &p_callable) {} @@ -338,8 +338,8 @@ public: return scale; } virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0; - virtual Color screen_get_pixel(const Point2i &p_position) const { return Color(); }; - virtual Ref screen_get_image(int p_screen = SCREEN_OF_MAIN_WINDOW) const { return Ref(); }; + virtual Color screen_get_pixel(const Point2i &p_position) const { return Color(); } + virtual Ref screen_get_image(int p_screen = SCREEN_OF_MAIN_WINDOW) const { return Ref(); } virtual bool is_touchscreen_available() const; // Keep the ScreenOrientation enum values in sync with the `display/window/handheld/orientation` @@ -398,9 +398,9 @@ public: virtual void show_window(WindowID p_id); virtual void delete_sub_window(WindowID p_id); - virtual WindowID window_get_active_popup() const { return INVALID_WINDOW_ID; }; - virtual void window_set_popup_safe_rect(WindowID p_window, const Rect2i &p_rect){}; - virtual Rect2i window_get_popup_safe_rect(WindowID p_window) const { return Rect2i(); }; + virtual WindowID window_get_active_popup() const { return INVALID_WINDOW_ID; } + virtual void window_set_popup_safe_rect(WindowID p_window, const Rect2i &p_rect) {} + virtual Rect2i window_get_popup_safe_rect(WindowID p_window) const { return Rect2i(); } virtual int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const; @@ -555,10 +555,10 @@ public: virtual Key keyboard_get_keycode_from_physical(Key p_keycode) const; virtual Key keyboard_get_label_from_physical(Key p_keycode) const; - virtual int tablet_get_driver_count() const { return 1; }; - virtual String tablet_get_driver_name(int p_driver) const { return "default"; }; - virtual String tablet_get_current_driver() const { return "default"; }; - virtual void tablet_set_current_driver(const String &p_driver){}; + virtual int tablet_get_driver_count() const { return 1; } + virtual String tablet_get_driver_name(int p_driver) const { return "default"; } + virtual String tablet_get_current_driver() const { return "default"; } + virtual void tablet_set_current_driver(const String &p_driver) {} virtual void process_events() = 0;