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.

1618 lines
48 KiB

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