scoop:scoop.surface:0.1.0
src/shared/animation/group.scoop
Selected production source · src/shared/animation/group.scoop
1
package scoop.surface3
import scoop.graphics.Color4
import scoop.graphics.Point5
import scoop.graphics.Size7
/** Owns a set of values on the same timeline with an independent frame gate. */8
public class AnimationGroup internal constructor(9
private val timeline: AnimationTimeline,10
initial: Boolean11
): Closeable {12
private val members = ArrayList<AnimationEntry>()13
private var closed = false14
private var enabled = initial15
public val isClosed: Boolean get() {16
timeline.checkThread()17
return closed18
}19
public var isFrameEnabled: Boolean20
get() {21
timeline.checkThread()22
return enabled23
}24
set(value) {25
checkOpen()26
if (enabled == value)27
return28
enabled = value29
if (value) {30
val time = timeline.now()31
for (member in members.toArray())32
member.sample(time)33
}34
timeline.changed(needsFrame())35
}36
public fun value(initial: Double): Animatable<Double> =37
value(initial, AnimationConverters.DoubleValue)38
public fun value(initial: Point): Animatable<Point> =39
value(initial, AnimationConverters.PointValue)40
public fun value(initial: Size): Animatable<Size> =41
value(initial, AnimationConverters.SizeValue)42
public fun value(initial: Color): Animatable<Color> =43
value(initial, AnimationConverters.ColorValue)44
public fun <T> value(initial: T, converter: AnimationConverter<T>): Animatable<T> {45
checkOpen()46
return timeline.createValue(initial, converter, Some(this))47
}48
internal fun add(entry: AnimationEntry) {49
members.add(entry)50
}51
internal fun remove(value: Closeable) {52
removeAnimationEntry(members, value)53
}54
private fun needsFrame(): Boolean {55
for (member in members)56
if (member.frameEnabled())57
return true58
return false59
}60
private fun checkOpen() {61
timeline.checkOpen()62
if (closed)63
throw IllegalStateException(Some("animation group is closed"))64
}65
public override fun close() {66
timeline.checkThread()67
if (closed)68
return69
val repaint = needsFrame()70
closed = true71
enabled = false72
var failure: Throwable? = None73
for (member in members.toArray())74
failure = cleanupFailure(failure) { member.owner.close() }75
members.clear()76
timeline.detachedGroup(this)77
throwFailure(cleanupFailure(failure) { timeline.changed(repaint) })78
}79
}