| 776 | } |
| 777 | |
| 778 | void RackWidget::setModulePosForce(ModuleWidget* mw, math::Vec pos) { |
| 779 | math::Rect mwBox; |
| 780 | mwBox.pos = ((pos - RACK_OFFSET) / RACK_GRID_SIZE).round(); |
| 781 | mwBox.size = mw->getGridSize(); |
| 782 | |
| 783 | // Collect modules to the left and right of new pos |
| 784 | std::set<ModuleWidget*, decltype(compareModuleLeft)*> leftModules(compareModuleLeft); |
| 785 | std::set<ModuleWidget*, decltype(compareModuleLeft)*> rightModules(compareModuleLeft); |
| 786 | for (widget::Widget* w2 : internal->moduleContainer->children) { |
| 787 | ModuleWidget* mw2 = (ModuleWidget*) w2; |
| 788 | // Skip this module |
| 789 | if (mw2 == mw) |
| 790 | continue; |
| 791 | // Modules must be on the same row as pos |
| 792 | if (mw2->getGridBox().getTop() != mwBox.getTop()) |
| 793 | continue; |
| 794 | // Insert into leftModules or rightModules |
| 795 | if (mw2->getGridBox().getLeft() >= mwBox.getLeft()) |
| 796 | rightModules.insert(mw2); |
| 797 | else |
| 798 | leftModules.insert(mw2); |
| 799 | } |
| 800 | |
| 801 | // Set module position |
| 802 | mw->setGridPosition(mwBox.pos); |
| 803 | |
| 804 | // Shove left modules |
| 805 | math::Vec cursor = mwBox.getTopLeft(); |
| 806 | for (auto it = leftModules.rbegin(); it != leftModules.rend(); it++) { |
| 807 | ModuleWidget* mw2 = (ModuleWidget*) *it; |
| 808 | math::Rect mw2Box = mw2->getGridBox(); |
| 809 | |
| 810 | if (mw2Box.getRight() <= cursor.x) |
| 811 | break; |
| 812 | |
| 813 | mw2Box.pos.x = cursor.x - mw2Box.size.x; |
| 814 | mw2->setGridPosition(mw2Box.pos); |
| 815 | cursor.x = mw2Box.getLeft(); |
| 816 | } |
| 817 | |
| 818 | // Shove right modules |
| 819 | cursor = mwBox.getTopRight(); |
| 820 | for (auto it = rightModules.begin(); it != rightModules.end(); it++) { |
| 821 | ModuleWidget* mw2 = (ModuleWidget*) *it; |
| 822 | math::Rect mw2Box = mw2->getGridBox(); |
| 823 | |
| 824 | if (mw2Box.getLeft() >= cursor.x) |
| 825 | break; |
| 826 | |
| 827 | mw2Box.pos.x = cursor.x; |
| 828 | mw2->setGridPosition(mw2Box.pos); |
| 829 | cursor.x = mw2Box.getRight(); |
| 830 | } |
| 831 | |
| 832 | updateExpanders(); |
| 833 | } |
| 834 | |
| 835 | void RackWidget::setModulePosSqueeze(ModuleWidget* mw, math::Vec pos) { |
no test coverage detected