Example #1
0
/* Transfers the console to another screen surface, and adjusts size */
int CON_Transfer(ConsoleInformation* console, SDL_Surface* new_outputscreen, SDL_Rect rect) {
	if(!console)
		return 1;

	console->OutputScreen = new_outputscreen;

	return( CON_Resize(console, rect) );
}
Example #2
0
void con_resize(void)
{
#ifdef CONSOLE
    if (!con_initialized)
        con_init_real();

    CON_Font(Console, SMALL_FONT, WHITE_RGBA, 0);
    CON_Resize(Console, 0, 0, SWIDTH, SHEIGHT / 2);
    con_background(CON_BG);
#endif
}
Example #3
0
/*
==================
CON_Input
==================
*/
char *CON_Input(void)
{
	int chr, num_chars = 0;
	static char text[MAX_EDIT_LINE];
	static int lasttime = -1;

	if (!curses_on)
		return CON_Input_tty();

	if (com_ansiColor->modified) {
		CON_Resize();
		com_ansiColor->modified = qfalse;
	}

	if (Com_RealTime(NULL) != lasttime) {
		lasttime = Com_RealTime(NULL);
		CON_UpdateClock();
		num_chars++;
	}

	while (1) {
		chr = getch();
		num_chars++;

		// Special characters
		switch (chr) {
		case ERR:
			if (num_chars > 1) {
				werase(inputwin);
				if (input_field.cursor < input_field.scroll) {
					input_field.scroll = input_field.cursor - INPUT_SCROLL;
					if (input_field.scroll < 0)
						input_field.scroll = 0;
				} else if (input_field.cursor >= input_field.scroll + input_field.widthInChars)
					input_field.scroll = input_field.cursor - input_field.widthInChars + INPUT_SCROLL;
				CON_ColorPrint(inputwin, input_field.buffer + input_field.scroll, qfalse);
#ifdef _WIN32
				wrefresh(inputwin); // If this is not done the cursor moves strangely
#else
				wnoutrefresh(inputwin);
#endif
				CON_UpdateCursor();
				doupdate();
			}
			return NULL;
		case '\n':
		case '\r':
		case KEY_ENTER:
			if (!input_field.buffer[0])
				continue;
			Hist_Add(input_field.buffer);
			strcpy(text, input_field.buffer);
			Field_Clear(&input_field);
			werase(inputwin);
			wnoutrefresh(inputwin);
			CON_UpdateCursor();
			//doupdate();
			Com_Printf(PROMPT "^7%s\n", text);
			return text;
		case '\t':
		case KEY_STAB:
			Field_AutoComplete(&input_field, PROMPT);
			input_field.cursor = strlen(input_field.buffer);
			continue;
		case '\f':
			CON_Resize();
			continue;
		case KEY_LEFT:
			if (input_field.cursor > 0)
				input_field.cursor--;
			continue;
		case KEY_RIGHT:
			if (input_field.cursor < strlen(input_field.buffer))
				input_field.cursor++;
			continue;
		case KEY_UP:
			Q_strncpyz(input_field.buffer, Hist_Prev(), sizeof(input_field.buffer));
			input_field.cursor = strlen(input_field.buffer);
			continue;
		case KEY_DOWN:
			Q_strncpyz(input_field.buffer, Hist_Next(input_field.buffer), sizeof(input_field.buffer));
			input_field.cursor = strlen(input_field.buffer);
			continue;
		case KEY_HOME:
			input_field.cursor = 0;
			continue;
		case KEY_END:
			input_field.cursor = strlen(input_field.buffer);
			continue;
		case KEY_NPAGE:
			if (lastline > scrollline + LOG_LINES) {
				scrollline += LOG_SCROLL;
				if (scrollline + LOG_LINES > lastline)
					scrollline = lastline - LOG_LINES;
				pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1);
				CON_DrawScrollBar();
			}
			continue;
		case KEY_PPAGE:
			if (scrollline > 0) {
				scrollline -= LOG_SCROLL;
				if (scrollline < 0)
					scrollline = 0;
				pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1);
				CON_DrawScrollBar();
			}
			continue;
		case '\b':
		case 127:
		case KEY_BACKSPACE:
			if (input_field.cursor <= 0)
				continue;
			input_field.cursor--;
			// Fall through
		case KEY_DC:
			if (input_field.cursor < strlen(input_field.buffer)) {
				memmove(input_field.buffer + input_field.cursor,
				        input_field.buffer + input_field.cursor + 1,
				        strlen(input_field.buffer) - input_field.cursor);
			}
			continue;
		}

		// Normal characters
		if (chr >= ' ' && chr < 256 && strlen(input_field.buffer) + 1 < sizeof(input_field.buffer)) {
			memmove(input_field.buffer + input_field.cursor + 1,
			        input_field.buffer + input_field.cursor,
			        strlen(input_field.buffer) - input_field.cursor);
			input_field.buffer[input_field.cursor] = chr;
			input_field.cursor++;
		}
	}
}