SDL standard library

Dependents:   H261_encoder

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SDL_rect.h Source File

SDL_rect.h

Go to the documentation of this file.
00001 /*
00002   Simple DirectMedia Layer
00003   Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
00004 
00005   This software is provided 'as-is', without any express or implied
00006   warranty.  In no event will the authors be held liable for any damages
00007   arising from the use of this software.
00008 
00009   Permission is granted to anyone to use this software for any purpose,
00010   including commercial applications, and to alter it and redistribute it
00011   freely, subject to the following restrictions:
00012 
00013   1. The origin of this software must not be misrepresented; you must not
00014      claim that you wrote the original software. If you use this software
00015      in a product, an acknowledgment in the product documentation would be
00016      appreciated but is not required.
00017   2. Altered source versions must be plainly marked as such, and must not be
00018      misrepresented as being the original software.
00019   3. This notice may not be removed or altered from any source distribution.
00020 */
00021 
00022 /**
00023  *  \file SDL_rect.h
00024  *
00025  *  Header file for SDL_rect definition and management functions.
00026  */
00027 
00028 #ifndef _SDL_rect_h
00029 #define _SDL_rect_h
00030 
00031 #include "SDL_stdinc.h"
00032 #include "SDL_error.h"
00033 #include "SDL_pixels.h"
00034 #include "SDL_rwops.h"
00035 
00036 #include "begin_code.h"
00037 /* Set up for C function definitions, even when using C++ */
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00042 /**
00043  *  \brief  The structure that defines a point
00044  *
00045  *  \sa SDL_EnclosePoints
00046  */
00047 typedef struct SDL_Point
00048 {
00049     int x;
00050     int y;
00051 } SDL_Point;
00052 
00053 /**
00054  *  \brief A rectangle, with the origin at the upper left.
00055  *
00056  *  \sa SDL_RectEmpty
00057  *  \sa SDL_RectEquals
00058  *  \sa SDL_HasIntersection
00059  *  \sa SDL_IntersectRect
00060  *  \sa SDL_UnionRect
00061  *  \sa SDL_EnclosePoints
00062  */
00063 typedef struct SDL_Rect
00064 {
00065     int x, y;
00066     int w, h;
00067 } SDL_Rect;
00068 
00069 /**
00070  *  \brief Returns true if the rectangle has no area.
00071  */
00072 SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
00073 {
00074     return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
00075 }
00076 
00077 /**
00078  *  \brief Returns true if the two rectangles are equal.
00079  */
00080 SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
00081 {
00082     return (a && b && (a->x == b->x) && (a->y == b->y) &&
00083             (a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
00084 }
00085 
00086 /**
00087  *  \brief Determine whether two rectangles intersect.
00088  *
00089  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
00090  */
00091 extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
00092                                                      const SDL_Rect * B);
00093 
00094 /**
00095  *  \brief Calculate the intersection of two rectangles.
00096  *
00097  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
00098  */
00099 extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
00100                                                    const SDL_Rect * B,
00101                                                    SDL_Rect * result);
00102 
00103 /**
00104  *  \brief Calculate the union of two rectangles.
00105  */
00106 extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
00107                                            const SDL_Rect * B,
00108                                            SDL_Rect * result);
00109 
00110 /**
00111  *  \brief Calculate a minimal rectangle enclosing a set of points
00112  *
00113  *  \return SDL_TRUE if any points were within the clipping rect
00114  */
00115 extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
00116                                                    int count,
00117                                                    const SDL_Rect * clip,
00118                                                    SDL_Rect * result);
00119 
00120 /**
00121  *  \brief Calculate the intersection of a rectangle and line segment.
00122  *
00123  *  \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
00124  */
00125 extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
00126                                                           rect, int *X1,
00127                                                           int *Y1, int *X2,
00128                                                           int *Y2);
00129 
00130 /* Ends C function definitions when using C++ */
00131 #ifdef __cplusplus
00132 }
00133 #endif
00134 #include "close_code.h"
00135 
00136 #endif /* _SDL_rect_h */
00137 
00138 /* vi: set ts=4 sw=4 expandtab: */