The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

760 lines
33KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_PATH_JUCEHEADER__
  19. #define __JUCE_PATH_JUCEHEADER__
  20. #include "juce_AffineTransform.h"
  21. #include "juce_Line.h"
  22. #include "juce_Rectangle.h"
  23. #include "../placement/juce_Justification.h"
  24. class Image;
  25. class InputStream;
  26. class OutputStream;
  27. //==============================================================================
  28. /**
  29. A path is a sequence of lines and curves that may either form a closed shape
  30. or be open-ended.
  31. To use a path, you can create an empty one, then add lines and curves to it
  32. to create shapes, then it can be rendered by a Graphics context or used
  33. for geometric operations.
  34. e.g. @code
  35. Path myPath;
  36. myPath.startNewSubPath (10.0f, 10.0f); // move the current position to (10, 10)
  37. myPath.lineTo (100.0f, 200.0f); // draw a line from here to (100, 200)
  38. myPath.quadraticTo (0.0f, 150.0f, 5.0f, 50.0f); // draw a curve that ends at (5, 50)
  39. myPath.closeSubPath(); // close the subpath with a line back to (10, 10)
  40. // add an ellipse as well, which will form a second sub-path within the path..
  41. myPath.addEllipse (50.0f, 50.0f, 40.0f, 30.0f);
  42. // double the width of the whole thing..
  43. myPath.applyTransform (AffineTransform::scale (2.0f, 1.0f));
  44. // and draw it to a graphics context with a 5-pixel thick outline.
  45. g.strokePath (myPath, PathStrokeType (5.0f));
  46. @endcode
  47. A path object can actually contain multiple sub-paths, which may themselves
  48. be open or closed.
  49. @see PathFlatteningIterator, PathStrokeType, Graphics
  50. */
  51. class JUCE_API Path
  52. {
  53. public:
  54. //==============================================================================
  55. /** Creates an empty path. */
  56. Path();
  57. /** Creates a copy of another path. */
  58. Path (const Path& other);
  59. /** Destructor. */
  60. ~Path();
  61. /** Copies this path from another one. */
  62. Path& operator= (const Path& other);
  63. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  64. Path (Path&& other) noexcept;
  65. Path& operator= (Path&& other) noexcept;
  66. #endif
  67. bool operator== (const Path& other) const noexcept;
  68. bool operator!= (const Path& other) const noexcept;
  69. //==============================================================================
  70. /** Returns true if the path doesn't contain any lines or curves. */
  71. bool isEmpty() const noexcept;
  72. /** Returns the smallest rectangle that contains all points within the path.
  73. */
  74. Rectangle<float> getBounds() const noexcept;
  75. /** Returns the smallest rectangle that contains all points within the path
  76. after it's been transformed with the given tranasform matrix.
  77. */
  78. Rectangle<float> getBoundsTransformed (const AffineTransform& transform) const noexcept;
  79. /** Checks whether a point lies within the path.
  80. This is only relevent for closed paths (see closeSubPath()), and
  81. may produce false results if used on a path which has open sub-paths.
  82. The path's winding rule is taken into account by this method.
  83. The tolerance parameter is the maximum error allowed when flattening the path,
  84. so this method could return a false positive when your point is up to this distance
  85. outside the path's boundary.
  86. @see closeSubPath, setUsingNonZeroWinding
  87. */
  88. bool contains (float x, float y,
  89. float tolerance = 1.0f) const;
  90. /** Checks whether a point lies within the path.
  91. This is only relevent for closed paths (see closeSubPath()), and
  92. may produce false results if used on a path which has open sub-paths.
  93. The path's winding rule is taken into account by this method.
  94. The tolerance parameter is the maximum error allowed when flattening the path,
  95. so this method could return a false positive when your point is up to this distance
  96. outside the path's boundary.
  97. @see closeSubPath, setUsingNonZeroWinding
  98. */
  99. bool contains (const Point<float>& point,
  100. float tolerance = 1.0f) const;
  101. /** Checks whether a line crosses the path.
  102. This will return positive if the line crosses any of the paths constituent
  103. lines or curves. It doesn't take into account whether the line is inside
  104. or outside the path, or whether the path is open or closed.
  105. The tolerance parameter is the maximum error allowed when flattening the path,
  106. so this method could return a false positive when your point is up to this distance
  107. outside the path's boundary.
  108. */
  109. bool intersectsLine (const Line<float>& line,
  110. float tolerance = 1.0f);
  111. /** Cuts off parts of a line to keep the parts that are either inside or
  112. outside this path.
  113. Note that this isn't smart enough to cope with situations where the
  114. line would need to be cut into multiple pieces to correctly clip against
  115. a re-entrant shape.
  116. @param line the line to clip
  117. @param keepSectionOutsidePath if true, it's the section outside the path
  118. that will be kept; if false its the section inside
  119. the path
  120. */
  121. Line<float> getClippedLine (const Line<float>& line, bool keepSectionOutsidePath) const;
  122. /** Returns the length of the path.
  123. @see getPointAlongPath
  124. */
  125. float getLength (const AffineTransform& transform = AffineTransform::identity) const;
  126. /** Returns a point that is the specified distance along the path.
  127. If the distance is greater than the total length of the path, this will return the
  128. end point.
  129. @see getLength
  130. */
  131. Point<float> getPointAlongPath (float distanceFromStart,
  132. const AffineTransform& transform = AffineTransform::identity) const;
  133. /** Finds the point along the path which is nearest to a given position.
  134. This sets pointOnPath to the nearest point, and returns the distance of this point from the start
  135. of the path.
  136. */
  137. float getNearestPoint (const Point<float>& targetPoint,
  138. Point<float>& pointOnPath,
  139. const AffineTransform& transform = AffineTransform::identity) const;
  140. //==============================================================================
  141. /** Removes all lines and curves, resetting the path completely. */
  142. void clear() noexcept;
  143. /** Begins a new subpath with a given starting position.
  144. This will move the path's current position to the co-ordinates passed in and
  145. make it ready to draw lines or curves starting from this position.
  146. After adding whatever lines and curves are needed, you can either
  147. close the current sub-path using closeSubPath() or call startNewSubPath()
  148. to move to a new sub-path, leaving the old one open-ended.
  149. @see lineTo, quadraticTo, cubicTo, closeSubPath
  150. */
  151. void startNewSubPath (float startX, float startY);
  152. /** Begins a new subpath with a given starting position.
  153. This will move the path's current position to the co-ordinates passed in and
  154. make it ready to draw lines or curves starting from this position.
  155. After adding whatever lines and curves are needed, you can either
  156. close the current sub-path using closeSubPath() or call startNewSubPath()
  157. to move to a new sub-path, leaving the old one open-ended.
  158. @see lineTo, quadraticTo, cubicTo, closeSubPath
  159. */
  160. void startNewSubPath (const Point<float>& start);
  161. /** Closes a the current sub-path with a line back to its start-point.
  162. When creating a closed shape such as a triangle, don't use 3 lineTo()
  163. calls - instead use two lineTo() calls, followed by a closeSubPath()
  164. to join the final point back to the start.
  165. This ensures that closes shapes are recognised as such, and this is
  166. important for tasks like drawing strokes, which needs to know whether to
  167. draw end-caps or not.
  168. @see startNewSubPath, lineTo, quadraticTo, cubicTo, closeSubPath
  169. */
  170. void closeSubPath();
  171. /** Adds a line from the shape's last position to a new end-point.
  172. This will connect the end-point of the last line or curve that was added
  173. to a new point, using a straight line.
  174. See the class description for an example of how to add lines and curves to a path.
  175. @see startNewSubPath, quadraticTo, cubicTo, closeSubPath
  176. */
  177. void lineTo (float endX, float endY);
  178. /** Adds a line from the shape's last position to a new end-point.
  179. This will connect the end-point of the last line or curve that was added
  180. to a new point, using a straight line.
  181. See the class description for an example of how to add lines and curves to a path.
  182. @see startNewSubPath, quadraticTo, cubicTo, closeSubPath
  183. */
  184. void lineTo (const Point<float>& end);
  185. /** Adds a quadratic bezier curve from the shape's last position to a new position.
  186. This will connect the end-point of the last line or curve that was added
  187. to a new point, using a quadratic spline with one control-point.
  188. See the class description for an example of how to add lines and curves to a path.
  189. @see startNewSubPath, lineTo, cubicTo, closeSubPath
  190. */
  191. void quadraticTo (float controlPointX,
  192. float controlPointY,
  193. float endPointX,
  194. float endPointY);
  195. /** Adds a quadratic bezier curve from the shape's last position to a new position.
  196. This will connect the end-point of the last line or curve that was added
  197. to a new point, using a quadratic spline with one control-point.
  198. See the class description for an example of how to add lines and curves to a path.
  199. @see startNewSubPath, lineTo, cubicTo, closeSubPath
  200. */
  201. void quadraticTo (const Point<float>& controlPoint,
  202. const Point<float>& endPoint);
  203. /** Adds a cubic bezier curve from the shape's last position to a new position.
  204. This will connect the end-point of the last line or curve that was added
  205. to a new point, using a cubic spline with two control-points.
  206. See the class description for an example of how to add lines and curves to a path.
  207. @see startNewSubPath, lineTo, quadraticTo, closeSubPath
  208. */
  209. void cubicTo (float controlPoint1X,
  210. float controlPoint1Y,
  211. float controlPoint2X,
  212. float controlPoint2Y,
  213. float endPointX,
  214. float endPointY);
  215. /** Adds a cubic bezier curve from the shape's last position to a new position.
  216. This will connect the end-point of the last line or curve that was added
  217. to a new point, using a cubic spline with two control-points.
  218. See the class description for an example of how to add lines and curves to a path.
  219. @see startNewSubPath, lineTo, quadraticTo, closeSubPath
  220. */
  221. void cubicTo (const Point<float>& controlPoint1,
  222. const Point<float>& controlPoint2,
  223. const Point<float>& endPoint);
  224. /** Returns the last point that was added to the path by one of the drawing methods.
  225. */
  226. Point<float> getCurrentPosition() const;
  227. //==============================================================================
  228. /** Adds a rectangle to the path.
  229. The rectangle is added as a new sub-path. (Any currently open paths will be left open).
  230. @see addRoundedRectangle, addTriangle
  231. */
  232. void addRectangle (float x, float y, float width, float height);
  233. /** Adds a rectangle to the path.
  234. The rectangle is added as a new sub-path. (Any currently open paths will be left open).
  235. @see addRoundedRectangle, addTriangle
  236. */
  237. template <typename ValueType>
  238. void addRectangle (const Rectangle<ValueType>& rectangle)
  239. {
  240. addRectangle (static_cast <float> (rectangle.getX()), static_cast <float> (rectangle.getY()),
  241. static_cast <float> (rectangle.getWidth()), static_cast <float> (rectangle.getHeight()));
  242. }
  243. /** Adds a rectangle with rounded corners to the path.
  244. The rectangle is added as a new sub-path. (Any currently open paths will be left open).
  245. @see addRectangle, addTriangle
  246. */
  247. void addRoundedRectangle (float x, float y, float width, float height,
  248. float cornerSize);
  249. /** Adds a rectangle with rounded corners to the path.
  250. The rectangle is added as a new sub-path. (Any currently open paths will be left open).
  251. @see addRectangle, addTriangle
  252. */
  253. void addRoundedRectangle (float x, float y, float width, float height,
  254. float cornerSizeX,
  255. float cornerSizeY);
  256. /** Adds a rectangle with rounded corners to the path.
  257. The rectangle is added as a new sub-path. (Any currently open paths will be left open).
  258. @see addRectangle, addTriangle
  259. */
  260. template <typename ValueType>
  261. void addRoundedRectangle (const Rectangle<ValueType>& rectangle, float cornerSizeX, float cornerSizeY)
  262. {
  263. addRoundedRectangle (static_cast <float> (rectangle.getX()), static_cast <float> (rectangle.getY()),
  264. static_cast <float> (rectangle.getWidth()), static_cast <float> (rectangle.getHeight()),
  265. cornerSizeX, cornerSizeY);
  266. }
  267. /** Adds a rectangle with rounded corners to the path.
  268. The rectangle is added as a new sub-path. (Any currently open paths will be left open).
  269. @see addRectangle, addTriangle
  270. */
  271. template <typename ValueType>
  272. void addRoundedRectangle (const Rectangle<ValueType>& rectangle, float cornerSize)
  273. {
  274. addRoundedRectangle (rectangle, cornerSize, cornerSize);
  275. }
  276. /** Adds a triangle to the path.
  277. The triangle is added as a new closed sub-path. (Any currently open paths will be left open).
  278. Note that whether the vertices are specified in clockwise or anticlockwise
  279. order will affect how the triangle is filled when it overlaps other
  280. shapes (the winding order setting will affect this of course).
  281. */
  282. void addTriangle (float x1, float y1,
  283. float x2, float y2,
  284. float x3, float y3);
  285. /** Adds a quadrilateral to the path.
  286. The quad is added as a new closed sub-path. (Any currently open paths will be left open).
  287. Note that whether the vertices are specified in clockwise or anticlockwise
  288. order will affect how the quad is filled when it overlaps other
  289. shapes (the winding order setting will affect this of course).
  290. */
  291. void addQuadrilateral (float x1, float y1,
  292. float x2, float y2,
  293. float x3, float y3,
  294. float x4, float y4);
  295. /** Adds an ellipse to the path.
  296. The shape is added as a new sub-path. (Any currently open paths will be left open).
  297. @see addArc
  298. */
  299. void addEllipse (float x, float y, float width, float height);
  300. /** Adds an elliptical arc to the current path.
  301. Note that when specifying the start and end angles, the curve will be drawn either clockwise
  302. or anti-clockwise according to whether the end angle is greater than the start. This means
  303. that sometimes you may need to use values greater than 2*Pi for the end angle.
  304. @param x the left-hand edge of the rectangle in which the elliptical outline fits
  305. @param y the top edge of the rectangle in which the elliptical outline fits
  306. @param width the width of the rectangle in which the elliptical outline fits
  307. @param height the height of the rectangle in which the elliptical outline fits
  308. @param fromRadians the angle (clockwise) in radians at which to start the arc segment (where 0 is the
  309. top-centre of the ellipse)
  310. @param toRadians the angle (clockwise) in radians at which to end the arc segment (where 0 is the
  311. top-centre of the ellipse). This angle can be greater than 2*Pi, so for example to
  312. draw a curve clockwise from the 9 o'clock position to the 3 o'clock position via
  313. 12 o'clock, you'd use 1.5*Pi and 2.5*Pi as the start and finish points.
  314. @param startAsNewSubPath if true, the arc will begin a new subpath from its starting point; if false,
  315. it will be added to the current sub-path, continuing from the current postition
  316. @see addCentredArc, arcTo, addPieSegment, addEllipse
  317. */
  318. void addArc (float x, float y, float width, float height,
  319. float fromRadians,
  320. float toRadians,
  321. bool startAsNewSubPath = false);
  322. /** Adds an arc which is centred at a given point, and can have a rotation specified.
  323. Note that when specifying the start and end angles, the curve will be drawn either clockwise
  324. or anti-clockwise according to whether the end angle is greater than the start. This means
  325. that sometimes you may need to use values greater than 2*Pi for the end angle.
  326. @param centreX the centre x of the ellipse
  327. @param centreY the centre y of the ellipse
  328. @param radiusX the horizontal radius of the ellipse
  329. @param radiusY the vertical radius of the ellipse
  330. @param rotationOfEllipse an angle by which the whole ellipse should be rotated about its centre, in radians (clockwise)
  331. @param fromRadians the angle (clockwise) in radians at which to start the arc segment (where 0 is the
  332. top-centre of the ellipse)
  333. @param toRadians the angle (clockwise) in radians at which to end the arc segment (where 0 is the
  334. top-centre of the ellipse). This angle can be greater than 2*Pi, so for example to
  335. draw a curve clockwise from the 9 o'clock position to the 3 o'clock position via
  336. 12 o'clock, you'd use 1.5*Pi and 2.5*Pi as the start and finish points.
  337. @param startAsNewSubPath if true, the arc will begin a new subpath from its starting point; if false,
  338. it will be added to the current sub-path, continuing from the current postition
  339. @see addArc, arcTo
  340. */
  341. void addCentredArc (float centreX, float centreY,
  342. float radiusX, float radiusY,
  343. float rotationOfEllipse,
  344. float fromRadians,
  345. float toRadians,
  346. bool startAsNewSubPath = false);
  347. /** Adds a "pie-chart" shape to the path.
  348. The shape is added as a new sub-path. (Any currently open paths will be
  349. left open).
  350. Note that when specifying the start and end angles, the curve will be drawn either clockwise
  351. or anti-clockwise according to whether the end angle is greater than the start. This means
  352. that sometimes you may need to use values greater than 2*Pi for the end angle.
  353. @param x the left-hand edge of the rectangle in which the elliptical outline fits
  354. @param y the top edge of the rectangle in which the elliptical outline fits
  355. @param width the width of the rectangle in which the elliptical outline fits
  356. @param height the height of the rectangle in which the elliptical outline fits
  357. @param fromRadians the angle (clockwise) in radians at which to start the arc segment (where 0 is the
  358. top-centre of the ellipse)
  359. @param toRadians the angle (clockwise) in radians at which to end the arc segment (where 0 is the
  360. top-centre of the ellipse)
  361. @param innerCircleProportionalSize if this is > 0, then the pie will be drawn as a curved band around a hollow
  362. ellipse at its centre, where this value indicates the inner ellipse's size with
  363. respect to the outer one.
  364. @see addArc
  365. */
  366. void addPieSegment (float x, float y,
  367. float width, float height,
  368. float fromRadians,
  369. float toRadians,
  370. float innerCircleProportionalSize);
  371. /** Adds a line with a specified thickness.
  372. The line is added as a new closed sub-path. (Any currently open paths will be
  373. left open).
  374. @see addArrow
  375. */
  376. void addLineSegment (const Line<float>& line, float lineThickness);
  377. /** Adds a line with an arrowhead on the end.
  378. The arrow is added as a new closed sub-path. (Any currently open paths will be left open).
  379. @see PathStrokeType::createStrokeWithArrowheads
  380. */
  381. void addArrow (const Line<float>& line,
  382. float lineThickness,
  383. float arrowheadWidth,
  384. float arrowheadLength);
  385. /** Adds a polygon shape to the path.
  386. @see addStar
  387. */
  388. void addPolygon (const Point<float>& centre,
  389. int numberOfSides,
  390. float radius,
  391. float startAngle = 0.0f);
  392. /** Adds a star shape to the path.
  393. @see addPolygon
  394. */
  395. void addStar (const Point<float>& centre,
  396. int numberOfPoints,
  397. float innerRadius,
  398. float outerRadius,
  399. float startAngle = 0.0f);
  400. /** Adds a speech-bubble shape to the path.
  401. @param bodyArea the area of the body of the bubble shape
  402. @param maximumArea an area which encloses the body area and defines the limits within which
  403. the arrow tip can be drawn - if the tip lies outside this area, the bubble
  404. will be drawn without an arrow
  405. @param arrowTipPosition the location of the tip of the arrow
  406. @param cornerSize the size of the rounded corners
  407. @param arrowBaseWidth the width of the base of the arrow where it joins the main rectangle
  408. */
  409. void addBubble (const Rectangle<float>& bodyArea,
  410. const Rectangle<float>& maximumArea,
  411. const Point<float>& arrowTipPosition,
  412. const float cornerSize,
  413. const float arrowBaseWidth);
  414. /** Adds another path to this one.
  415. The new path is added as a new sub-path. (Any currently open paths in this
  416. path will be left open).
  417. @param pathToAppend the path to add
  418. */
  419. void addPath (const Path& pathToAppend);
  420. /** Adds another path to this one, transforming it on the way in.
  421. The new path is added as a new sub-path, its points being transformed by the given
  422. matrix before being added.
  423. @param pathToAppend the path to add
  424. @param transformToApply an optional transform to apply to the incoming vertices
  425. */
  426. void addPath (const Path& pathToAppend,
  427. const AffineTransform& transformToApply);
  428. /** Swaps the contents of this path with another one.
  429. The internal data of the two paths is swapped over, so this is much faster than
  430. copying it to a temp variable and back.
  431. */
  432. void swapWithPath (Path& other) noexcept;
  433. //==============================================================================
  434. /** Applies a 2D transform to all the vertices in the path.
  435. @see AffineTransform, scaleToFit, getTransformToScaleToFit
  436. */
  437. void applyTransform (const AffineTransform& transform) noexcept;
  438. /** Rescales this path to make it fit neatly into a given space.
  439. This is effectively a quick way of calling
  440. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions))
  441. @param x the x position of the rectangle to fit the path inside
  442. @param y the y position of the rectangle to fit the path inside
  443. @param width the width of the rectangle to fit the path inside
  444. @param height the height of the rectangle to fit the path inside
  445. @param preserveProportions if true, it will fit the path into the space without altering its
  446. horizontal/vertical scale ratio; if false, it will distort the
  447. path to fill the specified ratio both horizontally and vertically
  448. @see applyTransform, getTransformToScaleToFit
  449. */
  450. void scaleToFit (float x, float y, float width, float height,
  451. bool preserveProportions) noexcept;
  452. /** Returns a transform that can be used to rescale the path to fit into a given space.
  453. @param x the x position of the rectangle to fit the path inside
  454. @param y the y position of the rectangle to fit the path inside
  455. @param width the width of the rectangle to fit the path inside
  456. @param height the height of the rectangle to fit the path inside
  457. @param preserveProportions if true, it will fit the path into the space without altering its
  458. horizontal/vertical scale ratio; if false, it will distort the
  459. path to fill the specified ratio both horizontally and vertically
  460. @param justificationType if the proportions are preseved, the resultant path may be smaller
  461. than the available rectangle, so this describes how it should be
  462. positioned within the space.
  463. @returns an appropriate transformation
  464. @see applyTransform, scaleToFit
  465. */
  466. AffineTransform getTransformToScaleToFit (float x, float y, float width, float height,
  467. bool preserveProportions,
  468. const Justification& justificationType = Justification::centred) const;
  469. /** Creates a version of this path where all sharp corners have been replaced by curves.
  470. Wherever two lines meet at an angle, this will replace the corner with a curve
  471. of the given radius.
  472. */
  473. Path createPathWithRoundedCorners (float cornerRadius) const;
  474. //==============================================================================
  475. /** Changes the winding-rule to be used when filling the path.
  476. If set to true (which is the default), then the path uses a non-zero-winding rule
  477. to determine which points are inside the path. If set to false, it uses an
  478. alternate-winding rule.
  479. The winding-rule comes into play when areas of the shape overlap other
  480. areas, and determines whether the overlapping regions are considered to be
  481. inside or outside.
  482. Changing this value just sets a flag - it doesn't affect the contents of the
  483. path.
  484. @see isUsingNonZeroWinding
  485. */
  486. void setUsingNonZeroWinding (bool isNonZeroWinding) noexcept;
  487. /** Returns the flag that indicates whether the path should use a non-zero winding rule.
  488. The default for a new path is true.
  489. @see setUsingNonZeroWinding
  490. */
  491. bool isUsingNonZeroWinding() const { return useNonZeroWinding; }
  492. //==============================================================================
  493. /** Iterates the lines and curves that a path contains.
  494. @see Path, PathFlatteningIterator
  495. */
  496. class JUCE_API Iterator
  497. {
  498. public:
  499. //==============================================================================
  500. Iterator (const Path& path);
  501. ~Iterator();
  502. //==============================================================================
  503. /** Moves onto the next element in the path.
  504. If this returns false, there are no more elements. If it returns true,
  505. the elementType variable will be set to the type of the current element,
  506. and some of the x and y variables will be filled in with values.
  507. */
  508. bool next();
  509. //==============================================================================
  510. enum PathElementType
  511. {
  512. startNewSubPath, /**< For this type, x1 and y1 will be set to indicate the first point in the subpath. */
  513. lineTo, /**< For this type, x1 and y1 indicate the end point of the line. */
  514. quadraticTo, /**< For this type, x1, y1, x2, y2 indicate the control point and endpoint of a quadratic curve. */
  515. cubicTo, /**< For this type, x1, y1, x2, y2, x3, y3 indicate the two control points and the endpoint of a cubic curve. */
  516. closePath /**< Indicates that the sub-path is being closed. None of the x or y values are valid in this case. */
  517. };
  518. PathElementType elementType;
  519. float x1, y1, x2, y2, x3, y3;
  520. //==============================================================================
  521. private:
  522. const Path& path;
  523. size_t index;
  524. JUCE_DECLARE_NON_COPYABLE (Iterator);
  525. };
  526. //==============================================================================
  527. /** Loads a stored path from a data stream.
  528. The data in the stream must have been written using writePathToStream().
  529. Note that this will append the stored path to whatever is currently in
  530. this path, so you might need to call clear() beforehand.
  531. @see loadPathFromData, writePathToStream
  532. */
  533. void loadPathFromStream (InputStream& source);
  534. /** Loads a stored path from a block of data.
  535. This is similar to loadPathFromStream(), but just reads from a block
  536. of data. Useful if you're including stored shapes in your code as a
  537. block of static data.
  538. @see loadPathFromStream, writePathToStream
  539. */
  540. void loadPathFromData (const void* data, size_t numberOfBytes);
  541. /** Stores the path by writing it out to a stream.
  542. After writing out a path, you can reload it using loadPathFromStream().
  543. @see loadPathFromStream, loadPathFromData
  544. */
  545. void writePathToStream (OutputStream& destination) const;
  546. //==============================================================================
  547. /** Creates a string containing a textual representation of this path.
  548. @see restoreFromString
  549. */
  550. String toString() const;
  551. /** Restores this path from a string that was created with the toString() method.
  552. @see toString()
  553. */
  554. void restoreFromString (const String& stringVersion);
  555. private:
  556. //==============================================================================
  557. friend class PathFlatteningIterator;
  558. friend class Path::Iterator;
  559. ArrayAllocationBase <float, DummyCriticalSection> data;
  560. size_t numElements;
  561. struct PathBounds
  562. {
  563. PathBounds() noexcept;
  564. Rectangle<float> getRectangle() const noexcept;
  565. void reset() noexcept;
  566. void reset (float, float) noexcept;
  567. void extend (float, float) noexcept;
  568. void extend (float, float, float, float) noexcept;
  569. float pathXMin, pathXMax, pathYMin, pathYMax;
  570. };
  571. PathBounds bounds;
  572. bool useNonZeroWinding;
  573. static const float lineMarker;
  574. static const float moveMarker;
  575. static const float quadMarker;
  576. static const float cubicMarker;
  577. static const float closeSubPathMarker;
  578. JUCE_LEAK_DETECTOR (Path);
  579. };
  580. #endif // __JUCE_PATH_JUCEHEADER__