Пример #1
0
int GUI::showDepthInput()
{
	int depth;
	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);
	setVisible(true);
	setColor(12);
	gotoxy(MID_X - 10, MID_Y - 3);
	cout << "ש�ששששששששששששששששששששששש�"; gotoxy(MID_X - 10, MID_Y - 2);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y - 1);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y);
	cout << "שר"; showTextColor(" ½׀¿י₪J¹q¸£ֳר«׳ (1~9) ", DEFAULT_COLOR); setColor(12); cout << "שר"; gotoxy(MID_X - 10, MID_Y + 1);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y + 2);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y + 3);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y + 4);
	cout << "שדשששששששששששששששששששששששו";
	setColor(DEFAULT_COLOR);
	gotoxy(MID_X - 5, MID_Y + 2);
	depth = _getch();
	WriteConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
	return depth - '0';
}
Пример #2
0
int _conio_gettext(int __left, int __top, int __right, int __bottom, void *__destin)
{
	int i;
	SMALL_RECT r;
	CHAR_INFO* buffer;
	char_info *buf;
	COORD s, c = { 0,0 };
	if (__right<__left || __bottom<__top) return 0;
	init_ti();
	r.Left = __left - 1;
	r.Top = __top - 1;
	r.Right = __right - 1;
	r.Bottom = __bottom - 1;
	s.X = __right - __left + 1;
	s.Y = __bottom - __top + 1;
	buffer = (CHAR_INFO*)malloc(s.X * s.Y * sizeof(CHAR_INFO));
	buf = (char_info *)__destin;
	if (ReadConsoleOutputA(GetStdHandle(STD_OUTPUT_HANDLE), buffer, s, c, &r))
	{
		for (i = 0; i < s.X * s.Y; i++)
		{
			buf[i].letter = buffer[i].Char.AsciiChar;
			buf[i].attr = (unsigned char)buffer[i].Attributes;
		}
	}
	free(buffer);
	return 0;
}
Пример #3
0
void GUI::showAlert(const string info, const short time)
{
	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);
	setVisible(false);
	setColor(12);
	gotoxy(MID_X - 10, MID_Y - 3);
	cout << "ש�ששששששששששששששששששששששש�"; gotoxy(MID_X - 10, MID_Y - 2);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y - 1);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y);
	cout << "שר"; showTextColor(info, DEFAULT_COLOR); setColor(12); cout << "שר"; gotoxy(MID_X - 10, MID_Y + 1);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y + 2);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y + 3);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y + 4);
	cout << "שדשששששששששששששששששששששששו";
	setColor(DEFAULT_COLOR);
	Sleep(time);
	WriteConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
	setVisible(true);
}
void AttachToRLLog::readLatest()
{
    if (consoleConnected) {
        CONSOLE_SCREEN_BUFFER_INFO console_buffer_info = {0};
        if (GetConsoleScreenBufferInfo(hConsole, &console_buffer_info))
        {
            COORD screenBufferSize = console_buffer_info.dwSize;
            COORD curserLoc = console_buffer_info.dwCursorPosition;

            // special case to clear console once curser reaches max screen buffer size
            if (curserLoc.Y == screenBufferSize.Y - 1) {
                COORD topLeft  = { 0, 10 };
                DWORD written;
                FillConsoleOutputCharacterA(
                        hConsole, ' ', screenBufferSize.X * screenBufferSize.Y, topLeft, &written
                    );
                    FillConsoleOutputAttribute(
                        hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE,
                        screenBufferSize.X * screenBufferSize.Y, topLeft, &written
                    );
                    SetConsoleCursorPosition(hConsole, topLeft);
                    curserLoc =  topLeft;
                    linesRead = 9;
            }

            // begin actually reading lines
            int readToLine = curserLoc.Y;
            int readFromLine = linesRead;
            int linesToReadNow = readToLine - readFromLine;
            if (linesToReadNow > 0) {
                CHAR_INFO buffer[screenBufferSize.X * linesToReadNow];
                COORD buffer_size  = { screenBufferSize.X, linesToReadNow};
                COORD buffer_index = { 0, 0 };
                SMALL_RECT read_region = { 0, readFromLine, screenBufferSize.X - 1, readToLine};

                if (!ReadConsoleOutputA(hConsole, buffer, buffer_size, buffer_index, &read_region)) {
                    std::cout << "Error reading console output " << GetLastError() << std::endl;
                }
                // iterate lines
                for (int i = 0; i < linesToReadNow; i++) {
                    std::string line = "";
                    // iterate characters in line
                    for (int j = 0; j < screenBufferSize.X - 1; j++) {
                        line+= buffer[i * screenBufferSize.X + j].Char.AsciiChar;
                    }
                    //std::cout << line << std::endl;
                    emit newLineFound(line);
                }

            linesRead = readToLine;
            }


        } else {
            std::wcout << L"Could not get ScreenBufferInfo, last error: " << GetLastError() << std::endl;
        }
    }
}
Пример #5
0
bool GUI::showConfirm(const string& info)
{
	/* A COORD struct for specificying the console's screen buffer dimensions */
	COORD bufferSize = { WINDOW_COLS, WINDOW_LINES };

	/* Setting up different variables for passing to WriteConsoleOutput */
	COORD characterBufferSize = { WINDOW_COLS, WINDOW_LINES };
	COORD characterPosition = { 0, 0 };
	SMALL_RECT consoleWriteArea = { 0, 0, WINDOW_COLS - 1, WINDOW_LINES - 1 };

	/* A CHAR_INFO structure containing data about a single character */
	CHAR_INFO consoleBuffer[WINDOW_COLS * WINDOW_LINES];

	/* Set the screen's buffer size */
	SetConsoleScreenBufferSize(hConsole, bufferSize);

	/* Write our character buffer (a single character currently) to the console buffer */
	ReadConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
	setVisible(false);
	bool point = false;
	setColor(12);
	gotoxy(MID_X - 10, MID_Y - 3);
	cout << "ש�ששששששששששששששששששששששש�"; gotoxy(MID_X - 10, MID_Y - 2);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y - 1);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y);
	cout << "שר"; showTextColor(info, DEFAULT_COLOR); setColor(12); cout << "שר"; gotoxy(MID_X - 10, MID_Y + 1);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y + 2);
	cout << "שר     ¬O        §_     שר"; gotoxy(MID_X - 10, MID_Y + 3);
	cout << "שר                      שר"; gotoxy(MID_X - 10, MID_Y + 4);
	cout << "שדשששששששששששששששששששששששו";
	char KB;
	while (true)
	{
		gotoxy(MID_X - 4, MID_Y + 2); 
		showTextColor("¬O", !point ? 15 : 240);
		gotoxy(MID_X + 6, MID_Y + 2);
		showTextColor("§_", point ? 15 : 240);
		KB = _getch();
		switch (KB)
		{
		case KB_LEFT:
		case KB_RIGHT:
			point = !point;
			break;
		case KB_ENTER:
			WriteConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
			return point;
			break;
		default:
			break;
		}
	}
	WriteConsoleOutputA(hConsole, consoleBuffer, characterBufferSize, characterPosition, &consoleWriteArea);
	return point;
}
		void refresh()   {
			sync();
			// refresh window
			COORD size = { short(_width),short(_height) };
			COORD pos = { 0,0 };
			SMALL_RECT rect = { 0, 0, short(_width - 1), short(_height - 1) };
			ReadConsoleOutputA(_handle, _screen_buffer.data(), size, pos, &rect);
			rect.Left = _x;
			rect.Right = _x + _width;
			rect.Top = _y;
			rect.Bottom = _y + _height;
			WriteConsoleOutputA(GetStdHandle(STD_OUTPUT_HANDLE), _screen_buffer.data(), size, pos, &rect);
		}
Пример #7
0
clibwindow* clib::open_window_noframe(int x, int y, int w, int h, unsigned short bgc, unsigned short fgc)
{
    // before drawing the window, we save the contents of the screen
    // where the window will be drawn so that we can redraw the screen
    // when the window is closed.
    clibwindow* wnd = new clibwindow(x, y, w, h);

    _COORD		w_sz;
    _COORD		w_p;
    _SMALL_RECT w_b;
    w_p.X		= 0;
    w_p.Y		= 0;
    w_sz.X		= w;
    w_sz.Y		= h;
    w_b.Left	= x;
    w_b.Top		= y;
    w_b.Right	= x + w-1;
    w_b.Bottom	= y + h-1;

    //if(!ReadConsoleOutputA(screen_, (_CHAR_INFO*)_window_buffer_, w_sz, w_p, &w_b))
    if(!ReadConsoleOutputA(screen_, (_CHAR_INFO*)wnd->buffer_, w_sz, w_p, &w_b))
    {
        char eb[1024];
        sprintf_s(eb,1024,"ReadConsoleOutputA failed!\n\nError Code: %d",GetLastError());
        ::MessageBox(0,eb,"Error",MB_OK|MB_ICONEXCLAMATION);
    }

    this->set_bgcolor(bgc);
    this->set_fgcolor(fgc);

    for (int cy = 0; cy < h; cy++)
    {
        for (int cx = 0; cx < w; cx++)
        {
            this->outchar(x + cx, y + cy, ' ');
        }
    }

    // return the saved window
    return wnd;
}
Пример #8
0
BOOL WINAPI Console::ReadConsoleOutput_Unicode(CHAR_INFO* buffer,
				      COORD size, COORD pos, SMALL_RECT *sr)
{
    if(!ReadConsoleOutputA(gStdOut, buffer, size, pos, sr))
        return(FALSE);

    CHAR_INFO* s = buffer;
    CHAR_INFO* e = buffer + (size.X * size.Y);
    DWORD	codepage = GetConsoleOutputCP();
    BYTE	ch[2];
    WCHAR	wch;

    while(s < e) {
        ch[0] = s->Char.AsciiChar;

        if(s->Attributes & COMMON_LVB_LEADING_BYTE) {
            if((s+1) < e && ((s+1)->Attributes & COMMON_LVB_TRAILING_BYTE)) {
                ch[1] = (s+1)->Char.AsciiChar;
                if(MultiByteToWideChar(codepage, 0, (LPCSTR)ch, 2, &wch, 1)) {
                    s->Char.UnicodeChar = wch;
                    s++;
                    s->Char.UnicodeChar = wch;
                    s++;
                    continue;
                }
            }
        }

        if(MultiByteToWideChar(codepage, 0, (LPCSTR)ch, 1, &wch, 1)) {
            s->Char.UnicodeChar = wch;
        }
        s->Attributes &= ~(COMMON_LVB_LEADING_BYTE | COMMON_LVB_TRAILING_BYTE);
        s++;
    }
    return(TRUE);
}
Пример #9
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;
}
Пример #10
0
//////////////////////////////////////
// new gui methods
clibwindow* clib::open_window(int x, int y, int w, int h, unsigned short bgc, unsigned short fgc)
{
    // before drawing the window, we save the contents of the screen
    // where the window will be drawn so that we can redraw the screen
    // when the window is closed.
    clibwindow* wnd = new clibwindow(x, y, w, h);

    _COORD		w_sz;
    _COORD		w_p;
    _SMALL_RECT w_b;
    w_p.X		= 0;
    w_p.Y		= 0;
    w_sz.X		= w;
    w_sz.Y		= h;
    w_b.Left	= x;
    w_b.Top		= y;
    w_b.Right	= x + w-1;
    w_b.Bottom	= y + h-1;

    //if(!ReadConsoleOutputA(screen_, (_CHAR_INFO*)_window_buffer_, w_sz, w_p, &w_b))
    if(!ReadConsoleOutputA(screen_, (_CHAR_INFO*)wnd->buffer_, w_sz, w_p, &w_b))
    {
        char eb[1024];
        sprintf_s(eb,1024,"ReadConsoleOutputA failed!\n\nError Code: %d",GetLastError());
        ::MessageBox(0,eb,"Error",MB_OK|MB_ICONEXCLAMATION);
    }


    // draw the window
    //this->set_bgcolor(4);		// blue background
    //this->set_fgcolor(1|2|4|8); // bright white foreground

    this->set_bgcolor(bgc);
    this->set_fgcolor(fgc);

    for (int cy = 1; cy < h - 1; cy++)
    {
        for (int cx = 1; cx < w - 1; cx++)
        {
            this->outchar(x+cx, y+cy, ' ');
        }
    }

    // draw top and bottom edge
    {   for (int cx = 0; cx < w; cx++)
        {
            this->outchar(x+cx, y, (char)205);
            this->outchar(x+cx, y+(h-1), (char)205);
        }
    }

    // draw left and right edge
    {   for (int cy = 0; cy < h; cy++)
        {
            this->outchar(x, y+cy, (char)186);
            this->outchar(x+(w-1), y+cy, (char)186);
        }
    }

    // draw corners
    this->outchar(x, y, (char)201);
    this->outchar(x, y+(h-1), (char)200);
    this->outchar(x+(w-1), y, (char)187);
    this->outchar(x+(w-1), y+(h-1), (char)188);

    // return the saved window
    return wnd;
}