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.

ZoomWidget.hpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include <widget/Widget.hpp>
  3. namespace rack {
  4. namespace widget {
  5. /** Resizes the scale of appearance and PositionEvents of children. */
  6. struct ZoomWidget : Widget {
  7. /** Use setZoom() and getZoom() instead of using this variable directly. */
  8. float zoom = 1.f;
  9. math::Vec getRelativeOffset(math::Vec v, Widget* ancestor) override;
  10. float getRelativeZoom(Widget* ancestor) override;
  11. math::Rect getViewport(math::Rect r) override;
  12. float getZoom();
  13. /** Sets zoom scale and triggers DirtyEvent recursively if scale is changed, so children FramebufferWidgets are redrawn. */
  14. void setZoom(float zoom);
  15. void draw(const DrawArgs& args) override;
  16. void drawLayer(const DrawArgs& args, int layer) override;
  17. void onHover(const HoverEvent& e) override {
  18. HoverEvent e2 = e;
  19. e2.pos = e.pos.div(zoom);
  20. Widget::onHover(e2);
  21. }
  22. void onButton(const ButtonEvent& e) override {
  23. ButtonEvent e2 = e;
  24. e2.pos = e.pos.div(zoom);
  25. Widget::onButton(e2);
  26. }
  27. void onHoverKey(const HoverKeyEvent& e) override {
  28. HoverKeyEvent e2 = e;
  29. e2.pos = e.pos.div(zoom);
  30. Widget::onHoverKey(e2);
  31. }
  32. void onHoverText(const HoverTextEvent& e) override {
  33. HoverTextEvent e2 = e;
  34. e2.pos = e.pos.div(zoom);
  35. Widget::onHoverText(e2);
  36. }
  37. void onHoverScroll(const HoverScrollEvent& e) override {
  38. HoverScrollEvent e2 = e;
  39. e2.pos = e.pos.div(zoom);
  40. Widget::onHoverScroll(e2);
  41. }
  42. void onDragHover(const DragHoverEvent& e) override {
  43. DragHoverEvent e2 = e;
  44. e2.pos = e.pos.div(zoom);
  45. Widget::onDragHover(e2);
  46. }
  47. void onPathDrop(const PathDropEvent& e) override {
  48. PathDropEvent e2 = e;
  49. e2.pos = e.pos.div(zoom);
  50. Widget::onPathDrop(e2);
  51. }
  52. };
  53. } // namespace widget
  54. } // namespace rack