29DrawableShape::DrawableShape()
31 mainFill (Colours::black),
32 strokeFill (Colours::black)
36DrawableShape::DrawableShape (
const DrawableShape& other)
38 strokeType (other.strokeType),
39 dashLengths (other.dashLengths),
40 mainFill (other.mainFill),
41 strokeFill (other.strokeFill)
45DrawableShape::~DrawableShape()
50void DrawableShape::setFill (
const FillType& newFill)
52 if (mainFill != newFill)
59void DrawableShape::setStrokeFill (
const FillType& newFill)
61 if (strokeFill != newFill)
70 if (strokeType != newStrokeType)
72 strokeType = newStrokeType;
77void DrawableShape::setDashLengths (
const Array<float>& newDashLengths)
79 if (dashLengths != newDashLengths)
81 dashLengths = newDashLengths;
86void DrawableShape::setStrokeThickness (
const float newThickness)
88 setStrokeType (
PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
91bool DrawableShape::isStrokeVisible() const noexcept
93 return strokeType.getStrokeThickness() > 0.0f && ! strokeFill.isInvisible();
99 transformContextToCorrectOrigin (g);
100 applyDrawableClipPath (g);
105 if (isStrokeVisible())
112void DrawableShape::pathChanged()
117void DrawableShape::strokeChanged()
120 const float extraAccuracy = 4.0f;
122 if (dashLengths.isEmpty())
123 strokeType.createStrokedPath (strokePath, path,
AffineTransform(), extraAccuracy);
125 strokeType.createDashedStroke (strokePath, path, dashLengths.getRawDataPointer(),
128 setBoundsToEnclose (getDrawableBounds());
134 if (isStrokeVisible())
135 return strokePath.getBounds();
137 return path.getBounds();
140bool DrawableShape::hitTest (
int x,
int y)
142 bool allowsClicksOnThisComponent, allowsClicksOnChildComponents;
143 getInterceptsMouseClicks (allowsClicksOnThisComponent, allowsClicksOnChildComponents);
145 if (! allowsClicksOnThisComponent)
148 auto globalX = (
float) (x - originRelativeToComponent.x);
149 auto globalY = (
float) (y - originRelativeToComponent.y);
151 return path.contains (globalX, globalY)
152 || (isStrokeVisible() && strokePath.contains (globalX, globalY));
158 if (fill.colour == original && fill.isColour())
169 bool changed1 = replaceColourInFill (mainFill, original, replacement);
170 bool changed2 = replaceColourInFill (strokeFill, original, replacement);
171 return changed1 || changed2;
174Path DrawableShape::getOutlineAsPath()
const
176 auto outline = isStrokeVisible() ? strokePath : path;
Holds a resizable array of primitive or copy-by-value objects.
Represents a colour, also including a transparency value.
Represents a colour or fill pattern to use for rendering paths.
A graphics context, used for drawing a component or image.
void setFillType(const FillType &newFill)
Changes the current fill settings.
void fillPath(const Path &path) const
Fills a path using the currently selected colour or brush.
Describes a type of stroke used to render a solid outline along a path.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
void applyTransform(const AffineTransform &transform) noexcept
Applies a 2D transform to all the vertices in the path.
Manages a rectangle and allows geometric operations to be performed on it.