-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputManager.d
56 lines (44 loc) · 1.07 KB
/
InputManager.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
module InputManager;
import derelict.sdl.sdl;
import IManagers;
class InputManager : IManager {
void delegate(SDL_Event)[SDLKey] keyFunctions;
void delegate(SDL_Event) onMouseMotion;
bool init() {
return true;
}
void bindKey(SDLKey key, void function(SDL_Event) func) {
bindKey(key, (SDL_Event e) { func(e); return; });
}
void bindKey(SDLKey key, void delegate(SDL_Event) func) {
keyFunctions[key] = func;
}
void bindMouseMotion(void function(SDL_Event) func) {
bindMouseMotion((SDL_Event e) { func(e); return; });
}
void bindMouseMotion(void delegate(SDL_Event) func) {
onMouseMotion = func;
}
bool update(float delta) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_QUIT:
return false;
case SDL_KEYDOWN:
case SDL_KEYUP:
if(event.key.keysym.sym in keyFunctions)
keyFunctions[event.key.keysym.sym](event);
break;
case SDL_MOUSEMOTION:
if(onMouseMotion !is null)
onMouseMotion(event);
default:
break;
}
}
return true;
}
void cleanup() {
}
}