diff options
author | Paul Duncan <pabs@pablotron.org> | 2019-01-12 15:34:56 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2019-01-12 15:34:56 -0500 |
commit | 8d45b2b70143972f6b7862835b8ae9876f49e214 (patch) | |
tree | fff3580aea54b0b33e5f6649b6371676d02de9f8 /src/sdl/action.c | |
parent | 3d0b7418b2c1a87d44144749f5f055cfa0995f6c (diff) | |
download | sok-8d45b2b70143972f6b7862835b8ae9876f49e214.tar.bz2 sok-8d45b2b70143972f6b7862835b8ae9876f49e214.zip |
functioning sdl
Diffstat (limited to 'src/sdl/action.c')
-rw-r--r-- | src/sdl/action.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/sdl/action.c b/src/sdl/action.c new file mode 100644 index 0000000..a4dcb79 --- /dev/null +++ b/src/sdl/action.c @@ -0,0 +1,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 }; + } +} |