SDL  2.0
SDL_rect_c.h File Reference
#include "../SDL_internal.h"
+ Include dependency graph for SDL_rect_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SDL_bool SDL_GetSpanEnclosingRect (int width, int height, int numrects, const SDL_Rect *rects, SDL_Rect *span)

Function Documentation

SDL_bool SDL_GetSpanEnclosingRect ( int  width,
int  height,
int  numrects,
const SDL_Rect rects,
SDL_Rect span 
)

Definition at line 469 of file SDL_rect.c.

References SDL_Rect::h, i, SDL_FALSE, SDL_InvalidParamError, SDL_TRUE, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_UpdateWindowTexture().

{
int i;
int span_y1, span_y2;
int rect_y1, rect_y2;
if (width < 1) {
return SDL_FALSE;
}
if (height < 1) {
return SDL_FALSE;
}
if (!rects) {
return SDL_FALSE;
}
if (!span) {
return SDL_FALSE;
}
if (numrects < 1) {
SDL_InvalidParamError("numrects");
return SDL_FALSE;
}
/* Initialize to empty rect */
span_y1 = height;
span_y2 = 0;
for (i = 0; i < numrects; ++i) {
rect_y1 = rects[i].y;
rect_y2 = rect_y1 + rects[i].h;
/* Clip out of bounds rectangles, and expand span rect */
if (rect_y1 < 0) {
span_y1 = 0;
} else if (rect_y1 < span_y1) {
span_y1 = rect_y1;
}
if (rect_y2 > height) {
span_y2 = height;
} else if (rect_y2 > span_y2) {
span_y2 = rect_y2;
}
}
if (span_y2 > span_y1) {
span->x = 0;
span->y = span_y1;
span->w = width;
span->h = (span_y2 - span_y1);
return SDL_TRUE;
}
return SDL_FALSE;
}