aboutsummaryrefslogtreecommitdiff
path: root/src/sdl/draw.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-01-15 00:10:46 -0500
committerPaul Duncan <pabs@pablotron.org>2019-01-15 00:10:46 -0500
commitdec30a82819f93903004a3e9d46bf22f352942b4 (patch)
tree46b06f9f7de3d0b3a5fa446dc13cf7727d0e87c3 /src/sdl/draw.c
parent7fdd6f36c8181115c60b781dc97b71107fb7da65 (diff)
downloadsok-dec30a82819f93903004a3e9d46bf22f352942b4.tar.bz2
sok-dec30a82819f93903004a3e9d46bf22f352942b4.zip
add theme.[hc] and refactor draw.c
Diffstat (limited to 'src/sdl/draw.c')
-rw-r--r--src/sdl/draw.c71
1 files changed, 19 insertions, 52 deletions
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());