Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

149 rindas
4.3 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2018 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. * \sa SDL_PointInRect
  39. */
  40. typedef struct SDL_Point
  41. {
  42. int x;
  43. int y;
  44. } SDL_Point;
  45. /**
  46. * \brief A rectangle, with the origin at the upper left.
  47. *
  48. * \sa SDL_RectEmpty
  49. * \sa SDL_RectEquals
  50. * \sa SDL_HasIntersection
  51. * \sa SDL_IntersectRect
  52. * \sa SDL_UnionRect
  53. * \sa SDL_EnclosePoints
  54. */
  55. typedef struct SDL_Rect
  56. {
  57. int x, y;
  58. int w, h;
  59. } SDL_Rect;
  60. /**
  61. * \brief Returns true if point resides inside a rectangle.
  62. */
  63. SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
  64. {
  65. return ( (p->x >= r->x) && (p->x < (r->x + r->w)) &&
  66. (p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
  67. }
  68. /**
  69. * \brief Returns true if the rectangle has no area.
  70. */
  71. SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
  72. {
  73. return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
  74. }
  75. /**
  76. * \brief Returns true if the two rectangles are equal.
  77. */
  78. SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
  79. {
  80. return (a && b && (a->x == b->x) && (a->y == b->y) &&
  81. (a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
  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. * \brief Calculate the intersection of two rectangles.
  92. *
  93. * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
  94. */
  95. extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
  96. const SDL_Rect * B,
  97. SDL_Rect * result);
  98. /**
  99. * \brief Calculate the union of two rectangles.
  100. */
  101. extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
  102. const SDL_Rect * B,
  103. SDL_Rect * result);
  104. /**
  105. * \brief Calculate a minimal rectangle enclosing a set of points
  106. *
  107. * \return SDL_TRUE if any points were within the clipping rect
  108. */
  109. extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
  110. int count,
  111. const SDL_Rect * clip,
  112. SDL_Rect * result);
  113. /**
  114. * \brief Calculate the intersection of a rectangle and line segment.
  115. *
  116. * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
  117. */
  118. extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
  119. rect, int *X1,
  120. int *Y1, int *X2,
  121. int *Y2);
  122. /* Ends C function definitions when using C++ */
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #include "close_code.h"
  127. #endif /* SDL_rect_h_ */
  128. /* vi: set ts=4 sw=4 expandtab: */