void dc_init(void) { if (debug_inited) { return; } debug_inited = TRUE; // Init window settings dc_font = FONT1; row_height = ((Current_font->h) * 3) / 2; // Row/Line height, in pixels col_width = Current_font->w; // Col/Character width, in pixels dc_scroll_x = 0; dc_scroll_y = 0; DCOLS = (gr_screen.max_w / col_width) - 1; // Subtract as needed. Windowed mode has some quirks with the resolution DROWS = (gr_screen.max_h / row_height) - 2; DBCOLS = DCOLS; DBROWS = 2 * DROWS; // Init History dc_history.clear(); dc_history.push_back(""); last_oldcommand = dc_history.begin(); // Init buffers dc_buffer.clear(); dc_buffer.push_back(""); dc_command_buf.reserve(MAX_CLI_LEN); dc_command_buf.clear(); sprintf(dc_title, "FreeSpace Open v%i.%i.%i", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD); dc_printf("Debug console started.\n" ); }
void dc_init(void) { if (debug_inited) { return; } debug_inited = TRUE; // Init window settings dc_font = font::FONT1; row_height = ((fl2i(font::get_current_font()->getHeight())) * 3) / 2; // Row/Line height, in pixels // This assumes that FONT1 is monospaced! gr_get_string_size(&col_width, nullptr, " "); // Col/Character width, in pixels dc_scroll_x = 0; dc_scroll_y = 0; DCOLS = (gr_screen.center_w / col_width) - 1; // Subtract as needed. Windowed mode has some quirks with the resolution DROWS = (gr_screen.center_h / row_height) - 2; DBCOLS = DCOLS; DBROWS = 2 * DROWS; // Init History dc_history.clear(); dc_history.push_back(""); last_oldcommand = dc_history.begin(); // Init buffers dc_buffer.clear(); dc_buffer.push_back(""); dc_command_buf.reserve(MAX_CLI_LEN); dc_command_buf.clear(); sprintf(dc_title, "FreeSpace Open v%i.%i.%i", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD); dc_printf("Debug console started.\n" ); }
void dc_putc(char c) { SCP_string* line_str = &(dc_buffer.back()); SCP_string temp_str; int i; int w; if (c == ' ') { /** * Push c onto the temp_str and get its gr_string width * * If we run out of room on the line, or * If we run out of room on the screen, change c to a '\n' and let subsequent block handle it, * Else, push the space onto the line and bail */ temp_str = *line_str; temp_str.push_back(c); gr_get_string_size(&w, NULL, temp_str.c_str()); if ((temp_str.size() >= DBCOLS) || (w > gr_screen.max_w)) { c = '\n'; } else { lastwhite = temp_str.size(); *line_str = temp_str; return; } } if (c == '\t') { /** * Calculate how many spaces to put in to align tabs, * Append temp_str with the spaces and get its gr_string width * * If we run out of room on the line, or * If we run out of room on the screen, change c to a '\n' and let subsequent block handle it, * Else, copy temp_str onto the line, update the lastwhite index, and bail */ i = DTABS - (line_str->size() % DTABS); temp_str = *line_str; temp_str.append(i, ' '); gr_get_string_size(&w, NULL, temp_str.c_str()); if ((temp_str.size() >= DBCOLS) || (w > gr_screen.max_w)) { c = '\n'; } else { lastwhite = temp_str.size(); *line_str = temp_str; return; } } if (c == '\n') { /** * Trash whatever char happens to be past (DBCOLS - 1), * Push a blank line onto the dc_buffer from the bottom, * Increment the scroller, if needed, * Trash the topmost line(s) in the buffer, * Reset the lastwhite index, * Increment the lastline counter, and finally * bail */ if (line_str->size() > DBCOLS) { line_str->resize(DBCOLS); } dc_buffer.push_back(""); if ((dc_buffer.size() > DROWS) && (dc_scroll_y < SCROLL_Y_MAX)) { dc_scroll_y++; } while (dc_buffer.size() > DBROWS) { dc_buffer.pop_front(); } lastwhite = 0; lastline++; return; } // By this point, c is probably a writable character temp_str = *line_str; temp_str.push_back(c); gr_get_string_size(&w, NULL, temp_str.c_str()); if ((temp_str.size() >= DBCOLS) || (w > gr_screen.max_w)) { /** * Word wrapping * Save the word, clear the line of the word, push new line with the word on it * Update scroll_y, if needed, * Pop off old lines, and finally * Push new character onto the new line */ temp_str = line_str->substr(lastwhite); line_str->resize(lastwhite); dc_buffer.push_back(temp_str); line_str = &dc_buffer.back(); if ((dc_buffer.size() > DROWS) && (dc_scroll_y < SCROLL_Y_MAX)) { dc_scroll_y++; } while (dc_buffer.size() > DBROWS) { dc_buffer.pop_front(); } lastwhite = 0; lastline++; line_str->push_back(c); return; } // Else, just push the char onto the line line_str->push_back(c); }