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