static void pane_text_display(void) { int sh_rows, rows; sheet_get_num_rows(&doc.sh, &sh_rows); rows = min(sh_rows - pane.sh_row + 1, pane.rows); /* Draw rows from the sheet. */ console_set_pos(con, 0, 0); pane_row_range_display(0, rows); /* Clear the remaining rows if file is short. */ int i; sysarg_t j; for (i = rows; i < pane.rows; ++i) { console_set_pos(con, 0, i); for (j = 0; j < scr_columns; ++j) putchar(' '); console_flush(con); } pane.rflags |= (REDRAW_STATUS | REDRAW_CARET); pane.rflags &= ~REDRAW_ROW; }
static void waitprompt(void) { console_set_pos(console, 0, console_rows-1); console_set_color(console, COLOR_WHITE, COLOR_BLUE, 0); printf("ENTER/SPACE/PAGE DOWN - next page, " "ESC/Q - quit, C - continue unpaged"); fflush(stdout); console_set_style(console, STYLE_NORMAL); }
/** Set cursor to reflect position of the caret. */ static void pane_caret_display(void) { spt_t caret_pt; coord_t coord; tag_get_pt(&pane.caret_pos, &caret_pt); spt_get_coord(&caret_pt, &coord); console_set_pos(con, coord.column - pane.sh_column, coord.row - pane.sh_row); }
/** Display text in the status line. */ static void status_display(char const *str) { console_set_pos(con, 0, scr_rows - 1); console_set_style(con, STYLE_INVERTED); int pos = -(scr_columns - 3); printf(" %*s ", pos, str); console_flush(con); console_set_style(con, STYLE_NORMAL); pane.rflags |= REDRAW_CARET; }
static int general_setup(void) { int i; maths_setup(); config_setup(); screen_w = cfgnum("screen.width", 800); screen_h = cfgnum("screen.height", 600); if (cfgnum("fullscreen", 0) == 1) displayflags |= SDL_FULLSCREEN; sprite_global.opt_alpha = cfgnum("alpha", 0); i = SDL_Init(SDL_INITFLAGS); assert(i == 0); atexit(atexit_cleanup); SDL_WM_SetCaption(VERSIONSTRING, 0); sprite_global.display = SDL_SetVideoMode(screen_w, screen_h, 0, displayflags); assert(sprite_global.display); SDL_ShowCursor(SDL_DISABLE); if (cfgnum("sound", 0) == 1) { sound_setup(); /* place the ear on the ground, in the center */ sound_move_ear(screen_w / 2, screen_h); } sprite_setup(); text_setup(); console_setup(); console_set_pos(9, 254); console_load_bg(path_to_data("console-bg.png")); sprite_types_setup(); char bg1[255]; char bg2[255]; sprintf(bg1,"data/bg%d.png",screen_w); sprintf(bg2,"data/bgmask%d.png",screen_w); sprite_background_load(bg1, bg2); level_setup(); winds_setup(); return 0; }
/** Display pane status in the status line. */ static void pane_status_display(void) { spt_t caret_pt; coord_t coord; tag_get_pt(&pane.caret_pos, &caret_pt); spt_get_coord(&caret_pt, &coord); const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>"; console_set_pos(con, 0, scr_rows - 1); console_set_style(con, STYLE_INVERTED); int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit Ctrl-S Save " "Ctrl-E Save As", coord.row, coord.column, fname); int pos = scr_columns - 1 - n; printf("%*s", pos, ""); console_flush(con); console_set_style(con, STYLE_NORMAL); pane.rflags |= REDRAW_CARET; }
static void tinput_console_set_lpos(tinput_t *ti, unsigned lpos) { console_set_pos(ti->console, LIN_TO_COL(ti, lpos), LIN_TO_ROW(ti, lpos)); }
static void pane_row_range_display(int r0, int r1) { int i, j, fill; spt_t rb, re, dep, pt; coord_t rbc, rec; char row_buf[ROW_BUF_SIZE]; wchar_t c; size_t pos, size; int s_column; coord_t csel_start, csel_end, ctmp; /* Determine selection start and end. */ tag_get_pt(&pane.sel_start, &pt); spt_get_coord(&pt, &csel_start); tag_get_pt(&pane.caret_pos, &pt); spt_get_coord(&pt, &csel_end); if (coord_cmp(&csel_start, &csel_end) > 0) { ctmp = csel_start; csel_start = csel_end; csel_end = ctmp; } /* Draw rows from the sheet. */ console_set_pos(con, 0, 0); for (i = r0; i < r1; ++i) { /* Starting point for row display */ rbc.row = pane.sh_row + i; rbc.column = pane.sh_column; sheet_get_cell_pt(&doc.sh, &rbc, dir_before, &rb); /* Ending point for row display */ rec.row = pane.sh_row + i; rec.column = pane.sh_column + pane.columns; sheet_get_cell_pt(&doc.sh, &rec, dir_before, &re); /* Copy the text of the row to the buffer. */ sheet_copy_out(&doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep); /* Display text from the buffer. */ if (coord_cmp(&csel_start, &rbc) <= 0 && coord_cmp(&rbc, &csel_end) < 0) { console_flush(con); console_set_style(con, STYLE_SELECTED); console_flush(con); } console_set_pos(con, 0, i); size = str_size(row_buf); pos = 0; s_column = pane.sh_column; while (pos < size) { if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) { console_flush(con); console_set_style(con, STYLE_SELECTED); console_flush(con); } if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { console_flush(con); console_set_style(con, STYLE_NORMAL); console_flush(con); } c = str_decode(row_buf, &pos, size); if (c != '\t') { printf("%lc", (wint_t) c); s_column += 1; } else { fill = 1 + ALIGN_UP(s_column, TAB_WIDTH) - s_column; for (j = 0; j < fill; ++j) putchar(' '); s_column += fill; } } if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { console_flush(con); console_set_style(con, STYLE_NORMAL); console_flush(con); } /* Fill until the end of display area. */ if (str_length(row_buf) < (unsigned) scr_columns) fill = scr_columns - str_length(row_buf); else fill = 0; for (j = 0; j < fill; ++j) putchar(' '); console_flush(con); console_set_style(con, STYLE_NORMAL); } pane.rflags |= REDRAW_CARET; }
/** Ask for a file name. */ static char *filename_prompt(char const *prompt, char const *init_value) { kbd_event_t ev; char *str; wchar_t buffer[INFNAME_MAX_LEN + 1]; int max_len; int nc; bool done; asprintf(&str, "%s: %s", prompt, init_value); status_display(str); console_set_pos(con, 1 + str_length(str), scr_rows - 1); free(str); console_set_style(con, STYLE_INVERTED); max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt)); str_to_wstr(buffer, max_len + 1, init_value); nc = wstr_length(buffer); done = false; while (!done) { console_get_kbd_event(con, &ev); if (ev.type == KEY_PRESS) { /* Handle key press. */ if (((ev.mods & KM_ALT) == 0) && (ev.mods & KM_CTRL) != 0) { ; } else if ((ev.mods & (KM_CTRL | KM_ALT)) == 0) { switch (ev.key) { case KC_ESCAPE: return NULL; case KC_BACKSPACE: if (nc > 0) { putchar('\b'); console_flush(con); --nc; } break; case KC_ENTER: done = true; break; default: if (ev.c >= 32 && nc < max_len) { putchar(ev.c); console_flush(con); buffer[nc++] = ev.c; } break; } } } } buffer[nc] = '\0'; str = wstr_to_astr(buffer); console_set_style(con, STYLE_NORMAL); return str; }
void moveto(sysarg_t r, sysarg_t c) { console_flush(console); console_set_pos(console, c, r); }