1 module evael.graphics.gui.animations.AlphaAnimation; 2 3 import evael.graphics.gui.animations.Animation; 4 import evael.graphics.gui.controls.Control; 5 6 /** 7 * AlphaAnimation. 8 */ 9 class AlphaAnimation : Animation 10 { 11 private float m_fromAlpha; 12 private float m_toAlpha; 13 private float m_currentValue; 14 15 private float m_inc; 16 17 @nogc @safe 18 public this(in float from = 0.0f, in float to = 1.0f) pure nothrow 19 { 20 super(); 21 22 this.m_currentValue = this.m_fromAlpha = from; 23 this.m_toAlpha = to; 24 this.m_duration = 250.0f; 25 } 26 27 public override void update(in float deltaTime) 28 { 29 if (this.m_status != Status.Playing) 30 { 31 this.onAnimationStart(); 32 33 this.m_inc = ( (this.m_toAlpha - this.m_fromAlpha) / this.m_duration) * deltaTime; 34 } 35 36 import std.math : approxEqual; 37 38 if (approxEqual(this.m_currentValue, this.m_toAlpha, 0.01f, 0.01f)) 39 { 40 this.onAnimationEnd(); 41 return; 42 } 43 44 this.m_currentValue += this.m_inc; 45 46 this.m_control.opacity = cast(ubyte)(this.m_currentValue * 255); 47 } 48 49 public override void reset() 50 { 51 super.reset(); 52 53 this.m_currentValue = this.m_fromAlpha; 54 } 55 }