LMMS
Loading...
Searching...
No Matches
juce_Path.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
65{
66public:
67 //==============================================================================
69 Path();
70
72 Path (const Path&);
73
75 ~Path();
76
78 Path& operator= (const Path&);
79
81 Path (Path&&) noexcept;
82
84 Path& operator= (Path&&) noexcept;
85
86 bool operator== (const Path&) const noexcept;
87 bool operator!= (const Path&) const noexcept;
88
89 static const float defaultToleranceForTesting;
91
92 //==============================================================================
94 bool isEmpty() const noexcept;
95
98
103
117 bool contains (float x, float y,
118 float tolerance = defaultToleranceForTesting) const;
119
133 bool contains (Point<float> point,
134 float tolerance = defaultToleranceForTesting) const;
135
146 bool intersectsLine (Line<float> line,
147 float tolerance = defaultToleranceForTesting) const;
148
161 Line<float> getClippedLine (Line<float> line, bool keepSectionOutsidePath) const;
162
166 float getLength (const AffineTransform& transform = AffineTransform(),
167 float tolerance = defaultToleranceForMeasurement) const;
168
174 Point<float> getPointAlongPath (float distanceFromStart,
176 float tolerance = defaultToleranceForMeasurement) const;
177
182 float getNearestPoint (Point<float> targetPoint,
183 Point<float>& pointOnPath,
185 float tolerance = defaultToleranceForMeasurement) const;
186
187 //==============================================================================
189 void clear() noexcept;
190
202 void startNewSubPath (float startX, float startY);
203
215 void startNewSubPath (Point<float> start);
216
229 void closeSubPath();
230
240 void lineTo (float endX, float endY);
241
251 void lineTo (Point<float> end);
252
262 void quadraticTo (float controlPointX,
263 float controlPointY,
264 float endPointX,
265 float endPointY);
266
276 void quadraticTo (Point<float> controlPoint,
277 Point<float> endPoint);
278
288 void cubicTo (float controlPoint1X,
289 float controlPoint1Y,
290 float controlPoint2X,
291 float controlPoint2Y,
292 float endPointX,
293 float endPointY);
294
304 void cubicTo (Point<float> controlPoint1,
305 Point<float> controlPoint2,
306 Point<float> endPoint);
307
311
312 //==============================================================================
317 void addRectangle (float x, float y, float width, float height);
318
323 template <typename ValueType>
324 void addRectangle (Rectangle<ValueType> rectangle)
325 {
326 addRectangle (static_cast<float> (rectangle.getX()), static_cast<float> (rectangle.getY()),
327 static_cast<float> (rectangle.getWidth()), static_cast<float> (rectangle.getHeight()));
328 }
329
334 void addRoundedRectangle (float x, float y, float width, float height,
335 float cornerSize);
336
341 void addRoundedRectangle (float x, float y, float width, float height,
342 float cornerSizeX,
343 float cornerSizeY);
344
349 void addRoundedRectangle (float x, float y, float width, float height,
350 float cornerSizeX, float cornerSizeY,
351 bool curveTopLeft, bool curveTopRight,
352 bool curveBottomLeft, bool curveBottomRight);
353
358 template <typename ValueType>
359 void addRoundedRectangle (Rectangle<ValueType> rectangle, float cornerSizeX, float cornerSizeY)
360 {
361 addRoundedRectangle (static_cast<float> (rectangle.getX()), static_cast<float> (rectangle.getY()),
362 static_cast<float> (rectangle.getWidth()), static_cast<float> (rectangle.getHeight()),
363 cornerSizeX, cornerSizeY);
364 }
365
370 template <typename ValueType>
371 void addRoundedRectangle (Rectangle<ValueType> rectangle, float cornerSize)
372 {
373 addRoundedRectangle (rectangle, cornerSize, cornerSize);
374 }
375
384 void addTriangle (float x1, float y1,
385 float x2, float y2,
386 float x3, float y3);
387
396 void addTriangle (Point<float> point1,
397 Point<float> point2,
398 Point<float> point3);
399
408 void addQuadrilateral (float x1, float y1,
409 float x2, float y2,
410 float x3, float y3,
411 float x4, float y4);
412
417 void addEllipse (float x, float y, float width, float height);
418
423 void addEllipse (Rectangle<float> area);
424
446 void addArc (float x, float y, float width, float height,
447 float fromRadians,
448 float toRadians,
449 bool startAsNewSubPath = false);
450
473 void addCentredArc (float centreX, float centreY,
474 float radiusX, float radiusY,
475 float rotationOfEllipse,
476 float fromRadians,
477 float toRadians,
478 bool startAsNewSubPath = false);
479
502 void addPieSegment (float x, float y,
503 float width, float height,
504 float fromRadians,
505 float toRadians,
506 float innerCircleProportionalSize);
507
526 void addPieSegment (Rectangle<float> segmentBounds,
527 float fromRadians,
528 float toRadians,
529 float innerCircleProportionalSize);
530
538 void addLineSegment (Line<float> line, float lineThickness);
539
544 void addArrow (Line<float> line,
545 float lineThickness,
546 float arrowheadWidth,
547 float arrowheadLength);
548
552 void addPolygon (Point<float> centre,
553 int numberOfSides,
554 float radius,
555 float startAngle = 0.0f);
556
560 void addStar (Point<float> centre,
561 int numberOfPoints,
562 float innerRadius,
563 float outerRadius,
564 float startAngle = 0.0f);
565
576 void addBubble (Rectangle<float> bodyArea,
577 Rectangle<float> maximumArea,
578 const Point<float> arrowTipPosition,
579 const float cornerSize,
580 const float arrowBaseWidth);
581
589 void addPath (const Path& pathToAppend);
590
599 void addPath (const Path& pathToAppend,
600 const AffineTransform& transformToApply);
601
607 void swapWithPath (Path&) noexcept;
608
609 //==============================================================================
619 void preallocateSpace (int numExtraCoordsToMakeSpaceFor);
620
621 //==============================================================================
626 void applyTransform (const AffineTransform& transform) noexcept;
627
643 void scaleToFit (float x, float y, float width, float height,
644 bool preserveProportions) noexcept;
645
663 AffineTransform getTransformToScaleToFit (float x, float y, float width, float height,
664 bool preserveProportions,
665 Justification justificationType = Justification::centred) const;
666
681 AffineTransform getTransformToScaleToFit (Rectangle<float> area,
682 bool preserveProportions,
683 Justification justificationType = Justification::centred) const;
684
690 Path createPathWithRoundedCorners (float cornerRadius) const;
691
692 //==============================================================================
708 void setUsingNonZeroWinding (bool isNonZeroWinding) noexcept;
709
717
718
719 //==============================================================================
725 {
726 public:
727 //==============================================================================
728 Iterator (const Path& path) noexcept;
729 ~Iterator() noexcept;
730
731 //==============================================================================
738 bool next() noexcept;
739
740 //==============================================================================
749
751
752 float x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0;
753
754 //==============================================================================
755 private:
756 const Path& path;
757 const float* index;
758
760 };
761
762 //==============================================================================
772 void loadPathFromStream (InputStream& source);
773
782 void loadPathFromData (const void* data, size_t numberOfBytes);
783
788 void writePathToStream (OutputStream& destination) const;
789
790 //==============================================================================
794 String toString() const;
795
799 void restoreFromString (StringRef stringVersion);
800
801private:
802 //==============================================================================
804 friend class Path::Iterator;
805 friend class EdgeTable;
806
808
810 {
811 PathBounds() noexcept;
812 Rectangle<float> getRectangle() const noexcept;
813 void reset() noexcept;
814 void reset (float, float) noexcept;
815 void extend (float, float) noexcept;
816
817 template <typename... Coords>
818 void extend (float x, float y, Coords... coords) noexcept
819 {
820 extend (x, y);
821 extend (coords...);
822 }
823
824 float pathXMin = 0, pathXMax = 0, pathYMin = 0, pathYMax = 0;
825 };
826
828 bool useNonZeroWinding = true;
829
830 static const float lineMarker;
831 static const float moveMarker;
832 static const float quadMarker;
833 static const float cubicMarker;
834 static const float closeSubPathMarker;
835
837};
838
839} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
#define final
Definition DistrhoDefines.h:74
Definition juce_AffineTransform.h:43
Definition juce_Array.h:56
Definition juce_InputStream.h:37
Definition juce_Justification.h:41
@ centred
Definition juce_Justification.h:138
Definition juce_Line.h:47
Definition juce_OutputStream.h:38
Definition juce_Path.h:725
const Path & path
Definition juce_Path.h:756
Iterator(const Path &path) noexcept
Definition juce_Path.cpp:1481
const float * index
Definition juce_Path.h:757
float y1
Definition juce_Path.h:752
float x1
Definition juce_Path.h:752
float y3
Definition juce_Path.h:752
float x2
Definition juce_Path.h:752
PathElementType elementType
Definition juce_Path.h:750
bool next() noexcept
Definition juce_Path.cpp:1490
float x3
Definition juce_Path.h:752
float y2
Definition juce_Path.h:752
PathElementType
Definition juce_Path.h:742
@ quadraticTo
Definition juce_Path.h:745
@ closePath
Definition juce_Path.h:747
@ lineTo
Definition juce_Path.h:744
@ cubicTo
Definition juce_Path.h:746
@ startNewSubPath
Definition juce_Path.h:743
Definition juce_Path.h:65
float getNearestPoint(Point< float > targetPoint, Point< float > &pointOnPath, const AffineTransform &transform=AffineTransform(), float tolerance=defaultToleranceForMeasurement) const
Definition juce_Path.cpp:1047
float getLength(const AffineTransform &transform=AffineTransform(), float tolerance=defaultToleranceForMeasurement) const
Definition juce_Path.cpp:1016
static const float defaultToleranceForMeasurement
Definition juce_Path.h:90
static const float cubicMarker
Definition juce_Path.h:833
bool contains(float x, float y, float tolerance=defaultToleranceForTesting) const
Definition juce_Path.cpp:937
void loadPathFromData(const void *data, size_t numberOfBytes)
Definition juce_Path.cpp:1293
void addRoundedRectangle(float x, float y, float width, float height, float cornerSize)
Definition juce_Path.cpp:412
void startNewSubPath(float startX, float startY)
Definition juce_Path.cpp:216
static const float closeSubPathMarker
Definition juce_Path.h:834
Point< float > getCurrentPosition() const
Definition juce_Path.cpp:298
friend class EdgeTable
Definition juce_Path.h:805
Path()
Definition juce_Path.cpp:106
void quadraticTo(float controlPointX, float controlPointY, float endPointX, float endPointY)
Definition juce_Path.cpp:249
friend class PathFlatteningIterator
Definition juce_Path.h:803
static const float quadMarker
Definition juce_Path.h:832
void cubicTo(float controlPoint1X, float controlPoint1Y, float controlPoint2X, float controlPoint2Y, float endPointX, float endPointY)
Definition juce_Path.cpp:268
void addRoundedRectangle(Rectangle< ValueType > rectangle, float cornerSize)
Definition juce_Path.h:371
void addRoundedRectangle(Rectangle< ValueType > rectangle, float cornerSizeX, float cornerSizeY)
Definition juce_Path.h:359
PathBounds bounds
Definition juce_Path.h:827
bool isUsingNonZeroWinding() const
Definition juce_Path.h:716
Rectangle< float > getBoundsTransformed(const AffineTransform &transform) const noexcept
Definition juce_Path.cpp:205
bool intersectsLine(Line< float > line, float tolerance=defaultToleranceForTesting) const
Definition juce_Path.cpp:973
void addRectangle(float x, float y, float width, float height)
Definition juce_Path.cpp:323
void clear() noexcept
Definition juce_Path.cpp:151
static const float lineMarker
Definition juce_Path.h:830
void restoreFromString(StringRef stringVersion)
Definition juce_Path.cpp:1415
bool useNonZeroWinding
Definition juce_Path.h:828
void closeSubPath()
Definition juce_Path.cpp:292
void writePathToStream(OutputStream &destination) const
Definition juce_Path.cpp:1299
Line< float > getClippedLine(Line< float > line, bool keepSectionOutsidePath) const
Definition juce_Path.cpp:985
Rectangle< float > getBounds() const noexcept
Definition juce_Path.cpp:200
String toString() const
Definition juce_Path.cpp:1346
Point< float > getPointAlongPath(float distanceFromStart, const AffineTransform &transform=AffineTransform(), float tolerance=defaultToleranceForMeasurement) const
Definition juce_Path.cpp:1027
void lineTo(float endX, float endY)
Definition juce_Path.cpp:233
static const float moveMarker
Definition juce_Path.h:831
void loadPathFromStream(InputStream &source)
Definition juce_Path.cpp:1227
static const float defaultToleranceForTesting
Definition juce_Path.h:89
Array< float > data
Definition juce_Path.h:807
bool isEmpty() const noexcept
Definition juce_Path.cpp:179
Definition juce_Point.h:42
Definition juce_Rectangle.h:67
ValueType getHeight() const noexcept
Definition juce_Rectangle.h:136
ValueType getX() const noexcept
Definition juce_Rectangle.h:127
ValueType getWidth() const noexcept
Definition juce_Rectangle.h:133
ValueType getY() const noexcept
Definition juce_Rectangle.h:130
Definition juce_String.h:53
Definition juce_StringRef.h:62
int y
Definition inflate.c:1588
unsigned x[BMAX+1]
Definition inflate.c:1586
static int int height
Definition pugl.h:1594
static int width
Definition pugl.h:1593
virtual ASIOError start()=0
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition juce_LeakedObjectDetector.h:138
#define JUCE_DECLARE_NON_COPYABLE(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
RangedDirectoryIterator end(const RangedDirectoryIterator &)
Definition juce_RangedDirectoryIterator.h:184
Definition juce_Path.h:810
void reset() noexcept
Definition juce_Path.cpp:85
PathBounds() noexcept
Definition juce_Path.cpp:76
float pathYMin
Definition juce_Path.h:824
Rectangle< float > getRectangle() const noexcept
Definition juce_Path.cpp:80
void extend(float, float) noexcept
Definition juce_Path.cpp:96
float pathXMin
Definition juce_Path.h:824
void extend(float x, float y, Coords... coords) noexcept
Definition juce_Path.h:818
float pathYMax
Definition juce_Path.h:824
float pathXMax
Definition juce_Path.h:824
#define const
Definition zconf.h:137