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.

37 lines
838B

  1. #include <app/CircularShadow.hpp>
  2. namespace rack {
  3. namespace app {
  4. CircularShadow::CircularShadow() {
  5. blurRadius = 0;
  6. opacity = 0.15;
  7. }
  8. void CircularShadow::draw(const DrawArgs& args) {
  9. if (opacity <= 0.0)
  10. return;
  11. math::Vec center = box.size.div(2.0);
  12. float radius = center.x;
  13. NVGcolor icol = nvgRGBAf(0.0, 0.0, 0.0, opacity);
  14. NVGcolor ocol = nvgRGBAf(0.0, 0.0, 0.0, 0.0);
  15. nvgBeginPath(args.vg);
  16. if (blurRadius > 0.0) {
  17. nvgRect(args.vg, -blurRadius, -blurRadius, box.size.x + 2 * blurRadius, box.size.y + 2 * blurRadius);
  18. NVGpaint paint = nvgRadialGradient(args.vg, center.x, center.y, radius - blurRadius, radius, icol, ocol);
  19. nvgFillPaint(args.vg, paint);
  20. }
  21. else {
  22. nvgCircle(args.vg, center.x, center.y, radius);
  23. nvgFillColor(args.vg, icol);
  24. }
  25. nvgFill(args.vg);
  26. }
  27. } // namespace app
  28. } // namespace rack