diff --git a/include/arm9/ui.h b/include/arm9/ui.h index 0a4ccd6..e26c070 100644 --- a/include/arm9/ui.h +++ b/include/arm9/ui.h @@ -3,17 +3,9 @@ #include "arm9/console.h" #include "hid.h" -#define uiPrintInfo(format, args...) \ - printf("\e[0m"); \ - printf(format, ## args); \ - -#define uiPrintWarning(format, args...) \ - printf("\x1B[33m"); \ - printf(format, ## args); \ - -#define uiPrintError(format, args...) \ - printf("\x1B[31m"); \ - printf(format, ## args); \ +#define uiPrintInfo(format, ...) uiPrintCentered(format, 0, ##__VA_ARGS__); +#define uiPrintWarning(format, ...) uiPrintCentered(format, 33, ##__VA_ARGS__); +#define uiPrintError(format, ...) uiPrintCentered(format, 31, ##__VA_ARGS__); // PrintConsole for each screen @@ -23,8 +15,10 @@ void uiDrawSplashScreen(); void uiClearConsoles(); void clearConsole(int which); +void uiSetVerbose(bool verb); bool uiDialogYesNo(const char *text, const char *textYes, const char *textNo); -void uiPrintCentered(const char *const format, ...); +void uiPrintIfVerbose(const char *const format, ...); +void uiPrintCentered(const char *const format, unsigned int color, ...); void uiPrintCenteredInLine(unsigned int y, const char *const format, ...); void uiPrintTextAt(unsigned int x, unsigned int y, const char *const format, ...); //void uiShowMessageWindow(format, args...); diff --git a/source/arm9/ui.c b/source/arm9/ui.c index cda4df6..8875066 100644 --- a/source/arm9/ui.c +++ b/source/arm9/ui.c @@ -11,10 +11,14 @@ #include "arm9/console.h" #include "banner_ppm_bin.h" + static u8 randomColor; +static bool verbose = false; static const void *bannerData = banner_ppm_bin; + + static void uiDrawPPM(unsigned start_x, unsigned start_y, const u8 *data); static void consoleMainInit() @@ -66,6 +70,11 @@ consoleClear(); } +void uiSetVerbose(bool verb) +{ + verbose = verb; +} + /* TODO: Should look similar to uiShowMessageWindow */ bool uiDialogYesNo(const char *text, const char *textYes, const char *textNo) { @@ -86,19 +95,36 @@ } while(1); } +void uiPrintIfVerbose(const char *const format, ...) +{ + if(verbose) + { + const unsigned int width = (unsigned int)consoleGet()->consoleWidth; + char tmp[width + 1]; + + va_list args; + va_start(args, format); + vsnprintf(tmp, width + 1, format, args); + va_end(args); + + size_t len = strlen(tmp); + printf("\x1B[0m%*s%s\n", (width - len) / 2, "", tmp); + } +} + /* Prints a given text in the center of the current line */ -void uiPrintCentered(const char *const format, ...) +void uiPrintCentered(const char *const format, unsigned int color, ...) { const unsigned int width = (unsigned int)consoleGet()->consoleWidth; char tmp[width + 1]; va_list args; - va_start(args, format); + va_start(args, color); vsnprintf(tmp, width + 1, format, args); va_end(args); size_t len = strlen(tmp); - printf("%*s%s\n", (width - len) / 2, "", tmp); + printf("\x1B[%um%*s%s\n", color, (width - len) / 2, "", tmp); } void uiPrintCenteredInLine(unsigned int y, const char *const format, ...)