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.

59 lines
1.3KB

  1. #include <app/SvgKnob.hpp>
  2. namespace rack {
  3. namespace app {
  4. SvgKnob::SvgKnob() {
  5. fb = new widget::FramebufferWidget;
  6. addChild(fb);
  7. shadow = new CircularShadow;
  8. fb->addChild(shadow);
  9. shadow->box.size = math::Vec();
  10. tw = new widget::TransformWidget;
  11. fb->addChild(tw);
  12. sw = new widget::SvgWidget;
  13. tw->addChild(sw);
  14. }
  15. void SvgKnob::setSvg(std::shared_ptr<Svg> svg) {
  16. sw->setSvg(svg);
  17. tw->box.size = sw->box.size;
  18. fb->box.size = sw->box.size;
  19. box.size = sw->box.size;
  20. shadow->box.size = sw->box.size;
  21. // Move shadow downward by 10%
  22. shadow->box.pos = math::Vec(0, sw->box.size.y * 0.10);
  23. // shadow->box = shadow->box.grow(math::Vec(2, 2));
  24. }
  25. void SvgKnob::onChange(const event::Change& e) {
  26. // Re-transform the widget::TransformWidget
  27. if (paramQuantity) {
  28. float angle;
  29. if (paramQuantity->isBounded()) {
  30. angle = math::rescale(paramQuantity->getScaledValue(), 0.f, 1.f, minAngle, maxAngle);
  31. }
  32. else {
  33. angle = math::rescale(paramQuantity->getValue(), -1.f, 1.f, minAngle, maxAngle);
  34. }
  35. angle = std::fmod(angle, 2 * M_PI);
  36. tw->identity();
  37. // Rotate SVG
  38. math::Vec center = sw->box.getCenter();
  39. tw->translate(center);
  40. tw->rotate(angle);
  41. tw->translate(center.neg());
  42. fb->dirty = true;
  43. }
  44. Knob::onChange(e);
  45. }
  46. } // namespace app
  47. } // namespace rack