Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

GdiplusRegion.h 13 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. SetStatus(DllExports::GdipIsEmptyRegion(nativeRegion,
  261. g->nativeGraphics,
  262. &booln));
  263. return booln;
  264. }
  265. inline BOOL
  266. Region::IsInfinite(IN const Graphics *g) const
  267. {
  268. BOOL booln = FALSE;
  269. SetStatus(DllExports::GdipIsInfiniteRegion(nativeRegion,
  270. g->nativeGraphics,
  271. &booln));
  272. return booln;
  273. }
  274. inline BOOL
  275. Region::Equals(IN const Region* region,
  276. IN const Graphics* g) const
  277. {
  278. BOOL booln = FALSE;
  279. SetStatus(DllExports::GdipIsEqualRegion(nativeRegion,
  280. region->nativeRegion,
  281. g->nativeGraphics,
  282. &booln));
  283. return booln;
  284. }
  285. // Get the size of the buffer needed for the GetData method
  286. inline UINT
  287. Region::GetDataSize() const
  288. {
  289. UINT bufferSize = 0;
  290. SetStatus(DllExports::GdipGetRegionDataSize(nativeRegion, &bufferSize));
  291. return bufferSize;
  292. }
  293. // buffer - where to put the data
  294. // bufferSize - how big the buffer is (should be at least as big as GetDataSize())
  295. // sizeFilled - if not NULL, this is an OUT param that says how many bytes
  296. // of data were written to the buffer.
  297. inline Status
  298. Region::GetData(OUT BYTE* buffer,
  299. IN UINT bufferSize,
  300. OUT UINT* sizeFilled) const
  301. {
  302. return SetStatus(DllExports::GdipGetRegionData(nativeRegion, buffer, bufferSize, sizeFilled));
  303. }
  304. /**
  305. * Hit testing operations
  306. */
  307. inline BOOL
  308. Region::IsVisible(IN const PointF& point,
  309. IN const Graphics* g) const
  310. {
  311. BOOL booln = FALSE;
  312. SetStatus(DllExports::GdipIsVisibleRegionPoint(nativeRegion,
  313. point.X, point.Y,
  314. (g == NULL) ? NULL : g->nativeGraphics,
  315. &booln));
  316. return booln;
  317. }
  318. inline BOOL
  319. Region::IsVisible(IN const RectF& rect,
  320. IN const Graphics* g) const
  321. {
  322. BOOL booln = FALSE;
  323. SetStatus(DllExports::GdipIsVisibleRegionRect(nativeRegion, rect.X,
  324. rect.Y, rect.Width,
  325. rect.Height,
  326. (g == NULL) ? NULL : g->nativeGraphics,
  327. &booln));
  328. return booln;
  329. }
  330. inline BOOL
  331. Region::IsVisible(IN const Point& point,
  332. IN const Graphics* g) const
  333. {
  334. BOOL booln = FALSE;
  335. SetStatus(DllExports::GdipIsVisibleRegionPointI(nativeRegion,
  336. point.X,
  337. point.Y,
  338. (g == NULL) ? NULL : g->nativeGraphics,
  339. &booln));
  340. return booln;
  341. }
  342. inline BOOL
  343. Region::IsVisible(IN const Rect& rect,
  344. IN const Graphics* g) const
  345. {
  346. BOOL booln = FALSE;
  347. SetStatus(DllExports::GdipIsVisibleRegionRectI(nativeRegion,
  348. rect.X,
  349. rect.Y,
  350. rect.Width,
  351. rect.Height,
  352. (g == NULL) ? NULL : g->nativeGraphics,
  353. &booln));
  354. return booln;
  355. }
  356. inline UINT
  357. Region::GetRegionScansCount(IN const Matrix* matrix) const
  358. {
  359. UINT count = 0;
  360. SetStatus(DllExports::GdipGetRegionScansCount(nativeRegion,
  361. &count,
  362. matrix->nativeMatrix));
  363. return count;
  364. }
  365. inline Status
  366. Region::GetRegionScans(
  367. IN const Matrix* matrix,
  368. OUT RectF* rects,
  369. IN OUT INT* count) const
  370. {
  371. return SetStatus(DllExports::GdipGetRegionScans(nativeRegion,
  372. rects,
  373. count,
  374. matrix->nativeMatrix));
  375. }
  376. // If rects is NULL, return the count of rects in the region.
  377. // Otherwise, assume rects is big enough to hold all the region rects
  378. // and fill them in and return the number of rects filled in.
  379. // The rects are returned in the units specified by the matrix
  380. // (which is typically a world-to-device transform).
  381. // Note that the number of rects returned can vary, depending on the
  382. // matrix that is used.
  383. inline Status
  384. Region::GetRegionScans(
  385. IN const Matrix* matrix,
  386. OUT Rect* rects, // NULL to just get the count
  387. IN OUT INT* count) const
  388. {
  389. return SetStatus(DllExports::GdipGetRegionScansI(nativeRegion,
  390. rects,
  391. count,
  392. matrix->nativeMatrix));
  393. }
  394. // protected method
  395. inline Region::Region(GpRegion* nativeRegion)
  396. {
  397. SetNativeRegion(nativeRegion);
  398. }
  399. // protected method
  400. inline VOID Region::SetNativeRegion(GpRegion* nativeRegion)
  401. {
  402. this->nativeRegion = nativeRegion;
  403. }
  404. inline Status Region::GetLastStatus() const
  405. {
  406. Status lastStatus = lastResult;
  407. lastResult = Ok;
  408. return lastStatus;
  409. }
  410. #endif // !_GDIPLUSREGION_H