@@ -57,18 +57,18 @@ struct Widget : WeakBase { | |||||
*/ | */ | ||||
virtual math::Rect getChildrenBoundingBox(); | virtual math::Rect getChildrenBoundingBox(); | ||||
virtual math::Rect getVisibleChildrenBoundingBox(); | virtual math::Rect getVisibleChildrenBoundingBox(); | ||||
/** Returns `v` (given in local coordinates) transformed into the coordinate system of `relative`. | |||||
/** Returns `v` (given in local coordinates) transformed into the coordinate system of `ancestor`. | |||||
*/ | */ | ||||
virtual math::Vec getRelativeOffset(math::Vec v, Widget* relative); | |||||
virtual math::Vec getRelativeOffset(math::Vec v, Widget* ancestor); | |||||
/** Returns `v` transformed into world/root/global/absolute coordinates. | /** Returns `v` transformed into world/root/global/absolute coordinates. | ||||
*/ | */ | ||||
math::Vec getAbsoluteOffset(math::Vec v) { | math::Vec getAbsoluteOffset(math::Vec v) { | ||||
return getRelativeOffset(v, NULL); | return getRelativeOffset(v, NULL); | ||||
} | } | ||||
/** Returns the zoom level in the coordinate system of `relative`. | |||||
/** Returns the zoom level in the coordinate system of `ancestor`. | |||||
Only `ZoomWidget` should override this to return value other than 1. | Only `ZoomWidget` should override this to return value other than 1. | ||||
*/ | */ | ||||
virtual float getRelativeZoom(Widget* relative); | |||||
virtual float getRelativeZoom(Widget* ancestor); | |||||
float getAbsoluteZoom() { | float getAbsoluteZoom() { | ||||
return getRelativeZoom(NULL); | return getRelativeZoom(NULL); | ||||
} | } | ||||
@@ -10,8 +10,8 @@ namespace widget { | |||||
struct ZoomWidget : Widget { | struct ZoomWidget : Widget { | ||||
float zoom = 1.f; | float zoom = 1.f; | ||||
math::Vec getRelativeOffset(math::Vec v, Widget* relative) override; | |||||
float getRelativeZoom(Widget* relative) override; | |||||
math::Vec getRelativeOffset(math::Vec v, Widget* ancestor) override; | |||||
float getRelativeZoom(Widget* ancestor) override; | |||||
math::Rect getViewport(math::Rect r) override; | math::Rect getViewport(math::Rect r) override; | ||||
void setZoom(float zoom); | void setZoom(float zoom); | ||||
float getZoom() { | float getZoom() { | ||||
@@ -112,23 +112,23 @@ math::Rect Widget::getVisibleChildrenBoundingBox() { | |||||
} | } | ||||
math::Vec Widget::getRelativeOffset(math::Vec v, Widget* relative) { | |||||
if (this == relative) | |||||
math::Vec Widget::getRelativeOffset(math::Vec v, Widget* ancestor) { | |||||
if (this == ancestor) | |||||
return v; | return v; | ||||
// Translate offset | // Translate offset | ||||
v = v.plus(box.pos); | v = v.plus(box.pos); | ||||
if (!parent) | if (!parent) | ||||
return v; | return v; | ||||
return parent->getRelativeOffset(v, relative); | |||||
return parent->getRelativeOffset(v, ancestor); | |||||
} | } | ||||
float Widget::getRelativeZoom(Widget* relative) { | |||||
if (this == relative) | |||||
float Widget::getRelativeZoom(Widget* ancestor) { | |||||
if (this == ancestor) | |||||
return 1.f; | return 1.f; | ||||
if (!parent) | if (!parent) | ||||
return 1.f; | return 1.f; | ||||
return parent->getRelativeZoom(relative); | |||||
return parent->getRelativeZoom(ancestor); | |||||
} | } | ||||
@@ -5,15 +5,15 @@ namespace rack { | |||||
namespace widget { | namespace widget { | ||||
math::Vec ZoomWidget::getRelativeOffset(math::Vec v, Widget* relative) { | |||||
math::Vec ZoomWidget::getRelativeOffset(math::Vec v, Widget* ancestor) { | |||||
// Transform `v` (which is in child coordinates) to local coordinates. | // Transform `v` (which is in child coordinates) to local coordinates. | ||||
v = v.mult(zoom); | v = v.mult(zoom); | ||||
return Widget::getRelativeOffset(v, relative); | |||||
return Widget::getRelativeOffset(v, ancestor); | |||||
} | } | ||||
float ZoomWidget::getRelativeZoom(Widget* relative) { | |||||
return zoom * Widget::getRelativeZoom(relative); | |||||
float ZoomWidget::getRelativeZoom(Widget* ancestor) { | |||||
return zoom * Widget::getRelativeZoom(ancestor); | |||||
} | } | ||||