Extend the 9-grid functions to handle a non-uniform grid layout (thanks @zaun!)

Fixes https://github.com/libsdl-org/SDL/issues/10389
This commit is contained in:
Sam Lantinga 2024-07-31 22:09:42 -07:00
parent a1c6f99877
commit a5f18048b2
7 changed files with 358 additions and 151 deletions
include/SDL3

View file

@ -1919,17 +1919,20 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderTextureTiled(SDL_Renderer *renderer, S
* Perform a scaled copy using the 9-grid algorithm to the current rendering
* target at subpixel precision.
*
* The pixels in the texture are split into a 3x3 grid, using the corner size
* for each corner, and the sides and center making up the remaining pixels.
* The corners are then scaled using `scale` and fit into the corners of the
* destination rectangle. The sides and center are then stretched into place
* to cover the remaining destination rectangle.
* The pixels in the texture are split into a 3x3 grid, using the different
* corner sizes for each corner, and the sides and center making up the
* remaining pixels. The corners are then scaled using `scale` and fit into
* the corners of the destination rectangle. The sides and center are then
* stretched into place to cover the remaining destination rectangle.
*
* \param renderer the renderer which should copy parts of a texture.
* \param texture the source texture.
* \param srcrect the SDL_Rect structure representing the rectangle to be used
* for the 9-grid, or NULL to use the entire texture.
* \param corner_size the size, in pixels, of the corner in `srcrect`.
* \param left_width the width, in pixels, of the left corners in `srcrect`.
* \param right_width the width, in pixels, of the right corners in `srcrect`.
* \param top_height the height, in pixels, of the top corners in `srcrect`.
* \param bottom_height the height, in pixels, of the bottom corners in `srcrect`.
* \param scale the scale used to transform the corner of `srcrect` into the
* corner of `dstrect`, or 0.0f for an unscaled copy.
* \param dstrect a pointer to the destination rectangle, or NULL for the
@ -1941,7 +1944,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderTextureTiled(SDL_Renderer *renderer, S
*
* \sa SDL_RenderTexture
*/
extern SDL_DECLSPEC int SDLCALL SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float corner_size, float scale, const SDL_FRect *dstrect);
extern SDL_DECLSPEC int SDLCALL SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect);
/**
* Render a list of triangles, optionally using a texture and indices into the