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.

44 lines
965B

  1. #include "widget/ZoomWidget.hpp"
  2. namespace rack {
  3. namespace widget {
  4. math::Vec ZoomWidget::getRelativeOffset(math::Vec v, Widget *relative) {
  5. return Widget::getRelativeOffset(v.mult(zoom), relative);
  6. }
  7. math::Rect ZoomWidget::getViewport(math::Rect r) {
  8. r.pos = r.pos.mult(zoom);
  9. r.size = r.size.mult(zoom);
  10. r = Widget::getViewport(r);
  11. r.pos = r.pos.div(zoom);
  12. r.size = r.size.div(zoom);
  13. return r;
  14. }
  15. void ZoomWidget::setZoom(float zoom) {
  16. if (zoom == this->zoom)
  17. return;
  18. this->zoom = zoom;
  19. event::Context eZoomContext;
  20. event::Zoom eZoom;
  21. eZoom.context = &eZoomContext;
  22. Widget::onZoom(eZoom);
  23. }
  24. void ZoomWidget::draw(const DrawArgs &args) {
  25. DrawArgs zoomCtx = args;
  26. zoomCtx.clipBox.pos = zoomCtx.clipBox.pos.div(zoom);
  27. zoomCtx.clipBox.size = zoomCtx.clipBox.size.div(zoom);
  28. // No need to save the state because that is done in the parent
  29. nvgScale(args.vg, zoom, zoom);
  30. Widget::draw(zoomCtx);
  31. }
  32. } // namespace widget
  33. } // namespace rack