Esempio n. 1
0
        public void SetLargerPhont(Phont larger)
        {
            this.larger            = larger;
            this.largerScaleFactor = (float)larger.sprite.Width / (float)this.sprite.Width;

            this.larger.smaller            = this;
            this.larger.smallerScaleFactor = 1 / this.largerScaleFactor;
        }
Esempio n. 2
0
        public void DrawString(RenderInfo info, string s, Vector2 position, Color color, float scale, float orientation, Vector2 origin, Phont outline, Color outlineColor)
        {
            Sprite spr         = this.sprite;
            float  spriteScale = scale;

            float scaleUp = (info.Renderer == null || info.Renderer.Policy == Renderer.ViewportPolicy.None || info.Renderer.Policy == Renderer.ViewportPolicy.Centered) ? 1 : (PhantomGame.Game.Width / PhantomGame.Game.Resolution.Width);

            //scale up?
            if (scale > scaleUp && larger != null)
            {
                Phont l = this;
                do
                {
                    spriteScale /= l.largerScaleFactor;
                    l            = l.larger;
                } while (spriteScale > scaleUp && l.larger != null);
                spr = l.sprite;
            }

            //scale down?
            if (smaller != null && scale <= this.smallerScaleFactor * scaleUp)
            {
                Phont l = this;
                do
                {
                    spriteScale /= l.smallerScaleFactor;
                    l            = l.smaller;
                } while (l.smaller != null && spriteScale <= l.smallerScaleFactor * scaleUp);
                spr = l.sprite;
            }

            Vector2 u = PhantomUtils.FromAngle(orientation);
            Vector2 p = position;

            p   -= origin.RotateBy(orientation) * scale;
            p.Y += u.X * LineSpacing * 0.5f * scale;
            p.X -= u.Y * LineSpacing * 0.5f * scale;
            float kerningTop    = -1;
            float kerningCenter = -1;
            float kerningBottom = -1;
            float r             = 0;

            for (int i = 0; i < s.Length; i++)
            {
                int index = (int)s[i] - 32;
                if (index == '\r' - 32)
                {
                    continue;
                }
                else if (index == '\n' - 32)
                {
                    kerningTop = -1;
                    p         -= u * r;
                    p.Y       += u.X * LineSpacing * scale;
                    p.X       -= u.Y * LineSpacing * scale;
                    r          = 0;
                }
                else if (index >= 0 && index < 8 * 16)
                {
                    float w;
                    if (index > 0)
                    {
                        if (kerningTop >= 0)
                        {
                            w = Math.Max(Math.Max(kerningTopLeft[index] + kerningTop, kerningCenterLeft[index] + kerningCenter), kerningBottomLeft[index] + kerningBottom);
                        }
                        else
                        {
                            w = Math.Max(Math.Max(kerningTopLeft[index], kerningCenterLeft[index]), kerningBottomLeft[index]);
                        }
                        //draws measure to determin kerning heights
                        //BaseSprites.Rect.RenderFrame(info, 0, p + new Vector2(0, -sprite.Height * 0.5f + kTop), new Vector2(1, 1), 0, Color.White);
                        //BaseSprites.Rect.RenderFrame(info, 0, p + new Vector2(0, -sprite.Height * 0.5f + kBottom), new Vector2(1, 1), 0, Color.White);
                        p += u * w * scale;
                        r += w * scale;
                        outline.sprite.RenderFrame(info, index, p, orientation, scale, outlineColor);
                        spr.RenderFrame(info, index, p, orientation, spriteScale, color);
                        kerningTop    = kerningTopRight[index];
                        kerningCenter = kerningCenterRight[index];
                        kerningBottom = kerningBottomRight[index];
                    }
                    else
                    {
                        p            += u * SpaceWidth * scale;
                        r            += SpaceWidth * scale;
                        kerningBottom = Math.Max(kerningBottom, Math.Max(kerningCenter, kerningTop));
                        kerningCenter = kerningBottom;
                        kerningTop    = kerningBottom;
                    }
                    p += u * CharacterSpacing * scale;
                    r += CharacterSpacing * scale;
                }
            }
        }