Browse Source

Use menu items for selecting SwitchQuantity params.

tags/v2.0.0
Andrew Belt 5 years ago
parent
commit
f819bd4255
2 changed files with 50 additions and 6 deletions
  1. +48
    -4
      src/app/ParamWidget.cpp
  2. +2
    -2
      src/engine/ParamQuantity.cpp

+ 48
- 4
src/app/ParamWidget.cpp View File

@@ -4,6 +4,7 @@
#include <app/Scene.hpp>
#include <context.hpp>
#include <engine/Engine.hpp>
#include <engine/ParamQuantity.hpp>
#include <settings.hpp>
#include <history.hpp>
#include <helpers.hpp>
@@ -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<engine::SwitchQuantity*>(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";


+ 2
- 2
src/engine/ParamQuantity.cpp View File

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




Loading…
Cancel
Save