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.

47 lines
812B

  1. #include "app.hpp"
  2. namespace rack {
  3. SVGKnob::SVGKnob() {
  4. tw = new TransformWidget();
  5. addChild(tw);
  6. sw = new SVGWidget();
  7. tw->addChild(sw);
  8. }
  9. void SVGKnob::setSVG(std::shared_ptr<SVG> svg) {
  10. sw->svg = svg;
  11. sw->wrap();
  12. tw->box.size = sw->box.size;
  13. box.size = sw->box.size;
  14. }
  15. void SVGKnob::step() {
  16. // Re-transform TransformWidget if dirty
  17. if (dirty) {
  18. tw->box.size = box.size;
  19. float angle = rescalef(value, minValue, maxValue, minAngle, maxAngle);
  20. tw->identity();
  21. // Scale SVG to box
  22. tw->scale(box.size.div(sw->box.size));
  23. // Rotate SVG
  24. Vec center = sw->box.getCenter();
  25. tw->translate(center);
  26. tw->rotate(angle);
  27. tw->translate(center.neg());
  28. }
  29. FramebufferWidget::step();
  30. }
  31. void SVGKnob::onChange(EventChange &e) {
  32. dirty = true;
  33. Knob::onChange(e);
  34. }
  35. } // namespace rack