MCPcopy Create free account
hub / github.com/VCVRack/Rack / draw

Method draw

src/app/ModuleWidget.cpp:206–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206void ModuleWidget::draw(const DrawArgs& args) {
207 nvgScissor(args.vg, RECT_ARGS(args.clipBox));
208
209 if (module && module->isBypassed()) {
210 nvgAlpha(args.vg, 0.33);
211 }
212
213 Widget::draw(args);
214
215 // Meter
216 if (module && settings::cpuMeter) {
217 float sampleRate = APP->engine->getSampleRate();
218 const float* meterBuffer = module->meterBuffer();
219 int meterLength = module->meterLength();
220 int meterIndex = module->meterIndex();
221
222 // // Text background
223 // nvgBeginPath(args.vg);
224 // nvgRect(args.vg, 0.0, box.size.y - infoHeight, box.size.x, infoHeight);
225 // nvgFillColor(args.vg, nvgRGBAf(0, 0, 0, 0.75));
226 // nvgFill(args.vg);
227
228 // Draw time plot
229 const float plotHeight = box.size.y - BND_WIDGET_HEIGHT;
230 nvgBeginPath(args.vg);
231 nvgMoveTo(args.vg, 0.0, plotHeight);
232 math::Vec p1;
233 for (int i = 0; i < meterLength; i++) {
234 int index = math::eucMod(meterIndex + i + 1, meterLength);
235 float meter = math::clamp(meterBuffer[index] * sampleRate, 0.f, 1.f);
236 meter = std::max(0.f, meter);
237 math::Vec p;
238 p.x = (float) i / (meterLength - 1) * box.size.x;
239 p.y = (1.f - meter) * plotHeight;
240 if (i == 0) {
241 nvgLineTo(args.vg, VEC_ARGS(p));
242 }
243 else {
244 math::Vec p2 = p;
245 p2.x -= 0.5f / (meterLength - 1) * box.size.x;
246 nvgBezierTo(args.vg, VEC_ARGS(p1), VEC_ARGS(p2), VEC_ARGS(p));
247 }
248 p1 = p;
249 p1.x += 0.5f / (meterLength - 1) * box.size.x;
250 }
251 nvgLineTo(args.vg, box.size.x, plotHeight);
252 nvgClosePath(args.vg);
253 NVGcolor color = componentlibrary::SCHEME_ORANGE;
254 nvgFillColor(args.vg, color::alpha(color, 0.75));
255 nvgFill(args.vg);
256 nvgStrokeWidth(args.vg, 2.0);
257 nvgStrokeColor(args.vg, color);
258 nvgStroke(args.vg);
259
260 // Text background
261 bndMenuBackground(args.vg, 0.0, plotHeight, box.size.x, BND_WIDGET_HEIGHT, BND_CORNER_ALL);
262
263 // Text

Callers

nothing calls this directly

Calls 12

eucModFunction · 0.85
maxFunction · 0.85
alphaFunction · 0.85
isBypassedMethod · 0.80
meterBufferMethod · 0.80
meterLengthMethod · 0.80
meterIndexMethod · 0.80
getWidthMethod · 0.80
isSelectedMethod · 0.80
clampFunction · 0.50
fFunction · 0.50
getSampleRateMethod · 0.45

Tested by

no test coverage detected