From a009d1a3f069c8030d893a211f869909e485dd97 Mon Sep 17 00:00:00 2001 From: yaya Date: Fri, 20 Dec 2019 09:16:53 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BB=BF.=20=E6=94=B9=E8=BF=9B=20setmenu=20?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=B4=A2=E5=BC=95=E5=92=8C=E8=8F=9C=E5=8D=95=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F=E5=86=85=E5=B1=85=E4=B8=AD=E3=80=82=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E5=8F=AF=E4=BB=A5=E4=BD=BF=E7=94=A8=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E8=89=B2=E3=80=82(issues=20#222)=20=20=20=20=20setmenu=20--str?= =?UTF-8?q?ing[=3DiINDEX]=3D[X|s|m]=3D[-]Y=3DCOLOR=3D"STRING"=20=20=20iIND?= =?UTF-8?q?EX=20=E8=8C=83=E5=9B=B4=E6=98=AF=20i0-i15.=20=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=20=3DiINDEX=20=E7=B4=A2=E5=BC=95=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=80=92=E5=A2=9E=E3=80=82=20=20=20=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=B0=B4=E5=B9=B3=E4=BD=8D=E7=BD=AE=E6=98=AF=20s=20=E5=88=99?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=9C=A8=E5=85=A8=E5=B1=8F=E5=B1=85?= =?UTF-8?q?=E4=B8=AD;=20=E5=A6=82=E6=9E=9C=E6=B0=B4=E5=B9=B3=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E6=98=AF=20m=20=E5=88=99=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E5=9C=A8=E8=8F=9C=E5=8D=95=E5=8C=BA=E5=9F=9F=E5=86=85=E5=B1=85?= =?UTF-8?q?=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit . 动态更新日期时间增加标题,可显示中文。 例如:“date&time日期时间: =MMM.dd.yyyy HH:mm:ss” --- ChangeLog_chenall.txt | 9 +++ stage2/asm.S | 8 +-- stage2/builtins.c | 157 ++++++++++++++++++++++++------------------ stage2/graphics.c | 2 +- stage2/shared.h | 14 ++-- stage2/stage2.c | 14 ++-- 6 files changed, 116 insertions(+), 88 deletions(-) diff --git a/ChangeLog_chenall.txt b/ChangeLog_chenall.txt index b78f7b31..2f2a8a48 100644 --- a/ChangeLog_chenall.txt +++ b/ChangeLog_chenall.txt @@ -1,4 +1,13 @@ 更新说明: +2019-12-20(yaya) + 1. 改进 setmenu 字符串功能,增加索引和菜单区域内居中。字符串可以使用背景色。 + setmenu --string[=iINDEX]=[X|s|m]=[-]Y=COLOR="STRING" + iINDEX 范围是 i0-i15. 如果没有 =iINDEX 索引自动递增。 + 如果水平位置是 s 则字符串在全屏居中; 如果水平位置是 m 则字符串在菜单区域内居中。 + + 2. 动态更新日期时间增加标题,可显示中文。 + 例如:“date&time日期时间: =MMM.dd.yyyy HH:mm:ss” + 2019-10-27(yaya) 1. 修正 udf 文件系统处理大于 4Gb 文件的错误。(issues #216) 2. 修正 map 函数碎片映射插槽错误。(issues #212) diff --git a/stage2/asm.S b/stage2/asm.S index 42b2eb18..d0ce5c5c 100644 --- a/stage2/asm.S +++ b/stage2/asm.S @@ -15031,9 +15031,9 @@ ENTRY(console_getkey) je 2f call beep_func 2: - cmpb $0, string_enable + cmpb $0, DateTime_enable je 2f - call string_refresh + call DateTime_refresh 2: cmpl $0, graphics_inited je 4b @@ -15178,9 +15178,9 @@ ENTRY(console_checkkey) jz 2f call beep_func 2: - cmpb $0, string_enable + cmpb $0, DateTime_enable je 2f - call string_refresh + call DateTime_refresh 2: cmpl $0, graphics_inited je 5f diff --git a/stage2/builtins.c b/stage2/builtins.c index 7d34ab3d..c17a1ab7 100644 --- a/stage2/builtins.c +++ b/stage2/builtins.c @@ -8170,7 +8170,7 @@ static struct builtin builtin_lock = lock_func, BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_SCRIPT | BUILTIN_HELP_LIST, "lock", - "Break a command execution unless the user is authenticated." + "Break a command execution unless the user is authenticated. errorcheck must be on." }; @@ -16480,12 +16480,10 @@ unsigned short graphic_high; unsigned short row_space; char graphic_file[128]; struct box DrawBox[16]; -struct string strings[16]; -char *p_string= (char *)MENU_TITLE; +struct string* strings = (struct string*) MENU_TITLE; extern int new_menu; -unsigned long string_total = 0; int num_text_char(char *p); -unsigned char string_enable; +unsigned char DateTime_enable; static int setmenu_func(char *arg, int flags) @@ -16498,13 +16496,11 @@ setmenu_func(char *arg, int flags) if (new_menu == 0) { num_string = 0; - string_total = 0; - string_enable = 0; - p_string = (char *)MENU_TITLE; + DateTime_enable = 0; for (i=0; i<16; i++) { - DrawBox[i].index = 0; - strings[i].index = 1; + DrawBox[i].enable = 0; + strings[i].enable = 0; } new_menu = 1; } @@ -16513,37 +16509,51 @@ setmenu_func(char *arg, int flags) { if (grub_memcmp (arg, "--string=", 9) == 0) { - i = num_string; int x_horiz_center = 0; int y_count_bottom = 0; - int string_width; char *p; arg += 9; - if (!*arg || *arg == '\n' || *arg == '\r') + if (!*arg) { num_string = 0; - string_total = 0; - string_enable = 0; - p_string = (char *)MENU_TITLE; + DateTime_enable = 0; + for (i=0; i<16; i++) + strings[i].enable = 0; goto cont; } + + if (*arg == 'i') + { + arg++; + if (safe_parse_maxint (&arg, &val)) + i = val; + else + i = num_string; + if (!*arg) + { + strings[i].enable = 0; + goto cont; + } + arg++; + } + else + i = num_string; if (i > 15) return 0; if (*arg == '=') - x_horiz_center++; - else if (grub_memcmp (arg, "date&time", 9) == 0) + x_horiz_center = 1; + else if (*arg == 's') { - string_enable = 0; - goto cont; + x_horiz_center = 1; + arg++; } - else if (safe_parse_maxint (&arg, &val)) - strings[i].start_x = val; //x - if (!*arg || *arg == '\n' || *arg == '\r') + else if (*arg == 'm') { - if (val > 0 && val < 17) - strings[val-1].index = 0; - goto cont; + x_horiz_center = 2; + arg++; } + else if (safe_parse_maxint (&arg, &val)) + strings[i].start_x = val; //x arg++; if (*arg == '-') { @@ -16561,55 +16571,61 @@ setmenu_func(char *arg, int flags) if (safe_parse_maxint (&arg, &val)) strings[i].color = val; //color arg += 2; - strings[i].addr = (int)p_string; //addr + strings[i].enable = 1; if (grub_memcmp (arg, "date&time", 9) == 0) { - string_enable = i+1; + DateTime_enable = i + 1; arg += 9; - *p_string++ = 0; } p = arg; while (*p++ != '"'); *(p - 1) = 0; - if (x_horiz_center) + if (x_horiz_center == 1) { - if (string_enable && !*arg) - strings[i].start_x = ((current_term->chars_per_line - 20) >> 1); //x + if (DateTime_enable == i + 1 && !*arg) + strings[i].start_x = (current_term->chars_per_line - 20) >> 1; //x else - strings[i].start_x = ((current_term->chars_per_line - num_text_char(arg)) >> 1); //x + strings[i].start_x = (current_term->chars_per_line - num_text_char(arg)) >> 1; + } + else if (x_horiz_center == 2) + { + if (DateTime_enable == i + 1 && !*arg) + strings[i].start_x = menu_border.menu_box_x + ((menu_border.menu_box_w - 20) >> 1); //x + else + strings[i].start_x = menu_border.menu_box_x + ((menu_border.menu_box_w - num_text_char(arg)) >> 1); + } + p = strings[i].string; + while (*arg && (p - strings[i].string) < 99) + *p++ = *arg++; + *p = 0; + p = strings[i].string; + if (DateTime_enable == i + 1) + { + while(*p++ != '='); + *(p - 1) = 0; } - string_width = parse_string(arg); - string_total += string_width; - if (string_total > 0x800) - return 0; - while (*arg && string_width--) - *p_string++ = *arg++; - *p_string++ = 0; num_string++; arg++; } else if (grub_memcmp (arg, "--draw-box=", 11) == 0) { arg += 11; - errorcheck_func ("off",0); - if (safe_parse_maxint (&arg, &val)) - i = val; - else + if (!*arg) { for (i=0; i<16; i++) - DrawBox[i].index = 0; - errorcheck_func ("on",0); + DrawBox[i].enable = 0; goto cont; } - errorcheck_func ("on",0); - if (*arg != '=') + if (safe_parse_maxint (&arg, &val)) + i = val; + if (!*arg) { - DrawBox[i].index = 0; + DrawBox[i].enable = 0; goto cont; } if (i > 16) return 0; - DrawBox[i].index = i; + DrawBox[i].enable = 1; arg++; if (safe_parse_maxint (&arg, &val)) DrawBox[i].start_x = val; @@ -16645,9 +16661,7 @@ setmenu_func(char *arg, int flags) { menu_tab = 0; num_string = 0; - string_total = 0; - string_enable = 0; - p_string= (char *)MENU_TITLE; + DateTime_enable = 0; menu_font_spacing = 0; menu_line_spacing = 0; font_spacing = 0; @@ -16662,7 +16676,10 @@ setmenu_func(char *arg, int flags) memmove ((char *)&menu_border,(char *)&tmp_broder,sizeof(tmp_broder)); graphic_type = 0; for (i=0; i<16; i++) - DrawBox[i].index = 0; + { + DrawBox[i].enable = 0; + strings[i].enable = 0; + } return 1; } else if (grub_memcmp (arg, "--ver-on", 8) == 0) @@ -16879,15 +16896,17 @@ static struct builtin builtin_setmenu = "--auto-num-off* --auto-num-all-on --auto-num-on --triangle-on* --triangle-off\n" "--highlight-short* --highlight-full --keyhelp-on* --keyhelp-off\n" "--font-spacing=FONT:LINE. default 0\n" - "--string=[X]=[-]Y=COLOR=\"STRING\" max 16 commands.\n" - " If no X, text in middle.\n" + "--string[=iINDEX]=[X|s|m]=[-]Y=COLOR=\"STRING\"\n" + " iINDEX range is i0-i15. Auto-increments if =iINDEX is omitted.\n" + " If the horizontal position is 's', \"STRING\" centers across the whole screen.\n" + " If the horizontal position is 'm', \"STRING\" centers within menu area.\n" " -Y represents the count from the bottom.\n" " \"STRING\"=\"date&time=FORMAT\" will update date FORMAT every second.\n" " e.g. \"date&time=MMM.dd.yyyy HH:mm:ss\"\n" " e.g. \"date&time=dd/MMM/yy AP hh:mm:ss\"\n" " \"STRING\"=\"date&time\" ISO8601 format. equivalent to: \"date&time=yyyy-MM-dd HH:mm:ss\"\n" - " --string=INDEX to disable the specified index. --string= to clear all strings.\n" - " --string=date&time to disable the date&time.\n" + " --string= to disable all strings.\n" + " --string=iINDEX to disable the specified index.\n" "--box x=X y=Y w=W h=H l=L\n" " If W=0, menu box in middle. L=menu border thickness 0-4, 0=none.\n" "--help=X=W=Y\n" @@ -16905,9 +16924,9 @@ static struct builtin builtin_setmenu = " bit4:Picture and text mixing bit7:transparent background.\n" " Naming rules for START_FILE: *n.??? n: 00-99\n" "--draw-box=INDEX=START_X=START_y=HORIZ=VERT=LINEWIDTH=COLOR.\n" - " LINEWIDTH:1-255; all dimensions in pixels.\n" + " LINEWIDTH:1-255; all dimensions in pixels. INDEX range is 0-15.\n" " --draw-box=INDEX to disable the specified index. --draw-box= to clear all indexes.\n" - "Note: * = default. Use only 0xRRGGBB for COLOR. INDEX range is 1-16." + "Note: * = default. Use only 0xRRGGBB for COLOR." }; static char *month_list[12] = @@ -16927,16 +16946,16 @@ static char *month_list[12] = }; unsigned short refresh = 0; -void string_refresh(void) +void DateTime_refresh(void) { - int i = string_enable-1; + int i = DateTime_enable-1; unsigned short year; unsigned char month, day, hour, min, sec; - char *p; + char *p, *q; - if (strings[i].index == 0) + if (strings[i].enable == 0) { - string_enable = 0; + DateTime_enable = 0; return; } if ((cursor_state & 1) == 1 || !show_menu) @@ -16967,12 +16986,14 @@ void string_refresh(void) hour = ((time >> 28) & 0xf) * 10 + ((time >> 24) & 0xf); min = time >> 16; sec = time >> 8; - p = (char *)(strings[i].addr) + 1; - if (*p != '=') + p = (char *)strings[i].string; + if (!*p) grub_printf("%04X-%02d-%02X %02d:%02X:%02X", year, month, day, hour, min, sec); else { - p++; + q = p; + while(*p++); + gotoxy (strings[i].start_x + p - q, y); while(*p) { if (*p == 'y' && *(p+1) == 'y') diff --git a/stage2/graphics.c b/stage2/graphics.c index 0ed7b016..3edfb410 100644 --- a/stage2/graphics.c +++ b/stage2/graphics.c @@ -621,7 +621,7 @@ print_unicode (unsigned long max_width) if (fontx + char_width > current_term->chars_per_line) { fontx = 0; check_scroll (); } - if (!(splashimage_loaded & 2) || !(cursor_state & 2) || (is_highlight && current_color_64bit >> 32)) + if (!(splashimage_loaded & 2) || !(cursor_state & 2) || (/*is_highlight &&*/ current_color_64bit >> 32)) bgcolor = current_color_64bit >> 32 | 0x1000000; else bgcolor = 0; diff --git a/stage2/shared.h b/stage2/shared.h index 454fe7aa..3d0f232a 100644 --- a/stage2/shared.h +++ b/stage2/shared.h @@ -488,7 +488,7 @@ extern unsigned long splashimage_loaded; extern unsigned long X_offset,Y_offset; struct box { - unsigned char index; + unsigned char enable; unsigned short start_x; unsigned short start_y; unsigned short horiz; @@ -499,16 +499,16 @@ struct box extern struct box DrawBox[16]; struct string { - unsigned char index; + unsigned char enable; unsigned char start_x; char start_y; unsigned long long color; - int addr; + char string[101]; } __attribute__ ((packed)); -extern struct string strings[16]; -extern unsigned long string_total; -extern unsigned char string_enable; -extern void string_refresh(void); + +extern struct string* strings; +extern unsigned char DateTime_enable; +extern void DateTime_refresh(void); #define MENU_TITLE 0x3A8000 #define MENU_TITLE_LENGTH 0x800 /* The Chinese patch will begin at here */ diff --git a/stage2/stage2.c b/stage2/stage2.c index a99f9dea..d19eda9a 100644 --- a/stage2/stage2.c +++ b/stage2/stage2.c @@ -915,7 +915,7 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h unsigned long long col = current_color_64bit; for (i=0; i<16; i++) { - if (DrawBox[i].index == 0) + if (DrawBox[i].enable == 0) continue; current_color_64bit = DrawBox[i].color; rectangle(DrawBox[i].start_x, DrawBox[i].start_y, DrawBox[i].horiz, DrawBox[i].vert, DrawBox[i].linewidth); @@ -923,11 +923,9 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h if (num_string) { - i = num_string; - - for (j=0; jmax_lines; @@ -939,7 +937,7 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h current_color_64bit = strings[j].color | (current_color_64bit & 0xffffffff00000000); else current_color_64bit = strings[j].color; - grub_printf("%s",strings[j].addr); + grub_printf("%s",strings[j].string); } } current_color_64bit = col; @@ -1110,8 +1108,8 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h animated(); if (beep_enable) beep_func((char *)beep_buf,1); - if (string_enable) - string_refresh(); + if (DateTime_enable) + DateTime_refresh(); } /* Check for a keypress, however if TIMEOUT has been expired (GRUB_TIMEOUT == -1) relax in GETKEY even if no key has been