hitpointbar using hp percent calculation */
| 1000 | |
| 1001 | /* hitpointbar using hp percent calculation */ |
| 1002 | static void |
| 1003 | curs_HPbar( |
| 1004 | char *text, /* pre-padded with trailing spaces if short */ |
| 1005 | int bar_len) /* width of space within the brackets */ |
| 1006 | { |
| 1007 | #ifdef STATUS_HILITES |
| 1008 | int coloridx = 0; |
| 1009 | #endif /* STATUS_HILITES */ |
| 1010 | int k, bar_pos; |
| 1011 | char bar[STATVAL_WIDTH], *bar2 = (char *) 0, savedch = '\0'; |
| 1012 | boolean twoparts = (hpbar_percent < 100); |
| 1013 | WINDOW *win = curses_get_nhwin(STATUS_WIN); |
| 1014 | |
| 1015 | if (bar_len < 1 || bar_len > 30) |
| 1016 | bar_len = 30; |
| 1017 | if (bar_len > (k = (int) strlen(text))) /* 26 for vertical status */ |
| 1018 | bar_len = k; |
| 1019 | (void) strncpy(bar, text, bar_len); |
| 1020 | bar[bar_len] = '\0'; |
| 1021 | if (hpbar_crit_hp) |
| 1022 | repad_with_dashes(bar); |
| 1023 | |
| 1024 | bar_pos = (bar_len * hpbar_percent) / 100; |
| 1025 | if (bar_pos < 1 && hpbar_percent > 0) |
| 1026 | bar_pos = 1; |
| 1027 | if (bar_pos >= bar_len && hpbar_percent < 100) |
| 1028 | bar_pos = bar_len - 1; |
| 1029 | if (twoparts) { |
| 1030 | bar2 = &bar[bar_pos]; |
| 1031 | savedch = *bar2; |
| 1032 | *bar2 = '\0'; |
| 1033 | } |
| 1034 | |
| 1035 | waddch(win, '['); |
| 1036 | if (hpbar_crit_hp) |
| 1037 | wattron(win, A_BLINK); |
| 1038 | if (*bar) { /* True unless dead (0 HP => bar_pos == 0) */ |
| 1039 | /* fixed attribute, not nhattr2curses((hpbar_color >> 8) & 0x00FF) */ |
| 1040 | wattron(win, A_REVERSE); /* do this even if hilite_delta is 0 */ |
| 1041 | #ifdef STATUS_HILITES |
| 1042 | if (iflags.hilite_delta) { |
| 1043 | coloridx = hpbar_color & 0x00FF; |
| 1044 | if (coloridx != NO_COLOR) |
| 1045 | curses_toggle_color_attr(win, coloridx, NONE, ON); |
| 1046 | } |
| 1047 | #endif /* STATUS_HILITES */ |
| 1048 | |
| 1049 | /* portion of title corresponding to current hit points */ |
| 1050 | waddstr(win, bar); |
| 1051 | |
| 1052 | #ifdef STATUS_HILITES |
| 1053 | if (iflags.hilite_delta) { |
| 1054 | if (coloridx != NO_COLOR) |
| 1055 | curses_toggle_color_attr(win, coloridx, NONE, OFF); |
| 1056 | } |
| 1057 | #endif /* STATUS_HILITES */ |
| 1058 | wattroff(win, A_REVERSE); /* do this even if hilite_delta is 0 */ |
| 1059 | } /* *bar (current HP > 0) */ |
no test coverage detected