Fusion.Engine.Graphics.SpriteFont.DrawString C# (CSharp) Method

DrawString() public method

Draws the string
public DrawString ( SpriteLayer spriteBatch, string text, float xPos, float yPos, Color color, int frameIndex, float tracking, bool useBaseLine = true, bool flip = false ) : void
spriteBatch SpriteLayer
text string
xPos float
yPos float
color Color
frameIndex int
tracking float
useBaseLine bool
flip bool
return void
		public void DrawString( SpriteLayer spriteBatch, string text, float xPos, float yPos, Color color, int frameIndex=0, float tracking = 0, bool useBaseLine = true, bool flip = false ) 
		{
			if (text==null) {
				return;
			}

			float x, y;

			if (!flip) {
				x = xPos;
				y = yPos;// - fontInfo.baseLine;
				if (useBaseLine) {
					y -= fontInfo.baseLine;
				}
			} else {
				x = yPos;
				y = xPos;// - fontInfo.baseLine;
				if (useBaseLine) {
					x -= fontInfo.baseLine;
				}
			}


			int length = text.Length;

			float w	=	fontTexture.Width;
			float h	=	fontTexture.Height;

			for (int i=0; i<length; i++) {

				char ch0	= text[i];

				if (ch0 == '\n') {
					y += fontInfo.lineHeight;
					x =  xPos;
				}

				char ch1	= (i+1)<length ? text[i+1] : '\0';
				var chi		= GetInfo(ch0);
				var kerning = GetKerning( ch0, ch1 );

				/*if (ch0=='^' && char.IsDigit(ch1)) {
					i++;
					color = EscColor(ch1);
					continue;
				} */

				RectangleF	dstRect = chi.dstRect;
				RectangleF	srcRect = chi.srcRect;

				dstRect.X	+= x;
				dstRect.Y	+= y;
				/*dstRect.Right	+= x;
				dstRect.Bottom  += y;*/
				if (!flip) {
					x += chi.xAdvance;
					x += kerning;
					x += tracking;
				} else {
					x -= chi.xAdvance;
					x -= kerning;
					x -= tracking;
				}

				//spriteBatch.Draw( fontTexture, dstRect, srcRect, color );
				var c = color;// * spriteBatch.ColorMultiplier;

				if (!flip) {
					var v0	=	new SpriteVertex( new Vector3(dstRect.X,                 dstRect.Y                 , 0), c, new Vector2((srcRect.X                ) / w, (srcRect.Y                 ) / h), frameIndex );
					var v1	=	new SpriteVertex( new Vector3(dstRect.X + dstRect.Width, dstRect.Y                 , 0), c, new Vector2((srcRect.X + srcRect.Width) / w, (srcRect.Y                 ) / h), frameIndex );
					var v2	=	new SpriteVertex( new Vector3(dstRect.X + dstRect.Width, dstRect.Y + dstRect.Height, 0), c, new Vector2((srcRect.X + srcRect.Width) / w, (srcRect.Y + srcRect.Height) / h), frameIndex );
					var v3	=	new SpriteVertex( new Vector3(dstRect.X,                 dstRect.Y + dstRect.Height, 0), c, new Vector2((srcRect.X                ) / w, (srcRect.Y + srcRect.Height) / h), frameIndex );
					spriteBatch.DrawQuad( fontTexture, v0, v1, v2, v3 );
				} else {																		                   
					var v0	=	new SpriteVertex( new Vector3(dstRect.Y                 , dstRect.X                , 0), c, new Vector2((srcRect.X                ) / w, (srcRect.Y                 ) / h), frameIndex );
					var v1	=	new SpriteVertex( new Vector3(dstRect.Y                 , dstRect.X - dstRect.Width, 0), c, new Vector2((srcRect.X + srcRect.Width) / w, (srcRect.Y                 ) / h), frameIndex );
					var v2	=	new SpriteVertex( new Vector3(dstRect.Y + dstRect.Height, dstRect.X - dstRect.Width, 0), c, new Vector2((srcRect.X + srcRect.Width) / w, (srcRect.Y + srcRect.Height) / h), frameIndex );
					var v3	=	new SpriteVertex( new Vector3(dstRect.Y + dstRect.Height, dstRect.X                , 0), c, new Vector2((srcRect.X                ) / w, (srcRect.Y + srcRect.Height) / h), frameIndex );
					spriteBatch.DrawQuad( fontTexture, v0, v1, v2, v3 );
				}

			}
		}