Skip to content

Commit 48a1b2c

Browse files
committed
surface: SDL_RotateSurface should update SDL_PROP_SURFACE_ROTATION_FLOAT.
Fixes #14616.
1 parent 334d36e commit 48a1b2c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/SDL3/SDL_surface.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,14 @@ extern SDL_DECLSPEC bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipM
10271027
* larger than the original, with the background filled in with the colorkey,
10281028
* if available, or RGBA 255/255/255/0 if not.
10291029
*
1030+
* If `surface` has the SDL_PROP_SURFACE_ROTATION_FLOAT property set on it,
1031+
* the new copy will have the adjusted value set: if the rotation property is
1032+
* 90 and `angle` was 30, the new surface will have a property value of 60
1033+
* (that is: to be upright vs gravity, this surface needs to rotate 60 more
1034+
* degrees). However, note that further rotations on the new surface in this
1035+
* example will produce unexpected results, since the image will have resized
1036+
* and padded to accommodate the not-90 degree angle.
1037+
*
10301038
* \param surface the surface to rotate.
10311039
* \param angle the rotation angle, in degrees.
10321040
* \returns a rotated copy of the surface or NULL on failure; call

src/video/SDL_surface.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,14 @@ SDL_Surface *SDL_RotateSurface(SDL_Surface *surface, float angle)
21982198
SDL_DestroySurface(convert);
21992199
}
22002200
}
2201+
2202+
if (rotated) {
2203+
if (SDL_HasProperty(surface->props, SDL_PROP_SURFACE_ROTATION_FLOAT)) {
2204+
const float rotation = (SDL_GetNumberProperty(surface->props, SDL_PROP_SURFACE_ROTATION_FLOAT, 0) - angle);
2205+
SDL_SetFloatProperty(SDL_GetSurfaceProperties(rotated), SDL_PROP_SURFACE_ROTATION_FLOAT, rotation);
2206+
}
2207+
}
2208+
22012209
return rotated;
22022210
}
22032211

0 commit comments

Comments
 (0)