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.

SvgSwitch.cpp 1009B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <app/SvgSwitch.hpp>
  2. namespace rack {
  3. namespace app {
  4. SvgSwitch::SvgSwitch() {
  5. fb = new widget::FramebufferWidget;
  6. addChild(fb);
  7. shadow = new CircularShadow;
  8. fb->addChild(shadow);
  9. shadow->box.size = math::Vec();
  10. sw = new widget::SvgWidget;
  11. fb->addChild(sw);
  12. }
  13. void SvgSwitch::addFrame(std::shared_ptr<Svg> svg) {
  14. frames.push_back(svg);
  15. // If this is our first frame, automatically set SVG and size
  16. if (!sw->svg) {
  17. sw->setSvg(svg);
  18. box.size = sw->box.size;
  19. fb->box.size = sw->box.size;
  20. // Move shadow downward by 10%
  21. shadow->box.size = sw->box.size;
  22. shadow->box.pos = math::Vec(0, sw->box.size.y * 0.10);
  23. }
  24. }
  25. void SvgSwitch::onChange(const event::Change& e) {
  26. if (!frames.empty() && paramQuantity) {
  27. int index = (int) std::round(paramQuantity->getValue() - paramQuantity->getMinValue());
  28. index = math::clamp(index, 0, (int) frames.size() - 1);
  29. sw->setSvg(frames[index]);
  30. fb->dirty = true;
  31. }
  32. ParamWidget::onChange(e);
  33. }
  34. } // namespace app
  35. } // namespace rack