diff options
author | Paul Duncan <pabs@pablotron.org> | 2019-01-16 07:15:26 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2019-01-16 07:15:26 -0500 |
commit | c17f5a5377f959a7e67526e0ae89b329bf99a101 (patch) | |
tree | a350ecb2d677a060795fbf20aade2a2c7a5759b6 /src/sdl/draw.c | |
parent | 19a5965400f9a252adf540050046d2dc3a026d13 (diff) | |
download | sok-c17f5a5377f959a7e67526e0ae89b329bf99a101.tar.bz2 sok-c17f5a5377f959a7e67526e0ae89b329bf99a101.zip |
solve in background thread
Diffstat (limited to 'src/sdl/draw.c')
-rw-r--r-- | src/sdl/draw.c | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/src/sdl/draw.c b/src/sdl/draw.c index 5bb8de7..322bd7a 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -230,12 +230,16 @@ draw_help_text( // build text char buf[256]; + if (draw_ctx->state == GAME_STATE_SOLVE) { + snprintf(buf, sizeof(buf), " Space: Cancel "); + } else { #define D " " - snprintf( - buf, sizeof(buf), - " %sU: Undo" D "R: Reset" D "S: Solve" D "Q: Quit ", - sok_ctx_is_done(draw_ctx->ctx) ? "Space: Next Level" D : "" - ); + snprintf( + buf, sizeof(buf), + " %sU: Undo" D "R: Reset" D "S: Solve" D "Q: Quit ", + sok_ctx_is_done(draw_ctx->ctx) ? "Space: Next Level" D : "" + ); + } #undef D // draw text @@ -243,6 +247,42 @@ draw_help_text( } static void +draw_solve_wait_text( + draw_ctx_t * const draw_ctx +) { + if (draw_ctx->state != GAME_STATE_SOLVE) { + return; + } + + // get text style + const text_style_t *style = theme_get_text_style(draw_ctx->theme, TEXT_STYLE_SOLVE_WAIT); + const char *text = " Solving, Please Wait (press space to cancel) "; + + // draw text + draw_text(draw_ctx->renderer, draw_ctx->font, style, text); +} + +static void +draw_solve_moves_text( + draw_ctx_t * const draw_ctx +) { + if (draw_ctx->state != GAME_STATE_SOLVE) { + return; + } + + // get text style + const text_style_t *style = theme_get_text_style(draw_ctx->theme, TEXT_STYLE_SOLVE_MOVES); + char buf[1024]; + + // fill buffer + snprintf(buf, sizeof(buf), " %lu attempts ", draw_ctx->solve_num_steps); + + // draw text + draw_text(draw_ctx->renderer, draw_ctx->font, style, buf); +} + + +static void draw_bg( draw_ctx_t * const draw_ctx ) { @@ -281,6 +321,8 @@ draw( draw_title_text(draw_ctx); draw_help_text(draw_ctx); draw_moves_text(draw_ctx); + draw_solve_wait_text(draw_ctx); + draw_solve_moves_text(draw_ctx); // flip SDL_RenderPresent(draw_ctx->renderer); |