示例#1
0
void Field::clear()
{
	memset( screenBuffer, ' ', _height * _width );
	unsigned long int written;
	WriteConsoleOutputCharacterA( hOut, screenBuffer, (int)( _height * _width ), { 0, 0 }, &written );
	//delete[] buffer;
}
示例#2
0
static int outputChars(struct current *current, const char *buf, int len)
{
    COORD pos;
    DWORD n;

    pos.Y = (SHORT)current->y;

#ifdef USE_UTF8
    while ( len > 0 ) {
        int c, s;
        wchar_t wc;

        s = utf8_tounicode(buf, &c);

        len -= s;
        buf += s;

        wc = (wchar_t)c;

        pos.X = (SHORT)current->x;

        /* fixed display utf8 character */
        WriteConsoleOutputCharacterW(current->outh, &wc, 1, pos, &n);

        current->x += utf8_width(c);
    }
#else
    pos.X = (SHORT)current->x;

    WriteConsoleOutputCharacterA(current->outh, buf, len, pos, &n);
    current->x += len;
#endif

    return 0;
}
示例#3
0
static void output(const char* str,
                   size_t      len,
                   int         x,
                   int         y)
{
    COORD pos = { (SHORT)x, (SHORT)y };
    WriteConsoleOutputCharacterA(console_out, str, len, pos, 0);
}
示例#4
0
static
VOID
DrawProgressBar(
    IN PPROGRESSBAR Bar)
{
    COORD coPos;
    DWORD Written;
    PROGRESSBAR BarBorder = *Bar;
    CHAR TextBuffer[256];

    /* Draw the progress bar "border" border */
    if (Bar->DoubleEdge)
    {
        BarBorder.Top -= 5;
        BarBorder.Bottom += 2;
        BarBorder.Right += 5;
        BarBorder.Left -= 5;
        DrawThickBorder(&BarBorder);
    }

    /* Draw the progress bar border */
    DrawBorder(Bar);

    /* Display the description text */
    if (Bar->DescriptionText)
        CONSOLE_SetTextXY(Bar->TextTop, Bar->TextRight, Bar->DescriptionText);

    /* Always update and display the progress */
    if (Bar->UpdateProgressProc &&
        Bar->UpdateProgressProc(Bar, TRUE, TextBuffer, ARRAYSIZE(TextBuffer)))
    {
        coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
        coPos.Y = Bar->Top;
        WriteConsoleOutputCharacterA(StdOutput,
                                     TextBuffer,
                                     strlen(TextBuffer),
                                     coPos,
                                     &Written);
    }

    /* Draw the empty bar */
    coPos.X = Bar->Left + 1;
    for (coPos.Y = Bar->Top + 2; coPos.Y <= Bar->Bottom - 1; coPos.Y++)
    {
        FillConsoleOutputAttribute(StdOutput,
                                   Bar->ProgressColour,
                                   Bar->Width - 2,
                                   coPos,
                                   &Written);

        FillConsoleOutputCharacterA(StdOutput,
                                    ' ',
                                    Bar->Width - 2,
                                    coPos,
                                    &Written);
    }
}
示例#5
0
	bool CHaloPrintStream::Write(const std::wstring& str)// str usually has endl appended
	{
		if (str.size() == 0) return true;
		
		bool ready = *(bool*)UlongToPtr(ADDR_CONSOLEREADY);
		if (!ready) {
			std::wcout << str;
			return true;
		}
		// Prepare for writing the string
		HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
		DWORD written = 0;

		CONSOLE_SCREEN_BUFFER_INFO info;
		SHORT oldX = 0; // used to set cursor back to old position

		// Get current console position info
		GetConsoleScreenBufferInfo(hConsole, &info);
		oldX = info.dwCursorPosition.X;

		// Set cursor to start of the last row (where we want to start writing)
		info.dwCursorPosition.X = 0;
		info.dwCursorPosition.Y = 299;
		SetConsoleCursorPosition(hConsole, info.dwCursorPosition);

		FillConsoleOutputCharacterA(hConsole, ' ', 95, info.dwCursorPosition, &written);
		FillConsoleOutputAttribute(hConsole, 7, 95, info.dwCursorPosition, &written);

		// Write the text
		WriteConsoleW(hConsole, str.c_str(), str.size(), &written, NULL);
		//WriteConsoleW(hConsole, L"\n", 1, &written, NULL);

		// Get the current text in the console
		LPBYTE ptr = (LPBYTE)ADDR_CONSOLEINFO;

		if (*ptr != 0) {
			// Build current command input
			std::string formatted = "halo( ";

			formatted += (char*)UlongToPtr(*(DWORD*)ptr + OFFSET_CONSOLETEXT); // current text

			// Rewrite the data to console
			GetConsoleScreenBufferInfo(hConsole, &info);
			FillConsoleOutputCharacterA(hConsole, ' ', 95, info.dwCursorPosition, &written);
			WriteConsoleOutputCharacterA(hConsole, formatted.c_str(), formatted.size(), info.dwCursorPosition, &written);

			// Set the cursor to its old position
			GetConsoleScreenBufferInfo(hConsole, &info);
			info.dwCursorPosition.X = oldX;
			SetConsoleCursorPosition(hConsole, info.dwCursorPosition);
		}
		return true;
	}
示例#6
0
void ConsoleImpl::display(const KG::Ascii::TextSurface& text)
{
    std::vector<char> line(text.cols());
    for (unsigned r = 0; r < text.rows(); ++r) {
        for (unsigned c = 0; c < text.cols(); ++c) {
            assert(KG::Ascii::Symbol(32) <= text(r, c) && text(r, c) <= KG::Ascii::Symbol(127));
            line[c] = text(r, c).charValue();
        }
        COORD xy = { 0, r };
        DWORD written;
        WriteConsoleOutputCharacterA(hndOutput_, &line[0], text.cols(), xy, &written);
    }
}
示例#7
0
static void
con_backspace (void)
{
    HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
    DWORD written = 0;
    // get cursor position
    CONSOLE_SCREEN_BUFFER_INFO info;
    GetConsoleScreenBufferInfo( hout, &info );
    // nudge cursor backwards
    info.dwCursorPosition.X--;
    SetConsoleCursorPosition( hout, info.dwCursorPosition );
    // blank out the last character
    WriteConsoleOutputCharacterA( hout, " ", 1, info.dwCursorPosition, &written );
}
示例#8
0
static void
con_output (char _in)
{
    HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
    DWORD written = 0;
    // get the cursor position
    CONSOLE_SCREEN_BUFFER_INFO info;
    GetConsoleScreenBufferInfo( hout, &info );
    // output this char
    WriteConsoleOutputCharacterA( hout, &_in, 1, info.dwCursorPosition, &written );
    // advance cursor position
    info.dwCursorPosition.X++;
    SetConsoleCursorPosition( hout, info.dwCursorPosition );
}
示例#9
0
文件: console.c 项目: geek-li/flinux
static void backspace(BOOL erase)
{
	if (console->x > 0)
	{
		console->at_right_margin = 0;
		console->x--;
		COORD pos;
		pos.X = console->x;
		pos.Y = console->y + console->top;
		if (erase && console->x)
		{
			DWORD bytes_written;
			WriteConsoleOutputCharacterA(console->out, " ", 1, pos, &bytes_written);
		}
		SetConsoleCursorPosition(console->out, pos);
	}
}
示例#10
0
void Field::run()
{
	//CellNode ***grid2 = new CellNode**[_height];
	//for( size_t i = 0; i < _height; i++ ) {
	//	grid2[i] = new CellNode*[_width];
	//	for( size_t j = 0; j < _width; j++ ) {
	//		CellNode *neightbours[CellNode::NEIGHBOURS_COUNT];

	//		neightbours[0] = ( i>0 && j < _width - 1 ) ? grid2[i - 1][j + 1] : nullptr;
	//		neightbours[1] = nullptr;
	//		neightbours[2] = nullptr;
	//		neightbours[3] = nullptr;
	//		neightbours[4] = nullptr;
	//		neightbours[5] = ( j > 0 ) ? grid2[i][j - 1] : nullptr;
	//		neightbours[6] = ( i > 0 && j > 0 ) ? grid2[i - 1][j - 1] : nullptr;
	//		neightbours[7] = ( i > 0 ) ? grid2[i - 1][j] : nullptr;

	//		grid2[i][j] = new CellNode( neightbours );
	//}
	Field tmp( *this );
	for( size_t i = 0; i < _height; i++ ) {
		for( size_t j = 0; j < _width; j++ ) {
			Cell::State st;
			Cell *tmpCell = tmp.grid[i][j]->getCell();
			Cell *cell = grid[i][j]->getCell();
			tmpCell->recheckState();
			st = tmpCell->getState();
			tmpCell->setState( cell->getState() );
			cell->setState( st );
			screenBuffer[_width*i + j] = cell->getState() ? 0x02 : ' ';
		}
	}
	unsigned long int written;
	WriteConsoleOutputCharacterA( hOut, screenBuffer, (int)( _height * _width ), { 0, 0 }, &written );
	//delete[] buffer;
}
示例#11
0
文件: genlist.c 项目: Strongc/reactos
static
VOID
DrawListEntries(
    PGENERIC_LIST GenericList)
{
    PGENERIC_LIST_ENTRY ListEntry;
    PLIST_ENTRY Entry;
    COORD coPos;
    DWORD Written;
    USHORT Width;

    coPos.X = GenericList->Left + 1;
    coPos.Y = GenericList->Top + 1;
    Width = GenericList->Right - GenericList->Left - 1;

    Entry = GenericList->FirstShown;
    while (Entry != &GenericList->ListHead)
    {
        ListEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry);

        if (coPos.Y == GenericList->Bottom)
            break;
        GenericList->LastShown = Entry;

        FillConsoleOutputAttribute (StdOutput,
                                    (GenericList->CurrentEntry == ListEntry) ?
                                    FOREGROUND_BLUE | BACKGROUND_WHITE :
                                    FOREGROUND_WHITE | BACKGROUND_BLUE,
                                    Width,
                                    coPos,
                                    &Written);

        FillConsoleOutputCharacterA (StdOutput,
                                     ' ',
                                     Width,
                                     coPos,
                                     &Written);

        coPos.X++;
        WriteConsoleOutputCharacterA (StdOutput,
                                      ListEntry->Text,
                                      min (strlen(ListEntry->Text), (SIZE_T)Width - 2),
                                      coPos,
                                      &Written);
        coPos.X--;

        coPos.Y++;
        Entry = Entry->Flink;
    }

    while (coPos.Y < GenericList->Bottom)
    {
        FillConsoleOutputAttribute (StdOutput,
                                    FOREGROUND_WHITE | BACKGROUND_BLUE,
                                    Width,
                                    coPos,
                                    &Written);

        FillConsoleOutputCharacterA (StdOutput,
                                     ' ',
                                     Width,
                                     coPos,
                                     &Written);
        coPos.Y++;
    }
}
示例#12
0
Field::Field( size_t height, size_t width ) :_height( height ), _width( width )
{
	grid = new CellNode**[height];
	for( size_t i = 0; i < _height; i++ ) {
		grid[i] = new CellNode*[_width];
	}
	srand( (int)time( nullptr ) );

	for( size_t i = 0; i < _height; i++ ) {
		for( size_t j = 0; j < _width; j++ ) {
			CellNode *neightbours[CellNode::NEIGHBOURS_COUNT];

			neightbours[0] = ( i>0 && j < _width - 1 ) ? grid[i - 1][j + 1] : nullptr;
			neightbours[1] = nullptr;
			neightbours[2] = nullptr;
			neightbours[3] = nullptr;
			neightbours[4] = nullptr;
			neightbours[5] = ( j > 0 ) ? grid[i][j - 1] : nullptr;
			neightbours[6] = ( i > 0 && j > 0 ) ? grid[i - 1][j - 1] : nullptr;
			neightbours[7] = ( i > 0 ) ? grid[i - 1][j] : nullptr;

			grid[i][j] = new CellNode( neightbours );
			if( rand() % INIT_PART ) {
				grid[i][j]->getCell()->setState( Cell::State::DEAD );
			} else {
				grid[i][j]->getCell()->setState( Cell::State::LIVE );
			}
		}
	}

	hOut = GetStdHandle( STD_OUTPUT_HANDLE );

	CONSOLE_SCREEN_BUFFER_INFO bufInfo;
	GetConsoleScreenBufferInfo( hOut, &bufInfo );

	SMALL_RECT winSize = bufInfo.srWindow;
	winSize.Bottom = winSize.Top + (short)_height - 1;
	winSize.Right = winSize.Left + (short)_width - 1;
	//winSize.Top = 0;
	//winSize.Left = 0;
	SetConsoleWindowInfo( hOut, TRUE, &winSize );
	SetConsoleScreenBufferSize( hOut, { (short)_width, (short)_height } );
	CONSOLE_CURSOR_INFO cursorInfo;
	cursorInfo.bVisible = FALSE;
	cursorInfo.dwSize = 1;
	SetConsoleCursorInfo( hOut, &cursorInfo );

	size_t bufSize = _width * _height;

	memset( screenBuffer = new char[bufSize], ' ', bufSize );
	unsigned long int written;
	WriteConsoleOutputCharacterA( hOut, screenBuffer, (int)bufSize, { 0, 0 }, &written );

	for( size_t i = 0; i < _height; i++ ) {
		for( size_t j = 0; j < _width; j++ ) {
			screenBuffer[_width*i + j] = grid[i][j]->getCell()->getState() == Cell::State::LIVE ? 0x02 : ' ';
		}
	}
	WriteConsoleOutputCharacterA( hOut, screenBuffer, (int)bufSize, { 0, 0 }, &written );
	//delete[] screenBuffer;
}
示例#13
0
VOID
ProgressSetStep(
    IN PPROGRESSBAR Bar,
    IN ULONG Step)
{
    COORD coPos;
    DWORD Written;
    ULONG NewPos;
    CHAR TextBuffer[256];

    if (Step > Bar->StepCount)
        return;

    Bar->CurrentStep = Step;

    /* Update the progress and redraw it if it has changed */
    if (Bar->UpdateProgressProc &&
        Bar->UpdateProgressProc(Bar, FALSE, TextBuffer, ARRAYSIZE(TextBuffer)))
    {
        coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
        coPos.Y = Bar->Top;
        WriteConsoleOutputCharacterA(StdOutput,
                                     TextBuffer,
                                     strlen(TextBuffer),
                                     coPos,
                                     &Written);
    }

    /* Calculate the bar position */
    NewPos = (((Bar->Width - 2) * 2 * Bar->CurrentStep + (Bar->StepCount / 2)) / Bar->StepCount);

    /* Redraw the bar if it has changed */
    if (Bar->Pos != NewPos)
    {
        Bar->Pos = NewPos;

        for (coPos.Y = Bar->Top + 2; coPos.Y <= Bar->Bottom - 1; coPos.Y++)
        {
            coPos.X = Bar->Left + 1;
            FillConsoleOutputCharacterA(StdOutput,
                                        0xDB,
                                        Bar->Pos / 2,
                                        coPos,
                                        &Written);
            coPos.X += Bar->Pos / 2;

            if (NewPos & 1)
            {
                FillConsoleOutputCharacterA(StdOutput,
                                            0xDD,
                                            1,
                                            coPos,
                                            &Written);
                coPos.X++;
            }

            if (coPos.X <= Bar->Right - 1)
            {
                FillConsoleOutputCharacterA(StdOutput,
                                            ' ',
                                            Bar->Right - coPos.X,
                                            coPos,
                                            &Written);
            }
        }
    }
}