From 4eaedd2930d0b8b7be09529382b4467307c7c841 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Wed, 15 Jun 2016 17:33:40 -0400 Subject: [PATCH] Menus now scroll with too many entries to show. Problem resolved. --- Makefile | 1 + source/display.c | 60 ++++++++++++++++++++--------------------------- source/menu.c | 4 ++-- source/std/draw.c | 6 ++--- 4 files changed, 31 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 371d4a3..54ad773 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,7 @@ clean: rm -f host/{font-emit,font.h,font_prop.h,termfont.bin} make -C external clean make -C patch clean + make -C host/bdfe clean rm -rf $(dir_out) $(dir_build) .PHONY: $(dir_out)/arm9loaderhax.bin diff --git a/source/display.c b/source/display.c index 1228ce5..7ddb1b8 100644 --- a/source/display.c +++ b/source/display.c @@ -1,28 +1,22 @@ #include "common.h" #include "firm/firm.h" #include "firm/headers.h" -#define MENU_MAIN 1 - -#define MENU_OPTIONS 2 -#define MENU_PATCHES 3 -#define MENU_INFO 4 -#define MENU_HELP 5 -#define MENU_RESET 6 -#define MENU_POWER 7 -#define MENU_BOOTME 8 void header(char *append); extern int is_n3ds; +extern unsigned int font_h; + int show_menu(struct options_s *options, uint8_t *toggles) { int cursor_y = 0; - int need_redraw = 1; int cursor_min = -1; int cursor_max = -1; int exit = 0; + int window_size = (TOP_HEIGHT / font_h) - 3; + int window_top = 0, window_bottom = window_size; clear_screen(TOP_SCREEN); @@ -57,50 +51,40 @@ show_menu(struct options_s *options, uint8_t *toggles) header("A:Enter B:Back DPAD:Nav"); - int i = 0; + int i = window_top; while (options[i].index != -1) { // -1 Sentinel. + if (i > window_bottom) + break; + + set_cursor(TOP_SCREEN, 0, i-window_top+2); + if (options[i].allowed == boolean_val || (is_n3ds && options[i].allowed == boolean_val_n3ds)) { if (cursor_y == i) fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m "); else fprintf(TOP_SCREEN, " "); - if (need_redraw) - fprintf(TOP_SCREEN, "[%c] %s\n", (toggles[options[i].index] ? 'X' : ' '), options[i].name); - else { - // Yes, this is weird. printf does a large number of extra things we - // don't - // want computed at the moment; this is faster. - putc(TOP_SCREEN, '['); - putc(TOP_SCREEN, (toggles[options[i].index] ? 'X' : ' ')); - putc(TOP_SCREEN, ']'); - putc(TOP_SCREEN, '\n'); - } + fprintf(TOP_SCREEN, "[%c] %s", (toggles[options[i].index] ? '*' : ' '), options[i].name); } else if (options[i].allowed == call_fun || options[i].allowed == break_menu) { if (cursor_y == i) fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m "); else fprintf(TOP_SCREEN, " "); - if (need_redraw) - fprintf(TOP_SCREEN, "%s\n", options[i].name); - else - putc(TOP_SCREEN, '\n'); + fprintf(TOP_SCREEN, "%s", options[i].name); } else if (options[i].allowed == ranged_val) { if (cursor_y == i) fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m "); else fprintf(TOP_SCREEN, " "); - fprintf(TOP_SCREEN, "[%u] %s \n", toggles[options[i].index], options[i].name); + fprintf(TOP_SCREEN, "[%u] %s ", toggles[options[i].index], options[i].name); } else if (options[i].allowed == not_option) { - fprintf(TOP_SCREEN, "%s\n", options[i].name); + fprintf(TOP_SCREEN, "%s", options[i].name); } ++i; } - need_redraw = 0; - uint32_t key = wait_key(1); switch (key) { @@ -134,10 +118,8 @@ show_menu(struct options_s *options, uint8_t *toggles) toggles[options[cursor_y].index]++; } else if (options[cursor_y].allowed == call_fun) { ((func_call_t)(options[cursor_y].a))(); // Call 'a' as a function. - need_redraw = 1; } else if (options[cursor_y].allowed == break_menu) { exit = 1; - need_redraw = 1; } break; case BUTTON_X: @@ -150,7 +132,6 @@ show_menu(struct options_s *options, uint8_t *toggles) break; case BUTTON_B: exit = 1; - need_redraw = 1; clear_screen(TOP_SCREEN); cursor_y = cursor_min; break; @@ -160,9 +141,18 @@ show_menu(struct options_s *options, uint8_t *toggles) cursor_y = cursor_max - 1; else if (cursor_y > cursor_max - 1) cursor_y = cursor_min; - } - clear_screen(TOP_SCREEN); + if (cursor_y < window_top + cursor_min) { + window_top = cursor_y - cursor_min; + window_bottom = window_top + window_size; + clear_screen(TOP_SCREEN); + + } else if (cursor_y > window_bottom - cursor_min) { + window_bottom = cursor_y + cursor_min; + window_top = window_bottom - window_size; + clear_screen(TOP_SCREEN); + } + } return 0; } diff --git a/source/menu.c b/source/menu.c index 8dd2344..28b52ad 100644 --- a/source/menu.c +++ b/source/menu.c @@ -223,7 +223,7 @@ menu_info() struct firm_signature *agb = get_firm_info(agb_firm_loc); struct firm_signature *twl = get_firm_info(twl_firm_loc); - fprintf(stdout, "\nNATIVE_FIRM / Firmware:\n" + fprintf(stdout, "NATIVE_FIRM / Firmware:\n" " Version: %s (%x)\n" "AGB_FIRM / GBA Firmware:\n" " Version: %s (%x)\n" @@ -246,7 +246,7 @@ menu_help() header("Any:Back"); - fprintf(stdout, "\nCorbenik is another 3DS CFW for power users.\n" + fprintf(stdout, "Corbenik is another 3DS CFW for power users.\n" " It seeks to address some faults in other\n" " CFWs and is generally just another choice\n" " for users - but primarily is intended for\n" diff --git a/source/std/draw.c b/source/std/draw.c index 425d6f3..51f1d8f 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -17,8 +17,8 @@ static unsigned int bottom_cursor_x = 0, bottom_cursor_y = 0; static size_t log_size = 0; static char log_buffer[4096]; // Log buffer. -static unsigned int font_w = 8; -static unsigned int font_h = 8; +unsigned int font_w = 8; +unsigned int font_h = 8; static unsigned int font_kern = 0; static unsigned int text_top_width = 20; @@ -231,7 +231,7 @@ putc(void *buf, const int c) cursor_y[0]++; } - while (cursor_y[0] >= height - 1) { + while (cursor_y[0] >= height) { clear_disp(buf); cursor_x[0] = 0; cursor_y[0] = 0; -- 2.39.5