GdiPlusPath.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  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. * GdiplusPath.h
  9. *
  10. * Abstract:
  11. *
  12. * GDI+ Graphics Path class
  13. *
  14. \**************************************************************************/
  15. #ifndef _GDIPLUSPATH_H
  16. #define _GDIPLUSPATH_H
  17. class GraphicsPath : public GdiplusBase
  18. {
  19. public:
  20. friend class Graphics;
  21. friend class Region;
  22. friend class PathGradientBrush;
  23. friend class GraphicsPathIterator;
  24. friend class CustomLineCap;
  25. GraphicsPath(IN FillMode fillMode = FillModeAlternate)
  26. {
  27. nativePath = NULL;
  28. lastResult = DllExports::GdipCreatePath(fillMode, &nativePath);
  29. }
  30. GraphicsPath(IN const PointF* points,
  31. IN const BYTE* types,
  32. IN INT count,
  33. IN FillMode fillMode = FillModeAlternate)
  34. {
  35. nativePath = NULL;
  36. lastResult = DllExports::GdipCreatePath2(points,
  37. types,
  38. count,
  39. fillMode,
  40. &nativePath);
  41. }
  42. GraphicsPath(IN const PointI* points,
  43. IN const BYTE* types,
  44. IN INT count,
  45. IN FillMode fillMode = FillModeAlternate)
  46. {
  47. nativePath = NULL;
  48. lastResult = DllExports::GdipCreatePath2I(points,
  49. types,
  50. count,
  51. fillMode,
  52. &nativePath);
  53. }
  54. ~GraphicsPath()
  55. {
  56. DllExports::GdipDeletePath(nativePath);
  57. }
  58. GraphicsPath* Clone() const
  59. {
  60. GpPath *clonepath = NULL;
  61. SetStatus(DllExports::GdipClonePath(nativePath, &clonepath));
  62. return new GraphicsPath(clonepath);
  63. }
  64. // Reset the path object to empty (and fill mode to FillModeAlternate)
  65. Status Reset()
  66. {
  67. return SetStatus(DllExports::GdipResetPath(nativePath));
  68. }
  69. FillMode GetFillMode() const
  70. {
  71. FillMode fillmode = FillModeAlternate;
  72. SetStatus(DllExports::GdipGetPathFillMode(nativePath, &fillmode));
  73. return fillmode;
  74. }
  75. Status SetFillMode(IN FillMode fillmode)
  76. {
  77. return SetStatus(DllExports::GdipSetPathFillMode(nativePath,
  78. fillmode));
  79. }
  80. Status GetPathData(OUT PathData* pathData) const
  81. {
  82. if (pathData == NULL)
  83. {
  84. return SetStatus(InvalidParameter);
  85. }
  86. INT count = GetPointCount();
  87. if ((count <= 0) || (pathData->Count>0 && pathData->Count<count))
  88. {
  89. pathData->Count = 0;
  90. if (pathData->Points)
  91. {
  92. delete pathData->Points;
  93. pathData->Points = NULL;
  94. }
  95. if (pathData->Types)
  96. {
  97. delete pathData->Types;
  98. pathData->Types = NULL;
  99. }
  100. if (count <= 0)
  101. {
  102. return lastResult;
  103. }
  104. }
  105. if (pathData->Count == 0)
  106. {
  107. pathData->Points = new PointF[count];
  108. if (pathData->Points == NULL)
  109. {
  110. return SetStatus(OutOfMemory);
  111. }
  112. pathData->Types = new byte[count];
  113. if (pathData->Types == NULL)
  114. {
  115. delete pathData->Points;
  116. pathData->Points = NULL;
  117. return SetStatus(OutOfMemory);
  118. }
  119. pathData->Count = count;
  120. }
  121. return SetStatus(DllExports::GdipGetPathData(nativePath, pathData));
  122. }
  123. Status StartFigure()
  124. {
  125. return SetStatus(DllExports::GdipStartPathFigure(nativePath));
  126. }
  127. Status CloseFigure()
  128. {
  129. return SetStatus(DllExports::GdipClosePathFigure(nativePath));
  130. }
  131. Status CloseAllFigures()
  132. {
  133. return SetStatus(DllExports::GdipClosePathFigures(nativePath));
  134. }
  135. Status SetMarker()
  136. {
  137. return SetStatus(DllExports::GdipSetPathMarker(nativePath));
  138. }
  139. Status ClearMarkers()
  140. {
  141. return SetStatus(DllExports::GdipClearPathMarkers(nativePath));
  142. }
  143. Status Reverse()
  144. {
  145. return SetStatus(DllExports::GdipReversePath(nativePath));
  146. }
  147. Status GetLastPoint(OUT PointF* lastPoint) const
  148. {
  149. return SetStatus(DllExports::GdipGetPathLastPoint(nativePath,
  150. lastPoint));
  151. }
  152. Status AddLine(IN const PointF& pt1,
  153. IN const PointF& pt2)
  154. {
  155. return AddLine(pt1.X, pt1.Y, pt2.X, pt2.Y);
  156. }
  157. Status AddLine(IN REAL x1,
  158. IN REAL y1,
  159. IN REAL x2,
  160. IN REAL y2)
  161. {
  162. return SetStatus(DllExports::GdipAddPathLine(nativePath, x1, y1,
  163. x2, y2));
  164. }
  165. Status AddLines(IN const PointF* points,
  166. IN INT count)
  167. {
  168. return SetStatus(DllExports::GdipAddPathLine2(nativePath, points,
  169. count));
  170. }
  171. Status AddLine(IN const PointI& pt1,
  172. IN const PointI& pt2)
  173. {
  174. return AddLine(pt1.X,
  175. pt1.Y,
  176. pt2.X,
  177. pt2.Y);
  178. }
  179. Status AddLine(IN INT x1,
  180. IN INT y1,
  181. IN INT x2,
  182. IN INT y2)
  183. {
  184. return SetStatus(DllExports::GdipAddPathLineI(nativePath,
  185. x1,
  186. y1,
  187. x2,
  188. y2));
  189. }
  190. Status AddLines(IN const PointI* points,
  191. IN INT count)
  192. {
  193. return SetStatus(DllExports::GdipAddPathLine2I(nativePath,
  194. points,
  195. count));
  196. }
  197. Status AddArc(IN const RectF& rect,
  198. IN REAL startAngle,
  199. IN REAL sweepAngle)
  200. {
  201. return AddArc(rect.X, rect.Y, rect.Width, rect.Height,
  202. startAngle, sweepAngle);
  203. }
  204. Status AddArc(IN REAL x,
  205. IN REAL y,
  206. IN REAL width,
  207. IN REAL height,
  208. IN REAL startAngle,
  209. IN REAL sweepAngle)
  210. {
  211. return SetStatus(DllExports::GdipAddPathArc(nativePath, x, y, width,
  212. height, startAngle,
  213. sweepAngle));
  214. }
  215. Status AddArc(IN const Rect& rect,
  216. IN REAL startAngle,
  217. IN REAL sweepAngle)
  218. {
  219. return AddArc(rect.X, rect.Y, rect.Width, rect.Height,
  220. startAngle, sweepAngle);
  221. }
  222. Status AddArc(IN INT x,
  223. IN INT y,
  224. IN INT width,
  225. IN INT height,
  226. IN REAL startAngle,
  227. IN REAL sweepAngle)
  228. {
  229. return SetStatus(DllExports::GdipAddPathArcI(nativePath,
  230. x,
  231. y,
  232. width,
  233. height,
  234. startAngle,
  235. sweepAngle));
  236. }
  237. Status AddBezier(IN const PointF& pt1,
  238. IN const PointF& pt2,
  239. IN const PointF& pt3,
  240. IN const PointF& pt4)
  241. {
  242. return AddBezier(pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X,
  243. pt4.Y);
  244. }
  245. Status AddBezier(IN REAL x1,
  246. IN REAL y1,
  247. IN REAL x2,
  248. IN REAL y2,
  249. IN REAL x3,
  250. IN REAL y3,
  251. IN REAL x4,
  252. IN REAL y4)
  253. {
  254. return SetStatus(DllExports::GdipAddPathBezier(nativePath, x1, y1, x2,
  255. y2, x3, y3, x4, y4));
  256. }
  257. Status AddBeziers(IN const PointF* points,
  258. IN INT count)
  259. {
  260. return SetStatus(DllExports::GdipAddPathBeziers(nativePath, points,
  261. count));
  262. }
  263. Status AddBezier(IN const PointI& pt1,
  264. IN const PointI& pt2,
  265. IN const PointI& pt3,
  266. IN const PointI& pt4)
  267. {
  268. return AddBezier(pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X,
  269. pt4.Y);
  270. }
  271. Status AddBezier(IN INT x1,
  272. IN INT y1,
  273. IN INT x2,
  274. IN INT y2,
  275. IN INT x3,
  276. IN INT y3,
  277. IN INT x4,
  278. IN INT y4)
  279. {
  280. return SetStatus(DllExports::GdipAddPathBezierI(nativePath,
  281. x1,
  282. y1,
  283. x2,
  284. y2,
  285. x3,
  286. y3,
  287. x4,
  288. y4));
  289. }
  290. Status AddBeziers(IN const PointI* points,
  291. IN INT count)
  292. {
  293. return SetStatus(DllExports::GdipAddPathBeziersI(nativePath,
  294. points,
  295. count));
  296. }
  297. Status AddCurve(IN const PointF* points,
  298. IN INT count)
  299. {
  300. return SetStatus(DllExports::GdipAddPathCurve(nativePath,
  301. points,
  302. count));
  303. }
  304. Status AddCurve(IN const PointF* points,
  305. IN INT count,
  306. IN REAL tension)
  307. {
  308. return SetStatus(DllExports::GdipAddPathCurve2(nativePath,
  309. points,
  310. count,
  311. tension));
  312. }
  313. Status AddCurve(IN const PointF* points,
  314. IN INT count,
  315. IN INT offset,
  316. IN INT numberOfSegments,
  317. IN REAL tension)
  318. {
  319. return SetStatus(DllExports::GdipAddPathCurve3(nativePath,
  320. points,
  321. count,
  322. offset,
  323. numberOfSegments,
  324. tension));
  325. }
  326. Status AddCurve(IN const PointI* points,
  327. IN INT count)
  328. {
  329. return SetStatus(DllExports::GdipAddPathCurveI(nativePath,
  330. points,
  331. count));
  332. }
  333. Status AddCurve(IN const PointI* points,
  334. IN INT count,
  335. IN REAL tension)
  336. {
  337. return SetStatus(DllExports::GdipAddPathCurve2I(nativePath,
  338. points,
  339. count,
  340. tension));
  341. }
  342. Status AddCurve(IN const PointI* points,
  343. IN INT count,
  344. IN INT offset,
  345. IN INT numberOfSegments,
  346. IN REAL tension)
  347. {
  348. return SetStatus(DllExports::GdipAddPathCurve3I(nativePath,
  349. points,
  350. count,
  351. offset,
  352. numberOfSegments,
  353. tension));
  354. }
  355. Status AddClosedCurve(IN const PointF* points,
  356. IN INT count)
  357. {
  358. return SetStatus(DllExports::GdipAddPathClosedCurve(nativePath,
  359. points,
  360. count));
  361. }
  362. Status AddClosedCurve(IN const PointF* points,
  363. IN INT count,
  364. IN REAL tension)
  365. {
  366. return SetStatus(DllExports::GdipAddPathClosedCurve2(nativePath,
  367. points,
  368. count,
  369. tension));
  370. }
  371. Status AddClosedCurve(IN const PointI* points,
  372. IN INT count)
  373. {
  374. return SetStatus(DllExports::GdipAddPathClosedCurveI(nativePath,
  375. points,
  376. count));
  377. }
  378. Status AddClosedCurve(IN const PointI* points,
  379. IN INT count,
  380. IN REAL tension)
  381. {
  382. return SetStatus(DllExports::GdipAddPathClosedCurve2I(nativePath,
  383. points,
  384. count,
  385. tension));
  386. }
  387. Status AddRectangle(IN const RectF& rect)
  388. {
  389. return SetStatus(DllExports::GdipAddPathRectangle(nativePath,
  390. rect.X,
  391. rect.Y,
  392. rect.Width,
  393. rect.Height));
  394. }
  395. Status AddRectangles(IN const RectF* rects,
  396. IN INT count)
  397. {
  398. return SetStatus(DllExports::GdipAddPathRectangles(nativePath,
  399. rects,
  400. count));
  401. }
  402. Status AddRectangle(IN const Rect& rect)
  403. {
  404. return SetStatus(DllExports::GdipAddPathRectangleI(nativePath,
  405. rect.X,
  406. rect.Y,
  407. rect.Width,
  408. rect.Height));
  409. }
  410. Status AddRectangles(IN const Rect* rects, INT count)
  411. {
  412. return SetStatus(DllExports::GdipAddPathRectanglesI(nativePath,
  413. rects,
  414. count));
  415. }
  416. Status AddEllipse(IN const RectF& rect)
  417. {
  418. return AddEllipse(rect.X, rect.Y, rect.Width, rect.Height);
  419. }
  420. Status AddEllipse(IN REAL x,
  421. IN REAL y,
  422. IN REAL width,
  423. IN REAL height)
  424. {
  425. return SetStatus(DllExports::GdipAddPathEllipse(nativePath,
  426. x,
  427. y,
  428. width,
  429. height));
  430. }
  431. Status AddEllipse(IN const Rect& rect)
  432. {
  433. return AddEllipse(rect.X, rect.Y, rect.Width, rect.Height);
  434. }
  435. Status AddEllipse(IN INT x,
  436. IN INT y,
  437. IN INT width,
  438. IN INT height)
  439. {
  440. return SetStatus(DllExports::GdipAddPathEllipseI(nativePath,
  441. x,
  442. y,
  443. width,
  444. height));
  445. }
  446. Status AddPie(IN const RectF& rect,
  447. IN REAL startAngle,
  448. IN REAL sweepAngle)
  449. {
  450. return AddPie(rect.X, rect.Y, rect.Width, rect.Height, startAngle,
  451. sweepAngle);
  452. }
  453. Status AddPie(IN REAL x,
  454. IN REAL y,
  455. IN REAL width,
  456. IN REAL height,
  457. IN REAL startAngle,
  458. IN REAL sweepAngle)
  459. {
  460. return SetStatus(DllExports::GdipAddPathPie(nativePath, x, y, width,
  461. height, startAngle,
  462. sweepAngle));
  463. }
  464. Status AddPie(IN const Rect& rect,
  465. IN REAL startAngle,
  466. IN REAL sweepAngle)
  467. {
  468. return AddPie(rect.X,
  469. rect.Y,
  470. rect.Width,
  471. rect.Height,
  472. startAngle,
  473. sweepAngle);
  474. }
  475. Status AddPie(IN INT x,
  476. IN INT y,
  477. IN INT width,
  478. IN INT height,
  479. IN REAL startAngle,
  480. IN REAL sweepAngle)
  481. {
  482. return SetStatus(DllExports::GdipAddPathPieI(nativePath,
  483. x,
  484. y,
  485. width,
  486. height,
  487. startAngle,
  488. sweepAngle));
  489. }
  490. Status AddPolygon(IN const PointF* points,
  491. IN INT count)
  492. {
  493. return SetStatus(DllExports::GdipAddPathPolygon(nativePath, points,
  494. count));
  495. }
  496. Status AddPolygon(IN const PointI* points,
  497. IN INT count)
  498. {
  499. return SetStatus(DllExports::GdipAddPathPolygonI(nativePath, points,
  500. count));
  501. }
  502. Status AddPath(IN const GraphicsPath* addingPath,
  503. IN BOOL connect)
  504. {
  505. GpPath* nativePath2 = NULL;
  506. if(addingPath)
  507. nativePath2 = addingPath->nativePath;
  508. return SetStatus(DllExports::GdipAddPathPath(nativePath, nativePath2,
  509. connect));
  510. }
  511. Status AddString(
  512. IN const WCHAR *string,
  513. IN INT length,
  514. IN const FontFamily *family,
  515. IN INT style,
  516. IN REAL emSize, // World units
  517. IN const PointF &origin,
  518. IN const StringFormat *format
  519. )
  520. {
  521. RectF rect(origin.X, origin.Y, 0.0f, 0.0f);
  522. return SetStatus(DllExports::GdipAddPathString(
  523. nativePath,
  524. string,
  525. length,
  526. family ? family->nativeFamily : NULL,
  527. style,
  528. emSize,
  529. &rect,
  530. format ? format->nativeFormat : NULL
  531. ));
  532. }
  533. Status AddString(
  534. IN const WCHAR *string,
  535. IN INT length,
  536. IN const FontFamily *family,
  537. IN INT style,
  538. IN REAL emSize, // World units
  539. IN const RectF &layoutRect,
  540. IN const StringFormat *format
  541. )
  542. {
  543. return SetStatus(DllExports::GdipAddPathString(
  544. nativePath,
  545. string,
  546. length,
  547. family ? family->nativeFamily : NULL,
  548. style,
  549. emSize,
  550. &layoutRect,
  551. format ? format->nativeFormat : NULL
  552. ));
  553. }
  554. Status AddString(
  555. IN const WCHAR *string,
  556. IN INT length,
  557. IN const FontFamily *family,
  558. IN INT style,
  559. IN REAL emSize, // World units
  560. IN const PointI &origin,
  561. IN const StringFormat *format
  562. )
  563. {
  564. Rect rect(origin.X, origin.Y, 0, 0);
  565. return SetStatus(DllExports::GdipAddPathStringI(
  566. nativePath,
  567. string,
  568. length,
  569. family ? family->nativeFamily : NULL,
  570. style,
  571. emSize,
  572. &rect,
  573. format ? format->nativeFormat : NULL
  574. ));
  575. }
  576. Status AddString(
  577. IN const WCHAR *string,
  578. IN INT length,
  579. IN const FontFamily *family,
  580. IN INT style,
  581. IN REAL emSize, // World units
  582. IN const Rect &layoutRect,
  583. IN const StringFormat *format
  584. )
  585. {
  586. return SetStatus(DllExports::GdipAddPathStringI(
  587. nativePath,
  588. string,
  589. length,
  590. family ? family->nativeFamily : NULL,
  591. style,
  592. emSize,
  593. &layoutRect,
  594. format ? format->nativeFormat : NULL
  595. ));
  596. }
  597. Status Transform(IN const Matrix* matrix)
  598. {
  599. if(matrix)
  600. return SetStatus(DllExports::GdipTransformPath(nativePath,
  601. matrix->nativeMatrix));
  602. else
  603. return Ok;
  604. }
  605. // This is not always the tightest bounds.
  606. Status GetBounds(OUT RectF* bounds,
  607. IN const Matrix* matrix = NULL,
  608. IN const Pen* pen = NULL) const;
  609. Status GetBounds(OUT Rect* bounds,
  610. IN const Matrix* matrix = NULL,
  611. IN const Pen* pen = NULL) const;
  612. // Once flattened, the resultant path is made of line segments and
  613. // the original path information is lost. When matrix is NULL the
  614. // identity matrix is assumed.
  615. Status Flatten(IN const Matrix* matrix = NULL,
  616. IN REAL flatness = FlatnessDefault)
  617. {
  618. GpMatrix* nativeMatrix = NULL;
  619. if(matrix)
  620. {
  621. nativeMatrix = matrix->nativeMatrix;
  622. }
  623. return SetStatus(DllExports::GdipFlattenPath(
  624. nativePath,
  625. nativeMatrix,
  626. flatness
  627. ));
  628. }
  629. Status Widen(
  630. IN const Pen* pen,
  631. IN const Matrix* matrix = NULL,
  632. IN REAL flatness = FlatnessDefault
  633. )
  634. {
  635. GpMatrix* nativeMatrix = NULL;
  636. if(matrix)
  637. nativeMatrix = matrix->nativeMatrix;
  638. return SetStatus(DllExports::GdipWidenPath(
  639. nativePath,
  640. pen->nativePen,
  641. nativeMatrix,
  642. flatness
  643. ));
  644. }
  645. Status Outline(
  646. IN const Matrix *matrix = NULL,
  647. IN REAL flatness = FlatnessDefault
  648. )
  649. {
  650. GpMatrix* nativeMatrix = NULL;
  651. if(matrix)
  652. {
  653. nativeMatrix = matrix->nativeMatrix;
  654. }
  655. return SetStatus(DllExports::GdipWindingModeOutline(
  656. nativePath, nativeMatrix, flatness
  657. ));
  658. }
  659. // Once this is called, the resultant path is made of line segments and
  660. // the original path information is lost. When matrix is NULL, the
  661. // identity matrix is assumed.
  662. Status Warp(IN const PointF* destPoints,
  663. IN INT count,
  664. IN const RectF& srcRect,
  665. IN const Matrix* matrix = NULL,
  666. IN WarpMode warpMode = WarpModePerspective,
  667. IN REAL flatness = FlatnessDefault)
  668. {
  669. GpMatrix* nativeMatrix = NULL;
  670. if(matrix)
  671. nativeMatrix = matrix->nativeMatrix;
  672. return SetStatus(DllExports::GdipWarpPath(
  673. nativePath,
  674. nativeMatrix,
  675. destPoints,
  676. count,
  677. srcRect.X,
  678. srcRect.Y,
  679. srcRect.Width,
  680. srcRect.Height,
  681. warpMode,
  682. flatness));
  683. }
  684. INT GetPointCount() const
  685. {
  686. INT count = 0;
  687. SetStatus(DllExports::GdipGetPointCount(nativePath, &count));
  688. return count;
  689. }
  690. Status GetPathTypes(OUT BYTE* types,
  691. IN INT count) const
  692. {
  693. return SetStatus(DllExports::GdipGetPathTypes(nativePath, types,
  694. count));
  695. }
  696. Status GetPathPoints(OUT PointF* points,
  697. IN INT count) const
  698. {
  699. return SetStatus(DllExports::GdipGetPathPoints(nativePath, points,
  700. count));
  701. }
  702. Status GetPathPoints(OUT PointI* points,
  703. IN INT count) const
  704. {
  705. return SetStatus(DllExports::GdipGetPathPointsI(nativePath, points,
  706. count));
  707. }
  708. Status GetLastStatus() const
  709. {
  710. Status lastStatus = lastResult;
  711. lastResult = Ok;
  712. return lastStatus;
  713. }
  714. BOOL IsVisible(IN const PointF& point,
  715. IN const Graphics* g = NULL) const
  716. {
  717. return IsVisible(point.X, point.Y, g);
  718. }
  719. BOOL IsVisible(IN REAL x,
  720. IN REAL y,
  721. IN const Graphics* g = NULL) const;
  722. BOOL IsVisible(IN const PointI& point,
  723. IN const Graphics* g = NULL) const
  724. {
  725. return IsVisible(point.X, point.Y, g);
  726. }
  727. BOOL IsVisible(IN INT x,
  728. IN INT y,
  729. IN const Graphics* g = NULL) const;
  730. BOOL IsOutlineVisible(IN const PointF& point,
  731. IN const Pen* pen,
  732. IN const Graphics* g = NULL) const
  733. {
  734. return IsOutlineVisible(point.X, point.Y, pen, g);
  735. }
  736. BOOL IsOutlineVisible(IN REAL x,
  737. IN REAL y,
  738. IN const Pen* pen,
  739. IN const Graphics* g = NULL) const;
  740. BOOL IsOutlineVisible(IN const PointI& point,
  741. IN const Pen* pen,
  742. IN const Graphics* g = NULL) const
  743. {
  744. return IsOutlineVisible(point.X, point.Y, pen, g);
  745. }
  746. BOOL IsOutlineVisible(IN INT x,
  747. IN INT y,
  748. IN const Pen* pen,
  749. IN const Graphics* g = NULL) const;
  750. protected:
  751. GraphicsPath(const GraphicsPath& path)
  752. {
  753. GpPath *clonepath = NULL;
  754. SetStatus(DllExports::GdipClonePath(path.nativePath, &clonepath));
  755. SetNativePath(clonepath);
  756. }
  757. private:
  758. GraphicsPath& operator=(const GraphicsPath &);
  759. protected:
  760. GraphicsPath(GpPath* nativePath)
  761. {
  762. lastResult = Ok;
  763. SetNativePath(nativePath);
  764. }
  765. VOID SetNativePath(GpPath *nativePath)
  766. {
  767. this->nativePath = nativePath;
  768. }
  769. Status SetStatus(Status status) const
  770. {
  771. if (status != Ok)
  772. return (lastResult = status);
  773. else
  774. return status;
  775. }
  776. protected:
  777. GpPath* nativePath;
  778. mutable Status lastResult;
  779. };
  780. //--------------------------------------------------------------------------
  781. // GraphisPathIterator class
  782. //--------------------------------------------------------------------------
  783. class GraphicsPathIterator : public GdiplusBase
  784. {
  785. public:
  786. GraphicsPathIterator(IN const GraphicsPath* path)
  787. {
  788. GpPath* nativePath = NULL;
  789. if(path)
  790. nativePath = path->nativePath;
  791. GpPathIterator *iter = NULL;
  792. lastResult = DllExports::GdipCreatePathIter(&iter, nativePath);
  793. SetNativeIterator(iter);
  794. }
  795. ~GraphicsPathIterator()
  796. {
  797. DllExports::GdipDeletePathIter(nativeIterator);
  798. }
  799. INT NextSubpath(OUT INT* startIndex,
  800. OUT INT* endIndex,
  801. OUT BOOL* isClosed)
  802. {
  803. INT resultCount;
  804. SetStatus(DllExports::GdipPathIterNextSubpath(nativeIterator,
  805. &resultCount, startIndex, endIndex, isClosed));
  806. return resultCount;
  807. }
  808. INT NextSubpath(OUT const GraphicsPath* path,
  809. OUT BOOL* isClosed)
  810. {
  811. GpPath* nativePath = NULL;
  812. INT resultCount;
  813. if(path)
  814. nativePath= path->nativePath;
  815. SetStatus(DllExports::GdipPathIterNextSubpathPath(nativeIterator,
  816. &resultCount, nativePath, isClosed));
  817. return resultCount;
  818. }
  819. INT NextPathType(OUT BYTE* pathType,
  820. OUT INT* startIndex,
  821. OUT INT* endIndex)
  822. {
  823. INT resultCount;
  824. SetStatus(DllExports::GdipPathIterNextPathType(nativeIterator,
  825. &resultCount, pathType, startIndex, endIndex));
  826. return resultCount;
  827. }
  828. INT NextMarker(OUT INT* startIndex,
  829. OUT INT* endIndex)
  830. {
  831. INT resultCount;
  832. SetStatus(DllExports::GdipPathIterNextMarker(nativeIterator,
  833. &resultCount, startIndex, endIndex));
  834. return resultCount;
  835. }
  836. INT NextMarker(OUT const GraphicsPath* path)
  837. {
  838. GpPath* nativePath = NULL;
  839. INT resultCount;
  840. if(path)
  841. nativePath= path->nativePath;
  842. SetStatus(DllExports::GdipPathIterNextMarkerPath(nativeIterator,
  843. &resultCount, nativePath));
  844. return resultCount;
  845. }
  846. INT GetCount() const
  847. {
  848. INT resultCount;
  849. SetStatus(DllExports::GdipPathIterGetCount(nativeIterator,
  850. &resultCount));
  851. return resultCount;
  852. }
  853. INT GetSubpathCount() const
  854. {
  855. INT resultCount;
  856. SetStatus(DllExports::GdipPathIterGetSubpathCount(nativeIterator,
  857. &resultCount));
  858. return resultCount;
  859. }
  860. BOOL HasCurve() const
  861. {
  862. BOOL hasCurve;
  863. SetStatus(DllExports::GdipPathIterHasCurve(nativeIterator, &hasCurve));
  864. return hasCurve;
  865. }
  866. VOID Rewind()
  867. {
  868. SetStatus(DllExports::GdipPathIterRewind(nativeIterator));
  869. }
  870. INT Enumerate(OUT PointF *points,
  871. OUT BYTE *types,
  872. IN INT count)
  873. {
  874. INT resultCount;
  875. SetStatus(DllExports::GdipPathIterEnumerate(nativeIterator,
  876. &resultCount, points, types, count));
  877. return resultCount;
  878. }
  879. INT CopyData(OUT PointF* points,
  880. OUT BYTE* types,
  881. IN INT startIndex,
  882. IN INT endIndex)
  883. {
  884. INT resultCount;
  885. SetStatus(DllExports::GdipPathIterCopyData(nativeIterator,
  886. &resultCount, points, types, startIndex, endIndex));
  887. return resultCount;
  888. }
  889. Status GetLastStatus() const
  890. {
  891. Status lastStatus = lastResult;
  892. lastResult = Ok;
  893. return lastStatus;
  894. }
  895. private:
  896. GraphicsPathIterator(const GraphicsPathIterator &);
  897. GraphicsPathIterator& operator=(const GraphicsPathIterator &);
  898. protected:
  899. VOID SetNativeIterator(GpPathIterator *nativeIterator)
  900. {
  901. this->nativeIterator = nativeIterator;
  902. }
  903. Status SetStatus(Status status) const
  904. {
  905. if (status != Ok)
  906. return (lastResult = status);
  907. else
  908. return status;
  909. }
  910. protected:
  911. GpPathIterator* nativeIterator;
  912. mutable Status lastResult;
  913. };
  914. //--------------------------------------------------------------------------
  915. // Path Gradient Brush
  916. //--------------------------------------------------------------------------
  917. class PathGradientBrush : public Brush
  918. {
  919. public:
  920. friend class Pen;
  921. PathGradientBrush(
  922. IN const PointF* points,
  923. IN INT count,
  924. IN WrapMode wrapMode = WrapModeClamp)
  925. {
  926. GpPathGradient *brush = NULL;
  927. lastResult = DllExports::GdipCreatePathGradient(
  928. points, count,
  929. wrapMode, &brush);
  930. SetNativeBrush(brush);
  931. }
  932. PathGradientBrush(
  933. IN const PointI* points,
  934. IN INT count,
  935. IN WrapMode wrapMode = WrapModeClamp)
  936. {
  937. GpPathGradient *brush = NULL;
  938. lastResult = DllExports::GdipCreatePathGradientI(
  939. points, count,
  940. wrapMode, &brush);
  941. SetNativeBrush(brush);
  942. }
  943. PathGradientBrush(
  944. IN const GraphicsPath* path
  945. )
  946. {
  947. GpPathGradient *brush = NULL;
  948. lastResult = DllExports::GdipCreatePathGradientFromPath(
  949. path->nativePath, &brush);
  950. SetNativeBrush(brush);
  951. }
  952. Status GetCenterColor(OUT GdiPlusColor* color) const
  953. {
  954. ARGB argb;
  955. if (color == NULL)
  956. {
  957. return SetStatus(InvalidParameter);
  958. }
  959. SetStatus(DllExports::GdipGetPathGradientCenterColor(
  960. (GpPathGradient*) nativeBrush, &argb));
  961. color->SetValue(argb);
  962. return lastResult;
  963. }
  964. Status SetCenterColor(IN const GdiPlusColor& color)
  965. {
  966. SetStatus(DllExports::GdipSetPathGradientCenterColor(
  967. (GpPathGradient*) nativeBrush,
  968. color.GetValue()));
  969. return lastResult;
  970. }
  971. INT GetPointCount() const
  972. {
  973. INT count;
  974. SetStatus(DllExports::GdipGetPathGradientPointCount(
  975. (GpPathGradient*) nativeBrush, &count));
  976. return count;
  977. }
  978. INT GetSurroundColorCount() const
  979. {
  980. INT count;
  981. SetStatus(DllExports::GdipGetPathGradientSurroundColorCount(
  982. (GpPathGradient*) nativeBrush, &count));
  983. return count;
  984. }
  985. Status GetSurroundColors(OUT GdiPlusColor* colors,
  986. IN OUT INT* count) const
  987. {
  988. if(colors == NULL || count == NULL)
  989. {
  990. return SetStatus(InvalidParameter);
  991. }
  992. INT count1;
  993. SetStatus(DllExports::GdipGetPathGradientSurroundColorCount(
  994. (GpPathGradient*) nativeBrush, &count1));
  995. if(lastResult != Ok)
  996. return lastResult;
  997. if((*count < count1) || (count1 <= 0))
  998. return SetStatus(InsufficientBuffer);
  999. ARGB* argbs = (ARGB*) new ARGB[count1];
  1000. if(argbs == NULL)
  1001. return SetStatus(OutOfMemory);
  1002. SetStatus(DllExports::GdipGetPathGradientSurroundColorsWithCount(
  1003. (GpPathGradient*)nativeBrush, argbs, &count1));
  1004. if(lastResult == Ok)
  1005. {
  1006. for(INT i = 0; i < count1; i++)
  1007. {
  1008. colors[i].SetValue(argbs[i]);
  1009. }
  1010. *count = count1;
  1011. }
  1012. delete [] argbs;
  1013. return lastResult;
  1014. }
  1015. Status SetSurroundColors(IN const GdiPlusColor* colors,
  1016. IN OUT INT* count)
  1017. {
  1018. if(colors == NULL || count == NULL)
  1019. {
  1020. return SetStatus(InvalidParameter);
  1021. }
  1022. INT count1 = GetPointCount();
  1023. if((*count > count1) || (count1 <= 0))
  1024. return SetStatus(InvalidParameter);
  1025. count1 = *count;
  1026. ARGB* argbs = (ARGB*) new ARGB[count1];
  1027. if(argbs == NULL)
  1028. return SetStatus(OutOfMemory);
  1029. for(INT i = 0; i < count1; i++)
  1030. {
  1031. argbs[i] = colors[i].GetValue();
  1032. }
  1033. SetStatus(DllExports::GdipSetPathGradientSurroundColorsWithCount(
  1034. (GpPathGradient*)nativeBrush, argbs, &count1));
  1035. if(lastResult == Ok)
  1036. *count = count1;
  1037. delete [] argbs;
  1038. return lastResult;
  1039. }
  1040. Status GetGraphicsPath(OUT GraphicsPath* path) const
  1041. {
  1042. if(path == NULL)
  1043. return SetStatus(InvalidParameter);
  1044. return SetStatus(DllExports::GdipGetPathGradientPath(
  1045. (GpPathGradient*)nativeBrush, path->nativePath));
  1046. }
  1047. Status SetGraphicsPath(IN const GraphicsPath* path)
  1048. {
  1049. if(path == NULL)
  1050. return SetStatus(InvalidParameter);
  1051. return SetStatus(DllExports::GdipSetPathGradientPath(
  1052. (GpPathGradient*)nativeBrush, path->nativePath));
  1053. }
  1054. Status GetCenterPoint(OUT PointF* point) const
  1055. {
  1056. return SetStatus(DllExports::GdipGetPathGradientCenterPoint(
  1057. (GpPathGradient*)nativeBrush,
  1058. point));
  1059. }
  1060. Status GetCenterPoint(OUT PointI* point) const
  1061. {
  1062. return SetStatus(DllExports::GdipGetPathGradientCenterPointI(
  1063. (GpPathGradient*)nativeBrush,
  1064. point));
  1065. }
  1066. Status SetCenterPoint(IN const PointF& point)
  1067. {
  1068. return SetStatus(DllExports::GdipSetPathGradientCenterPoint(
  1069. (GpPathGradient*)nativeBrush,
  1070. &point));
  1071. }
  1072. Status SetCenterPoint(IN const PointI& point)
  1073. {
  1074. return SetStatus(DllExports::GdipSetPathGradientCenterPointI(
  1075. (GpPathGradient*)nativeBrush,
  1076. &point));
  1077. }
  1078. Status GetRectangle(OUT RectF* rect) const
  1079. {
  1080. return SetStatus(DllExports::GdipGetPathGradientRect(
  1081. (GpPathGradient*)nativeBrush, rect));
  1082. }
  1083. Status GetRectangle(OUT Rect* rect) const
  1084. {
  1085. return SetStatus(DllExports::GdipGetPathGradientRectI(
  1086. (GpPathGradient*)nativeBrush, rect));
  1087. }
  1088. Status SetGammaCorrection(IN BOOL useGammaCorrection)
  1089. {
  1090. return SetStatus(DllExports::GdipSetPathGradientGammaCorrection(
  1091. (GpPathGradient*)nativeBrush, useGammaCorrection));
  1092. }
  1093. BOOL GetGammaCorrection() const
  1094. {
  1095. BOOL useGammaCorrection;
  1096. SetStatus(DllExports::GdipGetPathGradientGammaCorrection(
  1097. (GpPathGradient*)nativeBrush, &useGammaCorrection));
  1098. return useGammaCorrection;
  1099. }
  1100. INT GetBlendCount() const
  1101. {
  1102. INT count = 0;
  1103. SetStatus(DllExports::GdipGetPathGradientBlendCount(
  1104. (GpPathGradient*) nativeBrush, &count));
  1105. return count;
  1106. }
  1107. Status GetBlend(OUT REAL* blendFactors,
  1108. OUT REAL* blendPositions,
  1109. IN INT count) const
  1110. {
  1111. return SetStatus(DllExports::GdipGetPathGradientBlend(
  1112. (GpPathGradient*)nativeBrush,
  1113. blendFactors, blendPositions, count));
  1114. }
  1115. Status SetBlend(IN const REAL* blendFactors,
  1116. IN const REAL* blendPositions,
  1117. IN INT count)
  1118. {
  1119. return SetStatus(DllExports::GdipSetPathGradientBlend(
  1120. (GpPathGradient*)nativeBrush,
  1121. blendFactors, blendPositions, count));
  1122. }
  1123. INT GetInterpolationColorCount() const
  1124. {
  1125. INT count = 0;
  1126. SetStatus(DllExports::GdipGetPathGradientPresetBlendCount(
  1127. (GpPathGradient*) nativeBrush, &count));
  1128. return count;
  1129. }
  1130. Status SetInterpolationColors(IN const GdiPlusColor* presetColors,
  1131. IN const REAL* blendPositions,
  1132. IN INT count)
  1133. {
  1134. if ((count <= 0) || !presetColors)
  1135. {
  1136. return SetStatus(InvalidParameter);
  1137. }
  1138. ARGB* argbs = (ARGB*) new ARGB[count];
  1139. if(argbs)
  1140. {
  1141. for(INT i = 0; i < count; i++)
  1142. {
  1143. argbs[i] = presetColors[i].GetValue();
  1144. }
  1145. Status status = SetStatus(DllExports::
  1146. GdipSetPathGradientPresetBlend(
  1147. (GpPathGradient*) nativeBrush,
  1148. argbs,
  1149. blendPositions,
  1150. count));
  1151. delete[] argbs;
  1152. return status;
  1153. }
  1154. else
  1155. {
  1156. return SetStatus(OutOfMemory);
  1157. }
  1158. }
  1159. Status GetInterpolationColors(OUT GdiPlusColor* presetColors,
  1160. OUT REAL* blendPositions,
  1161. IN INT count) const
  1162. {
  1163. if ((count <= 0) || !presetColors)
  1164. {
  1165. return SetStatus(InvalidParameter);
  1166. }
  1167. ARGB* argbs = (ARGB*) new ARGB[count];
  1168. if (!argbs)
  1169. {
  1170. return SetStatus(OutOfMemory);
  1171. }
  1172. GpStatus status = SetStatus(DllExports::GdipGetPathGradientPresetBlend(
  1173. (GpPathGradient*)nativeBrush,
  1174. argbs,
  1175. blendPositions,
  1176. count));
  1177. for(INT i = 0; i < count; i++)
  1178. {
  1179. presetColors[i] = GdiPlusColor(argbs[i]);
  1180. }
  1181. delete [] argbs;
  1182. return status;
  1183. }
  1184. Status SetBlendBellShape(IN REAL focus,
  1185. IN REAL scale = 1.0)
  1186. {
  1187. return SetStatus(DllExports::GdipSetPathGradientSigmaBlend(
  1188. (GpPathGradient*)nativeBrush, focus, scale));
  1189. }
  1190. Status SetBlendTriangularShape(
  1191. IN REAL focus,
  1192. IN REAL scale = 1.0
  1193. )
  1194. {
  1195. return SetStatus(DllExports::GdipSetPathGradientLinearBlend(
  1196. (GpPathGradient*)nativeBrush, focus, scale));
  1197. }
  1198. Status GetTransform(OUT Matrix *matrix) const
  1199. {
  1200. return SetStatus(DllExports::GdipGetPathGradientTransform(
  1201. (GpPathGradient*) nativeBrush,
  1202. matrix->nativeMatrix));
  1203. }
  1204. Status SetTransform(IN const Matrix* matrix)
  1205. {
  1206. return SetStatus(DllExports::GdipSetPathGradientTransform(
  1207. (GpPathGradient*) nativeBrush,
  1208. matrix->nativeMatrix));
  1209. }
  1210. Status ResetTransform()
  1211. {
  1212. return SetStatus(DllExports::GdipResetPathGradientTransform(
  1213. (GpPathGradient*)nativeBrush));
  1214. }
  1215. Status MultiplyTransform(IN const Matrix* matrix,
  1216. IN MatrixOrder order = MatrixOrderPrepend)
  1217. {
  1218. return SetStatus(DllExports::GdipMultiplyPathGradientTransform(
  1219. (GpPathGradient*)nativeBrush,
  1220. matrix->nativeMatrix,
  1221. order));
  1222. }
  1223. Status TranslateTransform(IN REAL dx,
  1224. IN REAL dy,
  1225. IN MatrixOrder order = MatrixOrderPrepend)
  1226. {
  1227. return SetStatus(DllExports::GdipTranslatePathGradientTransform(
  1228. (GpPathGradient*)nativeBrush,
  1229. dx, dy, order));
  1230. }
  1231. Status ScaleTransform(IN REAL sx,
  1232. IN REAL sy,
  1233. IN MatrixOrder order = MatrixOrderPrepend)
  1234. {
  1235. return SetStatus(DllExports::GdipScalePathGradientTransform(
  1236. (GpPathGradient*)nativeBrush,
  1237. sx, sy, order));
  1238. }
  1239. Status RotateTransform(IN REAL angle,
  1240. IN MatrixOrder order = MatrixOrderPrepend)
  1241. {
  1242. return SetStatus(DllExports::GdipRotatePathGradientTransform(
  1243. (GpPathGradient*)nativeBrush,
  1244. angle, order));
  1245. }
  1246. Status GetFocusScales(OUT REAL* xScale,
  1247. OUT REAL* yScale) const
  1248. {
  1249. return SetStatus(DllExports::GdipGetPathGradientFocusScales(
  1250. (GpPathGradient*) nativeBrush, xScale, yScale));
  1251. }
  1252. Status SetFocusScales(IN REAL xScale,
  1253. IN REAL yScale)
  1254. {
  1255. return SetStatus(DllExports::GdipSetPathGradientFocusScales(
  1256. (GpPathGradient*) nativeBrush, xScale, yScale));
  1257. }
  1258. WrapMode GetWrapMode() const
  1259. {
  1260. WrapMode wrapMode;
  1261. SetStatus(DllExports::GdipGetPathGradientWrapMode(
  1262. (GpPathGradient*) nativeBrush, &wrapMode));
  1263. return wrapMode;
  1264. }
  1265. Status SetWrapMode(IN WrapMode wrapMode)
  1266. {
  1267. return SetStatus(DllExports::GdipSetPathGradientWrapMode(
  1268. (GpPathGradient*) nativeBrush, wrapMode));
  1269. }
  1270. private:
  1271. PathGradientBrush(const PathGradientBrush &);
  1272. PathGradientBrush& operator=(const PathGradientBrush &);
  1273. protected:
  1274. PathGradientBrush()
  1275. {
  1276. }
  1277. };
  1278. #endif // !_GRAPHICSPATH_HPP