음악, 삶, 개발
Juce 로 만드는 GUI 파트12 - Path 클래스 본문
< Path 클래스 >
디자인툴에서 말하는 Path 와 동일한 개념이다.
따라서 Illustrator 를 통해 Path 의 개념을 먼저 공부할것이다. (열린 Path, 닫힌 Path 등등..)
GUI 를 디자인함에 있어, 가장 뿌리가 되는것이 Path 이므로
이 클래스에서 제공하는 멤버 함수들을 또한 모두 공부할것이다.
Illustrator 에서도 Path 를 만드는데에 매우 많은 방법들이 필요한데,
Path 클래스 또한 약 40가지의 Set 함수를 제공한다.
이 함수들을 이용하여 일러스트레이터의 Path 를 Juce 의 Path 로 옮기는 함수들을 작성할것이다.
뒤에서 보겠지만 Path 객체는 Graphics 클래스의 멤버 함수의 인자로 넘김으로써 그려지게된다.
< 공식 문서 >
Path Class Reference
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
To use a path, you can create an empty one, then add lines and curves to it to create shapes,
then it can be rendered by a Graphics context or used for geometric operations.
e.g.
Path myPath;
myPath.startNewSubPath (10.0f, 10.0f); // move the current position to (10, 10)
myPath.lineTo (100.0f, 200.0f); // draw a line from here to (100, 200)
myPath.quadraticTo (0.0f, 150.0f, 5.0f, 50.0f); // draw a curve that ends at (5, 50)
myPath.closeSubPath(); // close the subpath with a line back to (10, 10)
// add an ellipse as well, which will form a second sub-path within the path..
myPath.addEllipse (50.0f, 50.0f, 40.0f, 30.0f);
// double the width of the whole thing..
myPath.applyTransform (AffineTransform::scale (2.0f, 1.0f));
// and draw it to a graphics context with a 5-pixel thick outline.
g.strokePath (myPath, PathStrokeType (5.0f));
A path object can actually contain multiple sub-paths, which may themselves be open or closed.
See also PathFlatteningIterator, PathStrokeType, Graphics
/* Constructor */
Path ()
Path (const Path& )
Path (Path &&) noexcept
/* Destructor */
~Path ()
/* Operator */
Path& operator= (const Path&)
Path& operator= (Path&& ) noexcept
bool operator== (const Path& ) const noexcept
bool operator!= (const Path& ) const noexcept
/* Get */
bool isEmpty () const noexcept
bool isUsingNonZeroWinding () const
bool contains (float x, float y, float tolerance=defaultToleranceForTesting) const
bool contains (Point<float> point, float tolerance=defaultToleranceForTesting) const
Rectangle<float> getBounds () const noexcept
Rectangle<float> getBoundsTransformed (const AffineTransform& transform) const noexcept
Line<float> getClippedLine (Line<float> line, bool keepSectionOutsidePath) const
Point<float> getPointAlongPath (float distanceFromStart, const AffineTransform& transform=AffineTransform(), float tolerance=defaultToleranceForMeasurement) const
Point<float> getCurrentPosition () const
float getNearestPoint (Point<float> targetPoint, Point<float>& pointOnPath, const AffineTransform& transform=AffineTransform(), float tolerance=defaultToleranceForMeasurement) const
float getLength (const AffineTransform& transform=AffineTransform(), float tolerance=defaultToleranceForMeasurement) const
AffineTransform getTransformToScaleToFit (float x, float y, float width, float height, bool preserveProportions, Justification justificationType=Justification::centred) const
AffineTransform getTransformToScaleToFit (Rectangle<float> area, bool preserveProportions, Justification justificationType=Justification::centred) const
/* Set */
void clear () noexcept
void startNewSubPath (float startX, float startY)
void startNewSubPath (Point<float> start)
void closeSubPath ()
void lineTo (float endX, float endY)
void lineTo (Point<float> end)
void quadraticTo (float controlPointX, float controlPointY, float endPointX, float endPointY)
void quadraticTo (Point<float> controlPoint, Point<float> endPoint)
void cubicTo (float controlPoint1X, float controlPoint1Y, float controlPoint2X, float controlPoint2Y, float endPointX, float endPointY)
void cubicTo (Point<float> controlPoint1, Point<float> controlPoint2, Point<float> endPoint)
void addRectangle (float x, float y, float width, float height)
void addRectangle (Rectangle<ValueType> rectangle)
void addRoundedRectangle (float x, float y, float width, float height, float cornerSize)
void addRoundedRectangle (float x, float y, float width, float height, float cornerSizeX, float cornerSizeY)
void addRoundedRectangle (float x, float y, float width, float height, float cornerSizeX, float cornerSizeY, bool curveTopLeft, bool curveTopRight, bool curveBottomLeft, bool curveBottomRight)
void addRoundedRectangle (Rectangle<ValueType> rectangle, float cornerSizeX, float cornerSizeY)
void addRoundedRectangle (Rectangle<ValueType> rectangle, float cornerSize)
void addTriangle (float x1, float y1, float x2, float y2, float x3, float y3)
void addTriangle (Point< float > point1, Point< float > point2, Point< float > point3)
void addQuadrilateral (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
void addEllipse (float x, float y, float width, float height)
void addEllipse (Rectangle<float> area)
void addArc (float x, float y, float width, float height, float fromRadians, float toRadians, bool startAsNewSubPath=false)
void addCentredArc (float centreX, float centreY, float radiusX, float radiusY, float rotationOfEllipse, float fromRadians, float toRadians, bool startAsNewSubPath=false)
void addPieSegment (float x, float y, float width, float height, float fromRadians, float toRadians, float innerCircleProportionalSize)
void addPieSegment (Rectangle<float> segmentBounds, float fromRadians, float toRadians, float innerCircleProportionalSize)
void addLineSegment (Line<float> line, float lineThickness)
void addArrow (Line<float> line, float lineThickness, float arrowheadWidth, float arrowheadLength)
void addPolygon (Point<float> centre, int numberOfSides, float radius, float startAngle=0.0f)
void addStar (Point<float> centre, int numberOfPoints, float innerRadius, float outerRadius, float startAngle=0.0f)
void addBubble (Rectangle<float> bodyArea, Rectangle<float> maximumArea, const Point<float> arrowTipPosition, const float cornerSize, const float arrowBaseWidth)
void addPath (const Path& pathToAppend)
void addPath (const Path& pathToAppend, const AffineTransform& transformToApply)
void swapWithPath (Path& ) noexcept
void preallocateSpace (int numExtraCoordsToMakeSpaceFor)
void applyTransform (const AffineTransform& transform) noexcept
void scaleToFit (float x, float y, float width, float height, bool preserveProportions) noexcept
void setUsingNonZeroWinding (bool isNonZeroWinding) noexcept
void loadPathFromStream (InputStream& source)
void loadPathFromData (const void* data, size_t numberOfBytes)
void restoreFromString (StringRef stringVersion)
bool intersectsLine (Line<float> line, float tolerance=defaultToleranceForTesting)
/* Create */
String toString () const
Path createPathWithRoundedCorners (float cornerRadius) const
/* Output Parameter */
void writePathToStream (OutputStream& destination) const
/* Static Public Attributes */
static const float defaultToleranceForTesting
static const float defaultToleranceForMeasurement
< Path 란? >
< Path 객체를 인자로 사용하는 Graphics 클래스의 4가지 함수 >
void fillPath (const Path& path) const
void fillPath (const Path& path, const AffineTransform& transform) const
void strokePath (const Path& path, const PathStrokeType& strokeType, const AffineTransform& transform={}) const
bool reduceClipRegion (const Path& path, const AffineTransform& transform=AffineTransform())
< Path 클래스의 크기 >
40 bytes = 320 bits 로 엄청 크지도 않지만, 마냥 작은 크기는 아니다.
하지만 Path 클래스는 Copy 와 Move 둘 다 허용하고있다.
Path (const Path& ) // Copy constructor
Path (Path &&) noexcept // Move constructor
Path& operator= (const Path&) // Copy Assignment
Path& operator= (Path&& ) // Move Assignment
내가 만약 Path 객체를 내가 만든 함수의 인자로 넘겨야한다면 const reference 로 넘겨야한다.
Juce 가 만든 코드도 그렇게 처리하고있다.
void fillPath (const Path& path) const