1 module evael.graphics.gui.animations.Animation; 2 3 import evael.graphics.gui.controls.Control; 4 5 /** 6 * Animation. 7 */ 8 abstract class Animation 9 { 10 public enum Status : ubyte 11 { 12 Waiting, 13 Playing, 14 Finished 15 } 16 17 protected alias OnAnimationStart = void delegate(Animation); 18 protected alias OnAnimationEnd = void delegate(Animation); 19 20 protected OnAnimationStart m_onAnimationStart; 21 protected OnAnimationEnd m_onAnimationEnd; 22 23 /// Animation duration in ms 24 protected float m_duration; 25 26 /// Animation status 27 protected Status m_status; 28 29 protected Control m_control; 30 31 private uint m_id; 32 33 @nogc @safe 34 public this() pure nothrow 35 { 36 this.m_status = Status.Waiting; 37 this.m_duration = 1000.0f; 38 } 39 40 public abstract void update(in float deltaTime); 41 42 @nogc @safe 43 public void reset() pure nothrow 44 { 45 this.m_status = Status.Waiting; 46 } 47 48 public void onAnimationStart() 49 { 50 this.m_status = Status.Playing; 51 52 if (this.m_onAnimationStart !is null) 53 { 54 this.m_onAnimationStart(this); 55 } 56 } 57 58 public void onAnimationEnd() 59 { 60 this.m_status = Status.Finished; 61 62 if (this.m_onAnimationEnd !is null) 63 { 64 this.m_onAnimationEnd(this); 65 } 66 } 67 68 @nogc @safe 69 @property pure nothrow 70 { 71 public void duration(in float value) 72 { 73 this.m_duration = value; 74 } 75 76 public void control(Control value) 77 { 78 this.m_control = value; 79 } 80 81 public Status status() const 82 { 83 return this.m_status; 84 } 85 86 public void onAnimationStartEvent(OnAnimationStart value) 87 { 88 this.m_onAnimationStart = value; 89 } 90 91 public void onAnimationEndEvent(OnAnimationEnd value) 92 { 93 this.m_onAnimationEnd = value; 94 } 95 96 package void id(in uint value) 97 { 98 this.m_id = value; 99 } 100 101 package uint id() const 102 { 103 return this.m_id; 104 } 105 } 106 }