From 91ba5fed49680585d51902f4afa0ebea5f89e52b Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Fri, 1 Sep 2017 16:12:26 +0200 Subject: [PATCH] previews overhaul (#13) * allow quitting if there are no themes or splashes * load preview only once if the user toggles more than once --- include/themes.h | 1 + source/draw.c | 4 ++-- source/main.c | 28 +++++++++++++++++----------- source/themes.c | 1 + 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/themes.h b/include/themes.h index 88ef7ef..4b9c472 100644 --- a/include/themes.h +++ b/include/themes.h @@ -38,6 +38,7 @@ typedef struct { ssize_t icon_id; bool has_preview; + int preview_offset; u16 path[0x106]; bool is_zip; diff --git a/source/draw.c b/source/draw.c index c7e9c4f..bdec776 100644 --- a/source/draw.c +++ b/source/draw.c @@ -119,9 +119,9 @@ void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_t if (current_theme.has_preview) { pp2d_begin_draw(GFX_TOP); - pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 6, 0, 400, 240); + pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, preview_offset, 0, 400, 240); pp2d_draw_on(GFX_BOTTOM); - pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 46, 240, 320, 240); + pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 40+preview_offset, 240, 320, 240); } } else diff --git a/source/main.c b/source/main.c index 2d94b10..3ac6b1e 100644 --- a/source/main.c +++ b/source/main.c @@ -72,6 +72,7 @@ int main(void) bool splash_mode = false; int selected_splash = 0; int selected_theme = 0; + int previously_selected = 0; int shuffle_theme_count = 0; bool preview_mode = false; @@ -83,6 +84,14 @@ int main(void) if (!splash_mode) draw_theme_interface(themes_list, theme_count, selected_theme, preview_mode); else draw_splash_interface(splashes_list, splash_count, selected_splash, preview_mode); + if (kDown & KEY_START) + { + exit_screens(); + exit_services(); + PTMSYSM_RebootAsync(0); + ptmSysmExit(); + } + if (themes_list == NULL && !splash_mode) continue; @@ -96,11 +105,10 @@ int main(void) { if (!preview_mode) { - load_theme_preview(current_theme); - if (current_theme->has_preview) - { - preview_mode = true; - } + if (!current_theme->has_preview) + load_theme_preview(current_theme); + + preview_mode = current_theme->has_preview; } else preview_mode = false; @@ -202,13 +210,11 @@ int main(void) if (splash_mode) selected_splash = splash_count - 1; else selected_theme = theme_count-1; } - - if (kDown & KEY_START) + + if (!splash_mode && selected_theme != previously_selected) { - exit_screens(); - exit_services(); - PTMSYSM_RebootAsync(0); - ptmSysmExit(); + current_theme->has_preview = false; + previously_selected = selected_theme; } } diff --git a/source/themes.c b/source/themes.c index b462013..1b34b21 100644 --- a/source/themes.c +++ b/source/themes.c @@ -80,6 +80,7 @@ void load_theme_preview(Theme_s *theme) theme->has_preview = true; pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height); + theme->preview_offset = (width-400)/2; } free(image);