aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-01-14 00:53:43 -0500
committerPaul Duncan <pabs@pablotron.org>2019-01-14 00:53:43 -0500
commitc711fdb3e9e3862ba26d2e05393b2bbacc7f012b (patch)
treed725a8ae540b6e1a62c7fba9f7fcfe58ffb1e0c2
parent55d22c6e36b6b575a971202cb62e53a3a6fb54cb (diff)
downloadsok-c711fdb3e9e3862ba26d2e05393b2bbacc7f012b.tar.bz2
sok-c711fdb3e9e3862ba26d2e05393b2bbacc7f012b.zip
add help text
-rw-r--r--src/sdl/draw.c46
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);