1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
From: "Ryan C. Gordon" <icculus@icculus.org>
Date: Sun, 7 Dec 2025 15:27:36 -0500
Subject: surface: SDL_RotateSurface should update
SDL_PROP_SURFACE_ROTATION_FLOAT.
Fixes #14616.
Origin: upstream, 3.3.6, commit:5813d0ec0aab618189eaa3ab33d8beaf5a9544d4
---
include/SDL3/SDL_surface.h | 8 ++++++++
src/video/SDL_surface.c | 8 ++++++++
2 files changed, 16 insertions(+)
diff --git a/include/SDL3/SDL_surface.h b/include/SDL3/SDL_surface.h
index e37cb59..437eeac 100644
--- a/include/SDL3/SDL_surface.h
+++ b/include/SDL3/SDL_surface.h
@@ -1027,6 +1027,14 @@ extern SDL_DECLSPEC bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipM
* larger than the original, with the background filled in with the colorkey,
* if available, or RGBA 255/255/255/0 if not.
*
+ * If `surface` has the SDL_PROP_SURFACE_ROTATION_FLOAT property set on it,
+ * the new copy will have the adjusted value set: if the rotation property is
+ * 90 and `angle` was 30, the new surface will have a property value of 60
+ * (that is: to be upright vs gravity, this surface needs to rotate 60 more
+ * degrees). However, note that further rotations on the new surface in this
+ * example will produce unexpected results, since the image will have resized
+ * and padded to accommodate the not-90 degree angle.
+ *
* \param surface the surface to rotate.
* \param angle the rotation angle, in degrees.
* \returns a rotated copy of the surface or NULL on failure; call
diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 2270920..3fc5f60 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -2198,6 +2198,14 @@ SDL_Surface *SDL_RotateSurface(SDL_Surface *surface, float angle)
SDL_DestroySurface(convert);
}
}
+
+ if (rotated) {
+ if (SDL_HasProperty(surface->props, SDL_PROP_SURFACE_ROTATION_FLOAT)) {
+ const float rotation = (SDL_GetNumberProperty(surface->props, SDL_PROP_SURFACE_ROTATION_FLOAT, 0) - angle);
+ SDL_SetFloatProperty(SDL_GetSurfaceProperties(rotated), SDL_PROP_SURFACE_ROTATION_FLOAT, rotation);
+ }
+ }
+
return rotated;
}
|