void do_cmd_snipe_browse(void) { int n = 0; int j, line; char temp[62 * 4]; screen_save(); while(1) { /* get power */ if (!get_snipe_power(&n, TRUE)) { screen_load(); return; } /* Clear lines, position cursor (really should use strlen here) */ Term_erase(12, 22, 255); Term_erase(12, 21, 255); Term_erase(12, 20, 255); Term_erase(12, 19, 255); Term_erase(12, 18, 255); roff_to_buf(snipe_tips[n], 62, temp, sizeof(temp)); for(j = 0, line = 19; temp[j]; j += (1 + strlen(&temp[j]))) { prt(&temp[j], line, 15); line++; } } }
/** * Get some input at the cursor location. * * The buffer is assumed to have been initialized to a default string. * Note that this string is often "empty" (see below). * * The default buffer is displayed in yellow until cleared, which happens * on the first keypress, unless that keypress is Return. * * Normal chars clear the default and append the char. * Backspace clears the default or deletes the final char. * Return accepts the current buffer contents and returns true. * Escape clears the buffer and the window and returns false. * * Note that 'len' refers to the size of the buffer. The maximum length * of the input is 'len-1'. * * 'keypress_h' is a pointer to a function to handle keypresses, altering * the input buffer, cursor position and suchlike as required. See * 'askfor_aux_keypress' (the default handler if you supply NULL for * 'keypress_h') for an example. */ bool askfor_aux(char *buf, size_t len, bool (*keypress_h)(char *, size_t, size_t *, size_t *, struct keypress, bool)) { int y, x; size_t k = 0; /* Cursor position */ size_t nul = 0; /* Position of the null byte in the string */ struct keypress ch = KEYPRESS_NULL; bool done = false; bool firsttime = true; if (keypress_h == NULL) keypress_h = askfor_aux_keypress; /* Locate the cursor */ Term_locate(&x, &y); /* Paranoia */ if ((x < 0) || (x >= 80)) x = 0; /* Restrict the length */ if (x + len > 80) len = 80 - x; /* Truncate the default entry */ buf[len-1] = '\0'; /* Get the position of the null byte */ nul = strlen(buf); /* Display the default answer */ Term_erase(x, y, (int)len); Term_putstr(x, y, -1, COLOUR_YELLOW, buf); /* Process input */ while (!done) { /* Place cursor */ Term_gotoxy(x + k, y); /* Get a key */ ch = inkey(); /* Let the keypress handler deal with the keypress */ done = keypress_h(buf, len, &k, &nul, ch, firsttime); /* Update the entry */ Term_erase(x, y, (int)len); Term_putstr(x, y, -1, COLOUR_WHITE, buf); /* Not the first time round anymore */ firsttime = false; } /* Done */ return (ch.code != ESCAPE); }
static void _list(menu_ptr menu, char *keys) { char temp[255]; int i; int y = 1; int x = 13; Term_erase(x, y, 255); if (menu->heading) put_str(format(" %s", menu->heading), y++, x); for (i = 0; i < menu->count; i++) { byte attr = TERM_WHITE; variant key, text, color; var_init(&key); var_init(&text); var_init(&color); menu->fn(MENU_KEY, i, menu->cookie, &key); if (var_is_null(&key)) keys[i] = I2A(i); else keys[i] = (char)var_get_int(&key); if (menu->count <= 26) keys[i] = tolower(keys[i]); menu->fn(MENU_TEXT, i, menu->cookie, &text); if (var_is_null(&text)) var_set_string(&text, ""); menu->fn(MENU_COLOR, i, menu->cookie, &color); if (!var_is_null(&color)) attr = var_get_int(&color); if (attr == TERM_DARK) keys[i] = '\0'; sprintf(temp, " %c) %s", keys[i], var_get_string(&text)); c_prt(attr, temp, y + i, x); var_clear(&key); var_clear(&text); var_clear(&color); } Term_erase(x, y + menu->count, 255); }
/** * Redraw the "monster mana bar" * * The "monster mana bar" provides visual feedback on the "mana" * of the monster currently being "tracked". It follows the lead of the * monster health bar for who to track. */ static void prt_mana(int row, int col) { byte attr = TERM_SLATE; /* Not tracking */ if (!p_ptr->health_who) { /* Erase the health bar */ Term_erase(col, row, 12); } /* Tracking an unseen, hallucinatory, or dead monster */ else if ((!m_list[p_ptr->health_who].ml) || /* Unseen */ (p_ptr->timed[TMD_IMAGE]) || /* Hallucination */ (m_list[p_ptr->health_who].hp < 0)) { /* Dead (?) */ /* The monster mana is "unknown" */ Term_putstr(col, row, 12, attr, "[----------]"); } /* Tracking a visible monster */ else { int pct, len; monster_type *m_ptr = &m_list[p_ptr->health_who]; monster_race *r_ptr = &r_info[m_ptr->r_idx]; /* no mana, stop here */ if (!r_ptr->mana) { /* Erase the mana bar */ Term_erase(col, row, 12); return; } attr = monster_mana_attr(); /* Extract the "percent" of mana */ pct = 100L * m_ptr->mana / r_ptr->mana; /* Convert percent into "mana" */ len = (pct < 10) ? 1 : (pct < 90) ? (pct / 10 + 1) : 10; /* Default to "unknown" */ Term_putstr(col, row, 12, TERM_WHITE, "[----------]"); /* Dump the current "mana" (use '*' symbols) */ Term_putstr(col + 1, row, len, attr, "**********"); } }
/* * Display tiles. */ static void display_tiles(int col, int row, int height, int width, byte attr_top, byte char_left) { int i, j; /* Clear the display lines */ for (i = 0; i < height; i++) Term_erase(col, row + i, width); width = logical_width(width); height = logical_height(height); /* Display lines until done */ for (i = 0; i < height; i++) { /* Display columns until done */ for (j = 0; j < width; j++) { byte a; unsigned char c; int x = col + actual_width(j); int y = row + actual_height(i); int ia, ic; ia = attr_top + i; ic = char_left + j; a = (byte) ia; c = (unsigned char) ic; /* Display symbol */ big_pad(x, y, a, c); } } }
/** * Display a string on the screen using an attribute, and clear to the * end of the line. */ void c_prt(byte attr, const char *str, int row, int col) { /* Clear line, position cursor */ Term_erase(col, row, 255); /* Dump the attr/text */ Term_addstr(-1, attr, str); }
/* * Hack -- Display the "name" and "attr/chars" of a monster race */ static void roff_top(const int r_idx, int m_idx) { byte a1, a2; char c1, c2; char desc[80]; monster_race *r_ptr = &r_info[r_idx]; /* Describe the monster */ if (m_idx) { /* Describe the monster */ monster_desc(desc, sizeof(desc), m_idx, 0x80); /* Capitalise the first letter */ if (islower(desc[0])) desc[0] = toupper(desc[0]); } /* Not describing a specific monster, so hack a description */ else { /* Get the name */ race_desc(desc, sizeof(desc), r_idx, 0x400, 1); /* Capitalise the first letter */ if (islower(desc[0])) desc[0] = toupper(desc[0]); } /* Get the chars */ c1 = r_ptr->d_char; c2 = r_ptr->x_char; /* Get the attrs */ a1 = r_ptr->d_attr; a2 = r_ptr->x_attr; /* Clear the top line */ Term_erase(0, 0, 255); /* Reset the cursor */ Term_gotoxy(0, 0); /* Dump the name */ Term_addstr(-1, TERM_WHITE, desc); if (!use_dbltile && !use_trptile) { /* Append the "standard" attr/char info */ Term_addstr(-1, TERM_WHITE, " ('"); Term_addch(a1, c1); Term_addstr(-1, TERM_WHITE, "')"); /* Append the "optional" attr/char info */ Term_addstr(-1, TERM_WHITE, "/('"); Term_addch(a2, c2); if (use_bigtile && (a2 & 0x80)) Term_addch(255, -1); Term_addstr(-1, TERM_WHITE, "'):"); } }
/** * Clear the bottom part of the screen */ void clear_from(int row) { int y; /* Erase requested rows */ for (y = row; y < Term->hgt; y++) Term_erase(0, y, 255); }
void region_erase(const region *loc) { region calc = region_calculate(*loc); int i = 0; for (i = 0; i < calc.page_rows; i++) Term_erase(calc.col, calc.row + i, calc.width); }
/** * Clear the previous question */ static void clear_question(void) { int i; for (i = QUESTION_ROW; i < TABLE_ROW; i++) /* Clear line, position cursor */ Term_erase(0, i, 255); }
/* * Clear a region of the screen, starting from (x,y1) * going to (255,y2) */ void clear_region(int x, int y1, int y2) { int y; for (y = y1; (y < Term->hgt) && (y <= y2); y++) { /* Erase part of the screen */ Term_erase(x, y, 255); } }
/* * Hack -- Display the "name" and "attr/chars" of a monster race */ void roff_top(int r_idx) { monster_race *r_ptr = &r_info[r_idx]; byte a1, a2; char c1, c2; /* Access the chars */ c1 = r_ptr->d_char; c2 = r_ptr->x_char; /* Access the attrs */ a1 = r_ptr->d_attr; a2 = r_ptr->x_attr; /* Clear the top line */ Term_erase(0, 0, 255); /* Reset the cursor */ Term_gotoxy(0, 0); /* A title (use "The" for non-uniques) */ if (!(r_ptr->flags1 & RF1_UNIQUE)) { Term_addstr(-1, TERM_WHITE, "The "); } /* Dump the name */ Term_addstr(-1, TERM_WHITE, (r_name + r_ptr->name)); /* Append the "standard" attr/char info */ Term_addstr(-1, TERM_WHITE, " ('"); Term_add_bigch(a1, c1); Term_addstr(-1, TERM_WHITE, "')"); /* Append the "optional" attr/char info */ Term_addstr(-1, TERM_WHITE, "/('"); Term_add_bigch(a2, c2); Term_addstr(-1, TERM_WHITE, "'):"); /* Wizards get extra info */ if (p_ptr->wizard) { char buf[6]; sprintf(buf, "%d", r_idx); Term_addstr(-1, TERM_WHITE, " ("); Term_addstr(-1, TERM_L_BLUE, buf); Term_addch(TERM_WHITE, ')'); } }
/* Display an event, with possible preference overrides */ static void display_action_aux(menu_action *act, byte color, int row, int col, int wid) { /* TODO: add preference support */ /* TODO: wizard mode should show more data */ Term_erase(col, row, wid); /*if (act->name) Term_putstr(col, row, wid, color, act->name);*/ if (act->text) Term_putstr(col, row, wid, color, act->text); }
/* * Clear part of the screen */ void clear_from(int row) { int y; /* Erase requested rows */ for (y = row; y < Term->hgt; y++) { /* Erase part of the screen */ Term_erase(0, y, 255); } }
void doc_sync_term(doc_ptr doc, doc_region_t range, doc_pos_t term_pos) { doc_pos_t pos; byte selection_color = _INVALID_COLOR; assert(doc_region_is_valid(&range)); if (doc_region_is_valid(&doc->selection)) { doc_style_t style = *doc_current_style(doc); doc_style_f f = _get_doc_style_f(doc, "selection"); if (f) { f(&style); selection_color = style.color; } } for (pos.y = range.start.y; pos.y <= range.stop.y; pos.y++) { int term_y = term_pos.y + (pos.y - range.start.y); int max_x = doc->width; pos.x = 0; if (pos.y == range.start.y) pos.x = range.start.x; if (pos.y == range.stop.y) max_x = range.stop.x; if (max_x > 0) Term_erase(term_pos.x + pos.x, term_y, doc->width - pos.x); if (pos.y <= doc->cursor.y) { doc_char_ptr cell = doc_char(doc, pos); for (; pos.x < max_x; pos.x++, cell++) { if (cell->c) { int term_x = term_pos.x + pos.x; byte a = cell->a; if ( selection_color != _INVALID_COLOR && doc_region_contains(&doc->selection, pos) ) { a = selection_color; } Term_putch(term_x, term_y, a, cell->c); } } } } }
void region_erase_bordered(const region *loc) { region calc = region_calculate(*loc); int i = 0; calc.col = MAX(calc.col - 1, 0); calc.row = MAX(calc.row - 1, 0); calc.width += 2; calc.page_rows += 2; for (i = 0; i < calc.page_rows; i++) Term_erase(calc.col, calc.row + i, calc.width); }
/* * Hack -- flush */ static void msg_flush(int x) { byte a = TERM_L_BLUE; /* Pause for response */ Term_putstr(x, 0, -1, a, "-more-"); if (!OPT(auto_more)) anykey(); /* Clear the line */ Term_erase(0, 0, 255); }
/* * Handle signal -- abort, kill, etc */ static void handle_signal_abort(int sig) { /* Disable handler */ (void)(*signal_aux)(sig, SIG_IGN); /* Nothing to save, just quit */ if (!character_generated || character_saved) quit(NULL); /* Clear the bottom line */ Term_erase(0, 23, 255); /* Give a warning */ Term_putstr(0, 23, -1, TERM_RED, "A gruesome software bug LEAPS out at you!"); /* Message */ Term_putstr(45, 23, -1, TERM_RED, "Panic save..."); /* Flush output */ Term_fresh(); /* Panic Save p_ptr->panic_save = 1; */ /* Panic save */ my_strcpy(p_ptr->died_from, "(panic save)", sizeof(p_ptr->died_from)); /* Forbid suspend */ signals_ignore_tstp(); /* Attempt to save */ if (old_save()) { Term_putstr(45, 23, -1, TERM_RED, "Panic save succeeded!"); } /* Save failed */ else { Term_putstr(45, 23, -1, TERM_RED, "Panic save failed!"); } /* Flush output */ Term_fresh(); /* Quit */ quit("software bug"); }
/* * Remove the visual list and clear the screen */ static void remove_visual_list(int col, int row, bool *visual_list_ptr, int width, int height) { int i; /* No more big cursor */ bigcurs = FALSE; /* Cancel visual list */ *visual_list_ptr = FALSE; /* Clear the display lines */ for (i = 0; i < height; i++) Term_erase(col, row + i, width); }
/* * Remove the tile display and clear the screen */ static void remove_tiles(int col, int row, bool * picker_ptr, int width, int height) { int i; /* No more big cursor */ bigcurs = FALSE; /* Cancel tile picker */ *picker_ptr = FALSE; /* Clear the display lines */ for (i = 0; i < height; i++) Term_erase(col, row + i, width); }
/* * Hack -- describe the given monster race at the top of the screen */ void screen_roff(int r_idx) { /* Flush messages */ message_flush(); /* Begin recall */ Term_erase(0, 1, 255); /* Output to the screen */ text_out_hook = text_out_to_screen; /* Recall monster */ describe_monster(r_idx, FALSE); /* Describe monster */ roff_top(r_idx); }
/** * Display monster recall statically. * * This is intended to be called in a subwindow, since it clears the entire * window before drawing, and has no interactivity. * * \param race is the monster race we are describing. * \param lore is the known information about the monster race. */ void lore_show_subwindow(const monster_race *race, const monster_lore *lore) { int y; textblock *tb; assert(race && lore); /* Erase the window, since textui_textblock_place() only clears what it * needs */ for (y = 0; y < Term->hgt; y++) Term_erase(0, y, 255); tb = textblock_new(); lore_description(tb, race, lore, FALSE); textui_textblock_place(tb, SCREEN_REGION, NULL); textblock_free(tb); }
static void display_area(const char *text, const byte *attrs, size_t *line_starts, size_t *line_lengths, size_t n_lines, region area, size_t line_from) { size_t i, j; n_lines = MIN(n_lines, (size_t) area.page_rows); for (i = 0; i < n_lines; i++) { Term_erase(area.col, area.row + i, area.width); for (j = 0; j < line_lengths[line_from + i]; j++) { Term_putch(area.col + j, area.row + i, attrs[line_starts[line_from + i] + j], text[line_starts[line_from + i] + j]); } } }
/* * Hack -- Display the "name" and "attr/chars" of a monster race */ static void roff_top(int r_idx) { monster_race *r_ptr = &r_info[r_idx]; byte a1, a2; char c1, c2; /* Get the chars */ c1 = r_ptr->d_char; c2 = r_ptr->x_char; /* Get the attrs */ a1 = r_ptr->d_attr; a2 = r_ptr->x_attr; /* Clear the top line */ Term_erase(0, 0, 255); /* Reset the cursor */ Term_gotoxy(0, 0); /* A title (use "The" for non-uniques) */ if (!(r_ptr->flags1 & RF1_UNIQUE)) { Term_addstr(-1, TERM_WHITE, "The "); } /* Dump the name */ Term_addstr(-1, TERM_WHITE, (r_name + r_ptr->name)); /* Append the "standard" attr/char info */ Term_addstr(-1, TERM_WHITE, " ('"); Term_addch(a1, c1); Term_addstr(-1, TERM_WHITE, "')"); /* Append the "optional" attr/char info */ Term_addstr(-1, TERM_WHITE, "/('"); Term_addch(a2, c2); if (use_bigtile && (a2 & 0x80)) Term_addch(255, -1); Term_addstr(-1, TERM_WHITE, "'):"); }
/* * Hack -- describe the given monster race at the top of the screen */ void screen_roff(const int r_idx, const monster_lore *l_ptr) { monster_race *r_ptr = &r_info[r_idx]; /* Flush messages */ message_flush(); /* Begin recall */ Term_erase(0, 1, 255); /* Output to the screen */ text_out_hook = text_out_to_screen; /* Recall monster */ describe_monster_race(r_ptr, l_ptr, FALSE); /* Describe monster */ roff_top(r_idx, 0); }
/* * Hack -- display recent messages in sub-windows * * XXX XXX XXX Adjust for width and split messages */ void fix_message(void) { s32b j, i; s32b w, h; s32b x, y; /* Scan windows */ for (j = 0; j < 8; j++) { term *old = Term; /* No window */ if (!angband_term[j]) continue; /* No relevant flags */ if (!flag_exists(&window_flag[j], FLAG_PW_MESSAGE)) continue; /* Activate */ Term_activate(angband_term[j]); /* Get size */ Term_get_size(&w, &h); /* Dump messages */ for (i = 0; i < h; i++) { /* Dump the message on the appropriate line */ display_message(0, (h - 1) - i, strlen(message_str((s16b)i)), message_color((s16b)i), message_str((s16b)i)); /* Cursor */ Term_locate(&x, &y); /* Clear to end of line */ Term_erase(x, y, 255); } /* Fresh */ Term_fresh(); /* Restore */ Term_activate(old); } }
/* * Display glyph and colours */ static void display_glyphs(int col, int row, int height, int width, byte a, wchar_t c) { int i; int x, y; /* Clear the display lines */ for (i = 0; i < height; i++) Term_erase(col, row + i, width); /* Prompt */ prt("Choose colour:", row + height / 2, col); Term_locate(&x, &y); for (i = 0; i < MAX_COLORS; i++) big_pad(x + i, y, i, c); /* Place the cursor */ Term_gotoxy(x + a, y); }
/** * Redraw the "monster health bar" * * The "monster health bar" provides visual feedback on the "health" * of the monster currently being "tracked". There are several ways * to "track" a monster, including targetting it, attacking it, and * affecting it (and nobody else) with a ranged attack. When nothing * is being tracked, we clear the health bar. If the monster being * tracked is not currently visible, a special health bar is shown. */ static void prt_health(int row, int col) { byte attr = monster_health_attr(); /* Not tracking */ if (!p_ptr->health_who) { /* Erase the health bar */ Term_erase(col, row, 12); } /* Tracking an unseen, hallucinatory, or dead monster */ else if ((!m_list[p_ptr->health_who].ml) || /* Unseen */ (p_ptr->timed[TMD_IMAGE]) || /* Hallucination */ (m_list[p_ptr->health_who].hp < 0)) { /* Dead (?) */ /* The monster health is "unknown" */ Term_putstr(col, row, 12, attr, "[----------]"); } /* Tracking a visible monster */ else { int pct, len; monster_type *m_ptr = &m_list[p_ptr->health_who]; /* Extract the "percent" of health */ pct = 100L * m_ptr->hp / m_ptr->maxhp; /* Convert percent into "health" */ len = (pct < 10) ? 1 : (pct < 90) ? (pct / 10 + 1) : 10; /* Default to "unknown" */ Term_putstr(col, row, 12, TERM_WHITE, "[----------]"); /* Dump the current "health" (handle monster stunning, confusion) */ if (m_ptr->confused) Term_putstr(col + 1, row, len, attr, "cccccccccc"); else if (m_ptr->stunned) Term_putstr(col + 1, row, len, attr, "ssssssssss"); else Term_putstr(col + 1, row, len, attr, "**********"); } }
static void _describe_form(int idx, int col_height) { char tmp[80*9]; int i, line; int race_idx = _forms[idx].race; race_t *race_ptr = get_race_t_aux(race_idx, 0); /* 2 lines below list of spells, X lines for description */ for (i = 0; i < 11; i++) Term_erase(12, col_height + i + 2, 255); /* Get the description, and line break it (max X lines) */ roff_to_buf(race_ptr->desc, 80, tmp, sizeof(tmp)); for(i = 0, line = col_height + 3; tmp[i]; i += 1+strlen(&tmp[i])) { prt(&tmp[i], line, 15); line++; } }
/** * Hook function - dump a char_attr line to the screen */ void dump_line_screen(char_attr *this_line) { int x = 0; char_attr xa = this_line[0]; /* Erase the row */ Term_erase(0, dump_row, 255); /* Dump the line */ while (xa.pchar != '\0') { /* Add the char/attr */ Term_addch(xa.pattr, xa.pchar); /* Advance */ xa = this_line[++x]; } /* Next row */ dump_row++; }