LMMS
Loading...
Searching...
No Matches
juce_DrawableShape.cpp
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
30 : strokeType (0.0f),
31 mainFill (Colours::black),
32 strokeFill (Colours::black)
33{
34}
35
37 : Drawable (other),
38 strokeType (other.strokeType),
40 mainFill (other.mainFill),
42{
43}
44
48
49//==============================================================================
50void DrawableShape::setFill (const FillType& newFill)
51{
52 if (mainFill != newFill)
53 {
54 mainFill = newFill;
55 repaint();
56 }
57}
58
60{
61 if (strokeFill != newFill)
62 {
63 strokeFill = newFill;
64 repaint();
65 }
66}
67
69{
70 if (strokeType != newStrokeType)
71 {
72 strokeType = newStrokeType;
74 }
75}
76
77void DrawableShape::setDashLengths (const Array<float>& newDashLengths)
78{
79 if (dashLengths != newDashLengths)
80 {
81 dashLengths = newDashLengths;
83 }
84}
85
86void DrawableShape::setStrokeThickness (const float newThickness)
87{
88 setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
89}
90
92{
93 return strokeType.getStrokeThickness() > 0.0f && ! strokeFill.isInvisible();
94}
95
96//==============================================================================
98{
101
102 g.setFillType (mainFill);
103 g.fillPath (path);
104
105 if (isStrokeVisible())
106 {
107 g.setFillType (strokeFill);
108 g.fillPath (strokePath);
109 }
110}
111
116
118{
119 strokePath.clear();
120 const float extraAccuracy = 4.0f;
121
122 if (dashLengths.isEmpty())
123 strokeType.createStrokedPath (strokePath, path, AffineTransform(), extraAccuracy);
124 else
125 strokeType.createDashedStroke (strokePath, path, dashLengths.getRawDataPointer(),
126 dashLengths.size(), AffineTransform(), extraAccuracy);
127
129 repaint();
130}
131
133{
134 if (isStrokeVisible())
135 return strokePath.getBounds();
136
137 return path.getBounds();
138}
139
141{
142 bool allowsClicksOnThisComponent, allowsClicksOnChildComponents;
143 getInterceptsMouseClicks (allowsClicksOnThisComponent, allowsClicksOnChildComponents);
144
145 if (! allowsClicksOnThisComponent)
146 return false;
147
148 auto globalX = (float) (x - originRelativeToComponent.x);
149 auto globalY = (float) (y - originRelativeToComponent.y);
150
151 return path.contains (globalX, globalY)
152 || (isStrokeVisible() && strokePath.contains (globalX, globalY));
153}
154
155//==============================================================================
156static bool replaceColourInFill (FillType& fill, Colour original, Colour replacement)
157{
158 if (fill.colour == original && fill.isColour())
159 {
160 fill = FillType (replacement);
161 return true;
162 }
163
164 return false;
165}
166
167bool DrawableShape::replaceColour (Colour original, Colour replacement)
168{
169 bool changed1 = replaceColourInFill (mainFill, original, replacement);
170 bool changed2 = replaceColourInFill (strokeFill, original, replacement);
171 return changed1 || changed2;
172}
173
175{
176 auto outline = isStrokeVisible() ? strokePath : path;
177 outline.applyTransform (getTransform());
178 return outline;
179}
180
181} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_AffineTransform.h:43
Definition juce_Array.h:56
Definition juce_Colour.h:38
AffineTransform getTransform() const
Definition juce_Component.cpp:1378
void repaint()
Definition juce_Component.cpp:1917
void getInterceptsMouseClicks(bool &allowsClicksOnThisComponent, bool &allowsClicksOnChildComponents) const noexcept
Definition juce_Component.cpp:1427
void setBoundsToEnclose(Rectangle< float >)
Definition juce_Drawable.cpp:133
void applyDrawableClipPath(Graphics &)
Definition juce_Drawable.cpp:54
Point< int > originRelativeToComponent
Definition juce_Drawable.h:203
Drawable()
Definition juce_Drawable.cpp:29
void transformContextToCorrectOrigin(Graphics &)
Definition juce_Drawable.cpp:123
Rectangle< float > getDrawableBounds() const override
Definition juce_DrawableShape.cpp:132
PathStrokeType strokeType
Definition juce_DrawableShape.h:116
bool hitTest(int x, int y) override
Definition juce_DrawableShape.cpp:140
void paint(Graphics &) override
Definition juce_DrawableShape.cpp:97
bool isStrokeVisible() const noexcept
Definition juce_DrawableShape.cpp:91
void pathChanged()
Definition juce_DrawableShape.cpp:112
void setStrokeFill(const FillType &newStrokeFill)
Definition juce_DrawableShape.cpp:59
void setStrokeThickness(float newThickness)
Definition juce_DrawableShape.cpp:86
void setDashLengths(const Array< float > &newDashLengths)
Definition juce_DrawableShape.cpp:77
FillType strokeFill
Definition juce_DrawableShape.h:121
bool replaceColour(Colour originalColour, Colour replacementColour) override
Definition juce_DrawableShape.cpp:167
Path getOutlineAsPath() const override
Definition juce_DrawableShape.cpp:174
void setFill(const FillType &newFill)
Definition juce_DrawableShape.cpp:50
~DrawableShape() override
Definition juce_DrawableShape.cpp:45
Path path
Definition juce_DrawableShape.h:118
Array< float > dashLengths
Definition juce_DrawableShape.h:117
Path strokePath
Definition juce_DrawableShape.h:118
FillType mainFill
Definition juce_DrawableShape.h:121
void setStrokeType(const PathStrokeType &newStrokeType)
Definition juce_DrawableShape.cpp:68
void strokeChanged()
Definition juce_DrawableShape.cpp:117
DrawableShape()
Definition juce_DrawableShape.cpp:29
Definition juce_FillType.h:41
Definition juce_GraphicsContext.h:45
Definition juce_Path.h:65
Definition juce_PathStrokeType.h:42
Definition juce_Rectangle.h:67
int y
Definition inflate.c:1588
int g
Definition inflate.c:1573
unsigned x[BMAX+1]
Definition inflate.c:1586
Definition juce_Colours.h:38
Definition carla_juce.cpp:31
static bool replaceColourInFill(FillType &fill, Colour original, Colour replacement)
Definition juce_DrawableShape.cpp:156
#define const
Definition zconf.h:137