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.

46 lines
954B

  1. #include "app/SVGSlider.hpp"
  2. namespace rack {
  3. SVGSlider::SVGSlider() {
  4. fb = new FramebufferWidget;
  5. addChild(fb);
  6. background = new SVGWidget;
  7. fb->addChild(background);
  8. handle = new SVGWidget;
  9. fb->addChild(handle);
  10. speed = 2.0;
  11. }
  12. void SVGSlider::setBackgroundSVG(std::shared_ptr<SVG> backgroundSVG) {
  13. background->setSVG(backgroundSVG);
  14. fb->box.size = background->box.size;
  15. box.size = background->box.size;
  16. }
  17. void SVGSlider::setHandleSVG(std::shared_ptr<SVG> handleSVG) {
  18. handle->setSVG(handleSVG);
  19. handle->box.pos = maxHandlePos;
  20. fb->dirty = true;
  21. }
  22. void SVGSlider::onChange(const event::Change &e) {
  23. if (paramQuantity) {
  24. // Interpolate handle position
  25. float v = paramQuantity->getScaledValue();
  26. handle->box.pos = math::Vec(
  27. math::rescale(v, 0.f, 1.f, minHandlePos.x, maxHandlePos.x),
  28. math::rescale(v, 0.f, 1.f, minHandlePos.y, maxHandlePos.y));
  29. fb->dirty = true;
  30. }
  31. ParamWidget::onChange(e);
  32. }
  33. } // namespace rack