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

Method onDragDrop

src/app/PortWidget.cpp:535–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

533
534
535void 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 }

Callers

nothing calls this directly

Calls 6

getIncompleteCablesMethod · 0.80
updateCableMethod · 0.80
isCableMethod · 0.80
getCableMethod · 0.45
setCableMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected