| 533 | |
| 534 | |
| 535 | void PortWidget::onDragDrop(const DragDropEvent& e) { |
| 536 | if (e.button != GLFW_MOUSE_BUTTON_LEFT) |
| 537 | return; |
| 538 | |
| 539 | PortWidget* pwOrigin = dynamic_cast<PortWidget*>(e.origin); |
| 540 | if (!pwOrigin) |
| 541 | return; |
| 542 | |
| 543 | // HACK: Only delete tooltip if we're not (normal) dragging it. |
| 544 | if (pwOrigin == this) { |
| 545 | createTooltip(); |
| 546 | } |
| 547 | |
| 548 | for (CableWidget* cw : APP->scene->rack->getIncompleteCables()) { |
| 549 | // These should already be NULL because onDragLeave() is called immediately before onDragDrop(). |
| 550 | cw->hoveredOutputPort = NULL; |
| 551 | cw->hoveredInputPort = NULL; |
| 552 | if (type == engine::Port::OUTPUT) { |
| 553 | // Check that similar cable doesn't exist |
| 554 | if (cw->inputPort && !APP->scene->rack->getCable(this, cw->inputPort)) { |
| 555 | cw->outputPort = this; |
| 556 | } |
| 557 | else { |
| 558 | continue; |
| 559 | } |
| 560 | } |
| 561 | else { |
| 562 | if (cw->outputPort && !APP->scene->rack->getCable(cw->outputPort, this)) { |
| 563 | cw->inputPort = this; |
| 564 | } |
| 565 | else { |
| 566 | continue; |
| 567 | } |
| 568 | } |
| 569 | cw->updateCable(); |
| 570 | |
| 571 | // This should always be true since the ComplexAction is created in onDragStart() |
| 572 | history::ComplexAction* history = pwOrigin->internal->history; |
| 573 | if (history) { |
| 574 | // Reject history if plugging into same port |
| 575 | auto& actions = history->actions; |
| 576 | auto it = std::find_if(actions.begin(), actions.end(), [&](history::Action* h) { |
| 577 | history::CableAdd* hca = dynamic_cast<history::CableAdd*>(h); |
| 578 | if (!hca) |
| 579 | return false; |
| 580 | return hca->isCable(cw); |
| 581 | }); |
| 582 | |
| 583 | if (it != actions.end()) { |
| 584 | actions.erase(it); |
| 585 | } |
| 586 | else { |
| 587 | // Push CableAdd action |
| 588 | history::CableAdd* h = new history::CableAdd; |
| 589 | h->setCable(cw); |
| 590 | history->push(h); |
| 591 | } |
| 592 | } |
nothing calls this directly
no test coverage detected