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.

55 lines
1.2KB

  1. #include <widget/ZoomWidget.hpp>
  2. namespace rack {
  3. namespace widget {
  4. math::Vec ZoomWidget::getRelativeOffset(math::Vec v, Widget* relative) {
  5. // Transform `v` (which is in child coordinates) to local coordinates.
  6. v = v.mult(zoom);
  7. return Widget::getRelativeOffset(v, relative);
  8. }
  9. float ZoomWidget::getRelativeZoom(Widget* relative) {
  10. return zoom * Widget::getRelativeZoom(relative);
  11. }
  12. math::Rect ZoomWidget::getViewport(math::Rect r) {
  13. r.pos = r.pos.mult(zoom);
  14. r.size = r.size.mult(zoom);
  15. r = Widget::getViewport(r);
  16. r.pos = r.pos.div(zoom);
  17. r.size = r.size.div(zoom);
  18. return r;
  19. }
  20. void ZoomWidget::setZoom(float zoom) {
  21. if (zoom == this->zoom)
  22. return;
  23. this->zoom = zoom;
  24. // Dispatch Dirty event
  25. widget::EventContext cDirty;
  26. DirtyEvent eDirty;
  27. eDirty.context = &cDirty;
  28. Widget::onDirty(eDirty);
  29. }
  30. void ZoomWidget::draw(const DrawArgs& args) {
  31. DrawArgs zoomCtx = args;
  32. zoomCtx.clipBox.pos = zoomCtx.clipBox.pos.div(zoom);
  33. zoomCtx.clipBox.size = zoomCtx.clipBox.size.div(zoom);
  34. // No need to save the state because that is done in the parent
  35. nvgScale(args.vg, zoom, zoom);
  36. Widget::draw(zoomCtx);
  37. }
  38. } // namespace widget
  39. } // namespace rack