1 /** 2 * Module for event handlers. 3 * 4 * Authors: 5 * Jacob Jensen 6 * License: 7 * https://github.com/PoisonEngine/poison-ui/blob/master/LICENSE 8 */ 9 module poison.core.eventhandler; 10 11 import poison.core.eventargs; 12 13 /// A base event handler. 14 interface IBaseEventHandler { } 15 16 /// An event handler. 17 class EventHandler(TEventArgs : EventArgs) : IBaseEventHandler { 18 private: 19 /// The function pointer of the event handler. 20 void function(TEventArgs) _f; 21 22 /// The delegate of the event handler. 23 void delegate(TEventArgs) _d; 24 25 public: 26 /** 27 * Creates a new event handler. 28 * Params: 29 * f = The function pointer. 30 */ 31 this(void function(TEventArgs) f) { 32 _f = f; 33 } 34 35 /** 36 * Creates a new event handler. 37 * Params: 38 * d = The delegate. 39 */ 40 this(void delegate(TEventArgs) d) { 41 _d = d; 42 } 43 44 /** 45 * Operator overload for calling the event handler implicit. 46 * Params: 47 * e = The event args. 48 */ 49 void opCall(TEventArgs e) { 50 if (_f) { 51 _f(e); 52 } 53 else if (_d) { 54 _d(e); 55 } 56 } 57 }