Beispiel #1
0
	void Console::MoveCursorBy( const int x_inc, const int y_inc, bool wrap )
	{
		GetConsoleScreenBufferInfo(mConsoleHandle, &mConsoleInfo);
		COORD current_position = mConsoleInfo.dwCursorPosition;
		int new_x = current_position.X + x_inc;
		int new_y = current_position.Y + y_inc;

		if(wrap)
		{
			while(new_x < 0)
			{
				new_x = mConsoleInfo.dwSize.X + new_x;
			}
			while(new_y < 0)
			{
				new_y = mConsoleInfo.dwSize.Y + new_y;
			}
			new_x %= mConsoleInfo.dwSize.X;
			new_y %= mConsoleInfo.dwSize.Y;
		}	
		else
		{
			if(new_x > mConsoleInfo.dwSize.X) { new_x = mConsoleInfo.dwSize.X; }
			if(new_y > mConsoleInfo.dwSize.Y) { new_y = mConsoleInfo.dwSize.Y; }
			if(new_x < 0 ) { new_x = 0; }
			if(new_y < 0) { new_y = 0; }
		}
		MoveCursorTo(new_x, new_y);
	}
Beispiel #2
0
	void Console::Clear( const int bg_colour )
	{
		assert((bg_colour >= 0 && bg_colour < 16) || bg_colour == -1);

		// Number of cells in current buffer
		int console_size = mConsoleInfo.dwSize.X * mConsoleInfo.dwSize.Y;

		if(bg_colour != -1)	SetBackgroundColour(bg_colour);

		DWORD cCharsWritten;
		COORD coordScreen = { 0, 0 };
		GetConsoleScreenBufferInfo(mConsoleHandle, &mConsoleInfo);
		// 		Fill screen with blanks
		FillConsoleOutputCharacter( mConsoleHandle, (TCHAR) ' ',
			console_size, coordScreen, &cCharsWritten );
		// Set buffer attributes
		FillConsoleOutputAttribute( mConsoleHandle, mConsoleInfo.wAttributes,
			console_size, coordScreen, &cCharsWritten );

		MoveCursorTo(0,0);
	}
Beispiel #3
0
void SimpleConsole::MoveCursor()
{
	MoveCursorTo( cursorX, cursorY );
	memcpyw( video + cursorY * width, buffer+ cursorY * width , width);	//刷新光标所在项
}
Beispiel #4
0
	void Console::Print( const int x, const int y, const std::string& text )
	{
		MoveCursorTo(x, y);
		cout << text;
	}