diff --git a/include/arm9/ui.h b/include/arm9/ui.h new file mode 100644 index 0000000..201d5af --- /dev/null +++ b/include/arm9/ui.h @@ -0,0 +1,25 @@ +#pragma once + +#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); \ + + +// PrintConsole for each screen +PrintConsole con_top, con_bottom; + +void uiInit(); +void uiClearConsoles(); +void clearConsole(int which); +bool uiDialogYesNo(const char *text, const char *textYes, const char *textNo); diff --git a/source/arm9/console.c b/source/arm9/console.c index 07852e8..f7b365f 100644 --- a/source/arm9/console.c +++ b/source/arm9/console.c @@ -9,14 +9,14 @@ //set up the palette for color printing static u16 colorTable[] = { - RGB8_to_565( 0, 0, 0), // black - RGB8_to_565(128, 0, 0), // red - RGB8_to_565( 0,128, 0), // green - RGB8_to_565(128,128, 0), // yellow - RGB8_to_565( 0, 0,128), // blue - RGB8_to_565(128, 0,128), // magenta - RGB8_to_565( 0,128,128), // cyan - RGB8_to_565(192,192,192), // white + RGB8_to_565( 0, 0, 0), // faint 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, 0,255), // bright magenta + 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(255, 0, 0), // bright red diff --git a/source/arm9/ui.c b/source/arm9/ui.c new file mode 100644 index 0000000..131e0c9 --- /dev/null +++ b/source/arm9/ui.c @@ -0,0 +1,104 @@ +#include +#include +#include +#include +#include "types.h" +#include "util.h" +#include "hid.h" +#include "arm9/timer.h" +#include "arm9/main.h" +#include "arm9/ui.h" + + +static void consoleMainInit() +{ + /* Initialize console for both screens using the two different PrintConsole we have defined */ + consoleInit(SCREEN_TOP, &con_top); + con_top.windowX = 1; + con_top.windowY = 1; + con_top.windowWidth -= 2; + con_top.windowHeight -= 2; + + drawConsoleWindow(&con_top, 4, con_top.fg); + + consoleInit(SCREEN_LOW, &con_bottom); + + consoleSelect(&con_top); +} + +void uiInit() +{ + consoleMainInit(); +} + +static void clearConsoles() +{ + consoleSelect(&con_bottom); + consoleClear(); + consoleSelect(&con_top); + consoleClear(); +} + +void uiClearConsoles() +{ + clearConsoles(); +} + +void clearConsole(int which) +{ + if(which) + consoleSelect(&con_top); + else + consoleSelect(&con_bottom); + + consoleClear(); +} + +/* TODO: Should look similar to uiShowMessageWindow */ +bool uiDialogYesNo(const char *text, const char *textYes, const char *textNo) +{ + u32 keys; + + /* Print dialog */ + uiPrintInfo("\n%s\n", text); + uiPrintInfo("\t(A): %s\n\t(B): %s\n", textYes, textNo); + + /* Get user input */ + do { + hidScanInput(); + keys = hidKeysDown() & HID_KEY_MASK_ALL; + if(keys == KEY_A) + return true; + if(keys & KEY_B) + return false; + } while(1); +} + +/* Prints a given text in the center of the current line */ +void uiPrintCentered(format, args...) +{ + // TODO +} + +/* Prints a given text at a certain position in the current window */ +void uiPrintTextAt(unsigned x, unsigned y, format, args...) +{ + // TODO +} + +/* Prints a given text surrounded by a graphical window */ +/* centered in the middle of the screen. */ +/* Waits for the user to press any button, after that the */ +/* original framebuffer gets restored */ +void uiShowMessageWindow(format, args...) +{ + // TODO +} + + +void uiPrintProgressBar(unsigned x, unsigned y, unsigned width, unsigned height, + double percentage) +{ + // TODO +} +