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.

51 lines
970B

  1. #include "app.hpp"
  2. #include "util/color.hpp"
  3. namespace rack {
  4. void LightWidget::draw(NVGcontext *vg) {
  5. drawLight(vg);
  6. drawHalo(vg);
  7. }
  8. void LightWidget::drawLight(NVGcontext *vg) {
  9. float radius = box.size.x / 2.0;
  10. nvgBeginPath(vg);
  11. nvgCircle(vg, radius, radius, radius);
  12. // Background
  13. nvgFillColor(vg, bgColor);
  14. nvgFill(vg);
  15. // Foreground
  16. nvgFillColor(vg, color);
  17. nvgFill(vg);
  18. // Border
  19. nvgStrokeWidth(vg, 0.5);
  20. nvgStrokeColor(vg, borderColor);
  21. nvgStroke(vg);
  22. }
  23. void LightWidget::drawHalo(NVGcontext *vg) {
  24. float radius = box.size.x / 2.0;
  25. float oradius = radius + 15.0;
  26. nvgBeginPath(vg);
  27. nvgRect(vg, radius - oradius, radius - oradius, 2*oradius, 2*oradius);
  28. NVGpaint paint;
  29. NVGcolor icol = colorMult(color, 0.08);
  30. NVGcolor ocol = nvgRGB(0, 0, 0);
  31. paint = nvgRadialGradient(vg, radius, radius, radius, oradius, icol, ocol);
  32. nvgFillPaint(vg, paint);
  33. nvgGlobalCompositeOperation(vg, NVG_LIGHTER);
  34. nvgFill(vg);
  35. }
  36. } // namespace rack