MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / onDragMove

Method onDragMove

src/override/ModuleWidget.cpp:495–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495void ModuleWidget::onDragMove(const DragMoveEvent& e) {
496 if (e.button == GLFW_MOUSE_BUTTON_LEFT) {
497 math::Vec mousePos = APP->scene->rack->getMousePos();
498
499 if (!internal->dragEnabled) {
500 // Set dragRackPos on the first time after dragging
501 if (!internal->dragRackPos.isFinite())
502 internal->dragRackPos = mousePos;
503 // Check if the mouse has moved enough to start dragging the module.
504 const float minDist = RACK_GRID_WIDTH;
505 if (internal->dragRackPos.minus(mousePos).square() >= std::pow(minDist, 2))
506 internal->dragEnabled = true;
507 }
508
509 // Move module
510 if (internal->dragEnabled) {
511 // Round y coordinate to nearest rack height
512 math::Vec pos = mousePos;
513 pos.x -= internal->dragOffset.x;
514 pos.y -= RACK_GRID_HEIGHT / 2;
515
516 if (APP->scene->rack->isSelected(this)) {
517 pos = (pos / RACK_GRID_SIZE).round() * RACK_GRID_SIZE;
518 math::Vec delta = pos.minus(box.pos);
519 APP->scene->rack->setSelectionPosNearest(delta);
520 }
521 else {
522 if (settings::squeezeModules) {
523 APP->scene->rack->setModulePosSqueeze(this, pos);
524 }
525 else {
526 if ((APP->window->getMods() & RACK_MOD_MASK) == RACK_MOD_CTRL)
527 APP->scene->rack->setModulePosForce(this, pos);
528 else
529 APP->scene->rack->setModulePosNearest(this, pos);
530 }
531 }
532 }
533 }
534}
535
536void ModuleWidget::onDragHover(const DragHoverEvent& e) {
537 if (APP->scene->rack->isSelected(this)) {

Callers

nothing calls this directly

Calls 6

isFiniteMethod · 0.80
squareMethod · 0.80
minusMethod · 0.80
roundMethod · 0.80
getMousePosMethod · 0.45
getModsMethod · 0.45

Tested by

no test coverage detected