| 470 | } |
| 471 | |
| 472 | void 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 | |
| 513 | void ModuleWidget::onDragHover(const DragHoverEvent& e) { |
| 514 | if (APP->scene->rack->isSelected(this)) { |
nothing calls this directly
no test coverage detected