A game framework written with osu! in mind.
at master 35 lines 1.2 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using osu.Framework.Bindables; 5using osu.Framework.Utils; 6 7namespace osu.Framework.Graphics.Transforms 8{ 9 internal class TransformBindable<TValue, TEasing, T> : Transform<TValue, TEasing, T> 10 where T : class, ITransformable 11 where TEasing : IEasingFunction 12 { 13 public override string TargetMember { get; } 14 15 private readonly Bindable<TValue> targetBindable; 16 17 public TransformBindable(Bindable<TValue> targetBindable) 18 { 19 this.targetBindable = targetBindable; 20 21 TargetMember = $"{targetBindable.GetHashCode()}.Value"; 22 } 23 24 private TValue valueAt(double time) 25 { 26 if (time < StartTime) return StartValue; 27 if (time >= EndTime) return EndValue; 28 29 return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); 30 } 31 32 protected override void Apply(T d, double time) => targetBindable.Value = valueAt(time); 33 protected override void ReadIntoStartValue(T d) => StartValue = targetBindable.Value; 34 } 35}