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.

51 lines
891B

  1. #include "app/SvgButton.hpp"
  2. namespace rack {
  3. namespace app {
  4. SvgButton::SvgButton() {
  5. fb = new widget::FramebufferWidget;
  6. addChild(fb);
  7. sw = new widget::SvgWidget;
  8. fb->addChild(sw);
  9. }
  10. void SvgButton::addFrame(std::shared_ptr<Svg> svg) {
  11. frames.push_back(svg);
  12. // If this is our first frame, automatically set SVG and size
  13. if (!sw->svg) {
  14. sw->setSvg(svg);
  15. box.size = sw->box.size;
  16. fb->box.size = sw->box.size;
  17. }
  18. }
  19. void SvgButton::onDragStart(const event::DragStart &e) {
  20. if (frames.size() >= 2) {
  21. sw->setSvg(frames[1]);
  22. fb->dirty = true;
  23. }
  24. e.consume(this);
  25. }
  26. void SvgButton::onDragEnd(const event::DragEnd &e) {
  27. if (frames.size() >= 1) {
  28. sw->setSvg(frames[0]);
  29. fb->dirty = true;
  30. }
  31. }
  32. void SvgButton::onDragDrop(const event::DragDrop &e) {
  33. if (e.origin == this) {
  34. event::Action eAction;
  35. onAction(eAction);
  36. }
  37. }
  38. } // namespace app
  39. } // namespace rack