SDL_rect.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_rect.h
  20. *
  21. * Header file for SDL_rect definition and management functions.
  22. */
  23. #ifndef _SDL_rect_h
  24. #define _SDL_rect_h
  25. #include "SDL_stdinc.h"
  26. #include "SDL_error.h"
  27. #include "SDL_pixels.h"
  28. #include "SDL_rwops.h"
  29. #include "begin_code.h"
  30. /* Set up for C function definitions, even when using C++ */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /**
  35. * \brief The structure that defines a point
  36. *
  37. * \sa SDL_EnclosePoints
  38. */
  39. typedef struct SDL_Point
  40. {
  41. int x;
  42. int y;
  43. } SDL_Point;
  44. /**
  45. * \brief A rectangle, with the origin at the upper left.
  46. *
  47. * \sa SDL_RectEmpty
  48. * \sa SDL_RectEquals
  49. * \sa SDL_HasIntersection
  50. * \sa SDL_IntersectRect
  51. * \sa SDL_UnionRect
  52. * \sa SDL_EnclosePoints
  53. */
  54. typedef struct SDL_Rect
  55. {
  56. int x, y;
  57. int w, h;
  58. } SDL_Rect;
  59. /**
  60. * \brief Returns true if the rectangle has no area.
  61. */
  62. SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
  63. {
  64. return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
  65. }
  66. /**
  67. * \brief Returns true if the two rectangles are equal.
  68. */
  69. SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
  70. {
  71. return (a && b && (a->x == b->x) && (a->y == b->y) &&
  72. (a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
  73. }
  74. /**
  75. * \brief Determine whether two rectangles intersect.
  76. *
  77. * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
  78. */
  79. extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
  80. const SDL_Rect * B);
  81. /**
  82. * \brief Calculate the intersection of two rectangles.
  83. *
  84. * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
  85. */
  86. extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
  87. const SDL_Rect * B,
  88. SDL_Rect * result);
  89. /**
  90. * \brief Calculate the union of two rectangles.
  91. */
  92. extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
  93. const SDL_Rect * B,
  94. SDL_Rect * result);
  95. /**
  96. * \brief Calculate a minimal rectangle enclosing a set of points
  97. *
  98. * \return SDL_TRUE if any points were within the clipping rect
  99. */
  100. extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
  101. int count,
  102. const SDL_Rect * clip,
  103. SDL_Rect * result);
  104. /**
  105. * \brief Calculate the intersection of a rectangle and line segment.
  106. *
  107. * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
  108. */
  109. extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
  110. rect, int *X1,
  111. int *Y1, int *X2,
  112. int *Y2);
  113. /* Ends C function definitions when using C++ */
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #include "close_code.h"
  118. #endif /* _SDL_rect_h */
  119. /* vi: set ts=4 sw=4 expandtab: */