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.

58 lines
1.3KB

  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. math::Rect getViewport(math::Rect r) override;
  10. void setZoom(float zoom);
  11. void draw(const DrawArgs& args) override;
  12. void onHover(const event::Hover& e) override {
  13. event::Hover e2 = e;
  14. e2.pos = e.pos.div(zoom);
  15. Widget::onHover(e2);
  16. }
  17. void onButton(const event::Button& e) override {
  18. event::Button e2 = e;
  19. e2.pos = e.pos.div(zoom);
  20. Widget::onButton(e2);
  21. }
  22. void onHoverKey(const event::HoverKey& e) override {
  23. event::HoverKey e2 = e;
  24. e2.pos = e.pos.div(zoom);
  25. Widget::onHoverKey(e2);
  26. }
  27. void onHoverText(const event::HoverText& e) override {
  28. event::HoverText e2 = e;
  29. e2.pos = e.pos.div(zoom);
  30. Widget::onHoverText(e2);
  31. }
  32. void onHoverScroll(const event::HoverScroll& e) override {
  33. event::HoverScroll e2 = e;
  34. e2.pos = e.pos.div(zoom);
  35. Widget::onHoverScroll(e2);
  36. }
  37. void onDragHover(const event::DragHover& e) override {
  38. event::DragHover e2 = e;
  39. e2.pos = e.pos.div(zoom);
  40. Widget::onDragHover(e2);
  41. }
  42. void onPathDrop(const event::PathDrop& e) override {
  43. event::PathDrop e2 = e;
  44. e2.pos = e.pos.div(zoom);
  45. Widget::onPathDrop(e2);
  46. }
  47. };
  48. } // namespace widget
  49. } // namespace rack