Browse Source

Merge branch 'v2' of github.com:VCVRack/Rack-private into v2

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
19390c83d4
3 changed files with 86 additions and 21 deletions
  1. +1
    -1
      dep/nanovg
  2. +25
    -15
      include/helpers.hpp
  3. +60
    -5
      src/app/PortWidget.cpp

+ 1
- 1
dep/nanovg

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

+ 25
- 15
include/helpers.hpp View File

@@ -169,31 +169,31 @@ TParamWidget* createLightParamCentered(math::Vec pos, engine::Module* module, in

template <class TMenu = ui::Menu>
TMenu* createMenu() {
TMenu* o = new TMenu;
o->box.pos = APP->scene->mousePos;
TMenu* menu = new TMenu;
menu->box.pos = APP->scene->mousePos;

ui::MenuOverlay* menuOverlay = new ui::MenuOverlay;
menuOverlay->addChild(o);
menuOverlay->addChild(menu);

APP->scene->addChild(menuOverlay);
return o;
return menu;
}


template <class TMenuLabel = ui::MenuLabel>
TMenuLabel* createMenuLabel(std::string text) {
TMenuLabel* o = new TMenuLabel;
o->text = text;
return o;
TMenuLabel* label = new TMenuLabel;
label->text = text;
return label;
}


template <class TMenuItem = ui::MenuItem>
TMenuItem* createMenuItem(std::string text, std::string rightText = "") {
TMenuItem* o = new TMenuItem;
o->text = text;
o->rightText = rightText;
return o;
TMenuItem* item = new TMenuItem;
item->text = text;
item->rightText = rightText;
return item;
}


@@ -327,8 +327,13 @@ Example:
template <typename T>
ui::MenuItem* createBoolPtrMenuItem(std::string text, std::string rightText, T* ptr) {
return createBoolMenuItem(text, rightText,
[=]() {return *ptr;},
[=](T val) {*ptr = val;}
[=]() {
return ptr ? *ptr : false;
},
[=](T val) {
if (ptr)
*ptr = val;
}
);
}

@@ -442,8 +447,13 @@ Example:
template <typename T>
ui::MenuItem* createIndexPtrSubmenuItem(std::string text, std::vector<std::string> labels, T* ptr) {
return createIndexSubmenuItem(text, labels,
[=]() {return *ptr;},
[=](size_t index) {*ptr = T(index);}
[=]() {
return ptr ? *ptr : 0;
},
[=](size_t index) {
if (ptr)
*ptr = T(index);
}
);
}



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

@@ -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);
}
}
}




Loading…
Cancel
Save