From d09fbf84f0e28b6b944e5ed5220f66d1427cd4e1 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 28 Oct 2021 05:05:34 -0400 Subject: [PATCH] Add cable menu item and create cable menu item to port context menu (WIP). --- dep/nanovg | 2 +- src/app/PortWidget.cpp | 59 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/dep/nanovg b/dep/nanovg index 14a22f1b..0bebdb31 160000 --- a/dep/nanovg +++ b/dep/nanovg @@ -1 +1 @@ -Subproject commit 14a22f1b2500f15e548f79a972be2c9b5b086bd5 +Subproject commit 0bebdb314aff9cfa28fde4744bcb037a2b3fd756 diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index 08ec2e91..1ebc7de0 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include @@ -61,6 +63,33 @@ struct PortTooltip : ui::Tooltip { }; +struct ColorMenuItem : ui::MenuItem { + NVGcolor color; + + void draw(const DrawArgs& args) override { + MenuItem::draw(args); + + // Color circle + nvgBeginPath(args.vg); + float radius = 6.0; + nvgCircle(args.vg, 8.0 + radius, box.size.y / 2, radius); + nvgFillColor(args.vg, color); + nvgFill(args.vg); + nvgStrokeWidth(args.vg, 1.0); + nvgStrokeColor(args.vg, color::mult(color, 0.5)); + nvgStroke(args.vg); + } +}; + + +struct PortCableItem : ColorMenuItem { +}; + + +struct PortCreateCableItem : ColorMenuItem { +}; + + struct PortWidget::Internal { ui::Tooltip* tooltip = NULL; }; @@ -132,25 +161,45 @@ void PortWidget::createContextMenu() { assert(portInfo); menu->addChild(createMenuLabel(portInfo->getFullName())); - CableWidget* cw = APP->scene->rack->getTopCable(this); + std::vector cws = APP->scene->rack->getCablesOnPort(this); + CableWidget* topCw = cws.empty() ? NULL : cws.back(); + menu->addChild(createMenuItem("Delete top cable", RACK_MOD_SHIFT_NAME "+click", [=]() { if (!weakThis) return; weakThis->deleteTopCableAction(); }, - !cw + !topCw )); // TODO if (type == engine::Port::INPUT) { - menu->addChild(createMenuItem("Duplicate cable", RACK_MOD_CTRL_NAME "+drag", NULL, true)); + menu->addChild(createMenuItem("Duplicate top cable", RACK_MOD_CTRL_NAME "+drag", NULL, true)); } else { - menu->addChild(createMenuItem("Create new cable", RACK_MOD_CTRL_NAME "+drag", NULL, true)); } - // TODO + // Create cable items + bool createCableDisabled = (type == engine::Port::INPUT) && topCw; + for (NVGcolor color : settings::cableColors) { + // Include extra leading spaces for the color circle + PortCreateCableItem* item = createMenuItem(" New cable", "Click+drag"); + item->disabled = createCableDisabled; + item->color = color; + menu->addChild(item); + } + + // Cable items + if (!cws.empty()) { + menu->addChild(new ui::MenuSeparator); + + for (CableWidget* cw : cws) { + PortCableItem* item = createMenuItem(" XXXX", "Click+drag"); + item->color = nvgRGBf(1, 0, 0); + menu->addChild(item); + } + } }