@@ -265,7 +265,7 @@ struct Vec { | |||
Vec ceil() const { | |||
return Vec(std::ceil(x), std::ceil(y)); | |||
} | |||
bool isEqual(Vec b) const { | |||
bool equals(Vec b) const { | |||
return x == b.x && y == b.y; | |||
} | |||
bool isZero() const { | |||
@@ -279,6 +279,11 @@ struct Vec { | |||
Vec crossfade(Vec b, float p) { | |||
return this->plus(b.minus(*this).mult(p)); | |||
} | |||
// Method aliases | |||
bool isEqual(Vec b) const { | |||
return equals(b); | |||
} | |||
}; | |||
@@ -297,22 +302,22 @@ struct Rect { | |||
} | |||
/** Returns whether this Rect contains an entire point, inclusive on the top/left, non-inclusive on the bottom/right. */ | |||
bool isContaining(Vec v) const { | |||
bool contains(Vec v) const { | |||
return pos.x <= v.x && v.x < pos.x + size.x | |||
&& pos.y <= v.y && v.y < pos.y + size.y; | |||
} | |||
/** Returns whether this Rect contains an entire Rect. */ | |||
bool isContaining(Rect r) const { | |||
bool contains(Rect r) const { | |||
return pos.x <= r.pos.x && r.pos.x + r.size.x <= pos.x + size.x | |||
&& pos.y <= r.pos.y && r.pos.y + r.size.y <= pos.y + size.y; | |||
} | |||
/** Returns whether this Rect overlaps with another Rect. */ | |||
bool isIntersecting(Rect r) const { | |||
bool intersects(Rect r) const { | |||
return (pos.x + size.x > r.pos.x && r.pos.x + r.size.x > pos.x) | |||
&& (pos.y + size.y > r.pos.y && r.pos.y + r.size.y > pos.y); | |||
} | |||
bool isEqual(Rect r) const { | |||
return pos.isEqual(r.pos) && size.isEqual(r.size); | |||
bool equals(Rect r) const { | |||
return pos.equals(r.pos) && size.equals(r.size); | |||
} | |||
float getLeft() const { | |||
return pos.x; | |||
@@ -390,14 +395,15 @@ struct Rect { | |||
return r; | |||
} | |||
DEPRECATED bool contains(Vec v) const { | |||
return isContaining(v); | |||
// Method aliases | |||
bool isContaining(Vec v) const { | |||
return contains(v); | |||
} | |||
DEPRECATED bool contains(Rect r) const { | |||
return isContaining(r); | |||
bool isIntersecting(Rect r) const { | |||
return intersects(r); | |||
} | |||
DEPRECATED bool intersects(Rect r) const { | |||
return isIntersecting(r); | |||
bool isEqual(Rect r) const { | |||
return equals(r); | |||
} | |||
}; | |||
@@ -456,10 +462,10 @@ inline Vec operator/=(Vec& a, const float& b) { | |||
return a = a.div(b); | |||
} | |||
inline bool operator==(const Vec& a, const Vec& b) { | |||
return a.isEqual(b); | |||
return a.equals(b); | |||
} | |||
inline bool operator!=(const Vec& a, const Vec& b) { | |||
return !a.isEqual(b); | |||
return !a.equals(b); | |||
} | |||
@@ -157,7 +157,7 @@ struct Widget : WeakBase { | |||
// Filter child by visibility and position | |||
if (!child->visible) | |||
continue; | |||
if (!child->box.isContaining(e.pos)) | |||
if (!child->box.contains(e.pos)) | |||
continue; | |||
// Clone event and adjust its position | |||
@@ -101,7 +101,7 @@ void RackWidget::draw(const DrawArgs& args) { | |||
math::Rect railBox; | |||
railBox.pos = args.clipBox.pos.div(BUS_BOARD_GRID_SIZE).floor().mult(BUS_BOARD_GRID_SIZE); | |||
railBox.size = args.clipBox.size.div(BUS_BOARD_GRID_SIZE).ceil().plus(math::Vec(1, 1)).mult(BUS_BOARD_GRID_SIZE); | |||
if (!railFb->box.size.isEqual(railBox.size)) { | |||
if (!railFb->box.size.equals(railBox.size)) { | |||
railFb->dirty = true; | |||
} | |||
railFb->box = railBox; | |||
@@ -353,12 +353,12 @@ static void RackWidget_updateExpanders(RackWidget* that) { | |||
math::Vec p2Right = w2->box.getTopRight().div(RACK_GRID_SIZE).round(); | |||
// Check if this is a left module | |||
if (p2Right.isEqual(pLeft)) { | |||
if (p2Right.equals(pLeft)) { | |||
mwLeft = dynamic_cast<ModuleWidget*>(w2); | |||
} | |||
// Check if this is a right module | |||
if (p2Left.isEqual(pRight)) { | |||
if (p2Left.equals(pRight)) { | |||
mwRight = dynamic_cast<ModuleWidget*>(w2); | |||
} | |||
} | |||
@@ -414,7 +414,7 @@ bool RackWidget::requestModulePos(ModuleWidget* mw, math::Vec pos) { | |||
if (!w2->visible) | |||
continue; | |||
// Check intersection | |||
if (mwBox.isIntersecting(w2->box)) | |||
if (mwBox.intersects(w2->box)) | |||
return false; | |||
} | |||
@@ -556,7 +556,7 @@ history::ComplexAction* RackWidget::getModuleDragAction() { | |||
assert(mw); | |||
// Create ModuleMove action if the module was moved. | |||
math::Vec oldPos = mw->oldPos(); | |||
if (!oldPos.isEqual(mw->box.pos)) { | |||
if (!oldPos.equals(mw->box.pos)) { | |||
history::ModuleMove* mmh = new history::ModuleMove; | |||
mmh->moduleId = mw->module->id; | |||
mmh->oldPos = oldPos; | |||
@@ -59,7 +59,7 @@ void Menu::draw(const DrawArgs& args) { | |||
} | |||
void Menu::onHoverScroll(const event::HoverScroll& e) { | |||
if (parent && !parent->box.isContaining(box)) | |||
if (parent && !parent->box.contains(box)) | |||
box.pos.y += e.scrollDelta.y; | |||
} | |||
@@ -95,7 +95,7 @@ void FramebufferWidget::step() { | |||
math::Vec newFbSize = internal->fbBox.size.mult(APP->window->pixelRatio).ceil(); | |||
// Create framebuffer if a new size is needed | |||
if (!internal->fb || !newFbSize.isEqual(internal->fbSize)) { | |||
if (!internal->fb || !newFbSize.equals(internal->fbSize)) { | |||
internal->fbSize = newFbSize; | |||
// Delete old framebuffer | |||
if (internal->fb) | |||
@@ -188,14 +188,14 @@ void FramebufferWidget::draw(const DrawArgs& args) { | |||
// DEBUG("%p dirty subpixel", this); | |||
dirty = true; | |||
} | |||
if (!internal->scale.isEqual(internal->fbScale)) { | |||
if (!internal->scale.equals(internal->fbScale)) { | |||
// If rescaled, rerender in the next frame. | |||
// DEBUG("%p dirty scale", this); | |||
dirty = true; | |||
} | |||
math::Vec scaleRatio = math::Vec(1, 1); | |||
if (!internal->fbScale.isZero() && !internal->scale.isEqual(internal->fbScale)) { | |||
if (!internal->fbScale.isZero() && !internal->scale.equals(internal->fbScale)) { | |||
// Continue to draw with the last framebuffer, but stretch it to rescale. | |||
scaleRatio = internal->scale.div(internal->fbScale); | |||
} | |||
@@ -32,7 +32,7 @@ math::Vec Widget::getPosition() { | |||
void Widget::setPosition(math::Vec pos) { | |||
if (pos.isEqual(box.pos)) | |||
if (pos.equals(box.pos)) | |||
return; | |||
box.pos = pos; | |||
// Trigger Reposition event | |||
@@ -47,7 +47,7 @@ math::Vec Widget::getSize() { | |||
void Widget::setSize(math::Vec size) { | |||
if (size.isEqual(box.size)) | |||
if (size.equals(box.size)) | |||
return; | |||
box.size = size; | |||
// Trigger Resize event | |||
@@ -226,7 +226,7 @@ void Widget::draw(const DrawArgs& args) { | |||
if (!child->visible) | |||
continue; | |||
// Don't draw if child is outside clip box | |||
if (!args.clipBox.isIntersecting(child->box)) | |||
if (!args.clipBox.intersects(child->box)) | |||
continue; | |||
DrawArgs childCtx = args; | |||