📄 bfu.c
字号:
if (it != menu->selected) { drv->fill_area(dev, menu->x + (G_MENU_LEFT_BORDER - 1) / 2 + 1, y, menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER, y + G_BFU_FONT_SIZE, bfu_bg_color); } else { menu->xl1 = menu->x; menu->yl1 = y; menu->xl2 = menu->x + menu->xw; menu->yl2 = y + G_BFU_FONT_SIZE; menu_ptr_set = 1; set_window_ptr(menu->win, menu->x + menu->xw, y); drv->fill_area(dev, menu->x + (G_MENU_LEFT_BORDER - 1) / 2 + 1, y, menu->x + G_MENU_LEFT_BORDER, y + G_BFU_FONT_SIZE, bfu_bg_color); drv->fill_area(dev, menu->x + menu->xw - G_MENU_LEFT_BORDER, y, menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2, y + G_BFU_FONT_SIZE, bfu_bg_color); drv->fill_area(dev, menu->x + G_MENU_LEFT_BORDER, y, menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER, y + G_BFU_FONT_SIZE, bfu_fg_color); } restrict_clip_area(dev, &r, menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER, y, menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER, y + G_BFU_FONT_SIZE); if (it == menu->selected) { p = menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER; g_print_text(drv, dev, p, y, bfu_style_wb, menu->hktxt1[it], &p); g_print_text(drv, dev, p, y, bfu_style_wb, menu->hktxt2[it], &p); g_print_text(drv, dev, p, y, bfu_style_wb, menu->hktxt3[it], &p); } else { p = menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER; g_print_text(drv, dev, p, y, bfu_style_bw, menu->hktxt1[it], &p); g_print_text(drv, dev, p, y, bfu_style_bw_u, menu->hktxt2[it], &p); g_print_text(drv, dev, p, y, bfu_style_bw, menu->hktxt3[it], &p); } if (!*rtext) { drv->set_clip_area(dev, &r); if (p > menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER) p = menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER; if (it != menu->selected) drv->fill_area(dev, p, y, menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2, y + G_BFU_FONT_SIZE, bfu_bg_color); else drv->fill_area(dev, p, y, menu->x + menu->xw - G_MENU_LEFT_BORDER, y + G_BFU_FONT_SIZE, bfu_fg_color); } else { int s = menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER - g_text_width(bfu_style_wb, rtext); if (s < p) s = p; drv->fill_area(dev, p, y, s, y + G_BFU_FONT_SIZE, it != menu->selected ? bfu_bg_color : bfu_fg_color); g_print_text(drv, dev, s, y, it != menu->selected ? bfu_style_bw : bfu_style_wb, rtext, NULL); drv->set_clip_area(dev, &r); if (it != menu->selected) drv->fill_area(dev, menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER, y, menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2, y + G_BFU_FONT_SIZE, bfu_bg_color); else drv->fill_area(dev, menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER, y, menu->x + menu->xw - G_MENU_LEFT_BORDER, y + G_BFU_FONT_SIZE, bfu_fg_color); } }}void display_menu_gfx(struct terminal *term, struct menu *menu){ int p; struct graphics_device *dev = term->dev; if (menu_oldview == menu->view) { if (menu_oldsel >= 0 && menu_oldsel < menu->ni && menu_oldsel < menu->view + menu->nview) display_menu_item_gfx(term, menu, menu_oldsel); if (menu->selected >= 0 && menu->selected < menu->ni && menu->selected < menu->view + menu->nview) display_menu_item_gfx(term, menu, menu->selected); return; }#define PX1 (menu->x + (G_MENU_LEFT_BORDER - 1) / 2)#define PX2 (menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2)#define PY1 (menu->y + (G_MENU_TOP_BORDER - 1) / 2)#define PY2 (menu->y + menu->yw - (G_MENU_TOP_BORDER + 1) / 2) drv->fill_area(dev, menu->x, menu->y, menu->x + menu->xw, PY1, bfu_bg_color); drv->fill_area(dev, menu->x, PY1, PX1, PY2 + 1, bfu_bg_color); drv->fill_area(dev, PX2 + 1, PY1, menu->x + menu->xw, PY2 + 1, bfu_bg_color); drv->fill_area(dev, menu->x, PY2 + 1, menu->x + menu->xw, menu->y + menu->yw, bfu_bg_color); drv->draw_hline(dev, PX1, PY1, PX2 + 1, bfu_fg_color); drv->draw_hline(dev, PX1, PY2, PX2 + 1, bfu_fg_color); drv->draw_vline(dev, PX1, PY1 + 1, PY2, bfu_fg_color); drv->draw_vline(dev, PX2, PY1 + 1, PY2, bfu_fg_color); drv->fill_area(dev, PX1 + 1, PY1 + 1, PX2, menu->y + G_MENU_TOP_BORDER, bfu_bg_color); drv->fill_area(dev, PX1 + 1, menu->y + menu->yw - G_MENU_TOP_BORDER, PX2, PY2, bfu_bg_color); menu->xl1 = menu->yl1 = menu->xl2 = menu->yl2 = 0; menu_ptr_set = 0; for (p = menu->view; p < menu->ni && p < menu->view + menu->nview; p++) display_menu_item_gfx(term, menu, p); if (!menu_ptr_set) set_window_ptr(menu->win, menu->x, menu->y);}#endifvoid menu_func(struct window *win, struct event *ev, int fwd){ int s = 0; int xp, yp; struct menu *menu = win->data; struct window *w1; menu->win = win; switch ((int)ev->ev) { case EV_INIT: case EV_RESIZE: get_parent_ptr(win, &menu->xp, &menu->yp); count_menu_size(win->term, menu); goto xxx; case EV_REDRAW: get_parent_ptr(win, &xp, &yp); if (xp != menu->xp || yp != menu->yp) { menu->xp = xp; menu->yp = yp; count_menu_size(win->term, menu); } xxx: menu->selected--; scroll_menu(menu, 1); draw_to_window(win, (void (*)(struct terminal *, void *))gf_val(display_menu_txt, display_menu_gfx), menu); break; case EV_MOUSE: if ((ev->b & BM_ACT) == B_MOVE) break; if (ev->x < menu->x || ev->x >= menu->x+menu->xw || ev->y < menu->y || ev->y >= menu->y+menu->yw) { int f = 1; for (w1 = win; (void *)w1 != &win->term->windows; w1 = w1->next) { struct menu *m1; if (w1->handler == mainmenu_func) {#ifdef G struct mainmenu *m2 = w1->data; if (F && !f && ev->x >= m2->xl1 && ev->x < m2->xl2 && ev->y >= m2->yl1 && ev->y < m2->yl2) goto bbb;#endif if (ev->y < gf_val(1, G_BFU_FONT_SIZE)) { del:delete_window_ev(win, ev); goto bbb; } break; } if (w1->handler != menu_func) break; m1 = w1->data;#ifdef G if (F && !f && ev->x >= m1->xl1 && ev->x < m1->xl2 && ev->y >= m1->yl1 && ev->y < m1->yl2) goto bbb;#endif if (ev->x > m1->x && ev->x < m1->x+m1->xw-1 && ev->y > m1->y && ev->y < m1->y+m1->yw-1) goto del; f--; } if ((ev->b & BM_ACT) == B_DOWN) goto del; bbb:; } else { if (!(ev->x < menu->x || ev->x >= menu->x+menu->xw || ev->y < menu->y + gf_val(1, G_MENU_TOP_BORDER) || ev->y >= menu->y + menu->yw - gf_val(1, G_MENU_TOP_BORDER))) { int s = gf_val(ev->y - menu->y-1 + menu->view, (ev->y - menu->y - G_MENU_TOP_BORDER) / G_BFU_FONT_SIZE + menu->view); if (s >= 0 && s < menu->ni && menu->items[s].hotkey != M_BAR) { menu_oldview = menu->view; menu_oldsel = menu->selected; menu->selected = s; scroll_menu(menu, 0); draw_to_window(win, (void (*)(struct terminal *, void *))gf_val(display_menu_txt, display_menu_gfx), menu); menu_oldview = menu_oldsel = -1; if ((ev->b & BM_ACT) == B_UP/* || menu->items[s].in_m*/) select_menu(win->term, menu); } } } break; case EV_KBD: if (ev->x == KBD_LEFT || ev->x == KBD_RIGHT) { if ((void *)win->next != &win->term->windows && win->next->handler == mainmenu_func) goto mm; /*for (w1 = win; (void *)w1 != &win->term->windows; w1 = w1->next) { if (w1->handler == mainmenu_func) goto mm; if (w1->handler != menu_func) break; }*/ if (ev->x == KBD_RIGHT) goto enter; delete_window(win); break; } if ((ev->x >= KBD_F1 && ev->x <= KBD_F12) || ev->y & KBD_ALT) { mm: delete_window_ev(win, ev); break; } if (ev->x == KBD_ESC) { delete_window_ev(win, (void *)win->next != &win->term->windows && win->next->handler == mainmenu_func ? ev : NULL); break; } menu_oldview = menu->view; menu_oldsel = menu->selected; if (ev->x == KBD_UP) scroll_menu(menu, -1); else if (ev->x == KBD_DOWN) scroll_menu(menu, 1); else if (ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) menu->selected = -1, scroll_menu(menu, 1); else if (ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) menu->selected = menu->ni, scroll_menu(menu, -1); else if (ev->x == KBD_PAGE_UP || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)) { if ((menu->selected -= menu->yw / gf_val(1, G_BFU_FONT_SIZE) - 3) < -1) menu->selected = -1; if ((menu->view -= menu->yw / gf_val(1, G_BFU_FONT_SIZE) - 2) < 0) menu->view = 0; scroll_menu(menu, -1); } else if (ev->x == KBD_PAGE_DOWN || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL)) { if ((menu->selected += menu->yw / gf_val(1, G_BFU_FONT_SIZE) - 3) > menu->ni) menu->selected = menu->ni; if ((menu->view += menu->yw / gf_val(1, G_BFU_FONT_SIZE) - 2) >= menu->ni - menu->yw + 2) menu->view = menu->ni - menu->yw + 2; scroll_menu(menu, 1); } else if (ev->x > ' ' && ev->x < 256) { int i; for (i = 0; i < menu->ni; i++) if (strchr(_(menu->items[i].hotkey, win->term), upcase(ev->x))) { menu->selected = i; scroll_menu(menu, 0); s = 1; } } draw_to_window(win, (void (*)(struct terminal *, void *))gf_val(display_menu_txt, display_menu_gfx), menu); if (s || ev->x == KBD_ENTER || ev->x == ' ') { enter: menu_oldview = menu_oldsel = -1; select_menu(win->term, menu); } menu_oldview = menu_oldsel = -1; break; case EV_ABORT:#ifdef G if (F) { int i; for (i = 0; menu->items[i].text; i++) { mem_free(menu->hktxt1[i]); mem_free(menu->hktxt2[i]); mem_free(menu->hktxt3[i]); } mem_free(menu->hktxt1); mem_free(menu->hktxt2); mem_free(menu->hktxt3); }#endif if (menu->items->free_i) { int i; for (i = 0; menu->items[i].text; i++) { if (menu->items[i].free_i & 2) mem_free(menu->items[i].text); if (menu->items[i].free_i & 4) mem_free(menu->items[i].rtext); } mem_free(menu->items); } break; }}void do_mainmenu(struct terminal *term, struct menu_item *items, void *data, int sel){ struct mainmenu *menu; menu = mem_alloc(sizeof(struct mainmenu)); menu->selected = sel == -1 ? 0 : sel; menu->items = items; menu->data = data; add_window(term, mainmenu_func, menu); if (sel != -1) { struct event ev = {EV_KBD, KBD_ENTER, 0, 0}; struct window *win = term->windows.next; win->handler(win, &ev, 0); }}void display_mainmenu(struct terminal *term, struct mainmenu *menu){ if (!F) { int i; int p = 2; fill_area(term, 0, 0, term->x, 1, COLOR_MAINMENU | ' '); for (i = 0; menu->items[i].text; i++) { int s = 0; int j; unsigned char c; unsigned char *tmptext = _(menu->items[i].text, term); unsigned char *ht = _(menu->items[i].hotkey, term); int co = i == menu->selected ? s = 1, COLOR_MAINMENU_SELECTED : COLOR_MAINMENU; if (s) { fill_area(term, p, 0, 2, 1, co); fill_area(term, p+strlen(tmptext)+2, 0, 2, 1, co); menu->sp = p; set_cursor(term, p, 0, term->x - 1, term->y - 1); set_window_ptr(menu->win, p, 1); } if (term->spec->braille) { s = 1; if (*ht) set_char(term, p, 0, *ht | COLOR_MAINMENU_HOTKEY); } p += 2; for (j = 0; (c = tmptext[j]); j++, p++) set_char(term, p, 0, (!s && strchr(ht, upcase(c)) ? s = 1, COLOR_MAINMENU_HOTKEY : co) | c); p += 2; } menu->ni = i;#ifdef G } else { struct graphics_device *dev = term->dev; int i, p; drv->fill_area(dev, 0, 0, p = G_MAINMENU_LEFT_BORDER, G_BFU_FONT_SIZE, bfu_bg_color); for (i = 0; menu->items[i].text; i++) { int s = i == menu->selected; unsigned char *text = _(menu->items[i].text, term); if (s) { menu->xl1 = p; menu->yl1 = 0; set_window_ptr(menu->win, p, G_BFU_FONT_SIZE); } drv->fill_area(dev, p, 0, p + G_MAINMENU_BORDER, G_BFU_FONT_SIZE, s ? bfu_fg_color : bfu_bg_color); p += G_MAINMENU_BORDER; g_print_text(drv, dev, p, 0, s ? bfu_style_wb : bfu_style_bw, text, &p); drv->fill_area(dev, p, 0, p + G_MAINMENU_BORDER, G_BFU_FONT_SIZE, s ? bfu_fg_color : bfu_bg_color); p += G_MAINMENU_BORDER; if (s) { menu->xl2 = p; menu->yl2 = G_BFU_FONT_SIZE; } } drv->fill_area(dev, p, 0, term->x, G_BFU_FONT_SIZE, bfu_bg_color); menu->ni = i;#endif }}void select_mainmenu(struct terminal *term, struct mainmenu *menu){ struct menu_item *it = &menu->items[menu->selected]; if (menu->selected < 0 || menu->selected >= menu->ni || it->hotkey == M_BAR) return; if (!it->in_m) { struct window *win, *win1; for (win = term->windows.next; (void *)win != &term->windows && (win->handler == menu_func || win->handler == mainmenu_func); win1 = win->next, delete_window(win), win = win1) ; } it->func(term, it->data, menu->data);}void mainmenu_func(struct window *win, struct event *ev, int fwd){ int s = 0; struct mainmenu *menu = win->data; menu->win = win; switch ((int)ev->ev) { case EV_INIT: case EV_RESIZE:#ifdef G if (F) set_window_pos(win, 0, 0, win->term->x, G_BFU_FONT_SIZE);#endif case EV_REDRAW: draw_to_window(win, (void (*)(struct terminal *, void *))display_mainmenu, menu); break; case EV_MOUSE: if ((ev->b & BM_ACT) == B_MOVE) break; if ((ev->b & BM_ACT) == B_DOWN && ev->y >= gf_val(1, G_BFU_FONT_SIZE)) delete_window_ev(win, ev); else if (ev->y < gf_val(1, G_BFU_FONT_SIZE)) { int i; int p = gf_val(2, G_MAINMENU_LEFT_BORDER); for (i = 0; i < menu->ni; i++) { int o = p; unsigned char *tmptext = _(menu->items[i].text, win->term); p += txtlen(tmptext) + gf_val(4, 2 * G_MAINMENU_BORDER); if (ev->x >= o && ev->x < p) { menu->selected = i; draw_to_window(win, (void (*)(struct terminal *, void *))display_mainmenu, menu); if ((ev->b & BM_ACT) == B_UP || menu->items[s].in_m) select_mainmenu(win->term, menu); break; } } } break; case EV_KBD: if (ev->x == ' ' || ev->x == KBD_ENTER || ev->x == KBD_DOWN || ev->x == KBD_UP || ev->x == KBD_PAGE_DOWN || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL) || ev->x == KBD_PAGE_UP || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)) { select_mainmenu(win->term, menu); break; } else if (ev->x == KBD_LEFT) { if (!menu->selected--) menu->selected = menu->ni - 1; s = 1; if (fwd) s = 2; } else if (ev->x == KBD_RIGHT) { if (++menu->selected >= menu->ni) menu->selected = 0; s = 1; if (fwd) s = 2; } else if (ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) { menu->selected = 0; s = 1; } else if (ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) { menu->selected = menu->ni - 1; s = 1; } else if (ev->x > ' ' && ev->x < 256) { int i; s = 1; for (i = 0; i < menu->ni; i++) if (strchr(_(menu->items[i].hotkey, win->term), upcase(ev->x))) { menu->selected = i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -