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