From 0bc1f87120bdec123ca6c33c1b2b486c3a15227d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 10 Feb 2025 11:50:22 -0800
Subject: [PATCH] Added SDL_PROP_SURFACE_HOTSPOT_X_NUMBER and
SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER
---
include/SDL3/SDL_surface.h | 4 ++++
src/events/SDL_mouse.c | 5 +++++
2 files changed, 9 insertions(+)
diff --git a/include/SDL3/SDL_surface.h b/include/SDL3/SDL_surface.h
index f2d20654bf0d0..fb2f6bd74999c 100644
--- a/include/SDL3/SDL_surface.h
+++ b/include/SDL3/SDL_surface.h
@@ -221,6 +221,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
* the same tone mapping that Chrome uses for HDR content, the form "*=N",
* where N is a floating point scale factor applied in linear space, and
* "none", which disables tone mapping. This defaults to "chrome".
+ * - `SDL_PROP_SURFACE_HOTSPOT_X_NUMBER`: the hotspot pixel offset from the left edge of the image, if this surface is being used as a cursor.
+ * - `SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER`: the hotspot pixel offset from the top edge of the image, if this surface is being used as a cursor.
*
* \param surface the SDL_Surface structure to query.
* \returns a valid property ID on success or 0 on failure; call
@@ -233,6 +235,8 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surfac
#define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT "SDL.surface.SDR_white_point"
#define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT "SDL.surface.HDR_headroom"
#define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
+#define SDL_PROP_SURFACE_HOTSPOT_X_NUMBER "SDL.surface.hotspot.x"
+#define SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER "SDL.surface.hotspot.y"
/**
* Set the colorspace used by a surface.
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 42933af95facb..0369b1091d0f2 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -1483,6 +1483,11 @@ SDL_Cursor *SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
return NULL;
}
+ // Allow specifying the hot spot via properties on the surface
+ SDL_PropertiesID props = SDL_GetSurfaceProperties(surface);
+ hot_x = (int)SDL_GetNumberProperty(props, SDL_PROP_SURFACE_HOTSPOT_X_NUMBER, hot_x);
+ hot_y = (int)SDL_GetNumberProperty(props, SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER, hot_y);
+
// Sanity check the hot spot
if ((hot_x < 0) || (hot_y < 0) ||
(hot_x >= surface->w) || (hot_y >= surface->h)) {