MCPcopy Create free account
hub / github.com/benkuper/Chataigne / parameterAddToContextMenu

Method parameterAddToContextMenu

Source/MainComponent.cpp:65–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64
65void MainContentComponent::parameterAddToContextMenu(ControllableUI* ui, PopupMenu* m)
66{
67 if (ui->controllable.wasObjectDeleted() || ui->controllable->type == Controllable::TRIGGER || ui->controllable->isControllableFeedbackOnly) return;
68
69 {
70 PopupMenu cvMenu;
71 for (auto& g : CVGroupManager::getInstance()->items)
72 {
73 cvMenu.addItem(g->niceName, [g, ui]() { g->addItemFromParameter((Parameter*)ui->controllable.get()); });
74 }
75 m->addSubMenu("Add & Link to Custom Variable...", cvMenu);
76 }
77
78 {
79 Module * genericModule = static_cast<ChataigneEngine*>(Engine::mainEngine)->module.get();
80 CommandDefinition* commandDef = genericModule->defManager->getCommandDefinitionFor("", "Set Parameter Value");
81 static const auto addOutput = [] (MappingLayer* layer, CommandDefinition* commandDef, Controllable* target)
82 {
83 MappingOutput* output = layer->mapping->om.createItem();
84 output->setCommand(commandDef);
85 GenericControllableCommand* command = dynamic_cast<GenericControllableCommand*>(output->command.get());
86 if (command)
87 {
88 command->target->setValueFromTarget(target);
89 }
90 layer->mapping->om.addItem(output);
91 };
92
93 PopupMenu seqMenu;
94 for (auto& sequence : ChataigneSequenceManager::getInstance()->items)
95 {
96 PopupMenu layerMenu;
97 for (auto& layer : sequence->layerManager->items)
98 {
99 MappingLayer* mappingLayer = dynamic_cast<MappingLayer*>(layer);
100 if (mappingLayer)
101 {
102 layerMenu.addItem(layer->niceName, [commandDef, mappingLayer, ui]
103 {
104 addOutput(mappingLayer, commandDef, ui->controllable);
105 });
106 }
107 }
108
109 if (layerMenu.getNumItems() > 0) layerMenu.addSeparator();
110 layerMenu.addItem("Create new Mapping", [commandDef, sequence, ui]
111 {
112 Controllable* controllable = ui->controllable;
113 MappingLayer* mappingLayer = nullptr;
114 if (controllable->type == Controllable::COLOR)
115 {
116 mappingLayer = ColorMappingLayer::create(sequence, {});
117 }
118 else
119 {
120 Mapping1DLayer * mapping1DLayer = Mapping1DLayer::create(sequence, {});
121 if (Parameter* parameter = dynamic_cast<Parameter*>(controllable))
122 {

Callers

nothing calls this directly

Calls 6

addItemFromParameterMethod · 0.80
createFunction · 0.50
getMethod · 0.45
createItemMethod · 0.45
setCommandMethod · 0.45

Tested by

no test coverage detected