Browse Source

Added ModuleWidget::createContextMenu() so subclasses can add

MenuEntries to the right-click context menu
tags/v0.3.2
Andrew Belt 7 years ago
parent
commit
ec34a36c05
3 changed files with 43 additions and 34 deletions
  1. +1
    -0
      include/app.hpp
  2. +41
    -34
      src/app/ModuleWidget.cpp
  3. +1
    -0
      src/widgets/MenuOverlay.cpp

+ 1
- 0
include/app.hpp View File

@@ -51,6 +51,7 @@ struct ModuleWidget : OpaqueWidget {
This method just randomizes parameters. Override and call this function if your module contains other state information that you wish to randomize.
*/
void randomize();
virtual Menu *createContextMenu();

void draw(NVGcontext *vg);



+ 41
- 34
src/app/ModuleWidget.cpp View File

@@ -9,6 +9,7 @@ namespace rack {
ModuleWidget::~ModuleWidget() {
// Make sure WireWidget destructors are called *before* removing `module` from the rack.
disconnect();
// Remove and delete the Module instance
setModule(NULL);
}

@@ -223,42 +224,48 @@ struct DeleteMenuItem : MenuItem {
}
};

Menu *ModuleWidget::createContextMenu() {
Menu *menu = gScene->createMenu();

MenuLabel *menuLabel = new MenuLabel();
menuLabel->text = model->plugin->name + ": " + model->name;
menu->pushChild(menuLabel);

InitializeMenuItem *resetItem = new InitializeMenuItem();
resetItem->text = "Initialize";
resetItem->rightText = MOD_KEY_NAME "+I";
resetItem->moduleWidget = this;
menu->pushChild(resetItem);

RandomizeMenuItem *randomizeItem = new RandomizeMenuItem();
randomizeItem->text = "Randomize";
randomizeItem->rightText = MOD_KEY_NAME "+R";
randomizeItem->moduleWidget = this;
menu->pushChild(randomizeItem);

DisconnectMenuItem *disconnectItem = new DisconnectMenuItem();
disconnectItem->text = "Disconnect cables";
disconnectItem->moduleWidget = this;
menu->pushChild(disconnectItem);

CloneMenuItem *cloneItem = new CloneMenuItem();
cloneItem->text = "Duplicate";
cloneItem->rightText = MOD_KEY_NAME "+D";
cloneItem->moduleWidget = this;
menu->pushChild(cloneItem);

DeleteMenuItem *deleteItem = new DeleteMenuItem();
deleteItem->text = "Delete";
deleteItem->rightText = "Backspace/Delete";
deleteItem->moduleWidget = this;
menu->pushChild(deleteItem);

return menu;
}

void ModuleWidget::onMouseDownOpaque(int button) {
if (button == 1) {
Menu *menu = gScene->createMenu();

MenuLabel *menuLabel = new MenuLabel();
menuLabel->text = model->plugin->name + ": " + model->name;
menu->pushChild(menuLabel);

InitializeMenuItem *resetItem = new InitializeMenuItem();
resetItem->text = "Initialize";
resetItem->rightText = MOD_KEY_NAME "+I";
resetItem->moduleWidget = this;
menu->pushChild(resetItem);

RandomizeMenuItem *randomizeItem = new RandomizeMenuItem();
randomizeItem->text = "Randomize";
randomizeItem->rightText = MOD_KEY_NAME "+R";
randomizeItem->moduleWidget = this;
menu->pushChild(randomizeItem);

DisconnectMenuItem *disconnectItem = new DisconnectMenuItem();
disconnectItem->text = "Disconnect cables";
disconnectItem->moduleWidget = this;
menu->pushChild(disconnectItem);

CloneMenuItem *cloneItem = new CloneMenuItem();
cloneItem->text = "Duplicate";
cloneItem->rightText = MOD_KEY_NAME "+D";
cloneItem->moduleWidget = this;
menu->pushChild(cloneItem);

DeleteMenuItem *deleteItem = new DeleteMenuItem();
deleteItem->text = "Delete";
deleteItem->rightText = "Backspace/Delete";
deleteItem->moduleWidget = this;
menu->pushChild(deleteItem);
createContextMenu();
}
}



+ 1
- 0
src/widgets/MenuOverlay.cpp View File

@@ -8,6 +8,7 @@ void MenuOverlay::step() {
for (Widget *child : children) {
child->box = child->box.clamp(Rect(Vec(0, 0), box.size));
}
Widget::step();
}

void MenuOverlay::onDragDrop(Widget *origin) {


Loading…
Cancel
Save