From dec30a82819f93903004a3e9d46bf22f352942b4 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Tue, 15 Jan 2019 00:10:46 -0500 Subject: add theme.[hc] and refactor draw.c --- src/sdl/draw.c | 71 ++++++++++++++++------------------------------------------ 1 file changed, 19 insertions(+), 52 deletions(-) (limited to 'src/sdl/draw.c') diff --git a/src/sdl/draw.c b/src/sdl/draw.c index 99faa19..0d2b17a 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -171,20 +171,13 @@ DRAW_CBS = { .on_box = draw_on_box, }; -static const text_style_t -TITLE_STYLE = { - .align = TEXT_ALIGN_TOP_CENTER, - .pad = { 0, 10 }, - .colors = { - { 0xff, 0xff, 0xff, 0xff }, - { 0x00, 0x00, 0x00, 0xff }, - }, -}; - static void draw_title_text( draw_ctx_t * const draw_ctx ) { + // get text style + const text_style_t *style = theme_get_text_style(draw_ctx->theme, TEXT_STYLE_TITLE); + // build text char buf[256]; snprintf( @@ -196,23 +189,16 @@ draw_title_text( ); // draw text - draw_text(draw_ctx->renderer, draw_ctx->font, &TITLE_STYLE, buf); + draw_text(draw_ctx->renderer, draw_ctx->font, style, buf); } -static const text_style_t -MOVES_STYLE = { - .align = TEXT_ALIGN_BOTTOM_LEFT, - .pad = { 10, 10 }, - .colors = { - { 0xff, 0xff, 0xff, 0xff }, - { 0x00, 0x00, 0x00, 0xff }, - }, -}; - static void draw_moves_text( draw_ctx_t * const draw_ctx ) { + // get text style + const text_style_t *style = theme_get_text_style(draw_ctx->theme, TEXT_STYLE_MOVES); + // build text char buf[256]; snprintf( @@ -223,23 +209,16 @@ draw_moves_text( ); // draw text - draw_text(draw_ctx->renderer, draw_ctx->font, &MOVES_STYLE, buf); + draw_text(draw_ctx->renderer, draw_ctx->font, style, buf); } -static const text_style_t -HELP_STYLE = { - .align = TEXT_ALIGN_BOTTOM_RIGHT, - .pad = { 10, 10 }, - .colors = { - { 0xff, 0xff, 0xff, 0xff }, - { 0x00, 0x00, 0x00, 0xff }, - }, -}; - static void draw_help_text( draw_ctx_t * const draw_ctx ) { + // get text style + const text_style_t *style = theme_get_text_style(draw_ctx->theme, TEXT_STYLE_HELP); + // build text char buf[256]; #define D " " @@ -251,34 +230,22 @@ draw_help_text( #undef D // draw text - draw_text(draw_ctx->renderer, draw_ctx->font, &HELP_STYLE, buf); + draw_text(draw_ctx->renderer, draw_ctx->font, style, buf); } -static const bg_style_t -BG_STYLES[] = {{ - // normal style - .r = { .base = 0x00 }, - .g = { .base = 0x00 }, - .b = { .base = 0x00 }, - .a = { .base = 0xFF }, -}, { - // won style - .r = { .base = 0x66, .scale = 0x33, .phase = 1000, .period = 2000 }, - .g = { .base = 0x66, .scale = 0x33, .phase = 3000, .period = 5000 }, - .b = { .base = 0x66, .scale = 0x33, .phase = 5000, .period = 7000 }, - .a = { .base = 0xFF }, -}}; - static void draw_bg( draw_ctx_t * const draw_ctx ) { - // get color - const SDL_Color c = bg_style_get_color( - BG_STYLES + (sok_ctx_is_done(draw_ctx->ctx) ? 1 : 0), - draw_ctx->ticks + // get bg style + const bg_style_t *style = theme_get_bg_style( + draw_ctx->theme, + sok_ctx_is_done(draw_ctx->ctx) ? BG_STYLE_WON : BG_STYLE_NORMAL ); + // get color + const SDL_Color c = bg_style_get_color(style, draw_ctx->ticks); + // set color if (SDL_SetRenderDrawColor(draw_ctx->renderer, c.r, c.g, c.b, c.a)) { die("SDL_SetRenderDrawColor(): %s", SDL_GetError()); -- cgit v1.2.3