sge_internal.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * SDL Graphics Extension
  3. * SGE internal header
  4. *
  5. * Started 000627
  6. *
  7. * License: LGPL v2+ (see the file LICENSE)
  8. * (c)2000-2003 Anders Lindström
  9. */
  10. /*********************************************************************
  11. * This library is free software; you can redistribute it and/or *
  12. * modify it under the terms of the GNU Library General Public *
  13. * License as published by the Free Software Foundation; either *
  14. * version 2 of the License, or (at your option) any later version. *
  15. *********************************************************************/
  16. #ifndef sge_internal_H
  17. #define sge_internal_H
  18. /* This header is included in all sge_*.h files */
  19. #include "sge_config.h"
  20. /*
  21. * C compatibility
  22. * Thanks to Ohbayashi Ippei (ohai@kmc.gr.jp) for this clever hack!
  23. */
  24. #ifdef _SGE_C_AND_CPP
  25. #ifdef __cplusplus
  26. #define _SGE_C /* use extern "C" on base functions */
  27. #else
  28. #define sge_C_ONLY /* remove overloaded functions */
  29. #define _SGE_NO_CLASSES /* no C++ classes */
  30. #endif
  31. #endif
  32. /*
  33. * This is traditional
  34. */
  35. #ifndef PI
  36. #define PI 3.1414926535
  37. #endif
  38. /*
  39. * Bit flags
  40. */
  41. #define SGE_FLAG0 0x00
  42. #define SGE_FLAG1 0x01
  43. #define SGE_FLAG2 0x02
  44. #define SGE_FLAG3 0x04
  45. #define SGE_FLAG4 0x08
  46. #define SGE_FLAG5 0x10
  47. #define SGE_FLAG6 0x20
  48. #define SGE_FLAG7 0x40
  49. #define SGE_FLAG8 0x80
  50. /*
  51. * Define the right alpha values
  52. * (they were fliped in SDL 1.1.5+)
  53. */
  54. #ifndef SDL_ALPHA_OPAQUE
  55. #define SDL_ALPHA_OPAQUE 255
  56. #endif
  57. #ifndef SDL_ALPHA_TRANSPARENT
  58. #define SDL_ALPHA_TRANSPARENT 0
  59. #endif
  60. /*
  61. * Older versions of SDL doesn't have SDL_VERSIONNUM
  62. */
  63. #ifndef SDL_VERSIONNUM
  64. #define SDL_VERSIONNUM(X, Y, Z) \
  65. (X)*1000 + (Y)*100 + (Z)
  66. #endif
  67. /*
  68. * Older versions of SDL doesn't have SDL_CreateRGBSurface
  69. */
  70. #ifndef SDL_AllocSurface
  71. #define SDL_CreateRGBSurface SDL_AllocSurface
  72. #endif
  73. /*
  74. * Macro to get clipping
  75. */
  76. #if SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL) >= \
  77. SDL_VERSIONNUM(1, 1, 5)
  78. #define sge_clip_xmin(pnt) pnt->clip_rect.x
  79. #define sge_clip_xmax(pnt) pnt->clip_rect.x + pnt->clip_rect.w-1
  80. #define sge_clip_ymin(pnt) pnt->clip_rect.y
  81. #define sge_clip_ymax(pnt) pnt->clip_rect.y + pnt->clip_rect.h-1
  82. #else
  83. #define sge_clip_xmin(pnt) pnt->clip_minx
  84. #define sge_clip_xmax(pnt) pnt->clip_maxx
  85. #define sge_clip_ymin(pnt) pnt->clip_miny
  86. #define sge_clip_ymax(pnt) pnt->clip_maxy
  87. #endif
  88. /*
  89. * Macro to get the smallest bounding box from two (SDL_Rect) rectangles
  90. */
  91. #define sge_RectUnion(dst_rect, rect1, rect2)\
  92. dst_rect.x = (rect1.x < rect2.x)? rect1.x:rect2.x;\
  93. dst_rect.y = (rect1.y < rect2.y)? rect1.y:rect2.y;\
  94. dst_rect.w = (rect1.x + rect1.w > rect2.x + rect2.w)? rect1.x + rect1.w - dst_rect.x : rect2.x + rect2.w - dst_rect.x;\
  95. dst_rect.h = (rect1.y + rect1.h > rect2.y + rect2.h)? rect1.y + rect1.h - dst_rect.y : rect2.y + rect2.h - dst_rect.y;
  96. /*
  97. * We need to use alpha sometimes but older versions of SDL doesn't have
  98. * alpha support.
  99. */
  100. #if SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL) >= \
  101. SDL_VERSIONNUM(1, 1, 5)
  102. #define sge_MapRGBA SDL_MapRGBA
  103. #define sge_GetRGBA SDL_GetRGBA
  104. #else
  105. #define sge_MapRGBA(fmt, r, g, b, a) SDL_MapRGB(fmt, r, g, b)
  106. #define sge_GetRGBA(pixel, fmt, r, g, b, a) SDL_GetRGBA(pixel, fmt, r, g, b)
  107. #endif
  108. /*
  109. * Some compilers use a special export keyword
  110. * Thanks to Seung Chan Lim (limsc@maya.com or slim@djslim.com) to pointing this out
  111. * (From SDL)
  112. */
  113. #ifndef DECLSPEC
  114. #ifdef __BEOS__
  115. #if defined(__GNUC__)
  116. #define DECLSPEC __declspec(dllexport)
  117. #else
  118. #define DECLSPEC __declspec(export)
  119. #endif
  120. #else
  121. #ifdef WIN32
  122. #define DECLSPEC __declspec(dllexport)
  123. #else
  124. #define DECLSPEC
  125. #endif
  126. #endif
  127. #endif
  128. #endif /* sge_internal_H */