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.

49 lines
885B

  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 = 0.0;
  20. if (std::isfinite(minValue) && std::isfinite(maxValue))
  21. angle = rescale(value, minValue, maxValue, minAngle, maxAngle);
  22. tw->identity();
  23. // Scale SVG to box
  24. tw->scale(box.size.div(sw->box.size));
  25. // Rotate SVG
  26. Vec center = sw->box.getCenter();
  27. tw->translate(center);
  28. tw->rotate(angle);
  29. tw->translate(center.neg());
  30. }
  31. FramebufferWidget::step();
  32. }
  33. void SVGKnob::onChange(EventChange &e) {
  34. dirty = true;
  35. Knob::onChange(e);
  36. }
  37. } // namespace rack