Exemplo n.º 1
0
bool
PointOverlayInteract::onOverlayPenUp(TimeValue time,
                                     const RenderScale & renderScale,
                                     ViewIdx view,
                                     const QPointF & viewportPos,
                                     const QPointF & penPos,
                                     double pressure,
                                     TimeValue timestamp)
{
    KnobDoublePtr knob = _imp->param.lock();

    // do not show interact if knob is secret or not enabled
    // see https://github.com/MrKepzie/Natron/issues/932
    if ( !knob || !knob->shouldDrawOverlayInteract() ) {
        return false;
    }

    RenderScale pscale;
    getPixelScale(pscale.x, pscale.y);
    
    bool didSomething = false;
    if (_imp->state == ePositionInteractStatePicked) {
        if (!_imp->interactiveDrag) {
            std::vector<double> p(2);
            p[0] = fround(_imp->lastPenPos.x(), pscale.x);
            p[1] = fround(_imp->lastPenPos.y(), pscale.y);
            for (int i = 0; i < 2; ++i) {
                if (knob->getValueIsNormalized(DimIdx(i)) != eValueIsNormalizedNone) {
                    p[i] = knob->normalize(DimIdx(i), time, p[i]);
                }
            }

            knob->setValueAcrossDimensions(p, DimIdx(0), view, eValueChangedReasonUserEdited);
        }

        _imp->state = ePositionInteractStateInactive;
        bool motion = onOverlayPenMotion(time, renderScale, view, viewportPos, penPos, pressure, timestamp);
        Q_UNUSED(motion);
        didSomething = true;
    }
    
    return didSomething;
} // onOverlayPenUp
Exemplo n.º 2
0
bool
PointOverlayInteract::onOverlayPenMotion(TimeValue time,
                                         const RenderScale & /*renderScale*/,
                                         ViewIdx view,
                                         const QPointF & /*viewportPos*/,
                                         const QPointF & penPos,
                                         double /*pressure*/,
                                         TimeValue /*timestamp*/)
{
    KnobDoublePtr knob = _imp->param.lock();

    // do not show interact if knob is secret or not enabled
    // see https://github.com/MrKepzie/Natron/issues/932
    if ( !knob || !knob->shouldDrawOverlayInteract() ) {
        return false;
    }

    RenderScale pscale;
    getPixelScale(pscale.x, pscale.y);

    QPointF pos;
    if (_imp->state == ePositionInteractStatePicked) {
        pos = _imp->lastPenPos;
    } else {
        double p[2];
        for (int i = 0; i < 2; ++i) {
            p[i] = knob->getValueAtTime(time, DimIdx(i));
            if (knob->getValueIsNormalized(DimIdx(i)) != eValueIsNormalizedNone) {
                p[i] = knob->denormalize(DimIdx(i), time, p[i]);
            }
        }
        pos.setX(p[0]);
        pos.setY(p[1]);
    }

    bool didSomething = false;
    bool valuesChanged = false;

    switch (_imp->state) {
        case ePositionInteractStateInactive:
        case ePositionInteractStatePoised: {
            // are we in the box, become 'poised'
            PositionInteractState newState;
            if ( ( std::fabs( penPos.x() - pos.x() ) <= _imp->pointTolerance() * pscale.x) &&
                ( std::fabs( penPos.y() - pos.y() ) <= _imp->pointTolerance() * pscale.y) ) {
                newState = ePositionInteractStatePoised;
            } else {
                newState = ePositionInteractStateInactive;
            }

            if (_imp->state != newState) {
                // state changed, must redraw
                redraw();
            }
            _imp->state = newState;
            //}
            break;
        }

        case ePositionInteractStatePicked: {
            valuesChanged = true;
            break;
        }
    }
    didSomething = (_imp->state == ePositionInteractStatePoised) || (_imp->state == ePositionInteractStatePicked);

    if ( (_imp->state != ePositionInteractStateInactive) && _imp->interactiveDrag && valuesChanged ) {
        std::vector<double> p(2);
        p[0] = fround(_imp->lastPenPos.x(), pscale.x);
        p[1] = fround(_imp->lastPenPos.y(), pscale.y);
        for (int i = 0; i < 2; ++i) {
            if (knob->getValueIsNormalized(DimIdx(i)) != eValueIsNormalizedNone) {
                p[i] = knob->normalize(DimIdx(i), time, p[i]);
            }
        }


        knob->setValueAcrossDimensions(p, DimIdx(0), ViewSetSpec(view), eValueChangedReasonUserEdited);
    }

    _imp->lastPenPos = penPos;

    return (didSomething || valuesChanged);
} // onOverlayPenMotion