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_rwops.h"
35 #include "SDL_version.h"
36 #if ! SDL_VERSION_ATLEAST(1,3,0)
37 #include "SDL_video.h"
38 #endif
39 
40 #include "begin_code.h"
41 /* Set up for C function definitions, even when using C++ */
42 #ifdef __cplusplus
43 /* *INDENT-OFF* */
44 extern "C" {
45 /* *INDENT-ON* */
46 #endif
47 
48 /**
49  *  \brief  The structure that defines a point
50  *
51  *  \sa SDL_EnclosePoints
52  */
53 typedef struct
54 {
55     int x;
56     int y;
57 } SDL_Point;
58 
59 /**
60  *  \brief A rectangle, with the origin at the upper left.
61  *
62  *  \sa SDL_RectEmpty
63  *  \sa SDL_RectEquals
64  *  \sa SDL_HasIntersection
65  *  \sa SDL_IntersectRect
66  *  \sa SDL_UnionRect
67  *  \sa SDL_EnclosePoints
68  */
69 #if SDL_VERSION_ATLEAST(1,3,0)
70 typedef struct SDL_Rect
71 {
72     int x, y;
73     int w, h;
74 } SDL_Rect;
75 #endif
76 
77 /**
78  *  \brief Returns true if the rectangle has no area.
79  */
80 #define SDL_RectEmpty(X)    (((X)->w <= 0) || ((X)->h <= 0))
81 
82 /**
83  *  \brief Returns true if the two rectangles are equal.
84  */
85 #define SDL_RectEquals(A, B)   (((A)->x == (B)->x) && ((A)->y == (B)->y) && \
86                                 ((A)->w == (B)->w) && ((A)->h == (B)->h))
87 
88 /**
89  *  \brief Determine whether two rectangles intersect.
90  *
91  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
92  */
93 extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
94                                                      const SDL_Rect * B);
95 
96 /**
97  *  \brief Calculate the intersection of two rectangles.
98  *
99  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
100  */
101 extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
102                                                    const SDL_Rect * B,
103                                                    SDL_Rect * result);
104 
105 /**
106  *  \brief Calculate the union of two rectangles.
107  */
108 extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
109                                            const SDL_Rect * B,
110                                            SDL_Rect * result);
111 
112 /**
113  *  \brief Calculate a minimal rectangle enclosing a set of points
114  *
115  *  \return SDL_TRUE if any points were within the clipping rect
116  */
117 extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
118                                                    int count,
119                                                    const SDL_Rect * clip,
120                                                    SDL_Rect * result);
121 
122 /**
123  *  \brief Calculate the intersection of a rectangle and line segment.
124  *
125  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
126  */
127 extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
128                                                           rect, int *X1,
129                                                           int *Y1, int *X2,
130                                                           int *Y2);
131 
132 /* Ends C function definitions when using C++ */
133 #ifdef __cplusplus
134 /* *INDENT-OFF* */
135 }
136 /* *INDENT-ON* */
137 #endif
138 #include "close_code.h"
139 
140 #endif /* _SDL_rect_h */
141 
142 /* vi: set ts=4 sw=4 expandtab: */
143