JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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//==============================================================================
64class JUCE_API Path final
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;
90 static const float defaultToleranceForMeasurement;
91
92 //==============================================================================
94 bool isEmpty() const noexcept;
95
97 Rectangle<float> getBounds() const noexcept;
98
102 Rectangle<float> getBoundsTransformed (const AffineTransform& transform) const noexcept;
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,
175 const AffineTransform& transform = AffineTransform(),
176 float tolerance = defaultToleranceForMeasurement) const;
177
182 float getNearestPoint (Point<float> targetPoint,
183 Point<float>& pointOnPath,
184 const AffineTransform& transform = AffineTransform(),
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
310 Point<float> getCurrentPosition() const;
311
312 //==============================================================================
317 void addRectangle (float x, float y, float width, float height);
318
323 template <typename ValueType>
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 Point<float> arrowTipPosition,
579 float cornerSize,
580 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
716 bool isUsingNonZeroWinding() const { return useNonZeroWinding; }
717
718
719 //==============================================================================
724 class JUCE_API Iterator
725 {
726 public:
727 //==============================================================================
728 Iterator (const Path& path) noexcept;
729 ~Iterator() noexcept;
730
731 //==============================================================================
738 bool next() noexcept;
739
740 //==============================================================================
749
750 PathElementType elementType;
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 //==============================================================================
803 friend class PathFlatteningIterator;
804 friend class Path::Iterator;
805 friend class EdgeTable;
806
807 Array<float> data;
808
809 struct PathBounds
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
827 PathBounds bounds;
828 bool useNonZeroWinding = true;
829
830 static constexpr float lineMarker = 100001.0f;
831 static constexpr float moveMarker = 100002.0f;
832 static constexpr float quadMarker = 100003.0f;
833 static constexpr float cubicMarker = 100004.0f;
834 static constexpr float closeSubPathMarker = 100005.0f;
835
836 JUCE_LEAK_DETECTOR (Path)
837};
838
839} // namespace juce
Represents a 2D affine-transformation matrix.
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
A table of horizontal scan-line segments - used for rasterising Paths.
The base class for streams that read data.
Represents a type of justification to be used when positioning graphical items.
Represents a line.
Definition juce_Line.h:47
The base class for streams that write data to some kind of destination.
Flattens a Path object into a series of straight-line sections.
Iterates the lines and curves that a path contains.
Definition juce_Path.h:725
@ quadraticTo
For this type, x1, y1, x2, y2 indicate the control point and endpoint of a quadratic curve.
Definition juce_Path.h:745
@ lineTo
For this type, x1 and y1 indicate the end point of the line.
Definition juce_Path.h:744
@ cubicTo
For this type, x1, y1, x2, y2, x3, y3 indicate the two control points and the endpoint of a cubic cur...
Definition juce_Path.h:746
@ startNewSubPath
For this type, x1 and y1 will be set to indicate the first point in the subpath.
Definition juce_Path.h:743
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
Definition juce_Path.h:65
void addRoundedRectangle(Rectangle< ValueType > rectangle, float cornerSize)
Adds a rectangle with rounded corners to the path.
Definition juce_Path.h:371
void addRoundedRectangle(Rectangle< ValueType > rectangle, float cornerSizeX, float cornerSizeY)
Adds a rectangle with rounded corners to the path.
Definition juce_Path.h:359
bool isUsingNonZeroWinding() const
Returns the flag that indicates whether the path should use a non-zero winding rule.
Definition juce_Path.h:716
void addRectangle(Rectangle< ValueType > rectangle)
Adds a rectangle to the path.
Definition juce_Path.h:324
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Manages a rectangle and allows geometric operations to be performed on it.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
ValueType getY() const noexcept
Returns the y coordinate of the rectangle's top edge.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
A simple class for holding temporary references to a string literal or String.
The JUCE String class!
Definition juce_String.h:53
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
#define JUCE_DECLARE_NON_COPYABLE(className)
This is a shorthand macro for deleting a class's copy constructor and copy assignment operator.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
y1