Exemple #1
4
void TextConsoleViewer::view()
{
#ifdef _WIN32
    int topline, leftpos;
    leftpos = topline = 0;
    INPUT_RECORD ir;

    HANDLE hCon  = GetStdHandle(STD_OUTPUT_HANDLE);
    HANDLE hConI = CreateFile("CONIN$", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
    if (hConI == INVALID_HANDLE_VALUE) return;
    SetConsoleMode(hConI, ENABLE_MOUSE_INPUT|ENABLE_WINDOW_INPUT);

    CONSOLE_SCREEN_BUFFER_INFO csbi;

    hCon = CreateConsoleScreenBuffer(GENERIC_WRITE|GENERIC_READ, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0);
    SetConsoleActiveScreenBuffer(hCon);
    GetConsoleScreenBufferInfo(hCon, &csbi);
    CONSOLE_CURSOR_INFO cci;
    cci.dwSize = 100;
    cci.bVisible = FALSE;
    SetConsoleCursorInfo(hCon, &cci);

    CHAR_INFO *buffer = new CHAR_INFO[csbi.dwSize.X * csbi.dwSize.Y];
    bool unc_fault = false;
    do {
        int lline = csbi.dwSize.Y;
        if (topline+lline > textLinesStore->getLineCount()) lline = textLinesStore->getLineCount()-topline;
        baseEditor->visibleTextEvent(topline, lline);

        for(int i = topline; i < topline + csbi.dwSize.Y; i++) {
            int Y = i-topline;

            int li;
            for(li = 0; li < csbi.dwSize.X; li++) {
                buffer[Y*csbi.dwSize.X + li].Char.UnicodeChar = ' ';
                buffer[Y*csbi.dwSize.X + li].Attributes = background;
            };

            if (i >= textLinesStore->getLineCount()) continue;
            DString iLine = textLinesStore->getLine(i);

            for(li = 0; li < csbi.dwSize.X; li++) {
                if (leftpos+li >= iLine.length()) break;
                buffer[Y*csbi.dwSize.X + li].Char.UnicodeChar = iLine[leftpos+li];
                if (unc_fault)
                    buffer[Y*csbi.dwSize.X + li].Char.AsciiChar = Encodings::toChar(encoding, iLine[leftpos+li]);
            };
            for(LineRegion *l1 = baseEditor->getLineRegions(i); l1 != null; l1 = l1->next) {
                if (l1->special || l1->rdef == null) continue;
                int end = l1->end;
                if (end == -1) end = iLine.length();
                int X = l1->start - leftpos;
                int len = end - l1->start;
                if (X < 0) {
                    len += X;
                    X = 0;
                };
                if (len < 0 || X >= csbi.dwSize.X) continue;
                if (len+X > csbi.dwSize.X) len = csbi.dwSize.X-X;
                WORD color = (WORD)(l1->styled()->fore + (l1->styled()->back<<4));
                if (!l1->styled()->bfore) color = (color&0xF0) + (background&0xF);
                if (!l1->styled()->bback) color = (color&0xF) + (background&0xF0);
                for(int li = 0; li < len; li++)
                    buffer[Y*csbi.dwSize.X + X + li].Attributes = color;
            };
        };
        COORD coor;
        coor.X = coor.Y = 0;
        SMALL_RECT sr;
        sr.Left = 0;
        sr.Right = csbi.dwSize.X-1;
        sr.Top = 0;
        sr.Bottom = csbi.dwSize.Y-1;
        if (!unc_fault && !WriteConsoleOutputW(hCon, buffer, csbi.dwSize, coor, &sr)) {
            unc_fault = true;
            continue;
        };
        if (unc_fault) WriteConsoleOutputA(hCon, buffer, csbi.dwSize, coor, &sr);

        // managing the keyboard
        do {
            DWORD tmp;
            ReadConsoleInput(hConI, &ir, 1, &tmp);
            if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) {
                GetConsoleScreenBufferInfo(hCon, &csbi);
                delete[] buffer;
                buffer = new CHAR_INFO[csbi.dwSize.X * csbi.dwSize.Y];
                break;
            };
            if (ir.EventType == MOUSE_EVENT && ir.Event.MouseEvent.dwEventFlags == 0x4) {
                switch(ir.Event.MouseEvent.dwButtonState) {
                case 0x780000:
                    topline-=csbi.dwSize.Y;
                    if (topline < 0) topline = 0;
                    break;
                case 0xFF880000:
                    topline += csbi.dwSize.Y;
                    if (topline > textLinesStore->getLineCount() - csbi.dwSize.Y) topline = textLinesStore->getLineCount() - csbi.dwSize.Y;
                    if (topline < 0) topline = 0;
                    break;
                };
                break;
            };
            if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) {
                // moving view position
                switch(ir.Event.KeyEvent.wVirtualKeyCode) {
                case VK_UP:
                    if (topline) topline--;
                    break;
                case VK_DOWN:
                    if (topline+csbi.dwSize.Y < textLinesStore->getLineCount()) topline++;
                    break;
                case VK_LEFT:
                    leftpos--;
                    if (ir.Event.KeyEvent.dwControlKeyState & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED))
                        leftpos -= 15;
                    if (leftpos < 0) leftpos = 0;
                    break;
                case VK_RIGHT:
                    leftpos++;
                    if (ir.Event.KeyEvent.dwControlKeyState & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED))
                        leftpos += 15;
                    break;
                case VK_PRIOR:
                    topline-=csbi.dwSize.Y;
                    if (topline < 0) topline = 0;
                    break;
                case VK_NEXT:
                case VK_SPACE:
                    topline += csbi.dwSize.Y;
                    if (topline > textLinesStore->getLineCount() - csbi.dwSize.Y) topline = textLinesStore->getLineCount() - csbi.dwSize.Y;
                    if (topline < 0) topline = 0;
                    break;
                case VK_HOME:
                    leftpos = topline = 0;
                    break;
                case VK_END:
                    topline = textLinesStore->getLineCount()-csbi.dwSize.Y;
                    if (topline < 0) topline = 0;
                    leftpos = 0;
                    break;
                };
                break;
            };
        } while(true);
    } while(ir.Event.KeyEvent.wVirtualKeyCode != VK_ESCAPE);

    delete[] buffer;
    SetConsoleActiveScreenBuffer(GetStdHandle(STD_OUTPUT_HANDLE));
    CloseHandle(hCon);

#else

    printf("unix edition doesn't support interactive text viewing\n\n");

    for(int i = 0; i < textLinesStore->getLineCount(); i++) {
        DString line = textLinesStore->getLine(i);
        printf("%s\n", line.getChars());
    };

#endif
};
Exemple #2
0
static void VGA_Poll_Text(void)
{
    char *dat, *old, *p_line;
    unsigned int X, Y;
    CHAR_INFO ch[256]; /* that should suffice for the largest text width */
    COORD siz, off;
    SMALL_RECT dest;
    HANDLE con = VGA_AlphaConsole();
    BOOL linechanged = FALSE; /* video memory area differs from stored copy? */

    /* Synchronize cursor position. */
    off.X = vga_text_x;
    off.Y = vga_text_y;
    SetConsoleCursorPosition(con,off);

    dat = VGA_AlphaBuffer();
    old = vga_text_old; /* pointer to stored video mem copy */
    siz.X = vga_text_width; siz.Y = 1;
    off.X = 0; off.Y = 0;

    /* copy from virtual VGA frame buffer to console */
    for (Y=0; Y<vga_text_height; Y++) {
	linechanged = memcmp(dat, old, vga_text_width*2);
	if (linechanged)
	{
	    /*TRACE("line %d changed\n", Y);*/
	    p_line = dat;
            for (X=0; X<vga_text_width; X++) {
                ch[X].Char.AsciiChar = *p_line++;
                /* WriteConsoleOutputA doesn't like "dead" chars */
                if (ch[X].Char.AsciiChar == '\0')
                    ch[X].Char.AsciiChar = ' ';
                ch[X].Attributes = *p_line++;
            }
            dest.Top=Y; dest.Bottom=Y;
            dest.Left=0; dest.Right=vga_text_width+1;
            WriteConsoleOutputA(con, ch, siz, off, &dest);
	    memcpy(old, dat, vga_text_width*2);
	}
	/* advance to next text line */
	dat += vga_text_width*2;
	old += vga_text_width*2;
    }
}
Exemple #3
0
void GUI::displayGameScreen(const Map& map, bool isWhosTurn, const Chess* ch)
{
	COORD bufferSize{ WINDOW_COLS, WINDOW_LINES };
	COORD characterBufferSize{ WINDOW_COLS, WINDOW_LINES };
	COORD characterPosition{ 0, 0 };
	SMALL_RECT consoleWriteArea{ 0, 0, WINDOW_COLS - 1, WINDOW_LINES - 1 };
	CHAR_INFO consoleBuffer[WINDOW_COLS * WINDOW_LINES];
	SetConsoleScreenBufferSize(hConsole, bufferSize);
	for (int y = 0; y < WINDOW_LINES; ++y) {
		for (int x = 0; x < WINDOW_COLS; ++x) {
			consoleBuffer[x + WINDOW_COLS * y].Char.AsciiChar = gameScreen[y][x];
			consoleBuffer[x + WINDOW_COLS * y].Attributes = DEFAULT_COLOR;
		}
	}
	WriteConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
	displayChessboard(map);
	displayBattleSituation(map);
	displayGameInfo(isWhosTurn, map, ch);
}
Exemple #4
0
		void print(int color,int option) {
			char* options[5] = { "ֲש₪H¹Cְ¸", "¹q¸£¹ן¾װ", "³]©wֳר«׳", "¡@ֳצ©ף¡@", "°h¥X¹Cְ¸" };
			SetConsoleScreenBufferSize(hConsole, bufferSize);
			for (int y = 0; y < WINDOW_LINES; ++y) {
				for (int x = 0; x < WINDOW_COLS; ++x) {
					consoleBuffer[x + WINDOW_COLS * y].Char.AsciiChar = mainMenuScreen[y][x];
					consoleBuffer[x + WINDOW_COLS * y].Attributes = (((y / 2 + x + color) / 20) % 6 + 1);
			}}
			for (int y = 13; y <= 21; ++y) {
				if (y % 2 == 0)continue;
				for (int x = 53; x <= 60; ++x) {
					consoleBuffer[x + WINDOW_COLS * y].Char.AsciiChar = options[(y - 13) / 2][x - 53];
					consoleBuffer[x + WINDOW_COLS * y].Attributes = 7;
					if (((y - 13) / 2) + 1 == option)
						consoleBuffer[x + WINDOW_COLS * y].Attributes = 112;
				}
			}
			WriteConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
		}
Exemple #5
0
void clib::close_window(clibwindow* wnd)
{
    _COORD		w_sz;
    _COORD		w_p;
    _SMALL_RECT w_b;
    w_p.X		= 0;
    w_p.Y		= 0;
    w_sz.X		= wnd->data_[2];
    w_sz.Y		= wnd->data_[3];
    w_b.Left	= wnd->data_[0];
    w_b.Top		= wnd->data_[1];
    w_b.Right	= wnd->data_[0] + wnd->data_[2]-1;
    w_b.Bottom	= wnd->data_[1] + wnd->data_[3]-1;
    //if(!WriteConsoleOutputA(screen_, (_CHAR_INFO*)_window_buffer_, w_sz, w_p, &w_b))
    if(!WriteConsoleOutputA(screen_, (_CHAR_INFO*)wnd->buffer_, w_sz, w_p, &w_b))
    {
        char eb[1024];
        sprintf_s(eb,1024,"WriteConsoleOutputA failed!\n\nError Code: %d",GetLastError());
        ::MessageBox(0,eb,"Error",MB_OK|MB_ICONEXCLAMATION);
    }

    delete wnd;
}
Exemple #6
0
void GUI::displayPossiblePath(Chess* ch, const Map& map)
{
	COORD bufferSize = { 34, 21 };
	COORD characterBufferSize = { 34, 21 };
	COORD characterPosition = { 0, 0 };
	SMALL_RECT consoleWriteArea = { CHESS_BOARD_X, CHESS_BOARD_Y, CHESS_BOARD_X + 34 - 1, CHESS_BOARD_Y + 21 - 1 };
	CHAR_INFO consoleBuffer[34 * 21];
	SetConsoleScreenBufferSize(hConsole, bufferSize);
	for (int y = 0; y < (21); ++y) {
		for (int x = 0; x < 34; ++x) {
			consoleBuffer[x + 34 * y].Attributes = ((y == 0 || y == 20) ? WD_Purple_BG_WHITE : WD_BLACK_BG_WHITE);
			consoleBuffer[x + 34 * y].Char.AsciiChar = ChessScreenChar[y][x];
		}
	}
	for (int x = 0; x < ROW_SIZE; x++)
		for (int y = 0; y < COLUMN_SIZE; y++)
			if (map.pChess[x][y] != NULL) {
				consoleBuffer[(x * 4) + 34 * (y * 2 + 1)].Attributes = ((map.pChess[x][y]->getColor() == true) ? CHESS_RED : CHESS_BLACK);
				consoleBuffer[(x * 4) + 34 * (y * 2 + 1) + 1].Attributes = ((map.pChess[x][y]->getColor() == true) ? CHESS_RED : CHESS_BLACK);
				consoleBuffer[(x * 4) + 34 * (y * 2 + 1)].Char.AsciiChar = map.pChess[x][y]->getName().at(0);
				consoleBuffer[(x * 4) + 34 * (y * 2 + 1) + 1].Char.AsciiChar = map.pChess[x][y]->getName().at(1);
			}
	for (unsigned int i = 0; i < ch->access.size(); i++)
	{
		int x = ch->access.at(i).X;
		int y = ch->access.at(i).Y;
		Chess *tempch = map.pChess[ch->access.at(i).X][ch->access.at(i).Y];
		consoleBuffer[(x * 4) + 34 * (y * 2 + 1)].Attributes = (tempch == NULL ? 120 : (tempch->getColor() ? 60 : 48));
		consoleBuffer[(x * 4) + 34 * (y * 2 + 1) + 1].Attributes = (tempch == NULL ? 120 : (tempch->getColor() ? 60 : 48));
		if (tempch != NULL) {
			consoleBuffer[(x * 4) + 34 * (y * 2 + 1)].Char.AsciiChar = tempch->getName().at(0);
			consoleBuffer[(x * 4) + 34 * (y * 2 + 1) + 1].Char.AsciiChar = tempch->getName().at(1);
		}
	}
	WriteConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
}
Exemple #7
0
short GUI::MenuInGame()
{
	COORD bufferSize = { WINDOW_COLS, WINDOW_LINES };
	COORD characterBufferSize = { WINDOW_COLS, WINDOW_LINES };
	COORD characterPosition = { 0, 0 };
	SMALL_RECT consoleWriteArea = { 0, 0, WINDOW_COLS - 1, WINDOW_LINES - 1 };
	CHAR_INFO consoleBuffer[WINDOW_COLS * WINDOW_LINES];
	SetConsoleScreenBufferSize(hConsole, bufferSize);
	ReadConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
	bool decided = false;
	string options[4] = { "ִ~ִע¹Cְ¸", "­«·s¶}©l", "¦^¥D¿ן³ז", "ֲק¶}¹Cְ¸" };
	short option = 1;
	setColor(9);
	gotoxy(MID_X - 6, MID_Y - 5);
	cout << "ש�ששששששששששששששש�"; gotoxy(MID_X - 6, MID_Y - 4);
	cout << "שר              שר"; gotoxy(MID_X - 6, MID_Y - 3);
	cout << "שאשששששששששששששששג"; gotoxy(MID_X - 6, MID_Y - 2);
	cout << "שר              שר"; gotoxy(MID_X - 6, MID_Y - 1);
	cout << "שאשששששששששששששששג"; gotoxy(MID_X - 6, MID_Y);
	cout << "שר              שר"; gotoxy(MID_X - 6, MID_Y + 1);
	cout << "שאשששששששששששששששג"; gotoxy(MID_X - 6, MID_Y + 2);
	cout << "שר              שר"; gotoxy(MID_X - 6, MID_Y + 3);
	cout << "שדשששששששששששששששו";
	setColor(DEFAULT_COLOR);
	CHAR Input;
	while (!decided)
	{
		for (int i = 0; i < 4; i++) {
			gotoxy(MID_X - 1, MID_Y - 4 + 2 * i);
			if (option == (i + 1))
				showTextColor(options[i], 240);
			else
				cout << options[i];
		}
		setVisible(false);
		Input = _getch();
		switch (Input)
		{
		case KB_UP:
			if (option != 1)
				option--;
			else
				option = 4;
			break;
		case KB_DOWN:
			if (option != 4)
				option++;
			else
				option = 1;
			break;
		case KB_ENTER:
			decided = true;
			break;
		case KB_ESC:
			option = 1;
			decided = true;
		default:
			break;
		}
	}
	WriteConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
	return option;
}
Exemple #8
0
void GUI::displayBattleSituation(const Map& map)
{
	const int cols = 26;
	const int lines = BATTLE_SITUATION_LINES + 2;
	COORD bufferSize = { cols, lines };// col = 26, lines = 16
	COORD characterBufferSize = { cols, lines };
	COORD characterPosition = { 0, 0 };
	SMALL_RECT consoleWriteArea = { 2, 1, (78 + cols) - 1, (1 + lines) - 1 };
	CHAR_INFO consoleBuffer[cols * lines];
	SetConsoleScreenBufferSize(hConsole, bufferSize);
	string wall = "שר";
	for (int y = 0; y < lines; ++y)
		for (int x = 0; x < cols; ++x) {
			consoleBuffer[y * cols + x].Char.AsciiChar = '\0';
			consoleBuffer[y * cols + x].Attributes = DEFAULT_COLOR;
			if (x == 0 || x == (cols-2)) {
				consoleBuffer[y * cols + x].Char.AsciiChar = wall.at(0);
				consoleBuffer[y * cols + x + 1].Char.AsciiChar = wall.at(1);
				consoleBuffer[y * cols + x + 1].Attributes = DEFAULT_COLOR;
				x++;
			}
		}

	string title = "ש�שש  ¾װ  ×p  ֵד  ¥�  ששש�";
	string bottom = "שדשששששששששששששששששששששששו";
	for (int x = 0; x < cols; ++x) {
		if (title[x] == '\0')break;
		consoleBuffer[x].Char.AsciiChar = title.at(x);
	}
	const std::string ChineseNum[9] = { "₪@", "₪G", "₪T", "¥|", "₪­", "₪»", "₪C", "₪K", "₪E" };
	const std::string ArabicNum[9] = { "¢°", "¢±", "¢²", "¢³", "¢´", "¢µ", "¢¶", "¢·", "¢¸" };
	int counter = 1;
	bool straight = false;
	int i = 0;
	const std::vector<chessStorage> *it = (map.chessStoragePointerConst());
	if (it->size() > BATTLE_SITUATION_LINES) {
		counter += it->size() - BATTLE_SITUATION_LINES;
		i += it->size() - BATTLE_SITUATION_LINES;
	}
	string line;
	int printer = 1;
	for (; i != map.chessStoragePointerConst()->size(); i++) {
		straight = false;
		bool color = it->at(i).moved->getColor();
		if (counter >= 100)line += " ";
		else if (counter >= 10)line += "  ";
		else if (counter < 10)line += "   ";
		line += std::to_string(counter);
		line += (color ? " ¬ץ¡G" : " ¶ֲ¡G");
		line += it->at(i).moved->getName() + " ";
		line += (color ? ChineseNum[(8 - it->at(i).prePos.X)] : ArabicNum[(it->at(i).prePos.X)]);
		if ((color ? (it->at(i).prePos.Y - it->at(i).Pos.Y) : (it->at(i).Pos.Y - it->at(i).prePos.Y)) > 0) {
			line += " ¶i ";
			if ((it->at(i).prePos.X - it->at(i).Pos.X) == 0) {
				line += (color ? (ChineseNum[(it->at(i).prePos.Y - it->at(i).Pos.Y) - 1]) : (ArabicNum[(it->at(i).Pos.Y - it->at(i).prePos.Y) - 1]));
				straight = true;
			}
		}
		else if ((color ? (it->at(i).Pos.Y - it->at(i).prePos.Y) : -(it->at(i).prePos.Y - it->at(i).Pos.Y)) == 0)
			line += " ¥­ ";
		else {
			line += " °h ";
			if ((it->at(i).prePos.X - it->at(i).Pos.X) == 0) {
				line += (color ? (ChineseNum[(it->at(i).Pos.Y - it->at(i).prePos.Y) - 1]) : (ArabicNum[(it->at(i).prePos.Y - it->at(i).Pos.Y) - 1]));
				straight = true;
			}
		}
		if (!straight)
			line += (color ? (ChineseNum[(8 - it->at(i).Pos.X)]) : (ArabicNum[(it->at(i).Pos.X)]));
		for (int x = 0; x < 26; ++x) {
			if (x == (line.size()))break;
			consoleBuffer[26 * printer + x + 2].Char.AsciiChar = line.at(x);
		}
		consoleBuffer[26 * printer + 7].Attributes = (color ? WD_RED_BG_BLACK : WD_GRAY_BG_BLACK);
		consoleBuffer[26 * printer + 8].Attributes = (color ? WD_RED_BG_BLACK : WD_GRAY_BG_BLACK);
		printer++;
		line.clear();
		counter++;
	}
	for (int x = 0; x < cols; ++x) {
		if (title[x] == '\0')break;
		consoleBuffer[21*cols+x].Char.AsciiChar = bottom.at(x);
	}
	WriteConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
}
// copies this object's buffer to the screen
void Console::DrawBuffer()
{
	COORD zero = {0,0};
	WriteConsoleOutputA(hScreen, bufConsole, size, zero, &screen_area);
}
Exemple #10
0
void Apep::flush() {
    WriteConsoleOutputA(tout, back_buffer, buffSize, start_pos, &consoleSize); 
}