GdiPlusRegion.h 14 KB

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