include/SDL_rect.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 11 Feb 2011 22:37:15 -0800
changeset 5262 b530ef003506
parent 5156 307ccc9c135e
child 5535 96594ac5fd1a
permissions -rw-r--r--
Happy 2011! :)
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2011 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 Returns true if the rectangle has no area.
    74  */
    75 #define SDL_RectEmpty(X)    (((X)->w <= 0) || ((X)->h <= 0))
    76 
    77 /**
    78  *  \brief Returns true if the two rectangles are equal.
    79  */
    80 #define SDL_RectEquals(A, B)   (((A)->x == (B)->x) && ((A)->y == (B)->y) && \
    81                                 ((A)->w == (B)->w) && ((A)->h == (B)->h))
    82 
    83 /**
    84  *  \brief Determine whether two rectangles intersect.
    85  *  
    86  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
    87  */
    88 extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
    89                                                      const SDL_Rect * B);
    90 
    91 /**
    92  *  \brief Calculate the intersection of two rectangles.
    93  *  
    94  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
    95  */
    96 extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
    97                                                    const SDL_Rect * B,
    98                                                    SDL_Rect * result);
    99 
   100 /**
   101  *  \brief Calculate the union of two rectangles.
   102  */
   103 extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
   104                                            const SDL_Rect * B,
   105                                            SDL_Rect * result);
   106 
   107 /**
   108  *  \brief Calculate a minimal rectangle enclosing a set of points
   109  *
   110  *  \return SDL_TRUE if any points were within the clipping rect
   111  */
   112 extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
   113                                                    int count,
   114                                                    const SDL_Rect * clip,
   115                                                    SDL_Rect * result);
   116 
   117 /**
   118  *  \brief Calculate the intersection of a rectangle and line segment.
   119  *  
   120  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
   121  */
   122 extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
   123                                                           rect, int *X1,
   124                                                           int *Y1, int *X2,
   125                                                           int *Y2);
   126 
   127 /* Ends C function definitions when using C++ */
   128 #ifdef __cplusplus
   129 /* *INDENT-OFF* */
   130 }
   131 /* *INDENT-ON* */
   132 #endif
   133 #include "close_code.h"
   134 
   135 #endif /* _SDL_rect_h */
   136 
   137 /* vi: set ts=4 sw=4 expandtab: */