diff options
Diffstat (limited to 'src/sdl')
-rw-r--r-- | src/sdl/draw.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/sdl/draw.c b/src/sdl/draw.c index aa16bca..6616ce7 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -334,7 +334,12 @@ draw_moves_text( ) { // build text char buf[256]; - snprintf(buf, sizeof(buf), "Moves: %zu", draw_ctx->ctx->num_moves); + snprintf( + buf, sizeof(buf), + "Moves: %zu%s", + draw_ctx->ctx->num_moves, + sok_ctx_is_done(draw_ctx->ctx) ? " (Won!)" : "" + ); // get renderer height int renderer_h; @@ -355,6 +360,44 @@ draw_moves_text( draw_text(draw_ctx, buf, &rect); } +#define DELIM " " + +static void +draw_help_text( + draw_ctx_t * const draw_ctx +) { + // build text + char buf[256]; + snprintf( + buf, sizeof(buf), + "%sU: Undo" DELIM "R: Reset" DELIM "S: Solve" DELIM "Q: Quit", + sok_ctx_is_done(draw_ctx->ctx) ? "Space: Next Level" DELIM : "" + ); + + // get renderer height + int renderer_w, renderer_h; + if (SDL_GetRendererOutputSize(draw_ctx->renderer, &renderer_w, &renderer_h)) { + die("SDL_GetRendererOutputSize(): %s", SDL_GetError()); + } + + // get text size + int text_w, text_h; + if (TTF_SizeText(draw_ctx->font, buf, &text_w, &text_h)) { + die("TTF_SizeText(): %s", TTF_GetError()); + } + + // build rect + const SDL_Rect rect = { + renderer_w - text_w - 10, + renderer_h - text_h - 10, + text_w, + text_h, + }; + + // draw text + draw_text(draw_ctx, buf, &rect); +} + static void set_bg_won_color( draw_ctx_t * const draw_ctx @@ -399,6 +442,7 @@ draw( // render text draw_level_text(draw_ctx); draw_moves_text(draw_ctx); + draw_help_text(draw_ctx); // flip SDL_RenderPresent(draw_ctx->renderer); |