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.

56 lines
1.1KB

  1. #include "app.hpp"
  2. namespace rack {
  3. SVGKnob::SVGKnob() {
  4. shadow = new CircularShadow();
  5. addChild(shadow);
  6. shadow->box.size = math::Vec();
  7. tw = new TransformWidget();
  8. addChild(tw);
  9. sw = new SVGWidget();
  10. tw->addChild(sw);
  11. }
  12. void SVGKnob::setSVG(std::shared_ptr<SVG> svg) {
  13. sw->setSVG(svg);
  14. tw->box.size = sw->box.size;
  15. box.size = sw->box.size;
  16. shadow->box.size = sw->box.size;
  17. shadow->box.pos = math::Vec(0, sw->box.size.y * 0.1);
  18. // shadow->box = shadow->box.grow(math::Vec(2, 2));
  19. }
  20. void SVGKnob::step() {
  21. // Re-transform TransformWidget if dirty
  22. if (dirty) {
  23. float angle;
  24. if (std::isfinite(minValue) && std::isfinite(maxValue)) {
  25. angle = math::rescale(value, minValue, maxValue, minAngle, maxAngle);
  26. }
  27. else {
  28. angle = math::rescale(value, -1.0, 1.0, minAngle, maxAngle);
  29. angle = std::fmod(angle, 2*M_PI);
  30. }
  31. tw->identity();
  32. // Rotate SVG
  33. math::Vec center = sw->box.getCenter();
  34. tw->translate(center);
  35. tw->rotate(angle);
  36. tw->translate(center.neg());
  37. }
  38. FramebufferWidget::step();
  39. }
  40. void SVGKnob::on(event::Change &e) {
  41. dirty = true;
  42. ParamWidget::on(e);
  43. }
  44. } // namespace rack