diff --git a/include/arm11/menu/menu_color.h b/include/arm11/menu/menu_color.h new file mode 100644 index 0000000..82abb22 --- /dev/null +++ b/include/arm11/menu/menu_color.h @@ -0,0 +1,38 @@ +#pragma once + +/* + * This file is part of fastboot 3DS + * Copyright (C) 2017 derrek, profi200, d0k3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + + +// ANSI escape sequences for colors +// see: https://en.wikipedia.org/wiki/ANSI_escape_code +#define ESC_RESET "\x1b[0m" +#define ESC_BOLD "\x1b[1m" +#define ESC_FAINT "\x1b[2m" +#define ESC_UNDERLINE "\x1b[4m" +#define ESC_CROSSEDOUT "\x1b[9m" +#define ESC_INVERT "\x1b[7m" +#define ESC_FGCOLOR(x) "\x1b[3" #x "m" +#define ESC_BGCOLOR(x) "\x1b[4" #x "m" + +// colors for color scheme +#define ESC_SCHEME_STD ESC_RESET ESC_FGCOLOR(7) ESC_BGCOLOR(0) +#define ESC_SCHEME_WEAK ESC_RESET ESC_FGCOLOR(7) ESC_BGCOLOR(0) ESC_BOLD +#define ESC_SCHEME_ACCENT0 ESC_RESET ESC_FGCOLOR(4) ESC_BGCOLOR(0) ESC_BOLD +#define ESC_SCHEME_ACCENT1 ESC_RESET ESC_FGCOLOR(3) ESC_BGCOLOR(0) ESC_BOLD diff --git a/include/arm11/menu/menu_util.h b/include/arm11/menu/menu_util.h index 84cb0fb..9db047b 100644 --- a/include/arm11/menu/menu_util.h +++ b/include/arm11/menu/menu_util.h @@ -19,18 +19,6 @@ #include "types.h" -// ANSI escape sequences for colors -// see: https://en.wikipedia.org/wiki/ANSI_escape_code -#define ESC_RESET "\x1b[0m" -#define ESC_BOLD "\x1b[1m" -#define ESC_FAINT "\x1b[2m" -#define ESC_UNDERLINE "\x1b[4m" -#define ESC_CROSSEDOUT "\x1b[9m" -#define ESC_INVERT "\x1b[7m" -#define ESC_FGCOLOR(x) "\x1b[3" #x "m" -#define ESC_BGCOLOR(x) "\x1b[4" #x "m" - - char* mallocpyString(const char* str); void truncateString(char* dest, const char* orig, int nsize, int tpos); void formatBytes(char* str, u64 bytes); diff --git a/source/arm11/console.c b/source/arm11/console.c index 26a219d..9d60536 100644 --- a/source/arm11/console.c +++ b/source/arm11/console.c @@ -23,16 +23,16 @@ RGB8_to_565( 0,255,255), // bright cyan RGB8_to_565(255,255,255), // bright white - RGB8_to_565(128,128,128), // bright black + RGB8_to_565( 64, 64, 64), // almost black RGB8_to_565(255, 0, 0), // bright red RGB8_to_565( 0,255, 0), // bright green - RGB8_to_565(255,255, 0), // bright yellow - RGB8_to_565( 0, 0,255), // bright blue + RGB8_to_565(255,255, 32), // acccent yellow + RGB8_to_565( 64, 64,255), // accent blue RGB8_to_565(255, 0,255), // bright magenta RGB8_to_565( 0,255,255), // bright cyan - RGB8_to_565(255,255,255), // bright white + RGB8_to_565(192,192,192), // almost white - RGB8_to_565( 0, 0, 0), // faint black + RGB8_to_565(128,128,128), // bright black RGB8_to_565( 64, 0, 0), // faint red RGB8_to_565( 0, 64, 0), // faint green RGB8_to_565( 64, 64, 0), // faint yellow diff --git a/source/arm11/main.c b/source/arm11/main.c index b5c9e98..cb9c0a7 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -111,10 +111,9 @@ // main loop + PrintConsole term_con; while(!g_startFirmLaunch) { - PrintConsole term_con; - // init screens (if we'll need them below) if((show_menu || err_string) && !gfx_initialized) { diff --git a/source/arm11/menu/menu.c b/source/arm11/menu/menu.c index c1dc82a..42db814 100644 --- a/source/arm11/menu/menu.c +++ b/source/arm11/menu/menu.c @@ -23,6 +23,7 @@ #include "types.h" #include "arm11/menu/menu.h" #include "arm11/menu/menu_util.h" +#include "arm11/menu/menu_color.h" #include "arm11/hardware/hid.h" #include "arm11/config.h" #include "arm11/console.h" @@ -33,8 +34,14 @@ -void menuBuildDescString(char* desc, u32 flags, u32 index, const char* name_raw, const char* desc_raw) +void menuBuildDescString(char* desc, u32 flags, u32 index, const char* desc_raw) { + char* desc_ptr = desc; + + // copy raw description + desc_ptr += ee_sprintf(desc_ptr, desc_raw); + + // flags only concern descriptions right now u32 slot = (flags & MENU_FLAG_SLOTS) ? index : (flags & MENU_FLAG_SLOT(1)) ? 0 : @@ -48,50 +55,39 @@ { char* modestr = (char*) configCopyText(KBootMode); if (!modestr) panicMsg("Config error"); - ee_snprintf(desc, 512, "%s:\n%s\n \ncurrent: %s", name_raw, desc_raw, modestr); + desc_ptr += ee_sprintf(desc_ptr, "\n \ncurrent: %s", modestr); free (modestr); } - else ee_snprintf(desc, 512, "%s:\n%s\n \ncurrent: - not set up -", name_raw, desc_raw); - stringWordWrap(desc, WORDWRAP_WIDTH); - return; + else desc_ptr += ee_sprintf(desc_ptr, "\n \ncurrent: - not set up -"); } - // using no slot description - else if (slot >= 3) + // boot slot description + else if (slot < 3) { + // get strings for path and keycombo + char slot_path_store[24+1]; + char* slot_path = NULL; + char* keycombo = NULL; - ee_snprintf(desc, 512, "%s:\n%s", name_raw, desc_raw); - stringWordWrap(desc, WORDWRAP_WIDTH); - return; + if(configDataExist(KBootOption1 + slot)) + { + slot_path = slot_path_store; + truncateString(slot_path, (char*) configGetData(KBootOption1 + slot), 24, 8); + } + + if(configDataExist(KBootOption1Buttons + slot)) + keycombo = (char*) configCopyText(KBootOption1Buttons + slot); + + // write description to desc string + desc_ptr += ee_sprintf(desc_ptr, "\n \npath: %s\nkeys: %s", + slot_path ? slot_path : "- not set up -", + keycombo ? keycombo : "- not set up -"); + + if (keycombo) free(keycombo); } - // raw description plus slot description - // get strings for path and keycombo - char slot_path_store[24+1]; - char* slot_path = NULL; - char* keycombo = NULL; - - if(configDataExist(KBootOption1 + slot)) - { - slot_path = slot_path_store; - truncateString(slot_path, (char*) configGetData(KBootOption1 + slot), 24, 8); - } - - if(configDataExist(KBootOption1Buttons + slot)) - keycombo = (char*) configCopyText(KBootOption1Buttons + slot); - - - // write description to desc string - ee_snprintf(desc, 512, "%s:\n%s\n \npath: %s\nkeys: %s", - name_raw, desc_raw, - slot_path ? slot_path : "- not set up -", - keycombo ? keycombo : "- not set up -"); - - // wordwrap description string + // wordwrap the whole string stringWordWrap(desc, WORDWRAP_WIDTH); - - - if (keycombo) free(keycombo); } void menuShowDesc(MenuInfo* curr_menu, PrintConsole* desc_con, u32 index) @@ -103,7 +99,7 @@ // print title at the top const char* title = "fastboot 3DS " VERS_STRING; consoleSetCursor(desc_con, (desc_con->consoleWidth - strlen(title)) >> 1, 1); - ee_printf(title); + ee_printf(ESC_SCHEME_ACCENT0 "%s" ESC_RESET, title); // get description, check if available MenuEntry* entry = &(curr_menu->entries[index]); @@ -116,7 +112,7 @@ // build description string char desc_ww[512]; - menuBuildDescString(desc_ww, curr_menu->flags, index, name, desc); + menuBuildDescString(desc_ww, curr_menu->flags, index, desc); // get width, height int desc_width = stringGetWidth(desc_ww); @@ -126,12 +122,17 @@ // write to console int desc_x = (desc_con->consoleWidth - desc_width) >> 1; - int desc_y = (desc_con->consoleHeight - 1 - desc_height); + int desc_y = (desc_con->consoleHeight - 2 - desc_height); + consoleSetCursor(desc_con, desc_x, desc_y++); + ee_printf(ESC_SCHEME_ACCENT1 "%s:\n" ESC_RESET, name); + + ee_printf(ESC_SCHEME_WEAK); for (char* str = strtok(desc_ww, "\n"); str != NULL; str = strtok(NULL, "\n")) { consoleSetCursor(desc_con, desc_x, desc_y++); ee_printf(str); } + ee_printf(ESC_RESET); } /** @@ -158,7 +159,7 @@ // menu title consoleSetCursor(menu_con, menu_x, menu_y++); - ee_printf(curr_menu->name); + ee_printf(ESC_SCHEME_ACCENT1 "%s" ESC_RESET, curr_menu->name); menu_y++; // menu entries @@ -169,7 +170,9 @@ bool is_selected = (i == index); consoleSetCursor(menu_con, menu_x, menu_y++); - if (is_selected) ee_printf(ESC_FGCOLOR(0) ESC_BGCOLOR(7)); + // ee_printf(((menu_preset >> i) & 0x1) ? ESC_SCHEME_STD : ESC_SCHEME_WEAK); + ee_printf(ESC_SCHEME_STD); + if (is_selected) ee_printf(ESC_INVERT); ee_printf("%.3s %-*.*s", ((menu_preset >> i) & 0x1) ? "[X]" : "[ ]", MENU_WIDTH-4, MENU_WIDTH-4, name); ee_printf(ESC_RESET); } @@ -177,7 +180,7 @@ // button instructions menu_y = MENU_OFFSET_BUTTONS; consoleSetCursor(menu_con, menu_x, menu_y++); - ee_printf("%-*.*s", MENU_WIDTH, MENU_WIDTH, "[A]:Choose [B]:Back"); + ee_printf(ESC_SCHEME_WEAK "%-*.*s" ESC_RESET, MENU_WIDTH, MENU_WIDTH, "[A]:Choose [B]:Back"); } /** diff --git a/source/arm11/menu/menu_fsel.c b/source/arm11/menu/menu_fsel.c index 3c81ec4..40882a4 100644 --- a/source/arm11/menu/menu_fsel.c +++ b/source/arm11/menu/menu_fsel.c @@ -26,6 +26,7 @@ #include "fsutils.h" #include "arm11/menu/menu_fsel.h" #include "arm11/menu/menu_util.h" +#include "arm11/menu/menu_color.h" #include "arm11/hardware/hid.h" #include "arm11/hardware/timer.h" #include "arm11/console.h" @@ -251,7 +252,7 @@ // browser title consoleSetCursor(menu_con, brws_x, brws_y++); truncateString(temp_str, *curr_path ? curr_path : "root", BRWS_WIDTH, 8); - ee_printf("%-*s", BRWS_WIDTH, temp_str); + ee_printf(ESC_SCHEME_ACCENT1 "%-*s" ESC_RESET, BRWS_WIDTH, temp_str); brws_y++; // menu entries @@ -271,17 +272,20 @@ consoleSetCursor(menu_con, brws_x, brws_y++); truncateString(temp_str, entry->fname, BRWS_WIDTH-13, 8); - if (is_selected) if (is_selected) ee_printf(ESC_FGCOLOR(0) ESC_BGCOLOR(7)); + ee_printf(entry->is_dir ? ESC_SCHEME_WEAK : ESC_SCHEME_STD); + if (is_selected)ee_printf(ESC_INVERT); ee_printf(" %-*.*s %10.10s ", BRWS_WIDTH-13, BRWS_WIDTH-13, temp_str, byte_str); ee_printf(ESC_RESET); } // button instructions brws_y = BRWS_OFFSET_BUTTONS; + ee_printf(ESC_SCHEME_WEAK); consoleSetCursor(menu_con, brws_x, brws_y++); ee_printf("%-*.*s", BRWS_WIDTH, BRWS_WIDTH, "[A]:Choose [B]:Back"); consoleSetCursor(menu_con, brws_x, brws_y++); ee_printf("%-*.*s", BRWS_WIDTH, BRWS_WIDTH, "[HOME] to cancel"); + ee_printf(ESC_RESET); }