DrawQuad() private method

Draws arbitrary quad with specified vertices.
private DrawQuad ( Texture texture, SpriteVertex v0, SpriteVertex v1, SpriteVertex v2, SpriteVertex v3 ) : void
texture Texture
v0 SpriteVertex
v1 SpriteVertex
v2 SpriteVertex
v3 SpriteVertex
return void
Exemplo n.º 1
0
        /*Color EscColor ( char ch ) {
         *      if (ch=='0') return Color.White;
         *      if (ch=='1') return Color.Red;
         *      if (ch=='2') return Color.Orange;
         *      if (ch=='3') return Color.Yellow;
         *      if (ch=='4') return Color.Green;
         *      if (ch=='5') return Color.Cyan;
         *      if (ch=='6') return Color.Blue;
         *      if (ch=='7') return Color.Magenta;
         *      if (ch=='8') return Color.Black;
         *      if (ch=='9') return Color.Gray;
         *      return Color.White;
         * } */


        /// <summary>
        /// Draws the string
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="text"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="color"></param>
        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);
                }
            }
        }
Exemplo n.º 2
0
		/*Color EscColor ( char ch ) {
			if (ch=='0') return Color.White;
			if (ch=='1') return Color.Red;
			if (ch=='2') return Color.Orange;
			if (ch=='3') return Color.Yellow;
			if (ch=='4') return Color.Green;
			if (ch=='5') return Color.Cyan;
			if (ch=='6') return Color.Blue;
			if (ch=='7') return Color.Magenta;
			if (ch=='8') return Color.Black;
			if (ch=='9') return Color.Gray;
			return Color.White;
		} */


		/// <summary>
		/// Draws the string
		/// </summary>
		/// <param name="sb"></param>
		/// <param name="text"></param>
		/// <param name="xPos"></param>
		/// <param name="yPos"></param>
		/// <param name="color"></param>
		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 );
				}

			}
		}