|
|
@@ -1,5 +1,7 @@ |
|
|
|
#include <app/PortWidget.hpp> |
|
|
|
#include <app/Scene.hpp> |
|
|
|
#include <ui/MenuItem.hpp> |
|
|
|
#include <ui/MenuSeparator.hpp> |
|
|
|
#include <window/Window.hpp> |
|
|
|
#include <context.hpp> |
|
|
|
#include <history.hpp> |
|
|
@@ -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,51 @@ void PortWidget::createContextMenu() { |
|
|
|
assert(portInfo); |
|
|
|
menu->addChild(createMenuLabel(portInfo->getFullName())); |
|
|
|
|
|
|
|
CableWidget* cw = APP->scene->rack->getTopCable(this); |
|
|
|
std::vector<CableWidget*> 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 |
|
|
|
menu->addChild(new ui::MenuSeparator); |
|
|
|
|
|
|
|
// 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<PortCreateCableItem>(" New cable", "Click+drag"); |
|
|
|
item->disabled = createCableDisabled; |
|
|
|
item->color = color; |
|
|
|
menu->addChild(item); |
|
|
|
} |
|
|
|
|
|
|
|
// Cable items |
|
|
|
if (!cws.empty()) { |
|
|
|
menu->addChild(new ui::MenuSeparator); |
|
|
|
|
|
|
|
for (auto it = cws.rbegin(); it != cws.rend(); it++) { |
|
|
|
CableWidget* cw = *it; |
|
|
|
PortWidget* pw = (type == engine::Port::INPUT) ? cw->outputPort : cw->inputPort; |
|
|
|
engine::PortInfo* portInfo = pw->getPortInfo(); |
|
|
|
|
|
|
|
PortCableItem* item = createMenuItem<PortCableItem>(" " + portInfo->module->model->name + ": " + portInfo->getName()); |
|
|
|
item->color = cw->color; |
|
|
|
menu->addChild(item); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|