From e82a0a3882c38575c8a5f3d1010db679f0daf75b Mon Sep 17 00:00:00 2001 From: Alex Taber Date: Tue, 29 Aug 2017 23:49:54 -0400 Subject: [PATCH] Adding controls and (some) theme previews, this feature really needs to improve --- include/themes.h | 5 +++++ source/main.c | 29 ++++++++++++++++++++++++++++- source/pp2d | 2 +- source/themes.c | 9 +++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/include/themes.h b/include/themes.h index 45496e5..4a5adcc 100644 --- a/include/themes.h +++ b/include/themes.h @@ -29,6 +29,8 @@ #include <3ds.h> +#define TEX_COUNT 1 + typedef struct { u16 name[0x40]; u16 desc[0x80]; @@ -37,6 +39,9 @@ typedef struct { u16 path[262]; bool is_zip; bool selected; + ssize_t preview_id; + bool has_preview; + char preview_path[0x106]; } theme; void parse_smdh(theme *entry, u16 *path); diff --git a/source/main.c b/source/main.c index fd5987f..8173b3f 100644 --- a/source/main.c +++ b/source/main.c @@ -125,11 +125,22 @@ int main(void) while(aptMainLoop()) { + theme *current_theme = themes_list[cursor_pos + top_pos - 1]; hidScanInput(); u32 kDown = hidKeysDown(); pp2d_begin_draw(GFX_TOP); pp2d_draw_rectangle(0, 0, 400, 23, color_accent); + pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, color_white, "Theme mode"); + + wchar_t title[0x40] = {0}; + utf16_to_utf32((u32*)title, current_theme->name, 0x40); + pp2d_draw_wtext(20, 30, 0.7, 0.7, color_white, title); + + if (current_theme->has_preview) + { + pp2d_draw_texture_scale(current_theme->preview_id, 220, 35, 0.4, 0.4); + } char time_string[6] = {0}; format_time(time_string); @@ -138,7 +149,6 @@ int main(void) u8 battery_val; MCUHWC_GetBatteryLevel(&battery_val); pp2d_draw_textf(350, 2, 0.6, 0.6, color_white, "%i%%", battery_val); - pp2d_draw_textf(20, 50, 0.7, 0.7, color_white, "top_pos: %i", top_pos); pp2d_draw_on(GFX_BOTTOM); pp2d_draw_rectangle(0, 0, 320, 24, color_accent); @@ -164,16 +174,33 @@ int main(void) else pp2d_draw_wtext(50, 40 + (48 * i), 0.55, 0.55, color_white, name); } + if (kDown & KEY_A) + { + single_install(*current_theme); + } + + if (kDown & KEY_B) + { + current_theme->selected = true; + } + + if (kDown & KEY_SELECT) + { + shuffle_install(themes_list, theme_count); + } + if (kDown & KEY_DOWN) { if (cursor_pos < MAX_THEMES && cursor_pos < theme_count) cursor_pos++; else if (cursor_pos + top_pos < theme_count) top_pos++; } + if (kDown & KEY_UP) { if (cursor_pos > 1) cursor_pos--; else if (top_pos > 0) top_pos--; } + if (kDown & KEY_START) { // close_archives(); diff --git a/source/pp2d b/source/pp2d index 824abba..8da5af2 160000 --- a/source/pp2d +++ b/source/pp2d @@ -1 +1 @@ -Subproject commit 824abba2eab5aca6553aa8a360227ada2d39f8e9 +Subproject commit 8da5af2efbf2705b64c2f79ce2ba0e61c7ce5f57 diff --git a/source/themes.c b/source/themes.c index 2ccff21..fb47712 100644 --- a/source/themes.c +++ b/source/themes.c @@ -32,6 +32,7 @@ #include "themes.h" #include "unicode.h" #include "fs.h" +#include "pp2d/pp2d/pp2d.h" void parse_smdh(theme *entry, u16 *path) { @@ -74,8 +75,16 @@ int scan_themes(theme **themes, int num_themes) if (!strcmp(entry->shortExt, "ZIP")) { theme_info->is_zip = true; + theme_info->has_preview = false; } else { theme_info->is_zip = false; + char u8_path[0x106] = {0}; + utf16_to_utf8((u8*)u8_path, theme_path, 0x106); + strcat(u8_path, "/Preview.png"); + strcpy(theme_info->preview_path, u8_path); + pp2d_load_texture_png(TEX_COUNT + 1 + i, u8_path); + theme_info->preview_id = TEX_COUNT + 1 + i; + theme_info->has_preview = true; } parse_smdh(theme_info, theme_path); memcpy(theme_info->path, theme_path, 0x106 * sizeof(u16));