X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fdraw_wins.c;h=5b6de1bfc5aa145aae40cd4f1b66bd28bbca99bf;hb=abdd94745a788288c022a017233014a1eedcaf80;hp=d4275d33fe39d813481909bda814df6da7996e53;hpb=140cadf8f8dc73a1756169dbfa7cb5f05e3b8b8c;p=plomrogue diff --git a/src/draw_wins.c b/src/draw_wins.c index d4275d3..5b6de1b 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -17,10 +17,15 @@ -/* Write "text" into window "win" as far as possible. Start on row "start_y". */ +/* Write "text" into window "win" as far as possible. Start on row "start_y". + * Break lines at newlines. + */ static void draw_with_linebreaks(struct Win * win, char * text, uint16_t start_y); +/* Write "line" into window "win" at line "y" as far as it fits into it. */ +static void draw_line(struct Win * win, uint16_t y, char * line); + /* Write "text" not starting from the top but from the bottom of "win". */ static void draw_text_from_bottom(struct Win * win, char * text); @@ -28,6 +33,21 @@ static void draw_text_from_bottom(struct Win * win, char * text); static void draw_map_objects(struct World * world, struct MapObj * start, struct Map * map, struct Win * win); +/* Draw from line "start" on config view for keybindings defined at "kb". */ +static void draw_kb_view(struct World * world, struct Win * win, + char * f_name, struct KeyBiData * kb, uint8_t start); + +/* Draw into window "win" from line "start" on a "title" followed by an empty + * line followed by a list of all keybindings starting at kb_p. + */ +static uint16_t draw_titled_keybinding_list(struct World * world, + struct Win * win, uint16_t start, + char * title, + struct KeyBinding * kb_p); + + + + static void draw_with_linebreaks(struct Win * win, char * text, @@ -74,6 +94,17 @@ static void draw_with_linebreaks(struct Win * win, char * text, +static void draw_line(struct Win * win, uint16_t y, char * line) +{ + uint16_t x = 0; + for (; x < win->frame.size.x && x < strlen(line); x++) + { + mvwaddch(win->frame.curses_win, y, x, line[x]); + } +} + + + static void draw_text_from_bottom (struct Win * win, char * text) { /* Determine number of lines text would have in a window of win's width, @@ -162,7 +193,119 @@ static void draw_map_objects(struct World * world, struct MapObj * start, -extern void draw_log_win(struct Win * win) +static void draw_kb_view(struct World * world, struct Win * win, + char * f_name, struct KeyBiData * kb, uint8_t start) +{ + char * err_hint = trouble_msg(world, f_name, "draw_scroll_hint()"); + uint16_t kb_max = get_n_of_keybs(kb->kbs) - 1; + uint16_t y, x, offset; + offset = center_offset(kb->select, kb_max, win->frame.size.y - 1 - start); + uint8_t keydescwidth = 9 + 1; /* get_name_to_keycode()'s max length + \0 */ + char keydesc[keydescwidth]; + uint16_t nav_max = kb_max + start; + uint16_t y_border = win->frame.size.y + offset - 1 - start; + for (y = start; y <= nav_max && y < win->frame.size.y; y++) + { + + if (start == y && offset > 0) + { + uint8_t test = draw_scroll_hint(&win->frame, y, offset + 1, '^'); + exit_err(test, world, err_hint); + continue; + } + else if (win->frame.size.y == y + 1 && kb_max > y_border) + { + uint16_t pos = kb_max - (offset + win->frame.size.y) + 2 + start; + uint8_t test = draw_scroll_hint(&win->frame, y, pos, 'v'); + exit_err(test, world, err_hint); + continue; + } + + attr_t attri = 0; + if (y - start == kb->select - offset) + { + attri = A_REVERSE; + if (1 == kb->edit) + { + attri = attri | A_BLINK; + } + } + + struct KeyBinding * kb_p; + kb_p = get_keyb_of_n(kb->kbs, (y - start) + offset); + char * keyname = get_name_to_keycode(world, kb_p->key); + snprintf(keydesc, keydescwidth, "%-9s", keyname); + free(keyname); + char * cmd_dsc = get_command_longdsc(world, kb_p->name); + uint8_t dsclen = strlen(keydesc); + for (x = 0; x < win->frame.size.x; x++) + { + if (x < dsclen) + { + mvwaddch(win->frame.curses_win, y, x, keydesc[x] | attri); + continue; + } + else if (dsclen < x && x < strlen(cmd_dsc) + strlen(keydesc) + 1) + { + chtype ch = cmd_dsc[x - strlen(keydesc) - 1] | attri; + mvwaddch(win->frame.curses_win, y, x, ch); + continue; + } + mvwaddch(win->frame.curses_win, y, x, ' ' | attri); + } + + } + free(err_hint); +} + + + +static uint16_t draw_titled_keybinding_list(struct World * world, + struct Win * win, uint16_t start, + char * title, + struct KeyBinding * kb_p) +{ + uint16_t x, y; + uint16_t i = 0; + uint8_t state = 0; + for (y = start; y < win->frame.size.y && (0 == state || 0 != kb_p); y++) + { + if (0 == state) + { + for (x = 0; x < win->frame.size.x; x++) + { + if (i == strlen(title)) + { + y++; + state = 1 + (0 == kb_p); + i = 0; + break; + } + mvwaddch(win->frame.curses_win, y, x, title[i]); + i++; + } + continue; + } + char * keyname = get_name_to_keycode(world, kb_p->key); + char * cmd_dsc = get_command_longdsc(world, kb_p->name); + char line[9 + 1 + strlen(cmd_dsc) + 1]; + sprintf(line, "%-9s %s", keyname, cmd_dsc); + free(keyname); + kb_p = kb_p->next; + draw_line(win, y, line); + } + if (2 == state) + { + char * line = "(none)"; + draw_line(win, y, line); + y++; + } + return y; +} + + + +extern void draw_win_log(struct Win * win) { struct World * world = (struct World *) win->data; draw_text_from_bottom(win, world->log); @@ -170,7 +313,7 @@ extern void draw_log_win(struct Win * win) -extern void draw_map_win(struct Win * win) +extern void draw_win_map(struct Win * win) { struct World * world = (struct World *) win->data; struct Map * map = world->map; @@ -206,7 +349,7 @@ extern void draw_map_win(struct Win * win) -extern void draw_info_win(struct Win * win) +extern void draw_win_info(struct Win * win) { struct World * world = (struct World *) win->data; char * dsc_turn = "Turn: "; @@ -224,81 +367,76 @@ extern void draw_info_win(struct Win * win) -extern void draw_keys_win(struct Win * win) +extern void draw_win_available_keybindings(struct Win * win) { - char * err_hint = "Trouble with draw_scroll_hint() in draw_keys_win()."; struct World * world = (struct World *) win->data; - uint16_t n_keybs = get_n_of_keybs(world); - uint16_t offset = center_offset(world->keyswindata->select, n_keybs - 1, - win->frame.size.y - 1); + char * title = "Active window's keybindings:"; + struct KeyBinding * kb_p; + struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active); + if (0 == wc->view) + { + kb_p = wc->kb.kbs; + } + else if (1 == wc->view) + { + kb_p = world->kb_wingeom.kbs; + } + else if (2 == wc->view) + { + kb_p = world->kb_winkeys.kbs; + } + uint16_t offset = draw_titled_keybinding_list(world, win, 0, title, kb_p); + draw_titled_keybinding_list(world, win, offset + 1, "Global keybindings:", + world->kb_global.kbs); +} - uint8_t keydescwidth = 9 + 1; /* get_name_to_keycode()'s max length + \0 */ - char keydesc[keydescwidth]; - uint16_t y, x; - for (y = 0; y <= n_keybs - 1 && y < win->frame.size.y; y++) - { - if (0 == y && offset > 0) - { - exit_err(draw_scroll_hint(&win->frame, y, offset + 1, '^'), - world, err_hint); - continue; - } - else if (win->frame.size.y == y + 1 - && 0 < (n_keybs - 1) - - (win->frame.size.y + offset - 1)) - { - exit_err(draw_scroll_hint(&win->frame, y, - (n_keybs - 1) - - (offset + win->frame.size.y) + 2, - 'v'), - world, err_hint); - continue; - } +extern void draw_win_keybindings_global(struct Win * win) +{ + char * f_name = "draw_win_keybindings_global()"; + struct World * world = (struct World *) win->data; + draw_kb_view(world, win, f_name, &world->kb_global, 0); +} - attr_t attri = 0; - if (y == world->keyswindata->select - offset) - { - attri = A_REVERSE; - if (1 == world->keyswindata->edit) - { - attri = attri | A_BLINK; - } - } - struct KeyBinding * kb_p = get_keyb_of_n(world, y + offset); - char * keyname = get_name_to_keycode(world, kb_p->key); - snprintf(keydesc, keydescwidth, "%-9s", keyname); - free(keyname); - char * cmd_dsc = get_command_longdsc(world, kb_p->name); - for (x = 0; x < win->frame.size.x; x++) - { - if (x < strlen(keydesc)) - { - mvwaddch(win->frame.curses_win, y, x, keydesc[x] | attri); - } - else if ( strlen(keydesc) < x - && x < strlen(cmd_dsc) + strlen(keydesc) + 1) - { - mvwaddch(win->frame.curses_win, y, x, - cmd_dsc[x - strlen(keydesc) - 1] | attri); - } - else - { - mvwaddch(win->frame.curses_win, y, x, ' ' | attri); - } - } - } + +extern void draw_win_keybindings_winconf_geometry(struct Win * win) +{ + char * f_name = "draw_win_keybindings_winconf_geometry()"; + struct World * world = (struct World *) win->data; + draw_kb_view(world, win, f_name, &world->kb_wingeom, 0); +} + + + +extern void draw_win_keybindings_winconf_keybindings(struct Win * win) +{ + char * f_name = "draw_win_keybindings_winconf_keybindings()"; + struct World * world = (struct World *) win->data; + draw_kb_view(world, win, f_name, &world->kb_winkeys, 0); +} + + + +extern void draw_winconf_keybindings(struct Win * win) +{ + char * f_name = "draw_winconf_keybindings()"; + struct World * world = (struct World *) win->data; + struct WinConf * wc = get_winconf_by_win(world, win); + char * title = "Window's keybindings:"; + uint8_t title_space = strlen(title) / win->frame.size.x + 2; + mvwaddstr(win->frame.curses_win, 0, 0, title); + draw_kb_view(world, win, f_name, &wc->kb, title_space); } -extern void draw_winconf(struct Win * win) +extern void draw_winconf_geometry(struct Win * win) { struct World * world = (struct World *) win->data; struct WinConf * wcp = get_winconf_by_win(world, win); - char * title = "Window configuration:\n"; + char * title = "Window's geometry:\n"; char * h_d = "\nWidth to save: "; char * h_pos = " (height in cells)"; char * h_neg = " (negative diff: cells to maximum height)";