You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2KB

  1. #include <app/LightWidget.hpp>
  2. #include <color.hpp>
  3. namespace rack {
  4. namespace app {
  5. void LightWidget::draw(const DrawArgs& args) {
  6. drawLight(args);
  7. drawHalo(args);
  8. }
  9. void LightWidget::drawLight(const DrawArgs& args) {
  10. float radius = std::min(box.size.x, box.size.y) / 2.0;
  11. nvgBeginPath(args.vg);
  12. nvgCircle(args.vg, radius, radius, radius);
  13. // Background
  14. if (bgColor.a > 0.0) {
  15. nvgFillColor(args.vg, bgColor);
  16. nvgFill(args.vg);
  17. }
  18. // Foreground
  19. if (color.a > 0.0) {
  20. nvgFillColor(args.vg, color);
  21. nvgFill(args.vg);
  22. }
  23. // Border
  24. if (borderColor.a > 0.0) {
  25. nvgStrokeWidth(args.vg, 0.5);
  26. nvgStrokeColor(args.vg, borderColor);
  27. nvgStroke(args.vg);
  28. }
  29. }
  30. void LightWidget::drawHalo(const DrawArgs& args) {
  31. float radius = std::min(box.size.x, box.size.y) / 2.0;
  32. float oradius = 4.0 * radius;
  33. nvgBeginPath(args.vg);
  34. nvgRect(args.vg, radius - oradius, radius - oradius, 2 * oradius, 2 * oradius);
  35. NVGpaint paint;
  36. NVGcolor icol = color::mult(color, 0.07);
  37. NVGcolor ocol = nvgRGB(0, 0, 0);
  38. paint = nvgRadialGradient(args.vg, radius, radius, radius, oradius, icol, ocol);
  39. nvgFillPaint(args.vg, paint);
  40. nvgGlobalCompositeOperation(args.vg, NVG_LIGHTER);
  41. nvgFill(args.vg);
  42. }
  43. } // namespace app
  44. } // namespace rack