From 58f2482df860fe878581423aedc8cadb1d94eb50 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 9 May 2024 08:19:33 -0400 Subject: [PATCH] Add "Create cable on top" item to port menu. Tweak menu labels. --- include/ui/MenuItem.hpp | 2 +- src/app/PortWidget.cpp | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/ui/MenuItem.hpp b/include/ui/MenuItem.hpp index 1d75488a..edabf430 100644 --- a/include/ui/MenuItem.hpp +++ b/include/ui/MenuItem.hpp @@ -32,7 +32,7 @@ struct MenuItem : MenuEntry { struct ColorDotMenuItem : MenuItem { - NVGcolor color; + NVGcolor color = color::BLACK_TRANSPARENT; void draw(const DrawArgs& args) override; void step() override; diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index 0b68aae5..e5506e57 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -150,7 +150,27 @@ struct PortCableItem : ui::ColorDotMenuItem { }; -struct PortCreateCableItem : ui::ColorDotMenuItem { +struct PortCreateCableItem : ui::MenuItem { + PortWidget* pw; + + void onButton(const ButtonEvent& e) override { + OpaqueWidget::onButton(e); + if (disabled) + return; + if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT && (e.mods & RACK_MOD_MASK) == 0) { + // Set PortWidget::onDragStart overrides + pw->internal->overrideCreateCable = true; + + // Pretend the PortWidget was clicked + e.consume(pw); + // Deletes `this` + doAction(); + } + } +}; + + +struct PortCreateCableColorItem : ui::ColorDotMenuItem { PortWidget* pw; size_t colorId; @@ -251,13 +271,19 @@ void PortWidget::createContextMenu() { )); { - PortCloneCableItem* item = createMenuItem("Duplicate top cable", RACK_MOD_CTRL_NAME "+drag"); + PortCloneCableItem* item = createMenuItem("Duplicate top cable", RACK_MOD_CTRL_NAME "+Shift+drag"); item->disabled = !topCw; item->pw = this; item->cw = topCw; menu->addChild(item); } + { + PortCreateCableItem* item = createMenuItem("Create cable on top", RACK_MOD_CTRL_NAME "+drag"); + item->pw = this; + menu->addChild(item); + } + menu->addChild(new ui::MenuSeparator); // New cable items @@ -265,8 +291,8 @@ void PortWidget::createContextMenu() { NVGcolor color = settings::cableColors[colorId]; std::string label = get(settings::cableLabels, colorId); if (label == "") - label = string::f("Color #%lld", (long long) (colorId + 1)); - PortCreateCableItem* item = createMenuItem(label, "Click+drag"); + label = string::f("#%lld", (long long) (colorId + 1)); + PortCreateCableColorItem* item = createMenuItem("Create cable: " + label); item->pw = this; item->color = color; item->colorId = colorId;