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.

48 lines
1019B

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