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.

70 lines
1.5KB

  1. #include <widget/ZoomWidget.hpp>
  2. namespace rack {
  3. namespace widget {
  4. math::Vec ZoomWidget::getRelativeOffset(math::Vec v, Widget* ancestor) {
  5. // Transform `v` (which is in child coordinates) to local coordinates.
  6. v = v.mult(zoom);
  7. return Widget::getRelativeOffset(v, ancestor);
  8. }
  9. float ZoomWidget::getRelativeZoom(Widget* ancestor) {
  10. return zoom * Widget::getRelativeZoom(ancestor);
  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. float ZoomWidget::getZoom() {
  21. return zoom;
  22. }
  23. void ZoomWidget::setZoom(float zoom) {
  24. if (zoom == this->zoom)
  25. return;
  26. this->zoom = zoom;
  27. // Dispatch Dirty event
  28. widget::EventContext cDirty;
  29. DirtyEvent eDirty;
  30. eDirty.context = &cDirty;
  31. Widget::onDirty(eDirty);
  32. }
  33. void ZoomWidget::draw(const DrawArgs& args) {
  34. DrawArgs zoomCtx = args;
  35. zoomCtx.clipBox.pos = zoomCtx.clipBox.pos.div(zoom);
  36. zoomCtx.clipBox.size = zoomCtx.clipBox.size.div(zoom);
  37. // No need to save the state because that is done in the parent
  38. nvgScale(args.vg, zoom, zoom);
  39. Widget::draw(zoomCtx);
  40. }
  41. void ZoomWidget::drawLayer(const DrawArgs& args, int layer) {
  42. DrawArgs zoomCtx = args;
  43. zoomCtx.clipBox.pos = zoomCtx.clipBox.pos.div(zoom);
  44. zoomCtx.clipBox.size = zoomCtx.clipBox.size.div(zoom);
  45. // No need to save the state because that is done in the parent
  46. nvgScale(args.vg, zoom, zoom);
  47. Widget::drawLayer(zoomCtx, layer);
  48. }
  49. } // namespace widget
  50. } // namespace rack