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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "widgets/Widget.hpp"
  3. namespace rack {
  4. struct ZoomWidget : virtual Widget {
  5. float zoom = 1.f;
  6. math::Vec getRelativeOffset(math::Vec v, Widget *relative) override {
  7. return Widget::getRelativeOffset(v.mult(zoom), relative);
  8. }
  9. math::Rect getViewport(math::Rect r) override {
  10. r.pos = r.pos.mult(zoom);
  11. r.size = r.size.mult(zoom);
  12. r = Widget::getViewport(r);
  13. r.pos = r.pos.div(zoom);
  14. r.size = r.size.div(zoom);
  15. return r;
  16. }
  17. void setZoom(float zoom) {
  18. this->zoom = zoom;
  19. event::Context eZoomContext;
  20. event::Zoom eZoom;
  21. eZoom.context = &eZoomContext;
  22. Widget::onZoom(eZoom);
  23. }
  24. void draw(NVGcontext *vg) override {
  25. // No need to save the state because that is done in the parent
  26. nvgScale(vg, zoom, zoom);
  27. Widget::draw(vg);
  28. }
  29. void onHover(const event::Hover &e) override {
  30. event::Hover e2 = e;
  31. e2.pos = e.pos.div(zoom);
  32. Widget::onHover(e2);
  33. }
  34. void onButton(const event::Button &e) override {
  35. event::Button e2 = e;
  36. e2.pos = e.pos.div(zoom);
  37. Widget::onButton(e2);
  38. }
  39. void onHoverKey(const event::HoverKey &e) override {
  40. event::HoverKey e2 = e;
  41. e2.pos = e.pos.div(zoom);
  42. Widget::onHoverKey(e2);
  43. }
  44. void onHoverText(const event::HoverText &e) override {
  45. event::HoverText e2 = e;
  46. e2.pos = e.pos.div(zoom);
  47. Widget::onHoverText(e2);
  48. }
  49. void onHoverScroll(const event::HoverScroll &e) override {
  50. event::HoverScroll e2 = e;
  51. e2.pos = e.pos.div(zoom);
  52. Widget::onHoverScroll(e2);
  53. }
  54. void onDragHover(const event::DragHover &e) override {
  55. event::DragHover e2 = e;
  56. e2.pos = e.pos.div(zoom);
  57. Widget::onDragHover(e2);
  58. }
  59. void onPathDrop(const event::PathDrop &e) override {
  60. event::PathDrop e2 = e;
  61. e2.pos = e.pos.div(zoom);
  62. Widget::onPathDrop(e2);
  63. }
  64. };
  65. } // namespace rack