GdiPlusRegion.h
上传用户:jinlangri
上传日期:2022-07-17
资源大小:10774k
文件大小:13k
源码类别:

GDI/图象编程

开发平台:

Visual C++

  1. /**************************************************************************
  2. *
  3. * Copyright (c) 1998-2000, Microsoft Corp.  All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. *   GdiplusRegion.h
  8. *
  9. * Abstract:
  10. *
  11. *   Region API related declarations
  12. *
  13. **************************************************************************/
  14. #ifndef _GDIPLUSREGION_H
  15. #define _GDIPLUSREGION_H
  16. /**
  17.  * Construct a new region object
  18.  */
  19. inline 
  20. Region::Region()
  21. {
  22.     GpRegion *region = NULL;
  23.     lastResult = DllExports::GdipCreateRegion(&region);
  24.     SetNativeRegion(region);
  25. }
  26. inline 
  27. Region::Region(IN const RectF& rect)
  28. {
  29.     GpRegion *region = NULL;
  30.     lastResult = DllExports::GdipCreateRegionRect(&rect, &region);
  31.     SetNativeRegion(region);
  32. }
  33. inline 
  34. Region::Region(IN const Rect& rect)
  35. {
  36.     GpRegion *region = NULL;
  37.     lastResult = DllExports::GdipCreateRegionRectI(&rect, &region);
  38.     SetNativeRegion(region);
  39. }
  40. inline 
  41. Region::Region(IN const GraphicsPath* path)
  42. {
  43.     GpRegion *region = NULL;
  44.     lastResult = DllExports::GdipCreateRegionPath(path->nativePath, &region);
  45.     SetNativeRegion(region);
  46. }
  47. inline 
  48. Region::Region(IN const BYTE* regionData, IN INT size)
  49. {
  50.     GpRegion *region = NULL;
  51.     lastResult = DllExports::GdipCreateRegionRgnData(regionData, size, &region);
  52.     SetNativeRegion(region);
  53. }
  54. inline 
  55. Region::Region(IN HRGN hRgn)
  56. {
  57.     GpRegion *region = NULL;
  58.     lastResult = DllExports::GdipCreateRegionHrgn(hRgn, &region);
  59.     SetNativeRegion(region);
  60. }
  61. inline 
  62. Region* Region::FromHRGN(IN HRGN hRgn)
  63. {
  64.     GpRegion *region = NULL;
  65.     if (DllExports::GdipCreateRegionHrgn(hRgn, &region) == Ok)
  66.     {
  67.         Region* newRegion = new Region(region);
  68.         if (newRegion == NULL) 
  69.         {
  70.             DllExports::GdipDeleteRegion(region);
  71.         }
  72.         return newRegion;
  73.     }
  74.     else
  75.         return NULL;
  76. }
  77. inline 
  78. Region::~Region()
  79. {
  80.     DllExports::GdipDeleteRegion(nativeRegion);
  81. }
  82. /**
  83.  * Make a copy of the region object
  84.  */
  85. inline Region* 
  86. Region::Clone() const
  87. {
  88.     GpRegion *region = NULL;
  89.     SetStatus(DllExports::GdipCloneRegion(nativeRegion, &region));
  90.     return new Region(region);
  91. }
  92. inline Status 
  93. Region::MakeInfinite()
  94. {
  95.     return SetStatus(DllExports::GdipSetInfinite(nativeRegion));
  96. }
  97. inline Status 
  98. Region::MakeEmpty()
  99. {
  100.     return SetStatus(DllExports::GdipSetEmpty(nativeRegion));
  101. }
  102. /**
  103.  * Region operations
  104.  */
  105. inline Status 
  106. Region::Intersect(IN const RectF& rect)
  107. {
  108.     return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeIntersect));
  109. }
  110. inline Status 
  111. Region::Intersect(IN const Rect& rect)
  112. {
  113.     return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeIntersect));
  114. }
  115. inline Status 
  116. Region::Intersect(IN const GraphicsPath* path)
  117. {
  118.     return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path->nativePath, CombineModeIntersect));
  119. }
  120. inline Status 
  121. Region::Intersect(IN const Region* region)
  122. {
  123.     return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion, region->nativeRegion, CombineModeIntersect));
  124. }
  125. inline Status 
  126. Region::Union(IN const RectF& rect)
  127. {
  128.     return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeUnion));
  129. }
  130. inline Status 
  131. Region::Union(IN const Rect& rect)
  132. {
  133.     return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeUnion));
  134. }
  135. inline Status 
  136. Region::Union(IN const GraphicsPath* path)
  137. {
  138.     return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path->nativePath, CombineModeUnion));
  139. }
  140. inline Status 
  141. Region::Union(IN const Region* region)
  142. {
  143.     return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion, region->nativeRegion, CombineModeUnion));
  144. }
  145. inline Status 
  146. Region::Xor(IN const RectF& rect)
  147. {
  148.     return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeXor));
  149. }
  150. inline Status 
  151. Region::Xor(IN const Rect& rect)
  152. {
  153.     return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeXor));
  154. }
  155. inline Status 
  156. Region::Xor(IN const GraphicsPath* path)
  157. {
  158.     return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path->nativePath, CombineModeXor));
  159. }
  160. inline Status 
  161. Region::Xor(IN const Region* region)
  162. {
  163.     return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion, region->nativeRegion, CombineModeXor));
  164. }
  165. inline Status 
  166. Region::Exclude(IN const RectF& rect)
  167. {
  168.     return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeExclude));
  169. }
  170. inline Status 
  171. Region::Exclude(IN const Rect& rect)
  172. {
  173.      return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeExclude));
  174. }
  175. inline Status 
  176. Region::Exclude(IN const GraphicsPath* path)
  177. {
  178.     return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path->nativePath, CombineModeExclude));
  179. }
  180. inline Status
  181. Region::Exclude(IN const Region* region)
  182. {
  183.     return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion,
  184.                                                region->nativeRegion, CombineModeExclude));
  185. }
  186. inline Status 
  187. Region::Complement(IN const RectF& rect)
  188. {
  189.     return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeComplement));
  190. }
  191. inline Status 
  192. Region::Complement(IN const Rect& rect)
  193. {
  194.     return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeComplement));
  195. }
  196. inline Status 
  197. Region::Complement(IN const GraphicsPath* path)
  198. {
  199.     return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion,
  200.                                                 path->nativePath, CombineModeComplement));
  201. }
  202. inline Status 
  203. Region::Complement(IN const Region* region)
  204. {
  205.     return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion,
  206.                                                   region->nativeRegion, CombineModeComplement));
  207. }
  208. /**
  209.  * Transform operations
  210.  */
  211. inline Status 
  212. Region::Translate(IN REAL dx, 
  213.                   IN REAL dy)
  214. {
  215.     return SetStatus(DllExports::GdipTranslateRegion(nativeRegion, dx, dy));
  216. }
  217. inline Status 
  218. Region::Translate(IN INT dx, 
  219.                   IN INT dy)
  220. {
  221.     return SetStatus(DllExports::GdipTranslateRegionI(nativeRegion, dx, dy));
  222. }
  223. inline Status 
  224. Region::Transform(IN const Matrix* matrix)
  225. {
  226.     return SetStatus(DllExports::GdipTransformRegion(nativeRegion, matrix->nativeMatrix));
  227. }
  228. /**
  229.  * Get region attributes
  230.  */
  231. inline Status 
  232. Region::GetBounds(OUT RectF* rect,
  233.                   IN const Graphics* g) const
  234. {
  235.     return SetStatus(DllExports::GdipGetRegionBounds(nativeRegion,
  236.                                                 g->nativeGraphics,
  237.                                                 rect));
  238. }
  239. inline Status 
  240. Region::GetBounds(OUT Rect* rect,
  241.                   IN const Graphics* g) const
  242. {
  243.     return SetStatus(DllExports::GdipGetRegionBoundsI(nativeRegion,
  244.                                                 g->nativeGraphics,
  245.                                                 rect));
  246. }
  247. inline HRGN
  248. Region::GetHRGN(IN const Graphics* g) const
  249. {
  250.     HRGN hrgn;
  251.     SetStatus(DllExports::GdipGetRegionHRgn(nativeRegion,
  252.                                             g->nativeGraphics,
  253.                                             &hrgn));
  254.     return hrgn;
  255. }
  256. inline BOOL 
  257. Region::IsEmpty(IN const Graphics *g) const
  258. {
  259.     BOOL booln = FALSE;
  260.    
  261.     SetStatus(DllExports::GdipIsEmptyRegion(nativeRegion,
  262.                                             g->nativeGraphics,
  263.                                             &booln));
  264.     return booln;
  265. }
  266. inline BOOL 
  267. Region::IsInfinite(IN const Graphics *g) const
  268. {
  269.     BOOL booln = FALSE;
  270.     SetStatus(DllExports::GdipIsInfiniteRegion(nativeRegion,
  271.                                                  g->nativeGraphics,
  272.                                                  &booln));
  273.     return booln;
  274. }
  275. inline BOOL 
  276. Region::Equals(IN const Region* region, 
  277.                IN const Graphics* g) const
  278. {
  279.     BOOL booln = FALSE;
  280.     SetStatus(DllExports::GdipIsEqualRegion(nativeRegion,
  281.                                               region->nativeRegion,
  282.                                               g->nativeGraphics,
  283.                                               &booln));
  284.     return booln;
  285. }
  286. // Get the size of the buffer needed for the GetData method
  287. inline UINT 
  288. Region::GetDataSize() const
  289. {
  290.     UINT     bufferSize = 0;
  291.     
  292.     SetStatus(DllExports::GdipGetRegionDataSize(nativeRegion, &bufferSize));
  293.     
  294.     return bufferSize;
  295. }
  296. // buffer     - where to put the data
  297. // bufferSize - how big the buffer is (should be at least as big as GetDataSize())
  298. // sizeFilled - if not NULL, this is an OUT param that says how many bytes
  299. //              of data were written to the buffer.
  300. inline Status 
  301. Region::GetData(OUT BYTE* buffer, 
  302.                 IN UINT bufferSize, 
  303.                 OUT UINT* sizeFilled) const
  304. {
  305.     return SetStatus(DllExports::GdipGetRegionData(nativeRegion, buffer, bufferSize, sizeFilled));
  306. }
  307. /**
  308.  * Hit testing operations
  309.  */
  310. inline BOOL 
  311. Region::IsVisible(IN const PointF& point, 
  312.                   IN const Graphics* g) const
  313. {
  314.     BOOL booln = FALSE;
  315.     SetStatus(DllExports::GdipIsVisibleRegionPoint(nativeRegion,
  316.                                      point.X, point.Y, 
  317.                                      (g == NULL) ? NULL : g->nativeGraphics,
  318.                                      &booln));
  319.     return booln;
  320. }
  321. inline BOOL 
  322. Region::IsVisible(IN const RectF& rect, 
  323.                   IN const Graphics* g) const
  324. {
  325.     BOOL booln = FALSE;
  326.     SetStatus(DllExports::GdipIsVisibleRegionRect(nativeRegion, rect.X,
  327.                                                     rect.Y, rect.Width,
  328.                                                     rect.Height,
  329.                                                     (g == NULL) ? NULL : g->nativeGraphics,
  330.                                                     &booln));
  331.     return booln;
  332. }
  333. inline BOOL 
  334. Region::IsVisible(IN const Point& point, 
  335.                   IN const Graphics* g) const
  336. {
  337.     BOOL booln = FALSE;
  338.     SetStatus(DllExports::GdipIsVisibleRegionPointI(nativeRegion,
  339.                                                    point.X,
  340.                                                    point.Y,
  341.                                                    (g == NULL) ? NULL : g->nativeGraphics,
  342.                                                    &booln));
  343.     return booln;
  344. }
  345. inline BOOL 
  346. Region::IsVisible(IN const Rect& rect, 
  347.                   IN const Graphics* g) const
  348. {
  349.     BOOL booln = FALSE;
  350.     SetStatus(DllExports::GdipIsVisibleRegionRectI(nativeRegion,
  351.                                                   rect.X,
  352.                                                   rect.Y,
  353.                                                   rect.Width,
  354.                                                   rect.Height,
  355.                                                   (g == NULL) ? NULL : g->nativeGraphics,
  356.                                                   &booln));
  357.     return booln;
  358. }
  359. inline UINT 
  360. Region::GetRegionScansCount(IN const Matrix* matrix) const
  361. {
  362.     UINT count = 0;
  363.     SetStatus(DllExports::GdipGetRegionScansCount(nativeRegion,
  364.                                                   &count,
  365.                                                   matrix->nativeMatrix));
  366.     return count;
  367. }
  368. inline Status 
  369. Region::GetRegionScans(
  370.     IN const Matrix* matrix,
  371.     OUT RectF* rects,
  372.     IN OUT INT* count) const
  373. {
  374.     return SetStatus(DllExports::GdipGetRegionScans(nativeRegion,
  375.                                           rects,
  376.                                           count,
  377.                                           matrix->nativeMatrix));
  378. }
  379. // If rects is NULL, return the count of rects in the region.
  380. // Otherwise, assume rects is big enough to hold all the region rects
  381. // and fill them in and return the number of rects filled in.
  382. // The rects are returned in the units specified by the matrix
  383. // (which is typically a world-to-device transform).
  384. // Note that the number of rects returned can vary, depending on the
  385. // matrix that is used.
  386. inline Status 
  387. Region::GetRegionScans(
  388.     IN const Matrix* matrix,
  389.     OUT Rect* rects,       // NULL to just get the count
  390.     IN OUT INT* count) const
  391. {
  392.     return SetStatus(DllExports::GdipGetRegionScansI(nativeRegion,
  393.                                           rects,
  394.                                           count,
  395.                                           matrix->nativeMatrix));
  396. }
  397. // protected method
  398. inline Region::Region(GpRegion* nativeRegion)
  399. {
  400.     SetNativeRegion(nativeRegion);
  401. }
  402. // protected method
  403. inline VOID Region::SetNativeRegion(GpRegion* nativeRegion)
  404. {
  405.     this->nativeRegion = nativeRegion;
  406. }
  407. inline Status Region::GetLastStatus() const
  408. {
  409.     Status lastStatus = lastResult;
  410.     lastResult = Ok;
  411.     return lastStatus;
  412. }
  413. #endif // !_GDIPLUSREGION_H