Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1536 lines
46 KiB

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