fillRegion.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "main.h"
  2. #include "./fillRegion.h"
  3. static BOOL
  4. FillRegion_TempRegionFromRect(FillRegion *region, const RECT *rect)
  5. {
  6. if (NULL == region || NULL == rect)
  7. return FALSE;
  8. if (NULL == region->tmp)
  9. {
  10. region->tmp = CreateRectRgn(rect->left, rect->top, rect->right, rect->bottom);
  11. if (NULL == region->tmp)
  12. return FALSE;
  13. }
  14. else
  15. {
  16. if (FALSE == SetRectRgn(region->tmp, rect->left, rect->top, rect->right, rect->bottom))
  17. return FALSE;
  18. }
  19. return TRUE;
  20. }
  21. BOOL
  22. FillRegion_Init(FillRegion *region, const RECT *rect)
  23. {
  24. if (NULL == region)
  25. return FALSE;
  26. region->fill = (NULL != rect) ?
  27. CreateRectRgn(rect->left, rect->top, rect->right, rect->bottom) :
  28. NULL;
  29. region->tmp = NULL;
  30. if (NULL == region->fill)
  31. return FALSE;
  32. return TRUE;
  33. }
  34. void
  35. FillRegion_Uninit(FillRegion *region)
  36. {
  37. if (NULL != region)
  38. {
  39. if (NULL != region->fill)
  40. {
  41. DeleteObject(region->fill);
  42. region->fill = NULL;
  43. }
  44. if (NULL != region->tmp)
  45. {
  46. DeleteObject(region->tmp);
  47. region->tmp = NULL;
  48. }
  49. }
  50. }
  51. BOOL
  52. FillRegion_ExcludeRect(FillRegion *region, const RECT *rect)
  53. {
  54. if (NULL == region || NULL == rect)
  55. return FALSE;
  56. return (FALSE != FillRegion_TempRegionFromRect(region, rect) &&
  57. ERROR != CombineRgn(region->fill, region->fill, region->tmp, RGN_DIFF));
  58. }
  59. BOOL
  60. FillRegion_ExcludeRgn(FillRegion *region, HRGN rgn)
  61. {
  62. if (NULL == region || NULL == rgn)
  63. return FALSE;
  64. return (ERROR != CombineRgn(region->fill, region->fill, rgn, RGN_DIFF));
  65. }
  66. BOOL
  67. FillRegion_AppendRect(FillRegion *region, const RECT *rect)
  68. {
  69. if (NULL == region || NULL == rect)
  70. return FALSE;
  71. return (FALSE != FillRegion_TempRegionFromRect(region, rect) &&
  72. ERROR != CombineRgn(region->fill, region->fill, region->tmp, RGN_OR));
  73. }
  74. BOOL
  75. FillRegion_AppendRgn(FillRegion *region, HRGN rgn)
  76. {
  77. if (NULL == region || NULL == rgn)
  78. return FALSE;
  79. return (ERROR != CombineRgn(region->fill, region->fill, rgn, RGN_OR));
  80. }
  81. BOOL
  82. FillRegion_BrushFill(FillRegion *region, HDC hdc, HBRUSH brush)
  83. {
  84. if (NULL == region)
  85. return FALSE;
  86. return FillRgn(hdc, region->fill, brush);
  87. }
  88. BOOL
  89. FillRegion_Offset(FillRegion *region, long x, long y)
  90. {
  91. if (NULL == region)
  92. return FALSE;
  93. return (ERROR != OffsetRgn(region->fill, x, y));
  94. }
  95. BOOL
  96. FillRegion_SetRect(FillRegion *region, const RECT *rect)
  97. {
  98. if (NULL == region || NULL == rect)
  99. return FALSE;
  100. return SetRectRgn(region->fill, rect->left, rect->top, rect->right, rect->bottom);
  101. }
  102. BOOL
  103. FillRegion_SetEmpty(FillRegion *region)
  104. {
  105. if (NULL == region)
  106. return FALSE;
  107. return SetRectRgn(region->fill, 0, 0, 0, 0);
  108. }