예제 #1
0
파일: Font.cs 프로젝트: T0chi/StorygenCC
        private FontText CreateSprite(String Text)
        {
            foreach (FontText Sprite in Sprites)
            {
                if (Sprite.getContent() == Text)
                {
                    return(Sprite);
                }
            }

            String StringId = Convert.ToString(Sprites.Count, 16);
            Image  i        = DrawText(Text);

            i.Save(StoryboardPath + Path + StringId + ".png", System.Drawing.Imaging.ImageFormat.Png);
            FontText s = new FontText(Text, StringId, i.Width, i.Height);

            Sprites.Add(s);
            return(s);
        }
예제 #2
0
파일: Font.cs 프로젝트: T0chi/StorygenCC
        public Sentence WriteSentence(String Text, int Time, Vector2 Position, Origin Origin, Layer Layer, TextAlign Alignment, bool ScaleSprite = true, bool CharByChar = true, double Scale = 480.0 / 1080.0)
        {
            Text = Text.Trim();

            List <Sprite> TextSprites = new List <Sprite>();

            double X = Position.X;
            double Y = Position.Y;

            double SentenceSize = 0;

            if (CharByChar)
            {
                foreach (char c in Text)
                {
                    SentenceSize += c == ' ' ? Scale * Size * 0.35 : Scale *CreateSprite(c.ToString()).getWidth() - Size * Scale * 0.45;
                }
            }
            else
            {
                SentenceSize = Scale * CreateSprite(Text).getWidth() - Size * Scale;
            }

            double XDec = -Size / 10;

            switch (Alignment)
            {
            case TextAlign.Left:
            {
                break;
            }

            case TextAlign.Centre:
            {
                XDec -= SentenceSize / 2;
                break;
            }

            case TextAlign.Right:
            {
                XDec -= SentenceSize;
                break;
            }
            }

            if (CharByChar)
            {
                foreach (char c in Text)
                {
                    if (c.Equals(' '))
                    {
                        X += Scale * Size * 0.35;
                        continue;
                    }

                    FontText s = CreateSprite(c.ToString());
                    Vector2  Dec = decByOrigin(Origin, Scale, s.getWidth(), s.getHeight());
                    double   LayerDecX = Dec.X, LayerDecY = Dec.Y;

                    Sprite Sprite = Layer.CreateSprite(Path + s.getFileName() + ".png", Origin, X + LayerDecX + XDec, Y + LayerDecY);
                    if (ScaleSprite)
                    {
                        Sprite.Scale(Time, Scale);
                    }

                    X += Scale * s.getWidth() - Size * Scale * 0.45;
                    TextSprites.Add(Sprite);
                }
            }
            else
            {
                FontText s = CreateSprite(Text);
                Vector2  Dec = decByOrigin(Origin, Scale, s.getWidth(), s.getHeight());
                double   LayerDecX = Dec.X, LayerDecY = Dec.Y;
                Sprite   Sprite = Layer.CreateSprite(Path + s.getFileName() + ".png", Origin, X + LayerDecX + XDec, Y + LayerDecY);
                if (ScaleSprite)
                {
                    Sprite.Scale(Time, Scale);
                }

                TextSprites.Add(Sprite);
            }

            return(new Sentence(SentenceSize, TextSprites, Alignment));
        }