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.

45 lines
1.1KB

  1. #include "ValleyWidgets.hpp"
  2. DynamicSwitchWidget::DynamicSwitchWidget() {
  3. visibility = nullptr;
  4. viewMode = ACTIVE_HIGH_VIEW;
  5. sw = new SVGWidget();
  6. addChild(sw);
  7. }
  8. void DynamicSwitchWidget::addFrame(std::shared_ptr<SVG> svg) {
  9. frames.push_back(svg);
  10. // If this is our first frame, automatically set SVG and size
  11. if (!sw->svg) {
  12. sw->setSVG(svg);
  13. box.size = sw->box.size;
  14. }
  15. }
  16. void DynamicSwitchWidget::step() {
  17. if(visibility != nullptr) {
  18. if(*visibility) {
  19. visible = true;
  20. }
  21. else {
  22. visible = false;
  23. }
  24. if(viewMode == ACTIVE_LOW_VIEW) {
  25. visible = !visible;
  26. }
  27. }
  28. else {
  29. visible = true;
  30. }
  31. FramebufferWidget::step();
  32. }
  33. void DynamicSwitchWidget::onChange(EventChange &e) {
  34. assert(frames.size() > 0);
  35. float valueScaled = rescale(value, minValue, maxValue, 0, frames.size() - 1);
  36. int index = clamp((int) roundf(valueScaled), 0, frames.size() - 1);
  37. sw->setSVG(frames[index]);
  38. dirty = true;
  39. ParamWidget::onChange(e);
  40. }