Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="v0"></param>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <param name="v3"></param>
        void PushQuad(ShaderResource texture, SpriteVertex v0, SpriteVertex v1, SpriteVertex v2, SpriteVertex v3)
        {
            if (vertexPointer > MaxVertices - 4)
            {
                FlushQueue();
            }

            /*Marshal.StructureToPtr( v0, mappedVertexBuffer.DataPointer, false );	mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;
             * Marshal.StructureToPtr( v1, mappedVertexBuffer.DataPointer, false );	mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;
             * Marshal.StructureToPtr( v2, mappedVertexBuffer.DataPointer, false );	mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;
             *
             * Marshal.StructureToPtr( v0, mappedVertexBuffer.DataPointer, false );     mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;
             * Marshal.StructureToPtr( v2, mappedVertexBuffer.DataPointer, false );     mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;
             * Marshal.StructureToPtr( v3, mappedVertexBuffer.DataPointer, false );     mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;*/

            int num = vertexPointer;

            vertices[vertexPointer] = v0;         vertexPointer++;
            vertices[vertexPointer] = v1;         vertexPointer++;
            vertices[vertexPointer] = v2;         vertexPointer++;
            vertices[vertexPointer] = v3;         vertexPointer++;


            if (!batches.Any())
            {
                batches.Add(new Batch(texture, num / 4 * 6, 6));
            }
            else
            {
                var last = batches.Last();

                if (last.texture == texture)
                {
                    last.num += 6;
                }
                else
                {
                    batches.Add(new Batch(texture, num / 4 * 6, 6));
                }
            }
        }
Пример #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(SpriteBatch spriteBatch, string text, float xPos, float yPos, Color color, float tracking = 0, bool bl = true, bool flip = false)
        {
            if (text == null)
            {
                return;
            }

            float x, y;

            if (!flip)
            {
                x = xPos;
                y = yPos;                // - fontInfo.baseLine;
                if (bl)
                {
                    y -= fontInfo.baseLine;
                }
            }
            else
            {
                x = yPos;
                y = xPos;                // - fontInfo.baseLine;
                if (bl)
                {
                    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));
                    var v1 = new SpriteVertex(new Vector3(dstRect.X + dstRect.Width, dstRect.Y, 0), c, new Vector2((srcRect.X + srcRect.Width) / w, (srcRect.Y) / h));
                    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));
                    var v3 = new SpriteVertex(new Vector3(dstRect.X, dstRect.Y + dstRect.Height, 0), c, new Vector2((srcRect.X) / w, (srcRect.Y + srcRect.Height) / h));
                    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));
                    var v1 = new SpriteVertex(new Vector3(dstRect.Y, dstRect.X - dstRect.Width, 0), c, new Vector2((srcRect.X + srcRect.Width) / w, (srcRect.Y) / h));
                    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));
                    var v3 = new SpriteVertex(new Vector3(dstRect.Y + dstRect.Height, dstRect.X, 0), c, new Vector2((srcRect.X) / w, (srcRect.Y + srcRect.Height) / h));
                    spriteBatch.DrawQuad(fontTexture, v0, v1, v2, v3);
                }
            }
        }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="texture"></param>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <param name="v2"></param>
 /// <param name="v3"></param>
 public void DrawQuad(ShaderResource texture, SpriteVertex v0, SpriteVertex v1, SpriteVertex v2, SpriteVertex v3)
 {
     PushQuad(texture, v0, v1, v2, v3);
 }
Пример #4
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( SpriteBatch spriteBatch, string text, float xPos, float yPos, Color color, float tracking = 0, bool bl = true, bool flip = false )
        {
            if (text==null) {
                return;
            }

            float x, y;

            if (!flip) {
                x = xPos;
                y = yPos;// - fontInfo.baseLine;
                if (bl) {
                    y -= fontInfo.baseLine;
                }
            } else {
                x = yPos;
                y = xPos;// - fontInfo.baseLine;
                if (bl) {
                    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) );
                    var v1	=	new SpriteVertex( new Vector3(dstRect.X + dstRect.Width, dstRect.Y                 , 0), c, new Vector2((srcRect.X + srcRect.Width) / w, (srcRect.Y                 ) / h) );
                    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) );
                    var v3	=	new SpriteVertex( new Vector3(dstRect.X,                 dstRect.Y + dstRect.Height, 0), c, new Vector2((srcRect.X                ) / w, (srcRect.Y + srcRect.Height) / h) );
                    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) );
                    var v1	=	new SpriteVertex( new Vector3(dstRect.Y                 , dstRect.X - dstRect.Width, 0), c, new Vector2((srcRect.X + srcRect.Width) / w, (srcRect.Y                 ) / h) );
                    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) );
                    var v3	=	new SpriteVertex( new Vector3(dstRect.Y + dstRect.Height, dstRect.X                , 0), c, new Vector2((srcRect.X                ) / w, (srcRect.Y + srcRect.Height) / h) );
                    spriteBatch.DrawQuad( fontTexture, v0, v1, v2, v3 );
                }

            }
        }
Пример #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="v0"></param>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <param name="v3"></param>
        void PushQuad( ShaderResource texture, SpriteVertex v0, SpriteVertex v1, SpriteVertex v2, SpriteVertex v3 )
        {
            if (vertexPointer>MaxVertices-4) {
                FlushQueue();
            }

            /*Marshal.StructureToPtr( v0, mappedVertexBuffer.DataPointer, false );	mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;
            Marshal.StructureToPtr( v1, mappedVertexBuffer.DataPointer, false );	mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;
            Marshal.StructureToPtr( v2, mappedVertexBuffer.DataPointer, false );	mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;

            Marshal.StructureToPtr( v0, mappedVertexBuffer.DataPointer, false ); 	mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;
            Marshal.StructureToPtr( v2, mappedVertexBuffer.DataPointer, false ); 	mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;
            Marshal.StructureToPtr( v3, mappedVertexBuffer.DataPointer, false ); 	mappedVertexBuffer.DataPointer +=	vertexSize;	   vertexCount ++;*/

            int num = vertexPointer;

            vertices[ vertexPointer ] = v0;		vertexPointer++;
            vertices[ vertexPointer ] = v1;		vertexPointer++;
            vertices[ vertexPointer ] = v2;		vertexPointer++;
            vertices[ vertexPointer ] = v3;		vertexPointer++;

            if (!batches.Any()) {
                batches.Add( new Batch( texture, num/4*6, 6 ) );
            } else {
                var last = batches.Last();

                if (last.texture==texture) {
                    last.num += 6;
                } else {
                    batches.Add( new Batch( texture, num/4*6, 6 ) );
                }
            }
        }
Пример #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="texture"></param>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <param name="v2"></param>
 /// <param name="v3"></param>
 public void DrawQuad( ShaderResource texture, SpriteVertex v0, SpriteVertex v1, SpriteVertex v2, SpriteVertex v3 )
 {
     PushQuad( texture, v0, v1, v2, v3 );
 }