openshot-audio  0.1.6
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_PATH_H_INCLUDED
26 #define JUCE_PATH_H_INCLUDED
27 
28 
29 //==============================================================================
63 {
64 public:
65  //==============================================================================
67  Path();
68 
70  Path (const Path&);
71 
73  ~Path();
74 
76  Path& operator= (const Path&);
77 
78  #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
79  Path (Path&&) noexcept;
80  Path& operator= (Path&&) noexcept;
81  #endif
82 
83  bool operator== (const Path&) const noexcept;
84  bool operator!= (const Path&) const noexcept;
85 
86  //==============================================================================
88  bool isEmpty() const noexcept;
89 
92  Rectangle<float> getBounds() const noexcept;
93 
97  Rectangle<float> getBoundsTransformed (const AffineTransform& transform) const noexcept;
98 
112  bool contains (float x, float y,
113  float tolerance = 1.0f) const;
114 
128  bool contains (const Point<float> point,
129  float tolerance = 1.0f) const;
130 
141  bool intersectsLine (const Line<float>& line,
142  float tolerance = 1.0f);
143 
156  Line<float> getClippedLine (const Line<float>& line, bool keepSectionOutsidePath) const;
157 
161  float getLength (const AffineTransform& transform = AffineTransform::identity) const;
162 
168  Point<float> getPointAlongPath (float distanceFromStart,
169  const AffineTransform& transform = AffineTransform::identity) const;
170 
175  float getNearestPoint (const Point<float> targetPoint,
176  Point<float>& pointOnPath,
177  const AffineTransform& transform = AffineTransform::identity) const;
178 
179  //==============================================================================
181  void clear() noexcept;
182 
194  void startNewSubPath (float startX, float startY);
195 
207  void startNewSubPath (const Point<float> start);
208 
221  void closeSubPath();
222 
232  void lineTo (float endX, float endY);
233 
243  void lineTo (const Point<float> end);
244 
254  void quadraticTo (float controlPointX,
255  float controlPointY,
256  float endPointX,
257  float endPointY);
258 
268  void quadraticTo (const Point<float> controlPoint,
269  const Point<float> endPoint);
270 
280  void cubicTo (float controlPoint1X,
281  float controlPoint1Y,
282  float controlPoint2X,
283  float controlPoint2Y,
284  float endPointX,
285  float endPointY);
286 
296  void cubicTo (const Point<float> controlPoint1,
297  const Point<float> controlPoint2,
298  const Point<float> endPoint);
299 
302  Point<float> getCurrentPosition() const;
303 
304  //==============================================================================
309  void addRectangle (float x, float y, float width, float height);
310 
315  template <typename ValueType>
316  void addRectangle (const Rectangle<ValueType>& rectangle)
317  {
318  addRectangle (static_cast <float> (rectangle.getX()), static_cast <float> (rectangle.getY()),
319  static_cast <float> (rectangle.getWidth()), static_cast <float> (rectangle.getHeight()));
320  }
321 
326  void addRoundedRectangle (float x, float y, float width, float height,
327  float cornerSize);
328 
333  void addRoundedRectangle (float x, float y, float width, float height,
334  float cornerSizeX,
335  float cornerSizeY);
336 
341  void addRoundedRectangle (float x, float y, float width, float height,
342  float cornerSizeX, float cornerSizeY,
343  bool curveTopLeft, bool curveTopRight,
344  bool curveBottomLeft, bool curveBottomRight);
345 
350  template <typename ValueType>
351  void addRoundedRectangle (const Rectangle<ValueType>& rectangle, float cornerSizeX, float cornerSizeY)
352  {
353  addRoundedRectangle (static_cast <float> (rectangle.getX()), static_cast <float> (rectangle.getY()),
354  static_cast <float> (rectangle.getWidth()), static_cast <float> (rectangle.getHeight()),
355  cornerSizeX, cornerSizeY);
356  }
357 
362  template <typename ValueType>
363  void addRoundedRectangle (const Rectangle<ValueType>& rectangle, float cornerSize)
364  {
365  addRoundedRectangle (rectangle, cornerSize, cornerSize);
366  }
367 
376  void addTriangle (float x1, float y1,
377  float x2, float y2,
378  float x3, float y3);
379 
388  void addTriangle (Point<float> point1,
389  Point<float> point2,
390  Point<float> point3);
391 
400  void addQuadrilateral (float x1, float y1,
401  float x2, float y2,
402  float x3, float y3,
403  float x4, float y4);
404 
409  void addEllipse (float x, float y, float width, float height);
410 
415  void addEllipse (Rectangle<float> area);
416 
438  void addArc (float x, float y, float width, float height,
439  float fromRadians,
440  float toRadians,
441  bool startAsNewSubPath = false);
442 
465  void addCentredArc (float centreX, float centreY,
466  float radiusX, float radiusY,
467  float rotationOfEllipse,
468  float fromRadians,
469  float toRadians,
470  bool startAsNewSubPath = false);
471 
494  void addPieSegment (float x, float y,
495  float width, float height,
496  float fromRadians,
497  float toRadians,
498  float innerCircleProportionalSize);
499 
518  void addPieSegment (Rectangle<float> segmentBounds,
519  float fromRadians,
520  float toRadians,
521  float innerCircleProportionalSize);
522 
530  void addLineSegment (const Line<float>& line, float lineThickness);
531 
536  void addArrow (const Line<float>& line,
537  float lineThickness,
538  float arrowheadWidth,
539  float arrowheadLength);
540 
544  void addPolygon (const Point<float> centre,
545  int numberOfSides,
546  float radius,
547  float startAngle = 0.0f);
548 
552  void addStar (const Point<float> centre,
553  int numberOfPoints,
554  float innerRadius,
555  float outerRadius,
556  float startAngle = 0.0f);
557 
568  void addBubble (const Rectangle<float>& bodyArea,
569  const Rectangle<float>& maximumArea,
570  const Point<float> arrowTipPosition,
571  const float cornerSize,
572  const float arrowBaseWidth);
573 
581  void addPath (const Path& pathToAppend);
582 
591  void addPath (const Path& pathToAppend,
592  const AffineTransform& transformToApply);
593 
599  void swapWithPath (Path&) noexcept;
600 
601  //==============================================================================
611  void preallocateSpace (int numExtraCoordsToMakeSpaceFor);
612 
613  //==============================================================================
618  void applyTransform (const AffineTransform& transform) noexcept;
619 
635  void scaleToFit (float x, float y, float width, float height,
636  bool preserveProportions) noexcept;
637 
655  AffineTransform getTransformToScaleToFit (float x, float y, float width, float height,
656  bool preserveProportions,
657  Justification justificationType = Justification::centred) const;
658 
673  AffineTransform getTransformToScaleToFit (const Rectangle<float>& area,
674  bool preserveProportions,
675  Justification justificationType = Justification::centred) const;
676 
682  Path createPathWithRoundedCorners (float cornerRadius) const;
683 
684  //==============================================================================
700  void setUsingNonZeroWinding (bool isNonZeroWinding) noexcept;
701 
708  bool isUsingNonZeroWinding() const { return useNonZeroWinding; }
709 
710 
711  //==============================================================================
717  {
718  public:
719  //==============================================================================
720  Iterator (const Path& path) noexcept;
721  ~Iterator() noexcept;
722 
723  //==============================================================================
730  bool next() noexcept;
731 
732  //==============================================================================
734  {
739  closePath
740  };
741 
743 
744  float x1, y1, x2, y2, x3, y3;
745 
746  //==============================================================================
747  private:
748  const Path& path;
749  size_t index;
750 
752  };
753 
754  //==============================================================================
764  void loadPathFromStream (InputStream& source);
765 
774  void loadPathFromData (const void* data, size_t numberOfBytes);
775 
782  void writePathToStream (OutputStream& destination) const;
783 
784  //==============================================================================
788  String toString() const;
789 
793  void restoreFromString (StringRef stringVersion);
794 
795 private:
796  //==============================================================================
798  friend class Path::Iterator;
800  size_t numElements;
801 
802  struct PathBounds
803  {
804  PathBounds() noexcept;
805  Rectangle<float> getRectangle() const noexcept;
806  void reset() noexcept;
807  void reset (float, float) noexcept;
808  void extend (float, float) noexcept;
809  void extend (float, float, float, float) noexcept;
810 
811  float pathXMin, pathXMax, pathYMin, pathYMax;
812  };
813 
814  PathBounds bounds;
815  bool useNonZeroWinding;
816 
817  static const float lineMarker;
818  static const float moveMarker;
819  static const float quadMarker;
820  static const float cubicMarker;
821  static const float closeSubPathMarker;
822 
824 };
825 
826 #endif // JUCE_PATH_H_INCLUDED
Definition: juce_Path.h:738
Definition: juce_PathIterator.h:39
void addRectangle(const Rectangle< ValueType > &rectangle)
Definition: juce_Path.h:316
ValueType getWidth() const noexcept
Definition: juce_Rectangle.h:113
Definition: juce_Line.h:44
#define noexcept
Definition: juce_CompilerSupport.h:141
ValueType getX() const noexcept
Definition: juce_Rectangle.h:107
ValueType getHeight() const noexcept
Definition: juce_Rectangle.h:116
Definition: juce_Path.h:736
Definition: juce_Path.h:735
PathElementType elementType
Definition: juce_Path.h:742
Definition: juce_Justification.h:38
Definition: juce_InputStream.h:41
Definition: juce_Point.h:39
Definition: juce_String.h:43
PathElementType
Definition: juce_Path.h:733
#define JUCE_API
Definition: juce_StandardHeader.h:139
static const AffineTransform identity
Definition: juce_AffineTransform.h:78
#define const
void addRoundedRectangle(const Rectangle< ValueType > &rectangle, float cornerSize)
Definition: juce_Path.h:363
float y3
Definition: juce_Path.h:744
Definition: juce_Rectangle.h:36
Definition: juce_Path.h:62
bool isUsingNonZeroWinding() const
Definition: juce_Path.h:708
Definition: juce_OutputStream.h:42
png_const_structrp png_const_inforp int png_fixed_point * width
Definition: juce_PNGLoader.cpp:2339
bool operator==(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:565
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition: juce_PlatformDefs.h:191
ValueType getY() const noexcept
Definition: juce_Rectangle.h:110
Definition: juce_Justification.h:140
Definition: juce_AffineTransform.h:40
JSAMPIMAGE data
Definition: jpeglib.h:945
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition: juce_LeakedObjectDetector.h:141
bool operator!=(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:566
void addRoundedRectangle(const Rectangle< ValueType > &rectangle, float cornerSizeX, float cornerSizeY)
Definition: juce_Path.h:351
Definition: juce_Path.h:737
Definition: juce_Path.h:716
Definition: juce_StringRef.h:65