Browse Source

Make SvgKnob::onChange() reset knob angle if ParamQuantity is null.

tags/v2.4.0
Andrew Belt 1 year ago
parent
commit
0e3ea2b7ff
1 changed files with 12 additions and 9 deletions
  1. +12
    -9
      src/app/SvgKnob.cpp

+ 12
- 9
src/app/SvgKnob.cpp View File

@@ -38,11 +38,12 @@ void SvgKnob::setSvg(std::shared_ptr<window::Svg> svg) {
} }


void SvgKnob::onChange(const ChangeEvent& e) { void SvgKnob::onChange(const ChangeEvent& e) {
// Re-transform the widget::TransformWidget
float angle = 0.f;

// Calculate angle from value
engine::ParamQuantity* pq = getParamQuantity(); engine::ParamQuantity* pq = getParamQuantity();
if (pq) { if (pq) {
float value = pq->getValue(); float value = pq->getValue();
float angle;
if (!pq->isBounded()) { if (!pq->isBounded()) {
// Number of rotations equals value for unbounded range // Number of rotations equals value for unbounded range
angle = value * (2 * M_PI); angle = value * (2 * M_PI);
@@ -56,14 +57,16 @@ void SvgKnob::onChange(const ChangeEvent& e) {
angle = math::rescale(value, pq->getMinValue(), pq->getMaxValue(), minAngle, maxAngle); angle = math::rescale(value, pq->getMinValue(), pq->getMaxValue(), minAngle, maxAngle);
} }
angle = std::fmod(angle, 2 * M_PI); angle = std::fmod(angle, 2 * M_PI);
tw->identity();
// Rotate SVG
math::Vec center = sw->box.getCenter();
tw->translate(center);
tw->rotate(angle);
tw->translate(center.neg());
fb->setDirty();
} }

tw->identity();
// Rotate SVG
math::Vec center = sw->box.getCenter();
tw->translate(center);
tw->rotate(angle);
tw->translate(center.neg());
fb->setDirty();

Knob::onChange(e); Knob::onChange(e);
} }




Loading…
Cancel
Save