diff options
Diffstat (limited to 'src/sdl')
-rw-r--r-- | src/sdl/action.c | 25 | ||||
-rw-r--r-- | src/sdl/draw.c | 8 | ||||
-rw-r--r-- | src/sdl/draw.h | 3 |
3 files changed, 24 insertions, 12 deletions
diff --git a/src/sdl/action.c b/src/sdl/action.c index 8307f19..84f415a 100644 --- a/src/sdl/action.c +++ b/src/sdl/action.c @@ -13,13 +13,27 @@ case SDLK_8: \ case SDLK_9: +#define CASE_DIR \ + case SDLK_UP: \ + case SDLK_DOWN: \ + case SDLK_LEFT: \ + case SDLK_RIGHT: \ + case SDLK_h: \ + case SDLK_j: \ + case SDLK_k: \ + case SDLK_l: + static const sok_dir_t keycode_to_dir(const SDL_Keycode code) { switch (code) { case SDLK_UP: return SOK_DIR_UP; + case SDLK_k: return SOK_DIR_UP; case SDLK_LEFT: return SOK_DIR_LEFT; + case SDLK_h: return SOK_DIR_LEFT; case SDLK_DOWN: return SOK_DIR_DOWN; + case SDLK_j: return SOK_DIR_DOWN; case SDLK_RIGHT: return SOK_DIR_RIGHT; + case SDLK_l: return SOK_DIR_RIGHT; default: return SOK_DIR_LAST; } } @@ -32,17 +46,14 @@ get_key_action( case SDLK_ESCAPE: case SDLK_q: return (action_t) { .type = ACTION_QUIT }; - case SDLK_UP: - case SDLK_DOWN: - case SDLK_LEFT: - case SDLK_RIGHT: + CASE_DIR return (action_t) { .type = ACTION_MOVE, .data = keycode_to_dir(code) }; case SDLK_u: return (action_t) { .type = ACTION_UNDO }; - case SDLK_n: + case SDLK_SPACE: return (action_t) { .type = ACTION_NEXT }; CASE_DIGIT return (action_t) { @@ -53,9 +64,9 @@ get_key_action( return (action_t) { .type = ACTION_WARP_BUF_POP }; case SDLK_RETURN: return (action_t) { .type = ACTION_WARP }; - case 'r': + case SDLK_r: return (action_t) { .type = ACTION_RESET }; - case 's': + case SDLK_s: return (action_t) { .type = ACTION_SOLVE }; default: return (action_t) { .type = ACTION_NONE }; diff --git a/src/sdl/draw.c b/src/sdl/draw.c index f6e350b..10d08ac 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -18,8 +18,8 @@ get_cell_rect( const size_t cell_size = get_cell_size(draw_ctx); return (SDL_Rect) { - draw_ctx->render_ofs.x + pos.x * cell_size, - draw_ctx->render_ofs.y + pos.y * cell_size, + draw_ctx->render_ofs_x + pos.x * cell_size, + draw_ctx->render_ofs_y + pos.y * cell_size, cell_size, cell_size }; @@ -41,8 +41,8 @@ draw_on_size( } // calculate renderer offset - draw_ctx->render_ofs.x = (renderer_x - level_size.x * cell_size) / 2; - draw_ctx->render_ofs.y = (renderer_y - level_size.y * cell_size) / 2; + draw_ctx->render_ofs_x = (renderer_x - level_size.x * cell_size) / 2; + draw_ctx->render_ofs_y = (renderer_y - level_size.y * cell_size) / 2; return true; } diff --git a/src/sdl/draw.h b/src/sdl/draw.h index 304d972..26f7cb0 100644 --- a/src/sdl/draw.h +++ b/src/sdl/draw.h @@ -13,7 +13,8 @@ typedef struct { const level_t *level; const size_t * const zoom; - sok_pos_t render_ofs; + // render offset + int render_ofs_x, render_ofs_y; } draw_ctx_t; void draw(draw_ctx_t * const); |