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.

60 lines
1.1KB

  1. #include <app/SvgButton.hpp>
  2. namespace rack {
  3. namespace app {
  4. SvgButton::SvgButton() {
  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 SvgButton::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 SvgButton::onDragStart(const event::DragStart& e) {
  26. if (e.button != GLFW_MOUSE_BUTTON_LEFT)
  27. return;
  28. if (frames.size() >= 2) {
  29. sw->setSvg(frames[1]);
  30. fb->dirty = true;
  31. }
  32. }
  33. void SvgButton::onDragEnd(const event::DragEnd& e) {
  34. if (frames.size() >= 1) {
  35. sw->setSvg(frames[0]);
  36. fb->dirty = true;
  37. }
  38. }
  39. void SvgButton::onDragDrop(const event::DragDrop& e) {
  40. if (e.origin == this) {
  41. event::Action eAction;
  42. onAction(eAction);
  43. }
  44. }
  45. } // namespace app
  46. } // namespace rack