GdiPlusRegion.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:15k
源码类别:

模拟服务器

开发平台:

C/C++

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