bool useTimeslice (const int elapsed) { if (auto* c = proxy != nullptr ? static_cast<Component*> (proxy) : static_cast<Component*> (component)) { msElapsed += elapsed; double newProgress = msElapsed / (double) msTotal; if (newProgress >= 0 && newProgress < 1.0) { const WeakReference<AnimationTask> weakRef (this); newProgress = timeToDistance (newProgress); const double delta = (newProgress - lastProgress) / (1.0 - lastProgress); jassert (newProgress >= lastProgress); lastProgress = newProgress; if (delta < 1.0) { bool stillBusy = false; if (isMoving) { left += (destination.getX() - left) * delta; top += (destination.getY() - top) * delta; right += (destination.getRight() - right) * delta; bottom += (destination.getBottom() - bottom) * delta; const Rectangle<int> newBounds (roundToInt (left), roundToInt (top), roundToInt (right - left), roundToInt (bottom - top)); if (newBounds != destination) { c->setBounds (newBounds); stillBusy = true; } } // Check whether the animation was cancelled/deleted during // a callback during the setBounds method if (weakRef.wasObjectDeleted()) return false; if (isChangingAlpha) { alpha += (destAlpha - alpha) * delta; c->setAlpha ((float) alpha); stillBusy = true; } if (stillBusy) return true; } } } moveToFinalDestination(); return false; }
void moveToFinalDestination() { if (component != nullptr) { const WeakReference<AnimationTask> weakRef (this); component->setAlpha ((float) destAlpha); component->setBounds (destination); if (! weakRef.wasObjectDeleted()) if (proxy != nullptr) component->setVisible (destAlpha > 0); } }
var Parameter::getValueFromScript(const juce::var::NativeFunctionArgs & a) { WeakReference<Parameter> c = getObjectFromJS<Parameter>(a); if (c == nullptr || c.wasObjectDeleted()) return var(); return c->getValue(); }