include/SDL_rect.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 02 Feb 2011 14:34:54 -0800
changeset 5154 fb424691cfc7
parent 3697 f7b03b6838cb
child 5156 307ccc9c135e
permissions -rw-r--r--
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /**
    24  *  \file SDL_rect.h
    25  *  
    26  *  Header file for SDL_rect definition and management functions.
    27  */
    28 
    29 #ifndef _SDL_rect_h
    30 #define _SDL_rect_h
    31 
    32 #include "SDL_stdinc.h"
    33 #include "SDL_error.h"
    34 #include "SDL_pixels.h"
    35 #include "SDL_rwops.h"
    36 
    37 #include "begin_code.h"
    38 /* Set up for C function definitions, even when using C++ */
    39 #ifdef __cplusplus
    40 /* *INDENT-OFF* */
    41 extern "C" {
    42 /* *INDENT-ON* */
    43 #endif
    44 
    45 /**
    46  *  \brief  The structure that defines a point
    47  *
    48  *  \sa SDL_EnclosePoints
    49  */
    50 typedef struct
    51 {
    52     int x;
    53     int y;
    54 } SDL_Point;
    55 
    56 /**
    57  *  \brief A rectangle, with the origin at the upper left.
    58  *  
    59  *  \sa SDL_RectEmpty
    60  *  \sa SDL_RectEquals
    61  *  \sa SDL_HasIntersection
    62  *  \sa SDL_IntersectRect
    63  *  \sa SDL_UnionRect
    64  *  \sa SDL_EnclosePoints
    65  */
    66 typedef struct SDL_Rect
    67 {
    68     int x, y;
    69     int w, h;
    70 } SDL_Rect;
    71 
    72 /**
    73  *  \brief A structure used to track dirty rectangles
    74  *  
    75  *  \sa SDL_AddDirtyRect
    76  *  \sa SDL_ClearDirtyRects
    77  *  \sa SDL_FreeDirtyRects
    78  */
    79 typedef struct SDL_DirtyRect
    80 {
    81     SDL_Rect rect;
    82     struct SDL_DirtyRect *next;
    83 } SDL_DirtyRect;
    84 
    85 typedef struct SDL_DirtyRectList
    86 {
    87     SDL_DirtyRect *list;
    88     SDL_DirtyRect *free;
    89 } SDL_DirtyRectList;
    90 
    91 /**
    92  *  \brief Returns true if the rectangle has no area.
    93  */
    94 #define SDL_RectEmpty(X)    (((X)->w <= 0) || ((X)->h <= 0))
    95 
    96 /**
    97  *  \brief Returns true if the two rectangles are equal.
    98  */
    99 #define SDL_RectEquals(A, B)   (((A)->x == (B)->x) && ((A)->y == (B)->y) && \
   100                                 ((A)->w == (B)->w) && ((A)->h == (B)->h))
   101 
   102 /**
   103  *  \brief Determine whether two rectangles intersect.
   104  *  
   105  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
   106  */
   107 extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
   108                                                      const SDL_Rect * B);
   109 
   110 /**
   111  *  \brief Calculate the intersection of two rectangles.
   112  *  
   113  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
   114  */
   115 extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
   116                                                    const SDL_Rect * B,
   117                                                    SDL_Rect * result);
   118 
   119 /**
   120  *  \brief Calculate the union of two rectangles.
   121  */
   122 extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
   123                                            const SDL_Rect * B,
   124                                            SDL_Rect * result);
   125 
   126 /**
   127  *  \brief Calculate a minimal rectangle enclosing a set of points
   128  *
   129  *  \return SDL_TRUE if any points were within the clipping rect
   130  */
   131 extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
   132                                                    int count,
   133                                                    const SDL_Rect * clip,
   134                                                    SDL_Rect * result);
   135 
   136 /**
   137  *  \brief Calculate the intersection of a rectangle and line segment.
   138  *  
   139  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
   140  */
   141 extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
   142                                                           rect, int *X1,
   143                                                           int *Y1, int *X2,
   144                                                           int *Y2);
   145 
   146 /**
   147  *  \brief Add a rectangle to a dirty rectangle list
   148  */
   149 extern DECLSPEC void SDLCALL SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect);
   150 
   151 /**
   152  *  \brief Remove all rectangles associated with a dirty rectangle list
   153  */
   154 extern DECLSPEC void SDLCALL SDL_ClearDirtyRects(SDL_DirtyRectList * list);
   155 
   156 /**
   157  *  \brief Free memory associated with a dirty rectangle list
   158  */
   159 extern DECLSPEC void SDLCALL SDL_FreeDirtyRects(SDL_DirtyRectList * list);
   160 
   161 
   162 /* Ends C function definitions when using C++ */
   163 #ifdef __cplusplus
   164 /* *INDENT-OFF* */
   165 }
   166 /* *INDENT-ON* */
   167 #endif
   168 #include "close_code.h"
   169 
   170 #endif /* _SDL_rect_h */
   171 
   172 /* vi: set ts=4 sw=4 expandtab: */