FLib_Macro.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef __FOO_FLIB_MACRO_H__
  2. #define __FOO_FLIB_MACRO_H__
  3. #include <memory.h>
  4. #undef FALSE
  5. #undef TRUE
  6. #undef NULL
  7. #undef BI_RGB
  8. #undef BI_BITFIELDS
  9. #define FALSE 0
  10. #define TRUE 1
  11. #define NULL 0
  12. #define BI_RGB 0
  13. #define BI_BITFIELDS 3
  14. typedef struct tagRECT
  15. {
  16. long left;
  17. long top;
  18. long right;
  19. long bottom;
  20. } RECT;
  21. typedef struct tagPOINT
  22. {
  23. long x;
  24. long y;
  25. } POINT;
  26. typedef struct tagSIZE
  27. {
  28. long cx;
  29. long cy;
  30. } SIZE;
  31. #ifndef PCL_3RD_LIBRARY_USE_FREEIMAGE
  32. typedef unsigned char BYTE;
  33. typedef unsigned short WORD;
  34. typedef unsigned long DWORD;
  35. typedef struct tagRGBQUAD
  36. {
  37. BYTE rgbBlue;
  38. BYTE rgbGreen;
  39. BYTE rgbRed;
  40. BYTE rgbReserved;
  41. } RGBQUAD;
  42. typedef struct tagBITMAPINFOHEADER
  43. {
  44. DWORD biSize;
  45. long biWidth;
  46. long biHeight;
  47. WORD biPlanes;
  48. WORD biBitCount;
  49. DWORD biCompression;
  50. DWORD biSizeImage;
  51. long biXPelsPerMeter;
  52. long biYPelsPerMeter;
  53. DWORD biClrUsed;
  54. DWORD biClrImportant;
  55. } BITMAPINFOHEADER ;
  56. #endif // PCL_3RD_LIBRARY_USE_FREEIMAGE
  57. //============================================================================
  58. inline bool IsRectEmpty (const RECT* pRC)
  59. {
  60. if (pRC) {
  61. return ((pRC->right <= pRC->left) || (pRC->bottom <= pRC->top)) ;
  62. }
  63. return true ;
  64. }
  65. inline bool PtInRect (const RECT* pRC, const POINT& pt)
  66. {
  67. return pRC && (pt.x >= pRC->left) && (pt.x < pRC->right) &&
  68. (pt.y >= pRC->top) && (pt.y < pRC->bottom) ;
  69. }
  70. inline void SetRect (RECT* pRC, int xLeft, int yTop, int xRight, int yBottom)
  71. {
  72. if (pRC) {
  73. pRC->left=xLeft ; pRC->top=yTop ; pRC->right=xRight ; pRC->bottom=yBottom ;
  74. }
  75. }
  76. inline void OffsetRect (RECT* pRC, int dx, int dy)
  77. {
  78. if (pRC) {
  79. pRC->left+=dx ; pRC->top+=dy ; pRC->right+=dx ; pRC->bottom+=dy ;
  80. }
  81. }
  82. inline void InflateRect (RECT* pRC, int dx, int dy) {
  83. if (pRC) {
  84. pRC->left-=dx ; pRC->top-=dy ; pRC->right+=dx ; pRC->bottom+=dy ;
  85. }
  86. }
  87. inline void UnionRect (RECT* pDst, const RECT* pSrc1, const RECT* pSrc2)
  88. {
  89. if (pDst && pSrc1 && pSrc2)
  90. {
  91. pDst->left = FMin (pSrc1->left, pSrc2->left) ;
  92. pDst->top = FMin (pSrc1->top, pSrc2->top) ;
  93. pDst->right = FMax (pSrc1->right, pSrc2->right) ;
  94. pDst->bottom = FMax (pSrc1->bottom, pSrc2->bottom) ;
  95. if (IsRectEmpty(pDst))
  96. memset (pDst, 0, sizeof(RECT)) ; // set rect empty
  97. }
  98. }
  99. inline bool IntersectRect (RECT* pDst, const RECT* pSrc1, const RECT* pSrc2)
  100. {
  101. if (pDst && pSrc1 && pSrc2)
  102. {
  103. pDst->left = FMax (pSrc1->left, pSrc2->left) ;
  104. pDst->top = FMax (pSrc1->top, pSrc2->top) ;
  105. pDst->right = FMin (pSrc1->right, pSrc2->right) ;
  106. pDst->bottom = FMin (pSrc1->bottom, pSrc2->bottom) ;
  107. if (IsRectEmpty(pDst))
  108. {
  109. memset (pDst, 0, sizeof(RECT)) ; // set rect empty
  110. return false ;
  111. }
  112. return true ;
  113. }
  114. return false ;
  115. }
  116. //============================================================================
  117. #endif