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
1.1KB

  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 ChangeEvent& e) {
  24. engine::ParamQuantity* pq = getParamQuantity();
  25. if (pq) {
  26. // Interpolate handle position
  27. float v = math::rescale(pq->getSmoothValue(), pq->getMinValue(), pq->getMaxValue(), 0.f, 1.f);
  28. handle->box.pos = math::Vec(
  29. math::rescale(v, 0.f, 1.f, minHandlePos.x, maxHandlePos.x),
  30. math::rescale(v, 0.f, 1.f, minHandlePos.y, maxHandlePos.y));
  31. fb->dirty = true;
  32. }
  33. ParamWidget::onChange(e);
  34. }
  35. } // namespace app
  36. } // namespace rack