Пример #1
0
//
// DrawString
// Draws a string from an Font at position.
//
void Nixin::Canvas::DrawString( const Font& font, const Point& position, const std::string& text, const Colour& tint )
{
	// Store the current position of the character on the screen.
	Point										currentPosition = position;

	// For each character in the given string.
	for( char character : text )
	{
		Rectangle								characterBounds = font.GetCharacterBounds( character );				// Get the character bounds.

		// If it's a space, we just increase the current position along the x axis.
		if( character == ' ' )
		{
			currentPosition.x += font.GetSpacing().x;
			currentPosition.x += font.GetCharacterPadding().x;
		}
		// If it's a new line, we reset the current x position, and decrease the y position by the font spacing.
		else if( character == '\n' )					
		{
			currentPosition.y -= characterBounds.height;
			currentPosition.y -= font.GetSpacing().x;
			currentPosition.y -= font.GetCharacterPadding().y;
			currentPosition.x = position.x;
		}
		// If it's just a normal character, we draw it like any other sprite and add spacing and it's dimensions to the current width.
		else											
		{
            //spriteBuffer.BufferSprite( font.GetCharacterBitmap(), Rectangle( currentPosition, characterBounds.width, characterBounds.height ), Point( 1, 1 ), 0, tint, characterBounds, Point( 0, 0 ), false );
			currentPosition.x += characterBounds.width;
			currentPosition.x += font.GetCharacterPadding().x;
		}
	}
}