Пример #1
0
        void CreateLines(Vector2 position, string wrappedText, List <string> tags = null)
        {
            TextBounds = MeasureStringFn(wrappedText);
            var TextPosition = position;
            var Origin       = TextBounds * 0.5f;

            if (Align.Has(Alignment.Top))
            {
                Origin.Y += Bounds.Height / 2f - TextBounds.Y / 2f;
            }

            if (Align.Has(Alignment.Bottom))
            {
                Origin.Y -= Bounds.Height / 2f - TextBounds.Y / 2f;
            }

            string[] TextLines = wrappedText.Split(NL);

            Lines.Clear();

            for (int i = 0; i < TextLines.Length; i++)
            {
                var LineSize   = MeasureStringFn(TextLines[i]);
                var LineOffset = new Vector2((TextBounds.X - LineSize.X) * 0.5f, i * (TextBounds.Y / TextLines.Length + 3));

                if (Align.Has(Alignment.Left))
                {
                    LineOffset.X -= Bounds.Width / 2f - LineSize.X / 2f;
                }

                if (Align.Has(Alignment.Right))
                {
                    LineOffset.X += Bounds.Width / 2f - LineSize.X / 2f;
                }

                var    LinePosition = TextPosition + LineOffset;
                var    Hitbox       = new Rectangle((int)(LinePosition.X - Origin.X), (int)(LinePosition.Y - Origin.Y), (int)LineSize.X, (int)LineSize.Y);
                string Tag          = null;
                if (tags != null && i < tags.Count)
                {
                    Tag = tags[i];
                }

                var NewLine = new TextLine(TextLines[i], LinePosition, Origin, Hitbox, Color, Tag);

                Lines.Add(NewLine);
            }

            Position = position;
        }