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 event::Hover& e) override {
  17. event::Hover e2 = e;
  18. e2.pos = e.pos.div(zoom);
  19. Widget::onHover(e2);
  20. }
  21. void onButton(const event::Button& e) override {
  22. event::Button e2 = e;
  23. e2.pos = e.pos.div(zoom);
  24. Widget::onButton(e2);
  25. }
  26. void onHoverKey(const event::HoverKey& e) override {
  27. event::HoverKey e2 = e;
  28. e2.pos = e.pos.div(zoom);
  29. Widget::onHoverKey(e2);
  30. }
  31. void onHoverText(const event::HoverText& e) override {
  32. event::HoverText e2 = e;
  33. e2.pos = e.pos.div(zoom);
  34. Widget::onHoverText(e2);
  35. }
  36. void onHoverScroll(const event::HoverScroll& e) override {
  37. event::HoverScroll e2 = e;
  38. e2.pos = e.pos.div(zoom);
  39. Widget::onHoverScroll(e2);
  40. }
  41. void onDragHover(const event::DragHover& e) override {
  42. event::DragHover e2 = e;
  43. e2.pos = e.pos.div(zoom);
  44. Widget::onDragHover(e2);
  45. }
  46. void onPathDrop(const event::PathDrop& e) override {
  47. event::PathDrop e2 = e;
  48. e2.pos = e.pos.div(zoom);
  49. Widget::onPathDrop(e2);
  50. }
  51. };
  52. } // namespace widget
  53. } // namespace rack