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.

62 lines
1.4KB

  1. #pragma once
  2. #include <widget/Widget.hpp>
  3. namespace rack {
  4. namespace widget {
  5. /** A Widget with a dynamic zoom level. */
  6. struct ZoomWidget : Widget {
  7. float zoom = 1.f;
  8. math::Vec getRelativeOffset(math::Vec v, Widget* relative) override;
  9. float getRelativeZoom(Widget* relative) override;
  10. math::Rect getViewport(math::Rect r) override;
  11. void setZoom(float zoom);
  12. float getZoom() {
  13. return zoom;
  14. }
  15. void draw(const DrawArgs& args) override;
  16. void onHover(const HoverEvent& e) override {
  17. HoverEvent e2 = e;
  18. e2.pos = e.pos.div(zoom);
  19. Widget::onHover(e2);
  20. }
  21. void onButton(const ButtonEvent& e) override {
  22. ButtonEvent e2 = e;
  23. e2.pos = e.pos.div(zoom);
  24. Widget::onButton(e2);
  25. }
  26. void onHoverKey(const HoverKeyEvent& e) override {
  27. HoverKeyEvent e2 = e;
  28. e2.pos = e.pos.div(zoom);
  29. Widget::onHoverKey(e2);
  30. }
  31. void onHoverText(const HoverTextEvent& e) override {
  32. HoverTextEvent e2 = e;
  33. e2.pos = e.pos.div(zoom);
  34. Widget::onHoverText(e2);
  35. }
  36. void onHoverScroll(const HoverScrollEvent& e) override {
  37. HoverScrollEvent e2 = e;
  38. e2.pos = e.pos.div(zoom);
  39. Widget::onHoverScroll(e2);
  40. }
  41. void onDragHover(const DragHoverEvent& e) override {
  42. DragHoverEvent e2 = e;
  43. e2.pos = e.pos.div(zoom);
  44. Widget::onDragHover(e2);
  45. }
  46. void onPathDrop(const PathDropEvent& e) override {
  47. PathDropEvent e2 = e;
  48. e2.pos = e.pos.div(zoom);
  49. Widget::onPathDrop(e2);
  50. }
  51. };
  52. } // namespace widget
  53. } // namespace rack