From c17f5a5377f959a7e67526e0ae89b329bf99a101 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 16 Jan 2019 07:15:26 -0500 Subject: solve in background thread --- src/sdl/draw.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) (limited to 'src/sdl/draw.c') 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,18 +230,58 @@ 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 draw_text(draw_ctx->renderer, draw_ctx->font, style, buf); } +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); -- cgit v1.2.3