@@ -116,19 +116,11 @@ struct ModuleWidget : widget::OpaqueWidget { | |||||
void removeAction(); | void removeAction(); | ||||
void createContextMenu(); | void createContextMenu(); | ||||
// Returns the position in grid coordinates | |||||
math::Vec getGridPosition() { | |||||
return getPosition().div(RACK_GRID_SIZE).round(); | |||||
} | |||||
void setGridPosition(math::Vec pos) { | |||||
setPosition(pos.mult(RACK_GRID_SIZE)); | |||||
} | |||||
math::Vec getGridSize() { | |||||
return getSize().div(RACK_GRID_SIZE).round(); | |||||
} | |||||
math::Rect getGridBox() { | |||||
return math::Rect(getGridPosition(), getGridSize()); | |||||
} | |||||
// Returns the rack position in grid coordinates | |||||
math::Vec getGridPosition(); | |||||
void setGridPosition(math::Vec pos); | |||||
math::Vec getGridSize(); | |||||
math::Rect getGridBox(); | |||||
PRIVATE math::Vec& dragOffset(); | PRIVATE math::Vec& dragOffset(); | ||||
PRIVATE bool& dragEnabled(); | PRIVATE bool& dragEnabled(); | ||||
@@ -1095,6 +1095,22 @@ void ModuleWidget::createContextMenu() { | |||||
appendContextMenu(menu); | appendContextMenu(menu); | ||||
} | } | ||||
math::Vec ModuleWidget::getGridPosition() { | |||||
return ((getPosition() - RACK_OFFSET) / RACK_GRID_SIZE).round(); | |||||
} | |||||
void ModuleWidget::setGridPosition(math::Vec pos) { | |||||
setPosition(pos * RACK_GRID_SIZE + RACK_OFFSET); | |||||
} | |||||
math::Vec ModuleWidget::getGridSize() { | |||||
return (getSize() / RACK_GRID_SIZE).round(); | |||||
} | |||||
math::Rect ModuleWidget::getGridBox() { | |||||
return math::Rect(getGridPosition(), getGridSize()); | |||||
} | |||||
math::Vec& ModuleWidget::dragOffset() { | math::Vec& ModuleWidget::dragOffset() { | ||||
return internal->dragOffset; | return internal->dragOffset; | ||||
} | } | ||||
@@ -700,7 +700,7 @@ static bool compareModuleLeft(ModuleWidget* a, ModuleWidget* b) { | |||||
void RackWidget::setModulePosForce(ModuleWidget* mw, math::Vec pos) { | void RackWidget::setModulePosForce(ModuleWidget* mw, math::Vec pos) { | ||||
math::Rect mwBox; | math::Rect mwBox; | ||||
mwBox.pos = pos.div(RACK_GRID_SIZE).round(); | |||||
mwBox.pos = ((pos - RACK_OFFSET) / RACK_GRID_SIZE).round(); | |||||
mwBox.size = mw->getGridSize(); | mwBox.size = mw->getGridSize(); | ||||
// Collect modules to the left and right of new pos | // Collect modules to the left and right of new pos | ||||
@@ -770,7 +770,7 @@ void RackWidget::setModulePosSqueeze(ModuleWidget* mw, math::Vec pos) { | |||||
void RackWidget::squeezeModulePos(ModuleWidget* mw, math::Vec pos) { | void RackWidget::squeezeModulePos(ModuleWidget* mw, math::Vec pos) { | ||||
math::Rect mwBox; | math::Rect mwBox; | ||||
mwBox.pos = pos.div(RACK_GRID_SIZE).round(); | |||||
mwBox.pos = ((pos - RACK_OFFSET) / RACK_GRID_SIZE).round(); | |||||
mwBox.size = mw->getGridSize(); | mwBox.size = mw->getGridSize(); | ||||
// Collect modules to the left and right of new pos | // Collect modules to the left and right of new pos | ||||