static void _display(rect_t r, int options) { doc_ptr doc = doc_alloc(r.cx); _list_spells(doc, options); doc_sync_term(doc, doc_range_all(doc), doc_pos_create(r.x, r.y)); doc_free(doc); }
void msg_line_redraw(void) { doc_sync_term( _msg_line_doc, doc_range_all(_msg_line_doc), doc_pos_create(_msg_line_rect.x, _msg_line_rect.y) ); _msg_line_sync_pos = doc_cursor(_msg_line_doc); }
static void msg_line_sync(void) { doc_sync_term( _msg_line_doc, doc_range_bottom(_msg_line_doc, _msg_line_sync_pos), doc_pos_create(_msg_line_rect.x, _msg_line_rect.y + _msg_line_sync_pos.y) ); _msg_line_sync_pos = doc_cursor(_msg_line_doc); /* inkey(); */ }
static void _display_spells_to_gain(object_type *o_ptr, rect_t r) { doc_ptr doc = doc_alloc(r.cx); int i; int realm = tval2realm(o_ptr->tval); int start_idx = o_ptr->sval * _SPELLS_PER_BOOK; doc_insert(doc, "<style:table>"); doc_printf(doc, "<color:G> %-20.20s Lvl SP Fail Desc</color>\n", "Name"); for (i = start_idx; i < start_idx + _SPELLS_PER_BOOK; i++) _list_spell(doc, realm, i, i - start_idx, _FROM_BOOK); doc_insert(doc, "</style>"); doc_sync_term(doc, doc_range_all(doc), doc_pos_create(r.x, r.y)); doc_free(doc); }
int doc_display_aux(doc_ptr doc, cptr caption, int top, rect_t display) { int rc = _OK; int i; char finder_str[81]; char back_str[81]; int page_size; bool done = FALSE; strcpy(finder_str, ""); page_size = display.cy - 4; if (top < 0) top = 0; if (top > doc->cursor.y - page_size) top = MAX(0, doc->cursor.y - page_size); for (i = 0; i < display.cy; i++) Term_erase(display.x, display.y + i, display.cx); while (!done) { int cmd; Term_erase(display.x, display.y, display.cx); put_str(format("[%s, Line %d/%d]", caption, top, doc->cursor.y), display.y, display.x); doc_sync_term(doc, doc_region_create(0, top, doc->width, top + page_size - 1), doc_pos_create(display.x, display.y + 2)); Term_erase(display.x, display.y + display.cy - 1, display.cx); put_str("[Press ESC to exit. Press ? for help]", display.y + display.cy - 1, display.x); cmd = inkey_special(TRUE); if ('a' <= cmd && cmd <= 'z') { doc_link_ptr link = int_map_find(doc->links, cmd); if (link) { rc = doc_display_help_aux(string_buffer(link->file), string_buffer(link->topic), display); if (rc == _UNWIND) done = TRUE; continue; } } switch (cmd) { case '?': if (!strstr(caption, "helpinfo.txt")) { rc = doc_display_help_aux("helpinfo.txt", NULL, display); if (rc == _UNWIND) done = TRUE; } break; case ESCAPE: done = TRUE; break; case 'q': done = TRUE; rc = _UNWIND; break; case SKEY_TOP: case '7': top = 0; break; case SKEY_BOTTOM: case '1': top = MAX(0, doc->cursor.y - page_size); break; case SKEY_PGUP: case '9': top -= page_size; if (top < 0) top = 0; break; case SKEY_PGDOWN: case '3': top += page_size; if (top > doc->cursor.y - page_size) top = MAX(0, doc->cursor.y - page_size); break; case SKEY_UP: case '8': top--; if (top < 0) top = 0; break; case SKEY_DOWN: case '2': top++; if (top > doc->cursor.y - page_size) top = MAX(0, doc->cursor.y - page_size); break; case '>': { doc_pos_t pos = doc_next_bookmark(doc, doc_pos_create(doc->width - 1, top)); if (doc_pos_is_valid(pos)) { top = pos.y; if (top > doc->cursor.y - page_size) top = MAX(0, doc->cursor.y - page_size); } break; } case '<': { doc_pos_t pos = doc_prev_bookmark(doc, doc_pos_create(0, top)); if (doc_pos_is_valid(pos)) top = pos.y; else top = 0; break; } case '|': { FILE *fp2; char buf[1024]; char name[82]; int cb; int format = DOC_FORMAT_TEXT; strcpy(name, string_buffer(doc->name)); if (!get_string("File name: ", name, 80)) break; path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name); fp2 = my_fopen(buf, "w"); if (!fp2) { msg_format("Failed to open file: %s", buf); break; } cb = strlen(buf); if (cb > 5 && strcmp(buf + cb - 5, ".html") == 0) format = DOC_FORMAT_HTML; else if (cb > 4 && strcmp(buf + cb - 4, ".htm") == 0) format = DOC_FORMAT_HTML; doc_write_file(doc, fp2, format); my_fclose(fp2); msg_format("Created file: %s", buf); msg_print(NULL); break; } case '/': Term_erase(display.x, display.y + display.cy - 1, display.cx); put_str("Find: ", display.y + display.cy - 1, display.x); strcpy(back_str, finder_str); if (askfor(finder_str, 80)) { if (finder_str[0]) { doc_pos_t pos = doc->selection.stop; if (!doc_pos_is_valid(pos)) pos = doc_pos_create(0, top); pos = doc_find_next(doc, finder_str, pos); if (doc_pos_is_valid(pos)) { top = pos.y; if (top > doc->cursor.y - page_size) top = MAX(0, doc->cursor.y - page_size); } } } else strcpy(finder_str, back_str); break; case '\\': Term_erase(display.x, display.y + display.cy - 1, display.cx); put_str("Find: ", display.y + display.cy - 1, display.x); strcpy(back_str, finder_str); if (askfor(finder_str, 80)) { if (finder_str[0]) { doc_pos_t pos = doc->selection.start; if (!doc_pos_is_valid(pos)) pos = doc_pos_create(doc->width, top + page_size); pos = doc_find_prev(doc, finder_str, pos); if (doc_pos_is_valid(pos)) { top = pos.y; if (top > doc->cursor.y - page_size) top = MAX(0, doc->cursor.y - page_size); } } } else strcpy(finder_str, back_str); break; default: { /* BETA: Any unhandled keystroke will navigate to the next topic based upon a comparison of the first letter. This is nice, say, for viewing the Character Sheet and navigating to the various sections */ doc_pos_t pos = doc_next_bookmark_char(doc, doc_pos_create(1, top), cmd); if (!doc_pos_is_valid(pos)) /* wrap */ pos = doc_next_bookmark_char(doc, doc_pos_create(0, 0), cmd); if (doc_pos_is_valid(pos)) { top = pos.y; if (top > doc->cursor.y - page_size) top = MAX(0, doc->cursor.y - page_size); } } } } return rc; }