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.

57 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. Knob::step();
  22. FramebufferWidget::step();
  23. }
  24. void SVGKnob::onChange(const event::Change &e) {
  25. // Re-transform the TransformWidget
  26. if (paramQuantity) {
  27. float angle;
  28. if (paramQuantity->isBounded()) {
  29. angle = math::rescale(paramQuantity->getScaledValue(), 0.f, 1.f, minAngle, maxAngle);
  30. angle = std::fmod(angle, 2*M_PI);
  31. }
  32. else {
  33. angle = math::rescale(paramQuantity->getValue(), 0.f, 1.f, minAngle, maxAngle);
  34. }
  35. tw->identity();
  36. // Rotate SVG
  37. math::Vec center = sw->box.getCenter();
  38. tw->translate(center);
  39. tw->rotate(angle);
  40. tw->translate(center.neg());
  41. dirty = true;
  42. }
  43. Knob::onChange(e);
  44. }
  45. } // namespace rack