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/SVGKnob.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 && quantity) {
  23. float angle;
  24. if (quantity->isBounded()) {
  25. angle = math::rescale(quantity->getValue(), -1.f, 1.f, minAngle, maxAngle);
  26. angle = std::fmod(angle, 2*M_PI);
  27. }
  28. else {
  29. angle = math::rescale(quantity->getScaledValue(), 0.f, 1.f, minAngle, maxAngle);
  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::onChange(event::Change &e) {
  41. dirty = true;
  42. ParamWidget::onChange(e);
  43. }
  44. } // namespace rack