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.

1537 lines
45KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. // tests that some coordinates aren't NaNs
  21. #define JUCE_CHECK_COORDS_ARE_VALID(x, y) \
  22. jassert (! std::isnan (x) && ! std::isnan (y));
  23. //==============================================================================
  24. namespace PathHelpers
  25. {
  26. const float ellipseAngularIncrement = 0.05f;
  27. static String nextToken (String::CharPointerType& t)
  28. {
  29. t.incrementToEndOfWhitespace();
  30. auto start = t;
  31. size_t numChars = 0;
  32. while (! (t.isEmpty() || t.isWhitespace()))
  33. {
  34. ++t;
  35. ++numChars;
  36. }
  37. return { start, numChars };
  38. }
  39. inline double lengthOf (float x1, float y1, float x2, float y2) noexcept
  40. {
  41. return juce_hypot ((double) (x1 - x2), (double) (y1 - y2));
  42. }
  43. }
  44. //==============================================================================
  45. const float Path::defaultToleranceForTesting = 1.0f;
  46. const float Path::defaultToleranceForMeasurement = 0.6f;
  47. static bool isMarker (float value, float marker) noexcept
  48. {
  49. return exactlyEqual (value, marker);
  50. }
  51. //==============================================================================
  52. Path::PathBounds::PathBounds() noexcept
  53. {
  54. }
  55. Rectangle<float> Path::PathBounds::getRectangle() const noexcept
  56. {
  57. return { pathXMin, pathYMin, pathXMax - pathXMin, pathYMax - pathYMin };
  58. }
  59. void Path::PathBounds::reset() noexcept
  60. {
  61. pathXMin = pathYMin = pathYMax = pathXMax = 0;
  62. }
  63. void Path::PathBounds::reset (float x, float y) noexcept
  64. {
  65. pathXMin = pathXMax = x;
  66. pathYMin = pathYMax = y;
  67. }
  68. void Path::PathBounds::extend (float x, float y) noexcept
  69. {
  70. if (x < pathXMin) pathXMin = x;
  71. else if (x > pathXMax) pathXMax = x;
  72. if (y < pathYMin) pathYMin = y;
  73. else if (y > pathYMax) pathYMax = y;
  74. }
  75. //==============================================================================
  76. Path::Path()
  77. {
  78. }
  79. Path::~Path()
  80. {
  81. }
  82. Path::Path (const Path& other)
  83. : data (other.data),
  84. bounds (other.bounds),
  85. useNonZeroWinding (other.useNonZeroWinding)
  86. {
  87. }
  88. Path& Path::operator= (const Path& other)
  89. {
  90. if (this != &other)
  91. {
  92. data = other.data;
  93. bounds = other.bounds;
  94. useNonZeroWinding = other.useNonZeroWinding;
  95. }
  96. return *this;
  97. }
  98. Path::Path (Path&& other) noexcept
  99. : data (std::move (other.data)),
  100. bounds (other.bounds),
  101. useNonZeroWinding (other.useNonZeroWinding)
  102. {
  103. }
  104. Path& Path::operator= (Path&& other) noexcept
  105. {
  106. data = std::move (other.data);
  107. bounds = other.bounds;
  108. useNonZeroWinding = other.useNonZeroWinding;
  109. return *this;
  110. }
  111. bool Path::operator== (const Path& other) const noexcept { return useNonZeroWinding == other.useNonZeroWinding && data == other.data; }
  112. bool Path::operator!= (const Path& other) const noexcept { return ! operator== (other); }
  113. void Path::clear() noexcept
  114. {
  115. data.clearQuick();
  116. bounds.reset();
  117. }
  118. void Path::swapWithPath (Path& other) noexcept
  119. {
  120. data.swapWith (other.data);
  121. std::swap (bounds.pathXMin, other.bounds.pathXMin);
  122. std::swap (bounds.pathXMax, other.bounds.pathXMax);
  123. std::swap (bounds.pathYMin, other.bounds.pathYMin);
  124. std::swap (bounds.pathYMax, other.bounds.pathYMax);
  125. std::swap (useNonZeroWinding, other.useNonZeroWinding);
  126. }
  127. //==============================================================================
  128. void Path::setUsingNonZeroWinding (const bool isNonZero) noexcept
  129. {
  130. useNonZeroWinding = isNonZero;
  131. }
  132. void Path::scaleToFit (float x, float y, float w, float h, bool preserveProportions) noexcept
  133. {
  134. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  135. }
  136. //==============================================================================
  137. bool Path::isEmpty() const noexcept
  138. {
  139. for (auto i = data.begin(), e = data.end(); i != e; ++i)
  140. {
  141. auto type = *i;
  142. if (isMarker (type, moveMarker))
  143. {
  144. i += 2;
  145. }
  146. else if (isMarker (type, lineMarker)
  147. || isMarker (type, quadMarker)
  148. || isMarker (type, cubicMarker))
  149. {
  150. return false;
  151. }
  152. }
  153. return true;
  154. }
  155. Rectangle<float> Path::getBounds() const noexcept
  156. {
  157. return bounds.getRectangle();
  158. }
  159. Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const noexcept
  160. {
  161. return getBounds().transformedBy (transform);
  162. }
  163. //==============================================================================
  164. void Path::preallocateSpace (int numExtraCoordsToMakeSpaceFor)
  165. {
  166. data.ensureStorageAllocated (data.size() + numExtraCoordsToMakeSpaceFor);
  167. }
  168. void Path::startNewSubPath (const float x, const float y)
  169. {
  170. JUCE_CHECK_COORDS_ARE_VALID (x, y)
  171. if (data.isEmpty())
  172. bounds.reset (x, y);
  173. else
  174. bounds.extend (x, y);
  175. data.add (moveMarker, x, y);
  176. }
  177. void Path::startNewSubPath (Point<float> start)
  178. {
  179. startNewSubPath (start.x, start.y);
  180. }
  181. void Path::lineTo (const float x, const float y)
  182. {
  183. JUCE_CHECK_COORDS_ARE_VALID (x, y)
  184. if (data.isEmpty())
  185. startNewSubPath (0, 0);
  186. data.add (lineMarker, x, y);
  187. bounds.extend (x, y);
  188. }
  189. void Path::lineTo (Point<float> end)
  190. {
  191. lineTo (end.x, end.y);
  192. }
  193. void Path::quadraticTo (const float x1, const float y1,
  194. const float x2, const float y2)
  195. {
  196. JUCE_CHECK_COORDS_ARE_VALID (x1, y1)
  197. JUCE_CHECK_COORDS_ARE_VALID (x2, y2)
  198. if (data.isEmpty())
  199. startNewSubPath (0, 0);
  200. data.add (quadMarker, x1, y1, x2, y2);
  201. bounds.extend (x1, y1, x2, y2);
  202. }
  203. void Path::quadraticTo (Point<float> controlPoint, Point<float> endPoint)
  204. {
  205. quadraticTo (controlPoint.x, controlPoint.y,
  206. endPoint.x, endPoint.y);
  207. }
  208. void Path::cubicTo (const float x1, const float y1,
  209. const float x2, const float y2,
  210. const float x3, const float y3)
  211. {
  212. JUCE_CHECK_COORDS_ARE_VALID (x1, y1)
  213. JUCE_CHECK_COORDS_ARE_VALID (x2, y2)
  214. JUCE_CHECK_COORDS_ARE_VALID (x3, y3)
  215. if (data.isEmpty())
  216. startNewSubPath (0, 0);
  217. data.add (cubicMarker, x1, y1, x2, y2, x3, y3);
  218. bounds.extend (x1, y1, x2, y2, x3, y3);
  219. }
  220. void Path::cubicTo (Point<float> controlPoint1,
  221. Point<float> controlPoint2,
  222. Point<float> endPoint)
  223. {
  224. cubicTo (controlPoint1.x, controlPoint1.y,
  225. controlPoint2.x, controlPoint2.y,
  226. endPoint.x, endPoint.y);
  227. }
  228. void Path::closeSubPath()
  229. {
  230. if (! (data.isEmpty() || isMarker (data.getLast(), closeSubPathMarker)))
  231. data.add (closeSubPathMarker);
  232. }
  233. Point<float> Path::getCurrentPosition() const
  234. {
  235. if (data.isEmpty())
  236. return {};
  237. auto* i = data.end() - 1;
  238. if (isMarker (*i, closeSubPathMarker))
  239. {
  240. while (i != data.begin())
  241. {
  242. if (isMarker (*--i, moveMarker))
  243. {
  244. i += 2;
  245. break;
  246. }
  247. }
  248. }
  249. if (i != data.begin())
  250. return { *(i - 1), *i };
  251. return {};
  252. }
  253. void Path::addRectangle (float x, float y, float w, float h)
  254. {
  255. auto x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  256. if (w < 0) std::swap (x1, x2);
  257. if (h < 0) std::swap (y1, y2);
  258. if (data.isEmpty())
  259. {
  260. bounds.pathXMin = x1;
  261. bounds.pathXMax = x2;
  262. bounds.pathYMin = y1;
  263. bounds.pathYMax = y2;
  264. }
  265. else
  266. {
  267. bounds.pathXMin = jmin (bounds.pathXMin, x1);
  268. bounds.pathXMax = jmax (bounds.pathXMax, x2);
  269. bounds.pathYMin = jmin (bounds.pathYMin, y1);
  270. bounds.pathYMax = jmax (bounds.pathYMax, y2);
  271. }
  272. data.add (moveMarker, x1, y2,
  273. lineMarker, x1, y1,
  274. lineMarker, x2, y1,
  275. lineMarker, x2, y2,
  276. closeSubPathMarker);
  277. }
  278. void Path::addRoundedRectangle (float x, float y, float w, float h, float csx, float csy)
  279. {
  280. addRoundedRectangle (x, y, w, h, csx, csy, true, true, true, true);
  281. }
  282. void Path::addRoundedRectangle (const float x, const float y, const float w, const float h,
  283. float csx, float csy,
  284. const bool curveTopLeft, const bool curveTopRight,
  285. const bool curveBottomLeft, const bool curveBottomRight)
  286. {
  287. csx = jmin (csx, w * 0.5f);
  288. csy = jmin (csy, h * 0.5f);
  289. auto cs45x = csx * 0.45f;
  290. auto cs45y = csy * 0.45f;
  291. auto x2 = x + w;
  292. auto y2 = y + h;
  293. if (curveTopLeft)
  294. {
  295. startNewSubPath (x, y + csy);
  296. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  297. }
  298. else
  299. {
  300. startNewSubPath (x, y);
  301. }
  302. if (curveTopRight)
  303. {
  304. lineTo (x2 - csx, y);
  305. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  306. }
  307. else
  308. {
  309. lineTo (x2, y);
  310. }
  311. if (curveBottomRight)
  312. {
  313. lineTo (x2, y2 - csy);
  314. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  315. }
  316. else
  317. {
  318. lineTo (x2, y2);
  319. }
  320. if (curveBottomLeft)
  321. {
  322. lineTo (x + csx, y2);
  323. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  324. }
  325. else
  326. {
  327. lineTo (x, y2);
  328. }
  329. closeSubPath();
  330. }
  331. void Path::addRoundedRectangle (float x, float y, float w, float h, float cs)
  332. {
  333. addRoundedRectangle (x, y, w, h, cs, cs);
  334. }
  335. void Path::addTriangle (float x1, float y1,
  336. float x2, float y2,
  337. float x3, float y3)
  338. {
  339. addTriangle ({ x1, y1 },
  340. { x2, y2 },
  341. { x3, y3 });
  342. }
  343. void Path::addTriangle (Point<float> p1, Point<float> p2, Point<float> p3)
  344. {
  345. startNewSubPath (p1);
  346. lineTo (p2);
  347. lineTo (p3);
  348. closeSubPath();
  349. }
  350. void Path::addQuadrilateral (float x1, float y1,
  351. float x2, float y2,
  352. float x3, float y3,
  353. float x4, float y4)
  354. {
  355. startNewSubPath (x1, y1);
  356. lineTo (x2, y2);
  357. lineTo (x3, y3);
  358. lineTo (x4, y4);
  359. closeSubPath();
  360. }
  361. void Path::addEllipse (float x, float y, float w, float h)
  362. {
  363. addEllipse ({ x, y, w, h });
  364. }
  365. void Path::addEllipse (Rectangle<float> area)
  366. {
  367. auto hw = area.getWidth() * 0.5f;
  368. auto hw55 = hw * 0.55f;
  369. auto hh = area.getHeight() * 0.5f;
  370. auto hh55 = hh * 0.55f;
  371. auto cx = area.getX() + hw;
  372. auto cy = area.getY() + hh;
  373. startNewSubPath (cx, cy - hh);
  374. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh55, cx + hw, cy);
  375. cubicTo (cx + hw, cy + hh55, cx + hw55, cy + hh, cx, cy + hh);
  376. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh55, cx - hw, cy);
  377. cubicTo (cx - hw, cy - hh55, cx - hw55, cy - hh, cx, cy - hh);
  378. closeSubPath();
  379. }
  380. void Path::addArc (float x, float y, float w, float h,
  381. float fromRadians, float toRadians,
  382. bool startAsNewSubPath)
  383. {
  384. auto radiusX = w / 2.0f;
  385. auto radiusY = h / 2.0f;
  386. addCentredArc (x + radiusX,
  387. y + radiusY,
  388. radiusX, radiusY,
  389. 0.0f,
  390. fromRadians, toRadians,
  391. startAsNewSubPath);
  392. }
  393. void Path::addCentredArc (float centreX, float centreY,
  394. float radiusX, float radiusY,
  395. float rotationOfEllipse,
  396. float fromRadians, float toRadians,
  397. bool startAsNewSubPath)
  398. {
  399. if (radiusX > 0.0f && radiusY > 0.0f)
  400. {
  401. Point<float> centre (centreX, centreY);
  402. auto rotation = AffineTransform::rotation (rotationOfEllipse, centreX, centreY);
  403. auto angle = fromRadians;
  404. if (startAsNewSubPath)
  405. startNewSubPath (centre.getPointOnCircumference (radiusX, radiusY, angle).transformedBy (rotation));
  406. if (fromRadians < toRadians)
  407. {
  408. if (startAsNewSubPath)
  409. angle += PathHelpers::ellipseAngularIncrement;
  410. while (angle < toRadians)
  411. {
  412. lineTo (centre.getPointOnCircumference (radiusX, radiusY, angle).transformedBy (rotation));
  413. angle += PathHelpers::ellipseAngularIncrement;
  414. }
  415. }
  416. else
  417. {
  418. if (startAsNewSubPath)
  419. angle -= PathHelpers::ellipseAngularIncrement;
  420. while (angle > toRadians)
  421. {
  422. lineTo (centre.getPointOnCircumference (radiusX, radiusY, angle).transformedBy (rotation));
  423. angle -= PathHelpers::ellipseAngularIncrement;
  424. }
  425. }
  426. lineTo (centre.getPointOnCircumference (radiusX, radiusY, toRadians).transformedBy (rotation));
  427. }
  428. }
  429. void Path::addPieSegment (float x, float y, float width, float height,
  430. float fromRadians, float toRadians,
  431. float innerCircleProportionalSize)
  432. {
  433. auto radiusX = width * 0.5f;
  434. auto radiusY = height * 0.5f;
  435. Point<float> centre (x + radiusX, y + radiusY);
  436. startNewSubPath (centre.getPointOnCircumference (radiusX, radiusY, fromRadians));
  437. addArc (x, y, width, height, fromRadians, toRadians);
  438. if (std::abs (fromRadians - toRadians) > MathConstants<float>::pi * 1.999f)
  439. {
  440. closeSubPath();
  441. if (innerCircleProportionalSize > 0)
  442. {
  443. radiusX *= innerCircleProportionalSize;
  444. radiusY *= innerCircleProportionalSize;
  445. startNewSubPath (centre.getPointOnCircumference (radiusX, radiusY, toRadians));
  446. addArc (centre.x - radiusX, centre.y - radiusY, radiusX * 2.0f, radiusY * 2.0f, toRadians, fromRadians);
  447. }
  448. }
  449. else
  450. {
  451. if (innerCircleProportionalSize > 0)
  452. {
  453. radiusX *= innerCircleProportionalSize;
  454. radiusY *= innerCircleProportionalSize;
  455. addArc (centre.x - radiusX, centre.y - radiusY, radiusX * 2.0f, radiusY * 2.0f, toRadians, fromRadians);
  456. }
  457. else
  458. {
  459. lineTo (centre);
  460. }
  461. }
  462. closeSubPath();
  463. }
  464. void Path::addPieSegment (Rectangle<float> segmentBounds,
  465. float fromRadians, float toRadians,
  466. float innerCircleProportionalSize)
  467. {
  468. addPieSegment (segmentBounds.getX(),
  469. segmentBounds.getY(),
  470. segmentBounds.getWidth(),
  471. segmentBounds.getHeight(),
  472. fromRadians,
  473. toRadians,
  474. innerCircleProportionalSize);
  475. }
  476. //==============================================================================
  477. void Path::addLineSegment (Line<float> line, float lineThickness)
  478. {
  479. auto reversed = line.reversed();
  480. lineThickness *= 0.5f;
  481. startNewSubPath (line.getPointAlongLine (0, lineThickness));
  482. lineTo (line.getPointAlongLine (0, -lineThickness));
  483. lineTo (reversed.getPointAlongLine (0, lineThickness));
  484. lineTo (reversed.getPointAlongLine (0, -lineThickness));
  485. closeSubPath();
  486. }
  487. void Path::addArrow (Line<float> line, float lineThickness,
  488. float arrowheadWidth, float arrowheadLength)
  489. {
  490. auto reversed = line.reversed();
  491. lineThickness *= 0.5f;
  492. arrowheadWidth *= 0.5f;
  493. arrowheadLength = jmin (arrowheadLength, 0.8f * line.getLength());
  494. startNewSubPath (line.getPointAlongLine (0, lineThickness));
  495. lineTo (line.getPointAlongLine (0, -lineThickness));
  496. lineTo (reversed.getPointAlongLine (arrowheadLength, lineThickness));
  497. lineTo (reversed.getPointAlongLine (arrowheadLength, arrowheadWidth));
  498. lineTo (line.getEnd());
  499. lineTo (reversed.getPointAlongLine (arrowheadLength, -arrowheadWidth));
  500. lineTo (reversed.getPointAlongLine (arrowheadLength, -lineThickness));
  501. closeSubPath();
  502. }
  503. void Path::addPolygon (Point<float> centre, int numberOfSides,
  504. float radius, float startAngle)
  505. {
  506. jassert (numberOfSides > 1); // this would be silly.
  507. if (numberOfSides > 1)
  508. {
  509. auto angleBetweenPoints = MathConstants<float>::twoPi / (float) numberOfSides;
  510. for (int i = 0; i < numberOfSides; ++i)
  511. {
  512. auto angle = startAngle + (float) i * angleBetweenPoints;
  513. auto p = centre.getPointOnCircumference (radius, angle);
  514. if (i == 0)
  515. startNewSubPath (p);
  516. else
  517. lineTo (p);
  518. }
  519. closeSubPath();
  520. }
  521. }
  522. void Path::addStar (Point<float> centre, int numberOfPoints, float innerRadius,
  523. float outerRadius, float startAngle)
  524. {
  525. jassert (numberOfPoints > 1); // this would be silly.
  526. if (numberOfPoints > 1)
  527. {
  528. auto angleBetweenPoints = MathConstants<float>::twoPi / (float) numberOfPoints;
  529. for (int i = 0; i < numberOfPoints; ++i)
  530. {
  531. auto angle = startAngle + (float) i * angleBetweenPoints;
  532. auto p = centre.getPointOnCircumference (outerRadius, angle);
  533. if (i == 0)
  534. startNewSubPath (p);
  535. else
  536. lineTo (p);
  537. lineTo (centre.getPointOnCircumference (innerRadius, angle + angleBetweenPoints * 0.5f));
  538. }
  539. closeSubPath();
  540. }
  541. }
  542. void Path::addBubble (Rectangle<float> bodyArea,
  543. Rectangle<float> maximumArea,
  544. Point<float> arrowTip,
  545. float cornerSize,
  546. float arrowBaseWidth)
  547. {
  548. auto halfW = bodyArea.getWidth() / 2.0f;
  549. auto halfH = bodyArea.getHeight() / 2.0f;
  550. auto cornerSizeW = jmin (cornerSize, halfW);
  551. auto cornerSizeH = jmin (cornerSize, halfH);
  552. auto cornerSizeW2 = 2.0f * cornerSizeW;
  553. auto cornerSizeH2 = 2.0f * cornerSizeH;
  554. startNewSubPath (bodyArea.getX() + cornerSizeW, bodyArea.getY());
  555. auto targetLimit = bodyArea.reduced (jmin (halfW - 1.0f, cornerSizeW + arrowBaseWidth),
  556. jmin (halfH - 1.0f, cornerSizeH + arrowBaseWidth));
  557. if (Rectangle<float> (targetLimit.getX(), maximumArea.getY(),
  558. targetLimit.getWidth(), bodyArea.getY() - maximumArea.getY()).contains (arrowTip))
  559. {
  560. lineTo (arrowTip.x - arrowBaseWidth, bodyArea.getY());
  561. lineTo (arrowTip.x, arrowTip.y);
  562. lineTo (arrowTip.x + arrowBaseWidth, bodyArea.getY());
  563. }
  564. lineTo (bodyArea.getRight() - cornerSizeW, bodyArea.getY());
  565. addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, MathConstants<float>::halfPi);
  566. if (Rectangle<float> (bodyArea.getRight(), targetLimit.getY(),
  567. maximumArea.getRight() - bodyArea.getRight(), targetLimit.getHeight()).contains (arrowTip))
  568. {
  569. lineTo (bodyArea.getRight(), arrowTip.y - arrowBaseWidth);
  570. lineTo (arrowTip.x, arrowTip.y);
  571. lineTo (bodyArea.getRight(), arrowTip.y + arrowBaseWidth);
  572. }
  573. lineTo (bodyArea.getRight(), bodyArea.getBottom() - cornerSizeH);
  574. addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants<float>::halfPi, MathConstants<float>::pi);
  575. if (Rectangle<float> (targetLimit.getX(), bodyArea.getBottom(),
  576. targetLimit.getWidth(), maximumArea.getBottom() - bodyArea.getBottom()).contains (arrowTip))
  577. {
  578. lineTo (arrowTip.x + arrowBaseWidth, bodyArea.getBottom());
  579. lineTo (arrowTip.x, arrowTip.y);
  580. lineTo (arrowTip.x - arrowBaseWidth, bodyArea.getBottom());
  581. }
  582. lineTo (bodyArea.getX() + cornerSizeW, bodyArea.getBottom());
  583. addArc (bodyArea.getX(), bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants<float>::pi, MathConstants<float>::pi * 1.5f);
  584. if (Rectangle<float> (maximumArea.getX(), targetLimit.getY(),
  585. bodyArea.getX() - maximumArea.getX(), targetLimit.getHeight()).contains (arrowTip))
  586. {
  587. lineTo (bodyArea.getX(), arrowTip.y + arrowBaseWidth);
  588. lineTo (arrowTip.x, arrowTip.y);
  589. lineTo (bodyArea.getX(), arrowTip.y - arrowBaseWidth);
  590. }
  591. lineTo (bodyArea.getX(), bodyArea.getY() + cornerSizeH);
  592. addArc (bodyArea.getX(), bodyArea.getY(), cornerSizeW2, cornerSizeH2, MathConstants<float>::pi * 1.5f, MathConstants<float>::twoPi - 0.05f);
  593. closeSubPath();
  594. }
  595. void Path::addPath (const Path& other)
  596. {
  597. const auto* d = other.data.begin();
  598. const auto size = other.data.size();
  599. for (int i = 0; i < size;)
  600. {
  601. const auto type = d[i++];
  602. if (isMarker (type, moveMarker))
  603. {
  604. startNewSubPath (d[i], d[i + 1]);
  605. i += 2;
  606. }
  607. else if (isMarker (type, lineMarker))
  608. {
  609. lineTo (d[i], d[i + 1]);
  610. i += 2;
  611. }
  612. else if (isMarker (type, quadMarker))
  613. {
  614. quadraticTo (d[i], d[i + 1], d[i + 2], d[i + 3]);
  615. i += 4;
  616. }
  617. else if (isMarker (type, cubicMarker))
  618. {
  619. cubicTo (d[i], d[i + 1], d[i + 2], d[i + 3], d[i + 4], d[i + 5]);
  620. i += 6;
  621. }
  622. else if (isMarker (type, closeSubPathMarker))
  623. {
  624. closeSubPath();
  625. }
  626. else
  627. {
  628. // something's gone wrong with the element list!
  629. jassertfalse;
  630. }
  631. }
  632. }
  633. void Path::addPath (const Path& other,
  634. const AffineTransform& transformToApply)
  635. {
  636. const auto* d = other.data.begin();
  637. const auto size = other.data.size();
  638. for (int i = 0; i < size;)
  639. {
  640. const auto type = d[i++];
  641. if (isMarker (type, closeSubPathMarker))
  642. {
  643. closeSubPath();
  644. }
  645. else
  646. {
  647. auto x = d[i++];
  648. auto y = d[i++];
  649. transformToApply.transformPoint (x, y);
  650. if (isMarker (type, moveMarker))
  651. {
  652. startNewSubPath (x, y);
  653. }
  654. else if (isMarker (type, lineMarker))
  655. {
  656. lineTo (x, y);
  657. }
  658. else if (isMarker (type, quadMarker))
  659. {
  660. auto x2 = d[i++];
  661. auto y2 = d[i++];
  662. transformToApply.transformPoint (x2, y2);
  663. quadraticTo (x, y, x2, y2);
  664. }
  665. else if (isMarker (type, cubicMarker))
  666. {
  667. auto x2 = d[i++];
  668. auto y2 = d[i++];
  669. auto x3 = d[i++];
  670. auto y3 = d[i++];
  671. transformToApply.transformPoints (x2, y2, x3, y3);
  672. cubicTo (x, y, x2, y2, x3, y3);
  673. }
  674. else
  675. {
  676. // something's gone wrong with the element list!
  677. jassertfalse;
  678. }
  679. }
  680. }
  681. }
  682. //==============================================================================
  683. void Path::applyTransform (const AffineTransform& transform) noexcept
  684. {
  685. bounds.reset();
  686. bool firstPoint = true;
  687. float* d = data.begin();
  688. auto* end = data.end();
  689. while (d < end)
  690. {
  691. auto type = *d++;
  692. if (isMarker (type, moveMarker))
  693. {
  694. transform.transformPoint (d[0], d[1]);
  695. JUCE_CHECK_COORDS_ARE_VALID (d[0], d[1])
  696. if (firstPoint)
  697. {
  698. firstPoint = false;
  699. bounds.reset (d[0], d[1]);
  700. }
  701. else
  702. {
  703. bounds.extend (d[0], d[1]);
  704. }
  705. d += 2;
  706. }
  707. else if (isMarker (type, lineMarker))
  708. {
  709. transform.transformPoint (d[0], d[1]);
  710. JUCE_CHECK_COORDS_ARE_VALID (d[0], d[1])
  711. bounds.extend (d[0], d[1]);
  712. d += 2;
  713. }
  714. else if (isMarker (type, quadMarker))
  715. {
  716. transform.transformPoints (d[0], d[1], d[2], d[3]);
  717. JUCE_CHECK_COORDS_ARE_VALID (d[0], d[1])
  718. JUCE_CHECK_COORDS_ARE_VALID (d[2], d[3])
  719. bounds.extend (d[0], d[1], d[2], d[3]);
  720. d += 4;
  721. }
  722. else if (isMarker (type, cubicMarker))
  723. {
  724. transform.transformPoints (d[0], d[1], d[2], d[3], d[4], d[5]);
  725. JUCE_CHECK_COORDS_ARE_VALID (d[0], d[1])
  726. JUCE_CHECK_COORDS_ARE_VALID (d[2], d[3])
  727. JUCE_CHECK_COORDS_ARE_VALID (d[4], d[5])
  728. bounds.extend (d[0], d[1], d[2], d[3], d[4], d[5]);
  729. d += 6;
  730. }
  731. }
  732. }
  733. //==============================================================================
  734. AffineTransform Path::getTransformToScaleToFit (Rectangle<float> area, bool preserveProportions,
  735. Justification justification) const
  736. {
  737. return getTransformToScaleToFit (area.getX(), area.getY(), area.getWidth(), area.getHeight(),
  738. preserveProportions, justification);
  739. }
  740. AffineTransform Path::getTransformToScaleToFit (float x, float y, float w, float h,
  741. bool preserveProportions,
  742. Justification justification) const
  743. {
  744. auto boundsRect = getBounds();
  745. if (preserveProportions)
  746. {
  747. if (w <= 0 || h <= 0 || boundsRect.isEmpty())
  748. return AffineTransform();
  749. float newW, newH;
  750. auto srcRatio = boundsRect.getHeight() / boundsRect.getWidth();
  751. if (srcRatio > h / w)
  752. {
  753. newW = h / srcRatio;
  754. newH = h;
  755. }
  756. else
  757. {
  758. newW = w;
  759. newH = w * srcRatio;
  760. }
  761. auto newXCentre = x;
  762. auto newYCentre = y;
  763. if (justification.testFlags (Justification::left)) newXCentre += newW * 0.5f;
  764. else if (justification.testFlags (Justification::right)) newXCentre += w - newW * 0.5f;
  765. else newXCentre += w * 0.5f;
  766. if (justification.testFlags (Justification::top)) newYCentre += newH * 0.5f;
  767. else if (justification.testFlags (Justification::bottom)) newYCentre += h - newH * 0.5f;
  768. else newYCentre += h * 0.5f;
  769. return AffineTransform::translation (boundsRect.getWidth() * -0.5f - boundsRect.getX(),
  770. boundsRect.getHeight() * -0.5f - boundsRect.getY())
  771. .scaled (newW / boundsRect.getWidth(),
  772. newH / boundsRect.getHeight())
  773. .translated (newXCentre, newYCentre);
  774. }
  775. else
  776. {
  777. return AffineTransform::translation (-boundsRect.getX(), -boundsRect.getY())
  778. .scaled (w / boundsRect.getWidth(),
  779. h / boundsRect.getHeight())
  780. .translated (x, y);
  781. }
  782. }
  783. //==============================================================================
  784. bool Path::contains (float x, float y, float tolerance) const
  785. {
  786. if (x <= bounds.pathXMin || x >= bounds.pathXMax
  787. || y <= bounds.pathYMin || y >= bounds.pathYMax)
  788. return false;
  789. PathFlatteningIterator i (*this, AffineTransform(), tolerance);
  790. int positiveCrossings = 0;
  791. int negativeCrossings = 0;
  792. while (i.next())
  793. {
  794. if ((i.y1 <= y && i.y2 > y) || (i.y2 <= y && i.y1 > y))
  795. {
  796. auto intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  797. if (intersectX <= x)
  798. {
  799. if (i.y1 < i.y2)
  800. ++positiveCrossings;
  801. else
  802. ++negativeCrossings;
  803. }
  804. }
  805. }
  806. return useNonZeroWinding ? (negativeCrossings != positiveCrossings)
  807. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  808. }
  809. bool Path::contains (Point<float> point, float tolerance) const
  810. {
  811. return contains (point.x, point.y, tolerance);
  812. }
  813. bool Path::intersectsLine (Line<float> line, float tolerance) const
  814. {
  815. PathFlatteningIterator i (*this, AffineTransform(), tolerance);
  816. Point<float> intersection;
  817. while (i.next())
  818. if (line.intersects (Line<float> (i.x1, i.y1, i.x2, i.y2), intersection))
  819. return true;
  820. return false;
  821. }
  822. Line<float> Path::getClippedLine (Line<float> line, bool keepSectionOutsidePath) const
  823. {
  824. Line<float> result (line);
  825. const bool startInside = contains (line.getStart());
  826. const bool endInside = contains (line.getEnd());
  827. if (startInside == endInside)
  828. {
  829. if (keepSectionOutsidePath == startInside)
  830. result = Line<float>();
  831. }
  832. else
  833. {
  834. PathFlatteningIterator i (*this, AffineTransform());
  835. Point<float> intersection;
  836. while (i.next())
  837. {
  838. if (line.intersects ({ i.x1, i.y1, i.x2, i.y2 }, intersection))
  839. {
  840. if ((startInside && keepSectionOutsidePath) || (endInside && ! keepSectionOutsidePath))
  841. result.setStart (intersection);
  842. else
  843. result.setEnd (intersection);
  844. }
  845. }
  846. }
  847. return result;
  848. }
  849. float Path::getLength (const AffineTransform& transform, float tolerance) const
  850. {
  851. float length = 0;
  852. PathFlatteningIterator i (*this, transform, tolerance);
  853. while (i.next())
  854. length += Line<float> (i.x1, i.y1, i.x2, i.y2).getLength();
  855. return length;
  856. }
  857. Point<float> Path::getPointAlongPath (float distanceFromStart,
  858. const AffineTransform& transform,
  859. float tolerance) const
  860. {
  861. PathFlatteningIterator i (*this, transform, tolerance);
  862. while (i.next())
  863. {
  864. const Line<float> line (i.x1, i.y1, i.x2, i.y2);
  865. auto lineLength = line.getLength();
  866. if (distanceFromStart <= lineLength)
  867. return line.getPointAlongLine (distanceFromStart);
  868. distanceFromStart -= lineLength;
  869. }
  870. return { i.x2, i.y2 };
  871. }
  872. float Path::getNearestPoint (Point<float> targetPoint, Point<float>& pointOnPath,
  873. const AffineTransform& transform,
  874. float tolerance) const
  875. {
  876. PathFlatteningIterator i (*this, transform, tolerance);
  877. float bestPosition = 0, bestDistance = std::numeric_limits<float>::max();
  878. float length = 0;
  879. Point<float> pointOnLine;
  880. while (i.next())
  881. {
  882. const Line<float> line (i.x1, i.y1, i.x2, i.y2);
  883. auto distance = line.getDistanceFromPoint (targetPoint, pointOnLine);
  884. if (distance < bestDistance)
  885. {
  886. bestDistance = distance;
  887. bestPosition = length + pointOnLine.getDistanceFrom (line.getStart());
  888. pointOnPath = pointOnLine;
  889. }
  890. length += line.getLength();
  891. }
  892. return bestPosition;
  893. }
  894. //==============================================================================
  895. Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  896. {
  897. if (cornerRadius <= 0.01f)
  898. return *this;
  899. Path p;
  900. int n = 0, indexOfPathStart = 0, indexOfPathStartThis = 0;
  901. auto* elements = data.begin();
  902. bool lastWasLine = false, firstWasLine = false;
  903. while (n < data.size())
  904. {
  905. auto type = elements[n++];
  906. if (isMarker (type, moveMarker))
  907. {
  908. indexOfPathStart = p.data.size();
  909. indexOfPathStartThis = n - 1;
  910. auto x = elements[n++];
  911. auto y = elements[n++];
  912. p.startNewSubPath (x, y);
  913. lastWasLine = false;
  914. firstWasLine = (isMarker (elements[n], lineMarker));
  915. }
  916. else if (isMarker (type, lineMarker) || isMarker (type, closeSubPathMarker))
  917. {
  918. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  919. if (isMarker (type, lineMarker))
  920. {
  921. endX = elements[n++];
  922. endY = elements[n++];
  923. if (n > 8)
  924. {
  925. startX = elements[n - 8];
  926. startY = elements[n - 7];
  927. joinX = elements[n - 5];
  928. joinY = elements[n - 4];
  929. }
  930. }
  931. else
  932. {
  933. endX = elements[indexOfPathStartThis + 1];
  934. endY = elements[indexOfPathStartThis + 2];
  935. if (n > 6)
  936. {
  937. startX = elements[n - 6];
  938. startY = elements[n - 5];
  939. joinX = elements[n - 3];
  940. joinY = elements[n - 2];
  941. }
  942. }
  943. if (lastWasLine)
  944. {
  945. auto len1 = PathHelpers::lengthOf (startX, startY, joinX, joinY);
  946. if (len1 > 0)
  947. {
  948. auto propNeeded = jmin (0.5, cornerRadius / len1);
  949. *(p.data.end() - 2) = (float) (joinX - (joinX - startX) * propNeeded);
  950. *(p.data.end() - 1) = (float) (joinY - (joinY - startY) * propNeeded);
  951. }
  952. auto len2 = PathHelpers::lengthOf (endX, endY, joinX, joinY);
  953. if (len2 > 0)
  954. {
  955. auto propNeeded = jmin (0.5, cornerRadius / len2);
  956. p.quadraticTo (joinX, joinY,
  957. (float) (joinX + (endX - joinX) * propNeeded),
  958. (float) (joinY + (endY - joinY) * propNeeded));
  959. }
  960. p.lineTo (endX, endY);
  961. }
  962. else if (isMarker (type, lineMarker))
  963. {
  964. p.lineTo (endX, endY);
  965. lastWasLine = true;
  966. }
  967. if (isMarker (type, closeSubPathMarker))
  968. {
  969. if (firstWasLine)
  970. {
  971. startX = elements[n - 3];
  972. startY = elements[n - 2];
  973. joinX = endX;
  974. joinY = endY;
  975. endX = elements[indexOfPathStartThis + 4];
  976. endY = elements[indexOfPathStartThis + 5];
  977. auto len1 = PathHelpers::lengthOf (startX, startY, joinX, joinY);
  978. if (len1 > 0)
  979. {
  980. auto propNeeded = jmin (0.5, cornerRadius / len1);
  981. *(p.data.end() - 2) = (float) (joinX - (joinX - startX) * propNeeded);
  982. *(p.data.end() - 1) = (float) (joinY - (joinY - startY) * propNeeded);
  983. }
  984. auto len2 = PathHelpers::lengthOf (endX, endY, joinX, joinY);
  985. if (len2 > 0)
  986. {
  987. auto propNeeded = jmin (0.5, cornerRadius / len2);
  988. endX = (float) (joinX + (endX - joinX) * propNeeded);
  989. endY = (float) (joinY + (endY - joinY) * propNeeded);
  990. p.quadraticTo (joinX, joinY, endX, endY);
  991. p.data.begin()[indexOfPathStart + 1] = endX;
  992. p.data.begin()[indexOfPathStart + 2] = endY;
  993. }
  994. }
  995. p.closeSubPath();
  996. }
  997. }
  998. else if (isMarker (type, quadMarker))
  999. {
  1000. lastWasLine = false;
  1001. auto x1 = elements[n++];
  1002. auto y1 = elements[n++];
  1003. auto x2 = elements[n++];
  1004. auto y2 = elements[n++];
  1005. p.quadraticTo (x1, y1, x2, y2);
  1006. }
  1007. else if (isMarker (type, cubicMarker))
  1008. {
  1009. lastWasLine = false;
  1010. auto x1 = elements[n++];
  1011. auto y1 = elements[n++];
  1012. auto x2 = elements[n++];
  1013. auto y2 = elements[n++];
  1014. auto x3 = elements[n++];
  1015. auto y3 = elements[n++];
  1016. p.cubicTo (x1, y1, x2, y2, x3, y3);
  1017. }
  1018. }
  1019. return p;
  1020. }
  1021. //==============================================================================
  1022. void Path::loadPathFromStream (InputStream& source)
  1023. {
  1024. while (! source.isExhausted())
  1025. {
  1026. switch (source.readByte())
  1027. {
  1028. case 'm':
  1029. {
  1030. auto x = source.readFloat();
  1031. auto y = source.readFloat();
  1032. startNewSubPath (x, y);
  1033. break;
  1034. }
  1035. case 'l':
  1036. {
  1037. auto x = source.readFloat();
  1038. auto y = source.readFloat();
  1039. lineTo (x, y);
  1040. break;
  1041. }
  1042. case 'q':
  1043. {
  1044. auto x1 = source.readFloat();
  1045. auto y1 = source.readFloat();
  1046. auto x2 = source.readFloat();
  1047. auto y2 = source.readFloat();
  1048. quadraticTo (x1, y1, x2, y2);
  1049. break;
  1050. }
  1051. case 'b':
  1052. {
  1053. auto x1 = source.readFloat();
  1054. auto y1 = source.readFloat();
  1055. auto x2 = source.readFloat();
  1056. auto y2 = source.readFloat();
  1057. auto x3 = source.readFloat();
  1058. auto y3 = source.readFloat();
  1059. cubicTo (x1, y1, x2, y2, x3, y3);
  1060. break;
  1061. }
  1062. case 'c':
  1063. closeSubPath();
  1064. break;
  1065. case 'n':
  1066. useNonZeroWinding = true;
  1067. break;
  1068. case 'z':
  1069. useNonZeroWinding = false;
  1070. break;
  1071. case 'e':
  1072. return; // end of path marker
  1073. default:
  1074. jassertfalse; // illegal char in the stream
  1075. break;
  1076. }
  1077. }
  1078. }
  1079. void Path::loadPathFromData (const void* const pathData, const size_t numberOfBytes)
  1080. {
  1081. MemoryInputStream in (pathData, numberOfBytes, false);
  1082. loadPathFromStream (in);
  1083. }
  1084. void Path::writePathToStream (OutputStream& dest) const
  1085. {
  1086. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  1087. for (auto* i = data.begin(); i != data.end();)
  1088. {
  1089. auto type = *i++;
  1090. if (isMarker (type, moveMarker))
  1091. {
  1092. dest.writeByte ('m');
  1093. dest.writeFloat (*i++);
  1094. dest.writeFloat (*i++);
  1095. }
  1096. else if (isMarker (type, lineMarker))
  1097. {
  1098. dest.writeByte ('l');
  1099. dest.writeFloat (*i++);
  1100. dest.writeFloat (*i++);
  1101. }
  1102. else if (isMarker (type, quadMarker))
  1103. {
  1104. dest.writeByte ('q');
  1105. dest.writeFloat (*i++);
  1106. dest.writeFloat (*i++);
  1107. dest.writeFloat (*i++);
  1108. dest.writeFloat (*i++);
  1109. }
  1110. else if (isMarker (type, cubicMarker))
  1111. {
  1112. dest.writeByte ('b');
  1113. dest.writeFloat (*i++);
  1114. dest.writeFloat (*i++);
  1115. dest.writeFloat (*i++);
  1116. dest.writeFloat (*i++);
  1117. dest.writeFloat (*i++);
  1118. dest.writeFloat (*i++);
  1119. }
  1120. else if (isMarker (type, closeSubPathMarker))
  1121. {
  1122. dest.writeByte ('c');
  1123. }
  1124. }
  1125. dest.writeByte ('e'); // marks the end-of-path
  1126. }
  1127. String Path::toString() const
  1128. {
  1129. MemoryOutputStream s (2048);
  1130. if (! useNonZeroWinding)
  1131. s << 'a';
  1132. float lastMarker = 0.0f;
  1133. for (int i = 0; i < data.size();)
  1134. {
  1135. auto type = data.begin()[i++];
  1136. char markerChar = 0;
  1137. int numCoords = 0;
  1138. if (isMarker (type, moveMarker))
  1139. {
  1140. markerChar = 'm';
  1141. numCoords = 2;
  1142. }
  1143. else if (isMarker (type, lineMarker))
  1144. {
  1145. markerChar = 'l';
  1146. numCoords = 2;
  1147. }
  1148. else if (isMarker (type, quadMarker))
  1149. {
  1150. markerChar = 'q';
  1151. numCoords = 4;
  1152. }
  1153. else if (isMarker (type, cubicMarker))
  1154. {
  1155. markerChar = 'c';
  1156. numCoords = 6;
  1157. }
  1158. else
  1159. {
  1160. jassert (isMarker (type, closeSubPathMarker));
  1161. markerChar = 'z';
  1162. }
  1163. if (! isMarker (type, lastMarker))
  1164. {
  1165. if (s.getDataSize() != 0)
  1166. s << ' ';
  1167. s << markerChar;
  1168. lastMarker = type;
  1169. }
  1170. while (--numCoords >= 0 && i < data.size())
  1171. {
  1172. String coord (data.begin()[i++], 3);
  1173. while (coord.endsWithChar ('0') && coord != "0")
  1174. coord = coord.dropLastCharacters (1);
  1175. if (coord.endsWithChar ('.'))
  1176. coord = coord.dropLastCharacters (1);
  1177. if (s.getDataSize() != 0)
  1178. s << ' ';
  1179. s << coord;
  1180. }
  1181. }
  1182. return s.toUTF8();
  1183. }
  1184. void Path::restoreFromString (StringRef stringVersion)
  1185. {
  1186. clear();
  1187. setUsingNonZeroWinding (true);
  1188. auto t = stringVersion.text;
  1189. juce_wchar marker = 'm';
  1190. int numValues = 2;
  1191. float values[6];
  1192. for (;;)
  1193. {
  1194. auto token = PathHelpers::nextToken (t);
  1195. auto firstChar = token[0];
  1196. int startNum = 0;
  1197. if (firstChar == 0)
  1198. break;
  1199. if (firstChar == 'm' || firstChar == 'l')
  1200. {
  1201. marker = firstChar;
  1202. numValues = 2;
  1203. }
  1204. else if (firstChar == 'q')
  1205. {
  1206. marker = firstChar;
  1207. numValues = 4;
  1208. }
  1209. else if (firstChar == 'c')
  1210. {
  1211. marker = firstChar;
  1212. numValues = 6;
  1213. }
  1214. else if (firstChar == 'z')
  1215. {
  1216. marker = firstChar;
  1217. numValues = 0;
  1218. }
  1219. else if (firstChar == 'a')
  1220. {
  1221. setUsingNonZeroWinding (false);
  1222. continue;
  1223. }
  1224. else
  1225. {
  1226. ++startNum;
  1227. values [0] = token.getFloatValue();
  1228. }
  1229. for (int i = startNum; i < numValues; ++i)
  1230. values [i] = PathHelpers::nextToken (t).getFloatValue();
  1231. switch (marker)
  1232. {
  1233. case 'm': startNewSubPath (values[0], values[1]); break;
  1234. case 'l': lineTo (values[0], values[1]); break;
  1235. case 'q': quadraticTo (values[0], values[1], values[2], values[3]); break;
  1236. case 'c': cubicTo (values[0], values[1], values[2], values[3], values[4], values[5]); break;
  1237. case 'z': closeSubPath(); break;
  1238. default: jassertfalse; break; // illegal string format?
  1239. }
  1240. }
  1241. }
  1242. //==============================================================================
  1243. Path::Iterator::Iterator (const Path& p) noexcept
  1244. : elementType (startNewSubPath), path (p), index (path.data.begin())
  1245. {
  1246. }
  1247. Path::Iterator::~Iterator() noexcept
  1248. {
  1249. }
  1250. bool Path::Iterator::next() noexcept
  1251. {
  1252. if (index != path.data.end())
  1253. {
  1254. auto type = *index++;
  1255. if (isMarker (type, moveMarker))
  1256. {
  1257. elementType = startNewSubPath;
  1258. x1 = *index++;
  1259. y1 = *index++;
  1260. }
  1261. else if (isMarker (type, lineMarker))
  1262. {
  1263. elementType = lineTo;
  1264. x1 = *index++;
  1265. y1 = *index++;
  1266. }
  1267. else if (isMarker (type, quadMarker))
  1268. {
  1269. elementType = quadraticTo;
  1270. x1 = *index++;
  1271. y1 = *index++;
  1272. x2 = *index++;
  1273. y2 = *index++;
  1274. }
  1275. else if (isMarker (type, cubicMarker))
  1276. {
  1277. elementType = cubicTo;
  1278. x1 = *index++;
  1279. y1 = *index++;
  1280. x2 = *index++;
  1281. y2 = *index++;
  1282. x3 = *index++;
  1283. y3 = *index++;
  1284. }
  1285. else if (isMarker (type, closeSubPathMarker))
  1286. {
  1287. elementType = closePath;
  1288. }
  1289. return true;
  1290. }
  1291. return false;
  1292. }
  1293. #undef JUCE_CHECK_COORDS_ARE_VALID
  1294. } // namespace juce