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.

76 lines
1.4KB

  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. }
  32. }
  33. void SvgButton::onDragStart(const DragStartEvent& e) {
  34. if (e.button != GLFW_MOUSE_BUTTON_LEFT)
  35. return;
  36. if (frames.size() >= 2) {
  37. sw->setSvg(frames[1]);
  38. fb->dirty = true;
  39. }
  40. }
  41. void SvgButton::onDragEnd(const DragEndEvent& e) {
  42. if (frames.size() >= 1) {
  43. sw->setSvg(frames[0]);
  44. fb->dirty = true;
  45. }
  46. }
  47. void SvgButton::onDragDrop(const DragDropEvent& e) {
  48. // Don't dispatch ActionEvent on DragDrop because it's already called on mouse down.
  49. // if (e.origin == this) {
  50. // ActionEvent eAction;
  51. // onAction(eAction);
  52. // }
  53. }
  54. } // namespace app
  55. } // namespace rack