diff options
Diffstat (limited to 'src/sdl')
-rw-r--r-- | src/sdl/action.c | 8 | ||||
-rw-r--r-- | src/sdl/action.h | 1 | ||||
-rw-r--r-- | src/sdl/draw.c | 6 | ||||
-rw-r--r-- | src/sdl/main.c | 65 |
4 files changed, 61 insertions, 19 deletions
diff --git a/src/sdl/action.c b/src/sdl/action.c index bc0cf89..fa032d6 100644 --- a/src/sdl/action.c +++ b/src/sdl/action.c @@ -105,6 +105,14 @@ get_action( case SDL_QUIT: return (action_t) { .type = ACTION_QUIT }; break; + case SDL_WINDOWEVENT: + switch (ev->window.event) { + case SDL_WINDOWEVENT_SIZE_CHANGED: + case SDL_WINDOWEVENT_RESIZED: + return (action_t) { .type = ACTION_RESIZE }; + break; + } + break; case SDL_MOUSEWHEEL: return get_wheel_action(ev->wheel.y); break; diff --git a/src/sdl/action.h b/src/sdl/action.h index afe6fd3..6e199bc 100644 --- a/src/sdl/action.h +++ b/src/sdl/action.h @@ -23,6 +23,7 @@ typedef enum { ACTION_SOLVE_EVENT_DONE, ACTION_RESET, ACTION_FULLSCREEN, + ACTION_RESIZE, ACTION_LAST, } action_type_t; diff --git a/src/sdl/draw.c b/src/sdl/draw.c index e980131..4209016 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -292,7 +292,11 @@ draw_solve_moves_text( char buf[1024]; // fill buffer - snprintf(buf, sizeof(buf), " %u attempts ", (unsigned int) draw_ctx->solve_num_steps); + snprintf( + buf, sizeof(buf), + " Moves Tried: %u ", + (unsigned int) draw_ctx->solve_num_steps + ); // draw text draw_text(draw_ctx->renderer, draw_ctx->font, style, buf); diff --git a/src/sdl/main.c b/src/sdl/main.c index 0d492a5..53f2377 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -47,6 +47,42 @@ load_font( } static void +on_resize( + draw_ctx_t * const draw_ctx +) { + if (draw_ctx->fade_tex) { + // free existing fade texture + SDL_DestroyTexture(draw_ctx->fade_tex); + draw_ctx->fade_tex = NULL; + } + + // get window size + int w, h; + if (SDL_GetRendererOutputSize(draw_ctx->renderer, &w, &h)) { + die("SDL_GetRendererOutputSize(): %s", SDL_GetError()); + } + + // create fade texture + draw_ctx->fade_tex = SDL_CreateTexture( + draw_ctx->renderer, + SDL_PIXELFORMAT_RGBA32, + SDL_TEXTUREACCESS_TARGET, + w, + h + ); + + // check for error + if (!draw_ctx->fade_tex) { + die("SDL_CreateTexture(): %s", SDL_GetError()); + } + + // set fade texture blend mode + if (SDL_SetTextureBlendMode(draw_ctx->fade_tex, SDL_BLENDMODE_BLEND)) { + die("SDl_SetTextureBlendMode(): %s", SDL_GetError()); + } +} + +static void draw_to_fade_tex( draw_ctx_t * const draw_ctx ) { @@ -229,26 +265,11 @@ int main(int argc, char *argv[]) { .theme = theme_get_default(), .bump_ticks = SDL_GetTicks() - 5000, .fade_ticks = SDL_GetTicks() - 5000, + .fade_tex = NULL, }; - // create fade texture - draw_ctx.fade_tex = SDL_CreateTexture( - renderer, - SDL_PIXELFORMAT_RGBA32, - SDL_TEXTUREACCESS_TARGET, - WINDOW_WIDTH, - WINDOW_HEIGHT - ); - - // set fade texture blend mode - if (SDL_SetTextureBlendMode(draw_ctx.fade_tex, SDL_BLENDMODE_BLEND)) { - die("SDl_SetTextureBlendMode(): %s", SDL_GetError()); - } - - // check for error - if (!draw_ctx.fade_tex) { - die("SDL_CreateTexture(): %s", SDL_GetError()); - } + // force resize (init fade texture) + on_resize(&draw_ctx); // set level set_level(&draw_ctx, &ctx, level_num); @@ -379,6 +400,14 @@ int main(int argc, char *argv[]) { // toggle flag is_fullscreen = !is_fullscreen; + // handle resize + on_resize(&draw_ctx); + + break; + case ACTION_RESIZE: + // handle resize + on_resize(&draw_ctx); + break; case ACTION_SOLVE_CANCEL: SDL_Log("solve cancelled by user"); |