box.sizetags/v0.5.0
@@ -69,7 +69,7 @@ struct Widget { | |||||
virtual ~Widget(); | virtual ~Widget(); | ||||
Rect getChildrenBoundingBox(); | |||||
virtual Rect getChildrenBoundingBox(); | |||||
/** Returns `v` transformed into the coordinate system of `relative` */ | /** Returns `v` transformed into the coordinate system of `relative` */ | ||||
virtual Vec getRelativeOffset(Vec v, Widget *relative); | virtual Vec getRelativeOffset(Vec v, Widget *relative); | ||||
/** Returns `v` transformed into world coordinates */ | /** Returns `v` transformed into world coordinates */ | ||||
@@ -159,6 +159,7 @@ struct TransformWidget : Widget { | |||||
/** The transformation matrix */ | /** The transformation matrix */ | ||||
float transform[6]; | float transform[6]; | ||||
TransformWidget(); | TransformWidget(); | ||||
Rect getChildrenBoundingBox() override; | |||||
void identity(); | void identity(); | ||||
void translate(Vec delta); | void translate(Vec delta); | ||||
void rotate(float angle); | void rotate(float angle); | ||||
@@ -348,7 +348,6 @@ void RackWidget::step() { | |||||
Vec cellMargin = Vec(20, 1); | Vec cellMargin = Vec(20, 1); | ||||
rails->box.pos = bound.pos.div(RACK_GRID_SIZE).floor().minus(cellMargin).mult(RACK_GRID_SIZE); | rails->box.pos = bound.pos.div(RACK_GRID_SIZE).floor().minus(cellMargin).mult(RACK_GRID_SIZE); | ||||
rails->box.size = bound.size.plus(cellMargin.mult(RACK_GRID_SIZE).mult(2)); | rails->box.size = bound.size.plus(cellMargin.mult(RACK_GRID_SIZE).mult(2)); | ||||
printf("%f %f %f %f\n", rails->box.pos.x, rails->box.pos.y, rails->box.size.x, rails->box.size.y); | |||||
rails->dirty = true; | rails->dirty = true; | ||||
rail->box.size = rails->box.size; | rail->box.size = rails->box.size; | ||||
@@ -22,6 +22,7 @@ void SVGKnob::setSVG(std::shared_ptr<SVG> svg) { | |||||
void SVGKnob::step() { | void SVGKnob::step() { | ||||
// Re-transform TransformWidget if dirty | // Re-transform TransformWidget if dirty | ||||
if (dirty) { | if (dirty) { | ||||
tw->box.size = box.size; | |||||
float angle = rescalef(value, minValue, maxValue, minAngle, maxAngle); | float angle = rescalef(value, minValue, maxValue, minAngle, maxAngle); | ||||
tw->identity(); | tw->identity(); | ||||
// Scale SVG to box | // Scale SVG to box | ||||
@@ -8,6 +8,16 @@ TransformWidget::TransformWidget() { | |||||
identity(); | identity(); | ||||
} | } | ||||
Rect TransformWidget::getChildrenBoundingBox() { | |||||
Rect bound = Widget::getChildrenBoundingBox(); | |||||
Vec topLeft = bound.pos; | |||||
Vec bottomRight = bound.getBottomRight(); | |||||
nvgTransformPoint(&topLeft.x, &topLeft.y, transform, topLeft.x, topLeft.y); | |||||
nvgTransformPoint(&bottomRight.x, &bottomRight.y, transform, bottomRight.x, bottomRight.y); | |||||
printf("%f\n", 42.1); | |||||
return Rect(topLeft, bottomRight.minus(topLeft)); | |||||
} | |||||
void TransformWidget::identity() { | void TransformWidget::identity() { | ||||
nvgTransformIdentity(transform); | nvgTransformIdentity(transform); | ||||
} | } | ||||