All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.nacular.doodle.animation.impl.AnimatorImpl.kt Maven / Gradle / Ivy

There is a newer version: 0.10.4
Show newest version
package io.nacular.doodle.animation.impl

import io.nacular.doodle.animation.Animation
import io.nacular.doodle.animation.Animator
import io.nacular.doodle.animation.Animator.Listener
import io.nacular.doodle.animation.Animator.MeasureTransitionBuilder
import io.nacular.doodle.animation.Animator.TransitionBuilder
import io.nacular.doodle.animation.Moment
import io.nacular.doodle.animation.NoneUnit
import io.nacular.doodle.animation.noneUnits
import io.nacular.doodle.animation.transition.Transition
import io.nacular.doodle.scheduler.AnimationScheduler
import io.nacular.doodle.scheduler.Task
import io.nacular.doodle.time.Timer
import io.nacular.doodle.utils.Completable
import io.nacular.doodle.utils.CompletableImpl
import io.nacular.doodle.utils.CompletableImpl.State.Active
import io.nacular.doodle.utils.CompletableImpl.State.Canceled
import io.nacular.doodle.utils.ObservableSet
import io.nacular.doodle.utils.Pool
import io.nacular.doodle.utils.SetPool
import io.nacular.measured.units.Measure
import io.nacular.measured.units.Time
import io.nacular.measured.units.Time.Companion.milliseconds
import io.nacular.measured.units.Units
import io.nacular.measured.units.div
import io.nacular.measured.units.times

/**
 * Created by Nicholas Eddy on 1/12/20.
 */

public class AnimatorImpl(private val timer: Timer, private val animationScheduler: AnimationScheduler): Animator {

    private class KeyFrame {
        var time = 0 * milliseconds
    }

    private class InternalProperty(initialValue: Measure) {

        val transitions      = mutableListOf>()
        var activeTransition = null as TransitionNode?
            private set

        var value = Moment(initialValue, 0 * initialValue / (1 * milliseconds))

        fun add(transition: Transition) {
            val start = if (transitions.isEmpty()) KeyFrame() else transitions.last().endTime
            val end   = KeyFrame()

            add(transition, start, end)
        }

        fun add(transition: Transition, start: KeyFrame, end: KeyFrame) {
            transitions += TransitionNode(transition, start, end)
        }

        fun nextTransition(initialValue: Moment, elapsedTime: Measure




© 2015 - 2025 Weber Informatics LLC | Privacy Policy