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_GetSpanEnclosingRect()

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

Definition at line 463 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().

465 {
466  int i;
467  int span_y1, span_y2;
468  int rect_y1, rect_y2;
469 
470  if (width < 1) {
471  SDL_InvalidParamError("width");
472  return SDL_FALSE;
473  }
474 
475  if (height < 1) {
476  SDL_InvalidParamError("height");
477  return SDL_FALSE;
478  }
479 
480  if (!rects) {
481  SDL_InvalidParamError("rects");
482  return SDL_FALSE;
483  }
484 
485  if (!span) {
486  SDL_InvalidParamError("span");
487  return SDL_FALSE;
488  }
489 
490  if (numrects < 1) {
491  SDL_InvalidParamError("numrects");
492  return SDL_FALSE;
493  }
494 
495  /* Initialize to empty rect */
496  span_y1 = height;
497  span_y2 = 0;
498 
499  for (i = 0; i < numrects; ++i) {
500  rect_y1 = rects[i].y;
501  rect_y2 = rect_y1 + rects[i].h;
502 
503  /* Clip out of bounds rectangles, and expand span rect */
504  if (rect_y1 < 0) {
505  span_y1 = 0;
506  } else if (rect_y1 < span_y1) {
507  span_y1 = rect_y1;
508  }
509  if (rect_y2 > height) {
510  span_y2 = height;
511  } else if (rect_y2 > span_y2) {
512  span_y2 = rect_y2;
513  }
514  }
515  if (span_y2 > span_y1) {
516  span->x = 0;
517  span->y = span_y1;
518  span->w = width;
519  span->h = (span_y2 - span_y1);
520  return SDL_TRUE;
521  }
522  return SDL_FALSE;
523 }
GLint GLint GLsizei width
Definition: SDL_opengl.h:1565
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1565
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
int h
Definition: SDL_rect.h:67
int y
Definition: SDL_rect.h:66