@@ -72,12 +72,14 @@ struct Quantity { | |||||
/** Returns a string representation of the quantity. */ | /** Returns a string representation of the quantity. */ | ||||
virtual std::string getString(); | virtual std::string getString(); | ||||
// Helper methods | |||||
/** Resets the value to the default value. */ | /** Resets the value to the default value. */ | ||||
void reset(); | |||||
virtual void reset(); | |||||
/** Sets the value to a uniform random value between the bounds. */ | /** Sets the value to a uniform random value between the bounds. */ | ||||
void randomize(); | |||||
virtual void randomize(); | |||||
// Helper methods | |||||
/** Checks whether the value is at the min value. */ | /** Checks whether the value is at the min value. */ | ||||
bool isMin(); | bool isMin(); | ||||
/** Checks whether the value is at the max value. */ | /** Checks whether the value is at the max value. */ | ||||
@@ -68,6 +68,9 @@ struct ParamQuantity : Quantity { | |||||
int getDisplayPrecision() override; | int getDisplayPrecision() override; | ||||
std::string getLabel() override; | std::string getLabel() override; | ||||
std::string getUnit() override; | std::string getUnit() override; | ||||
void reset() override; | |||||
void randomize() override; | |||||
virtual std::string getDescription(); | virtual std::string getDescription(); | ||||
}; | }; | ||||
@@ -288,7 +288,7 @@ void ParamWidget::createContextMenu() { | |||||
void ParamWidget::resetAction() { | void ParamWidget::resetAction() { | ||||
engine::ParamQuantity* pq = getParamQuantity(); | engine::ParamQuantity* pq = getParamQuantity(); | ||||
if (pq && pq->resetEnabled) { | |||||
if (pq && pq->resetEnabled && pq->isBounded()) { | |||||
float oldValue = pq->getValue(); | float oldValue = pq->getValue(); | ||||
pq->reset(); | pq->reset(); | ||||
float newValue = pq->getValue(); | float newValue = pq->getValue(); | ||||
@@ -246,6 +246,8 @@ void Module::onReset(const ResetEvent& e) { | |||||
for (ParamQuantity* pq : paramQuantities) { | for (ParamQuantity* pq : paramQuantities) { | ||||
if (!pq->resetEnabled) | if (!pq->resetEnabled) | ||||
continue; | continue; | ||||
if (!pq->isBounded()) | |||||
continue; | |||||
pq->reset(); | pq->reset(); | ||||
} | } | ||||
// Call deprecated event | // Call deprecated event | ||||
@@ -258,6 +260,8 @@ void Module::onRandomize(const RandomizeEvent& e) { | |||||
for (ParamQuantity* pq : paramQuantities) { | for (ParamQuantity* pq : paramQuantities) { | ||||
if (!pq->randomizeEnabled) | if (!pq->randomizeEnabled) | ||||
continue; | continue; | ||||
if (!pq->isBounded()) | |||||
continue; | |||||
pq->randomize(); | pq->randomize(); | ||||
} | } | ||||
// Call deprecated event | // Call deprecated event | ||||
@@ -122,6 +122,24 @@ std::string ParamQuantity::getUnit() { | |||||
return unit; | return unit; | ||||
} | } | ||||
void ParamQuantity::reset() { | |||||
// Same as Quantity::reset | |||||
setValue(getDefaultValue()); | |||||
} | |||||
void ParamQuantity::randomize() { | |||||
if (snapEnabled) { | |||||
// Randomize inclusive of the maximum value | |||||
float value = math::rescale(random::uniform(), 0.f, 1.f, getMinValue(), getMaxValue() + 1.f); | |||||
value = std::floor(value); | |||||
setValue(value); | |||||
} | |||||
else { | |||||
// Same as Quantity::randomize | |||||
setScaledValue(random::uniform()); | |||||
} | |||||
} | |||||
std::string ParamQuantity::getDescription() { | std::string ParamQuantity::getDescription() { | ||||
return description; | return description; | ||||
} | } | ||||