MCPcopy Create free account
hub / github.com/andrewreeman/SpectralSuite / paint

Method paint

shared/components/ControlPointComponent.cpp:88–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88void ControlPointComponent::paint (Graphics& g)
89{
90// g.fillAll(Colours::purple);
91// g.setColour(Colours::purple);
92//
93// Rectangle<int> drawRect(getBounds().getX(), getBounds().getY(), getBounds().getWidth(), getBounds().getHeight());
94// g.drawRect(drawRect);
95//
96
97 if (points.size() >= 3)
98 {
99 Array<juce::Point<double>> dpoints;
100 for (auto p : points)
101 dpoints.add ({ double (p.getX()), double (p.getY())});
102
103 Spline spline (dpoints);
104
105 g.setColour (Colours::red);
106
107 Path p;
108
109 p.startNewSubPath (points.getFirst().toFloat());
110 for (int x = points.getFirst().getX(); x < points.getLast().getX(); x++)
111 {
112 double y = spline.interpolate (x);
113 if(y < 0.0) {
114 y = 2.0;
115 }
116 else if(y > (double)getLocalBounds().getBottom()) {
117 y = (double)getLocalBounds().getBottom() - 2.0;
118 }
119
120 p.lineTo (float (x), float (y));
121 }
122 p.lineTo (points.getLast().toFloat());
123
124 g.strokePath (p, PathStrokeType (2));
125 }
126 else if(points.size() == 2) {
127 g.setColour (Colours::red);
128
129 Path p;
130
131 p.startNewSubPath (points.getFirst().toFloat());
132 for (auto& point : points)
133 {
134 p.lineTo (float (point.x), float (point.y));
135 }
136
137 g.strokePath (p, PathStrokeType (2));
138 }
139
140 g.setColour (Colours::blue);
141 for (auto pt : points)
142 g.fillEllipse ((float)pt.getX() - 4.f, (float)pt.getY() - 4.f, 8.0f, 8.0f);
143
144 if (points.isEmpty())
145 g.drawText ("Click from left to right to add points.\n Double click to remove.", getLocalBounds(), Justification::centred);

Callers

nothing calls this directly

Calls 2

interpolateMethod · 0.80
isEmptyMethod · 0.45

Tested by

no test coverage detected