MCPcopy Create free account
hub / github.com/VCVRack/Rack / setModulePosForce

Method setModulePosForce

src/app/RackWidget.cpp:778–833  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

776}
777
778void 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
835void RackWidget::setModulePosSqueeze(ModuleWidget* mw, math::Vec pos) {

Callers 1

onDragMoveMethod · 0.80

Calls 9

roundMethod · 0.80
getGridSizeMethod · 0.80
getTopMethod · 0.80
getGridBoxMethod · 0.80
getLeftMethod · 0.80
setGridPositionMethod · 0.80
getTopLeftMethod · 0.80
getRightMethod · 0.80
getTopRightMethod · 0.80

Tested by

no test coverage detected