Browse Source

Add cable menu item and create cable menu item to port context menu (WIP).

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
d09fbf84f0
2 changed files with 55 additions and 6 deletions
  1. +1
    -1
      dep/nanovg
  2. +54
    -5
      src/app/PortWidget.cpp

+ 1
- 1
dep/nanovg

@@ -1 +1 @@
Subproject commit 14a22f1b2500f15e548f79a972be2c9b5b086bd5
Subproject commit 0bebdb314aff9cfa28fde4744bcb037a2b3fd756

+ 54
- 5
src/app/PortWidget.cpp View File

@@ -1,5 +1,7 @@
#include <app/PortWidget.hpp> #include <app/PortWidget.hpp>
#include <app/Scene.hpp> #include <app/Scene.hpp>
#include <ui/MenuItem.hpp>
#include <ui/MenuSeparator.hpp>
#include <window/Window.hpp> #include <window/Window.hpp>
#include <context.hpp> #include <context.hpp>
#include <history.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 { struct PortWidget::Internal {
ui::Tooltip* tooltip = NULL; ui::Tooltip* tooltip = NULL;
}; };
@@ -132,25 +161,45 @@ void PortWidget::createContextMenu() {
assert(portInfo); assert(portInfo);
menu->addChild(createMenuLabel(portInfo->getFullName())); 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", menu->addChild(createMenuItem("Delete top cable", RACK_MOD_SHIFT_NAME "+click",
[=]() { [=]() {
if (!weakThis) if (!weakThis)
return; return;
weakThis->deleteTopCableAction(); weakThis->deleteTopCableAction();
}, },
!cw
!topCw
)); ));


// TODO // TODO
if (type == engine::Port::INPUT) { 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 { 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<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 (CableWidget* cw : cws) {
PortCableItem* item = createMenuItem<PortCableItem>(" XXXX", "Click+drag");
item->color = nvgRGBf(1, 0, 0);
menu->addChild(item);
}
}
} }






Loading…
Cancel
Save