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

471 {
472  int i;
473  int span_y1, span_y2;
474  int rect_y1, rect_y2;
475 
476  if (width < 1) {
477  SDL_InvalidParamError("width");
478  return SDL_FALSE;
479  }
480 
481  if (height < 1) {
482  SDL_InvalidParamError("height");
483  return SDL_FALSE;
484  }
485 
486  if (!rects) {
487  SDL_InvalidParamError("rects");
488  return SDL_FALSE;
489  }
490 
491  if (!span) {
492  SDL_InvalidParamError("span");
493  return SDL_FALSE;
494  }
495 
496  if (numrects < 1) {
497  SDL_InvalidParamError("numrects");
498  return SDL_FALSE;
499  }
500 
501  /* Initialize to empty rect */
502  span_y1 = height;
503  span_y2 = 0;
504 
505  for (i = 0; i < numrects; ++i) {
506  rect_y1 = rects[i].y;
507  rect_y2 = rect_y1 + rects[i].h;
508 
509  /* Clip out of bounds rectangles, and expand span rect */
510  if (rect_y1 < 0) {
511  span_y1 = 0;
512  } else if (rect_y1 < span_y1) {
513  span_y1 = rect_y1;
514  }
515  if (rect_y2 > height) {
516  span_y2 = height;
517  } else if (rect_y2 > span_y2) {
518  span_y2 = rect_y2;
519  }
520  }
521  if (span_y2 > span_y1) {
522  span->x = 0;
523  span->y = span_y1;
524  span->w = width;
525  span->h = (span_y2 - span_y1);
526  return SDL_TRUE;
527  }
528  return SDL_FALSE;
529 }
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
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
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
int h
Definition: SDL_rect.h:67
int y
Definition: SDL_rect.h:66