diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index 817110b6..8e4c5de4 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,32 @@ struct ParamField : ui::TextField { }; +struct ParamValueItem : ui::MenuItem { + ParamWidget* paramWidget; + float value; + + void onAction(const event::Action& e) override { + engine::ParamQuantity* pq = paramWidget->getParamQuantity(); + if (pq) { + float oldValue = pq->getValue(); + pq->setValue(value); + float newValue = pq->getValue(); + + if (oldValue != newValue) { + // Push ParamChange history action + history::ParamChange* h = new history::ParamChange; + h->name = "set parameter"; + h->moduleId = paramWidget->module->id; + h->paramId = paramWidget->paramId; + h->oldValue = oldValue; + h->newValue = newValue; + APP->history->push(h); + } + } + } +}; + + struct ParamTooltip : ui::Tooltip { ParamWidget* paramWidget; @@ -209,14 +236,31 @@ void ParamWidget::onLeave(const event::Leave& e) { void ParamWidget::createContextMenu() { ui::Menu* menu = createMenu(); + engine::ParamQuantity* pq = getParamQuantity(); + engine::SwitchQuantity* switchQuantity = dynamic_cast(pq); + ParamLabel* paramLabel = new ParamLabel; paramLabel->paramWidget = this; menu->addChild(paramLabel); - ParamField* paramField = new ParamField; - paramField->box.size.x = 100; - paramField->setParamWidget(this); - menu->addChild(paramField); + if (switchQuantity) { + int index = (int) std::floor(pq->getValue()); + for (int i = 0; i < (int) switchQuantity->labels.size(); i++) { + std::string label = switchQuantity->labels[i]; + ParamValueItem* paramValueItem = new ParamValueItem; + paramValueItem->text = label; + paramValueItem->rightText = CHECKMARK(i == index); + paramValueItem->paramWidget = this; + paramValueItem->value = i; + menu->addChild(paramValueItem); + } + } + else { + ParamField* paramField = new ParamField; + paramField->box.size.x = 100; + paramField->setParamWidget(this); + menu->addChild(paramField); + } ParamResetItem* resetItem = new ParamResetItem; resetItem->text = "Initialize"; diff --git a/src/engine/ParamQuantity.cpp b/src/engine/ParamQuantity.cpp index 162355cf..b48bf3ab 100644 --- a/src/engine/ParamQuantity.cpp +++ b/src/engine/ParamQuantity.cpp @@ -128,7 +128,7 @@ std::string ParamQuantity::getDescription() { std::string SwitchQuantity::getDisplayValueString() { - int index = std::floor(getDisplayValue()); + int index = (int) std::floor(getValue()); if (!(0 <= index && index < (int) labels.size())) return ""; return labels[index]; @@ -141,7 +141,7 @@ void SwitchQuantity::setDisplayValueString(std::string s) { if (it == labels.end()) return; int index = std::distance(labels.begin(), it); - setDisplayValue(index); + setValue(index); }