blob: a4dcb7974124e1e69469fecaee4faa75bf12d1e4 (
plain)
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
58
59
60
61
62
63
|
#include "../libsok/sok.h"
#include "action.h"
#define CASE_DIGIT \
case SDLK_0: \
case SDLK_1: \
case SDLK_2: \
case SDLK_3: \
case SDLK_4: \
case SDLK_5: \
case SDLK_6: \
case SDLK_7: \
case SDLK_8: \
case SDLK_9:
static const sok_dir_t
keycode_to_dir(const SDL_Keycode code) {
switch (code) {
case SDLK_UP: return SOK_DIR_UP;
case SDLK_LEFT: return SOK_DIR_LEFT;
case SDLK_DOWN: return SOK_DIR_DOWN;
case SDLK_RIGHT: return SOK_DIR_RIGHT;
default: return SOK_DIR_LAST;
}
}
action_t
get_action(
const SDL_Keycode code
) {
switch (code) {
case SDLK_ESCAPE:
case SDLK_q:
return (action_t) { .type = ACTION_QUIT };
case SDLK_UP:
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:
return (action_t) {
.type = ACTION_MOVE,
.data = keycode_to_dir(code)
};
case SDLK_u:
return (action_t) { .type = ACTION_UNDO };
case SDLK_n:
return (action_t) { .type = ACTION_NEXT };
CASE_DIGIT
return (action_t) {
.type = ACTION_WARP_BUF_PUSH,
.data = (code - SDLK_0),
};
case SDLK_DELETE:
return (action_t) { .type = ACTION_WARP_BUF_POP };
case SDLK_RETURN:
return (action_t) { .type = ACTION_WARP };
case 'r':
return (action_t) { .type = ACTION_RESET };
case 's':
return (action_t) { .type = ACTION_SOLVE };
default:
return (action_t) { .type = ACTION_NONE };
}
}
|