コード例 #1
0
        protected internal void DrawString(SpriteBatch batch, string cs,
                                           Vector2f local, LColor color, float rotation, Vector2f origin,
                                           Vector2f scale, SpriteEffects spriteEffects)
        {
            pos.Set(0, 0);
            int   flip            = 1;
            float beginningofline = 0f;
            bool  flag            = true;

            if (spriteEffects == SpriteEffects.FlipHorizontally)
            {
                beginningofline = this.Measure(cs).x *scale.x;
                flip            = -1;
            }
            if (spriteEffects == SpriteEffects.FlipVertically)
            {
                pos.y = (this.Measure(cs).y - this.lineSpacing) * scale.y;
            }
            else
            {
                pos.y = 0f;
            }
            pos.x = beginningofline;
            for (int i = 0; i < cs.Length; i++)
            {
                char character = cs[i];
                switch ((int)character)
                {
                case '\r':
                    break;

                case '\n':
                    flag  = true;
                    pos.x = beginningofline;
                    if (spriteEffects == SpriteEffects.FlipVertically)
                    {
                        pos.y -= this.lineSpacing * scale.y;
                    }
                    else
                    {
                        pos.y += this.lineSpacing * scale.y;
                    }
                    break;

                default:
                {
                    int     indexForCharacter = this.CharacterIndex(character);
                    float[] charkerning       = this.kerning[indexForCharacter];
                    if (flag)
                    {
                        charkerning[0] = Math.Max(charkerning[0], 0f);
                    }
                    else
                    {
                        pos.x += (this.spacing * scale.x) * flip;
                    }
                    pos.x += (charkerning[0] * scale.x) * flip;
                    RectBox  rectangle  = this.glyphs[indexForCharacter];
                    RectBox  rectangle2 = this.cropping[indexForCharacter];
                    Vector2f position   = pos.Cpy();
                    position.x += rectangle2.x * scale.x;
                    position.y += rectangle2.y * scale.y;
                    position.AddLocal(local);
                    batch.Draw(this.texture, position, rectangle, color, rotation,
                               origin, scale, spriteEffects);
                    flag   = false;
                    pos.x += ((charkerning[1] + charkerning[2]) * scale.x) * flip;
                    break;
                }
                }
            }
        }