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

Method onDragMove

src/app/ModuleWidget.cpp:472–511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

470}
471
472void ModuleWidget::onDragMove(const DragMoveEvent& e) {
473 if (e.button == GLFW_MOUSE_BUTTON_LEFT) {
474 math::Vec mousePos = APP->scene->rack->getMousePos();
475
476 if (!internal->dragEnabled) {
477 // Set dragRackPos on the first time after dragging
478 if (!internal->dragRackPos.isFinite())
479 internal->dragRackPos = mousePos;
480 // Check if the mouse has moved enough to start dragging the module.
481 const float minDist = RACK_GRID_WIDTH;
482 if (internal->dragRackPos.minus(mousePos).square() >= std::pow(minDist, 2))
483 internal->dragEnabled = true;
484 }
485
486 // Move module
487 if (internal->dragEnabled) {
488 // Round y coordinate to nearest rack height
489 math::Vec pos = mousePos;
490 pos.x -= internal->dragOffset.x;
491 pos.y -= RACK_GRID_HEIGHT / 2;
492
493 if (APP->scene->rack->isSelected(this)) {
494 pos = (pos / RACK_GRID_SIZE).round() * RACK_GRID_SIZE;
495 math::Vec delta = pos.minus(box.pos);
496 APP->scene->rack->setSelectionPosNearest(delta);
497 }
498 else {
499 if (settings::squeezeModules) {
500 APP->scene->rack->setModulePosSqueeze(this, pos);
501 }
502 else {
503 if ((APP->window->getMods() & RACK_MOD_MASK) == RACK_MOD_CTRL)
504 APP->scene->rack->setModulePosForce(this, pos);
505 else
506 APP->scene->rack->setModulePosNearest(this, pos);
507 }
508 }
509 }
510 }
511}
512
513void ModuleWidget::onDragHover(const DragHoverEvent& e) {
514 if (APP->scene->rack->isSelected(this)) {

Callers

nothing calls this directly

Calls 12

powFunction · 0.85
isFiniteMethod · 0.80
squareMethod · 0.80
minusMethod · 0.80
isSelectedMethod · 0.80
roundMethod · 0.80
setModulePosSqueezeMethod · 0.80
getModsMethod · 0.80
setModulePosForceMethod · 0.80
setModulePosNearestMethod · 0.80
getMousePosMethod · 0.45

Tested by

no test coverage detected