SDL_BlitSurface9Grid(3)

πŸ’… SDL_BlitSurface9Grid β€” the SDL3 FUNCTIONS girlies' fave πŸ’…

okay bestie, sit DOWN, because this one is genuinely iconic. it's SDL_BlitSurface9Grid, and yes the name is a mouthful but the vibe is immaculate. we're doing a scaled blit using the 9-grid algorithm to a destination surface, which may be of a different format. different format!! we love a flexible queen 🫢


✨ NAME ✨

SDL_BlitSurface9Grid β€” perform a scaled blit using the 9-grid algorithm to a destination surface, which may be of a different format. periodt. πŸŽ€


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_surface.h>

bool SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect);

like, look at that signature. eleven arguments. she's high maintenance and she KNOWS it. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, and honestly it's kind of genius. the pixels in the source surface get split into a 3x3 grid β€” using the different corner sizes for each corner β€” and the sides and center make up the remaining pixels. so far so good? ✨

then the corners get scaled using scale and fit into the corners of the destination rectangle. corners stay cute and crisp. πŸ’–

then the sides and center are stretched into place to cover the remaining destination rectangle. the way that only the corners get scaled and everything else just stretches? that's the whole trick. it's giving "border image" energy, iykyk. 🧚


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • src β€” the SDL_Surface structure to be copied from. your source material, your muse. 🌈
  • srcrect β€” the SDL_Rect structure representing the rectangle to be used for the 9-grid, or NULL to use the entire surface. yes bestie, NULL is allowed, she'll just take the whole thing. 😌
  • left_width β€” the width, in pixels, of the left corners in srcrect. πŸ“
  • right_width β€” the width, in pixels, of the right corners in srcrect. πŸ“
  • top_height β€” the height, in pixels, of the top corners in srcrect. ⬆️
  • bottom_height β€” the height, in pixels, of the bottom corners in srcrect. ⬇️
  • scale β€” the scale used to transform the corner of srcrect into the corner of dstrect, or 0.0f for an unscaled blit. (yes, literally 0.0f. float, with the f. no cap.) πŸ”₯
  • scaleMode β€” scale algorithm to be used. she's picky about her scaling, let her choose. πŸ’…
  • dst β€” the SDL_Surface structure that is the blit target. where it's all going, the final destination. 🌟
  • dstrect β€” the SDL_Rect structure representing the target rectangle in the destination surface, or NULL to fill the entire surface. again, NULL = whole surface, she's flexible like that. πŸ’œ

⭐ RETURN VALUE ⭐

returns true on success or false on failure β€” and if it's a false bestie, do NOT just sit there wondering what went wrong. call SDL_GetError() for more information. she will tell you. 😭


πŸ’€ THREAD SAFETY πŸ’€

only one thread should be using the src and dst surfaces at any given time. not two. not "well technically they're different surfaces". one. thread. don't make it weird, bestie. πŸ™ˆ

πŸ‘‘ AVAILABILITY πŸ‘‘

this function is available since SDL 3.2.0. so if you're on something older, no she's not there, don't gaslight yourself. 🌸


πŸ”₯ SEE ALSO πŸ”₯

  • SDL_BlitSurface(3) β€” her simpler sister, also iconic, also worth your time. πŸ’–

and that's the whole page, bestie!! πŸŽ€ this lil' manual page came to you courtesy of Simple Directmedia Layer, rockin' SDL 3.4.18, and it was dated and stamped as SDL_BlitSurface9Grid(3) β€” go forth and blit those nine grids, you absolute main character. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from