From 065795330a7e0c254fdb755498c7724fba45ea5d Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 14 Jan 2019 03:49:02 -0500 Subject: remove level zero, add border, sync to vblank, add spaces around text, misc cleanups --- src/sdl/draw.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src/sdl/draw.c') diff --git a/src/sdl/draw.c b/src/sdl/draw.c index 6616ce7..630ecd1 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -64,6 +64,32 @@ draw_cell( } } +static void +draw_border( + draw_ctx_t * const draw_ctx, + const sok_pos_t level_size +) { + const size_t cell_size = get_cell_size(draw_ctx); + + // calc rect + const SDL_Rect rect = { + draw_ctx->render_ofs_x - cell_size / 8, + draw_ctx->render_ofs_y - cell_size / 8, + level_size.x * cell_size + cell_size / 4, + level_size.y * cell_size + cell_size / 4, + }; + + // set color + if (SDL_SetRenderDrawColor(draw_ctx->renderer, 0, 0, 0, 0xFF)) { + die("SDL_SetRenderDrawColor(): %s", SDL_GetError()); + } + + // fill border rect + if (SDL_RenderFillRect(draw_ctx->renderer, &rect)) { + die("SDL_RenderFillRect(): %s", SDL_GetError()); + } +} + static bool draw_sprites_on_size( const sok_ctx_t * const ctx, @@ -73,6 +99,8 @@ draw_sprites_on_size( on_size(ctx, level_size, data); draw_ctx_t * const draw_ctx = data; + draw_border(draw_ctx, level_size); + // draw floor for (size_t y = 0; y < level_size.y; y++) { for (size_t x = 0; x < level_size.x; x++) { @@ -296,14 +324,14 @@ draw_text( } static void -draw_level_text( +draw_title_text( draw_ctx_t * const draw_ctx ) { // build text char buf[256]; snprintf( buf, sizeof(buf), - "%s: %s (#%zu)", + " %s: %s (#%zu) ", draw_ctx->level->pack, draw_ctx->level->name, *draw_ctx->level_num @@ -336,7 +364,7 @@ draw_moves_text( char buf[256]; snprintf( buf, sizeof(buf), - "Moves: %zu%s", + " Moves: %zu%s ", draw_ctx->ctx->num_moves, sok_ctx_is_done(draw_ctx->ctx) ? " (Won!)" : "" ); @@ -370,7 +398,7 @@ draw_help_text( char buf[256]; snprintf( buf, sizeof(buf), - "%sU: Undo" DELIM "R: Reset" DELIM "S: Solve" DELIM "Q: Quit", + " %sU: Undo" DELIM "R: Reset" DELIM "S: Solve" DELIM "Q: Quit ", sok_ctx_is_done(draw_ctx->ctx) ? "Space: Next Level" DELIM : "" ); @@ -440,7 +468,7 @@ draw( sok_ctx_walk(draw_ctx->ctx, &DRAW_CBS, draw_ctx); // render text - draw_level_text(draw_ctx); + draw_title_text(draw_ctx); draw_moves_text(draw_ctx); draw_help_text(draw_ctx); -- cgit v1.2.3