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.

77 lines
1.5KB

  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::onButton(const ButtonEvent& e) {
  14. OpaqueWidget::onButton(e);
  15. // Dispatch ActionEvent on left click
  16. if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
  17. ActionEvent eAction;
  18. onAction(eAction);
  19. }
  20. }
  21. void SvgButton::addFrame(std::shared_ptr<window::Svg> svg) {
  22. frames.push_back(svg);
  23. // If this is our first frame, automatically set SVG and size
  24. if (!sw->svg) {
  25. sw->setSvg(svg);
  26. box.size = sw->box.size;
  27. fb->box.size = sw->box.size;
  28. // Move shadow downward by 10%
  29. shadow->box.size = sw->box.size;
  30. shadow->box.pos = math::Vec(0, sw->box.size.y * 0.10);
  31. fb->setDirty();
  32. }
  33. }
  34. void SvgButton::onDragStart(const DragStartEvent& e) {
  35. if (e.button != GLFW_MOUSE_BUTTON_LEFT)
  36. return;
  37. if (frames.size() >= 2) {
  38. sw->setSvg(frames[1]);
  39. fb->setDirty();
  40. }
  41. }
  42. void SvgButton::onDragEnd(const DragEndEvent& e) {
  43. if (frames.size() >= 1) {
  44. sw->setSvg(frames[0]);
  45. fb->setDirty();
  46. }
  47. }
  48. void SvgButton::onDragDrop(const DragDropEvent& e) {
  49. // Don't dispatch ActionEvent on DragDrop because it's already called on mouse down.
  50. // if (e.origin == this) {
  51. // ActionEvent eAction;
  52. // onAction(eAction);
  53. // }
  54. }
  55. } // namespace app
  56. } // namespace rack