| 307 | |
| 308 | |
| 309 | void CableWidget::drawLayer(const DrawArgs& args, int layer) { |
| 310 | // Cable shadow and cable |
| 311 | float opacity = settings::cableOpacity; |
| 312 | bool thick = false; |
| 313 | |
| 314 | if (isComplete()) { |
| 315 | engine::Output* output = &cable->outputModule->outputs[cable->outputId]; |
| 316 | // Increase thickness if output port is polyphonic |
| 317 | if (output->isPolyphonic()) { |
| 318 | thick = true; |
| 319 | } |
| 320 | |
| 321 | // Draw opaque if mouse is hovering over a connected port |
| 322 | Widget* hoveredWidget = APP->event->hoveredWidget; |
| 323 | if (outputPort == hoveredWidget || inputPort == hoveredWidget) { |
| 324 | opacity = 1.0; |
| 325 | } |
| 326 | // Draw translucent cable if not active (i.e. 0 channels) |
| 327 | else if (output->getChannels() == 0) { |
| 328 | opacity *= 0.5; |
| 329 | } |
| 330 | } |
| 331 | else { |
| 332 | // Draw opaque if the cable is incomplete |
| 333 | opacity = 1.0; |
| 334 | } |
| 335 | |
| 336 | if (opacity <= 0.0) |
| 337 | return; |
| 338 | nvgAlpha(args.vg, std::pow(opacity, 1.5)); |
| 339 | |
| 340 | math::Vec outputPos = getOutputPos(); |
| 341 | math::Vec inputPos = getInputPos(); |
| 342 | |
| 343 | float thickness = thick ? 9.0 : 6.0; |
| 344 | |
| 345 | // The endpoints are off-center |
| 346 | math::Vec slump = getSlumpPos(outputPos, inputPos); |
| 347 | float dist = 14.f; |
| 348 | outputPos = outputPos.plus(slump.minus(outputPos).normalize().mult(dist)); |
| 349 | inputPos = inputPos.plus(slump.minus(inputPos).normalize().mult(dist)); |
| 350 | |
| 351 | nvgLineCap(args.vg, NVG_ROUND); |
| 352 | // Avoids glitches when cable is bent |
| 353 | nvgLineJoin(args.vg, NVG_ROUND); |
| 354 | |
| 355 | if (layer == -1) { |
| 356 | // Draw cable shadow |
| 357 | math::Vec shadowSlump = slump.plus(math::Vec(0, 30)); |
| 358 | nvgBeginPath(args.vg); |
| 359 | nvgMoveTo(args.vg, VEC_ARGS(outputPos)); |
| 360 | nvgQuadTo(args.vg, VEC_ARGS(shadowSlump), VEC_ARGS(inputPos)); |
| 361 | NVGcolor shadowColor = nvgRGBAf(0, 0, 0, 0.10); |
| 362 | nvgStrokeColor(args.vg, shadowColor); |
| 363 | nvgStrokeWidth(args.vg, thickness - 1.0); |
| 364 | nvgStroke(args.vg); |
| 365 | } |
| 366 | else if (layer == 0) { |
nothing calls this directly
no test coverage detected