Esempio n. 1
0
        private int AlignCenterLineTextTokens(ref Vector2f cursor, List <TextToken2D> tokensInLine, int offsetLine)
        {
            cursor.X += offsetLine / 2;
            int     maxHeight    = 0;
            IntRect tokenCanevas = new IntRect();
            int     i            = 0;

            foreach (TextToken2D textToken2D in tokensInLine)
            {
                tokenCanevas = textToken2D.Canevas;

                textToken2D.Position = cursor;
                cursor.X            += tokenCanevas.Width;

                if (tokenCanevas.Height > maxHeight)
                {
                    maxHeight = tokenCanevas.Height;
                }

                if (i < tokensInLine.Count - 1)
                {
                    cursor.X += AObject2DFactory.GetWidthFromTextToken(textToken2D);
                }

                i++;
            }

            return(maxHeight);
        }
Esempio n. 2
0
        public TextToken2D(string text, Color fillColor, bool updateCanevas = true)
            : base(null)
        {
            this.fullText = text;

            this.textCursor = -1;

            this.text2D = new Text();

            //if(text.StartsWith("{") && text.EndsWith("}") && int.TryParse(text.Substring(1, text.Length - 2), out int parameterIndex))
            //{
            //    this.ParameterIndex = parameterIndex;
            //}
            //else
            //{
            //    this.ParameterIndex = -1;
            //}

            this.TextCursor  = this.FullText.Count();
            this.text2D.Font = AObject2DFactory.GetFontByName("Sans");

            this.text2D.FillColor        = fillColor;
            this.text2D.OutlineThickness = 2;
            this.text2D.OutlineColor     = new Color(0, 0, 0, fillColor.A);

            if (updateCanevas)
            {
                this.UpdateCanevas();
            }
        }
Esempio n. 3
0
        public TitleTextToken2D(string text, Color fillColor)
            : base(text, fillColor, false)
        {
            this.text2D.Font = AObject2DFactory.GetFontByName("dumbTitle");

            this.text2D.FillColor        = fillColor;
            this.text2D.OutlineThickness = 0;
            this.text2D.OutlineColor     = Color.Black;

            this.UpdateCanevas();
        }
Esempio n. 4
0
        private void AlignTextTokens()
        {
            FloatRect bounds = this.Bounds;

            Vector2f startCursor   = new Vector2f(bounds.Left, bounds.Top);
            Vector2f maxCursor     = new Vector2f(bounds.Left + bounds.Width, bounds.Top + bounds.Height);
            Vector2f currentCursor = startCursor;

            int maxHeight = 0;

            List <TextToken2D> tokensInLine = new List <TextToken2D>();

            IEnumerator <TextToken2D> tokenEnumerator = this.textToken2Ds.GetEnumerator();
            int lineWidth = 0;
            int maxWidth  = (int)(maxCursor.X - startCursor.X);

            bool notReachEnd = true;

            IntRect tokenCanevas = new IntRect();

            TextLineHandler LineHandler = this.AlignLeftLineTextTokens;

            switch (this.ParagraphAlignment)
            {
            case Alignment.LEFT:
                LineHandler = this.AlignLeftLineTextTokens;
                break;

            case Alignment.RIGHT:
                LineHandler = this.AlignRightLineTextTokens;
                break;

            case Alignment.CENTER:
                LineHandler = this.AlignCenterLineTextTokens;
                break;

            case Alignment.JUSTIFY:
                LineHandler = this.AlignJustifyLineTextTokens;
                break;
            }

            while (notReachEnd)
            {
                while ((notReachEnd = tokenEnumerator.MoveNext()) && tokenEnumerator.Current is ParameterTextToken2D)
                {
                    ;
                }

                //notReachEnd = tokenEnumerator.MoveNext();

                if (notReachEnd)
                {
                    tokenCanevas = tokenEnumerator.Current.Canevas;
                }

                if (notReachEnd == false ||
                    lineWidth + tokenCanevas.Width > maxWidth ||
                    tokenEnumerator.Current.FullText == "\n")
                {
                    int diffWidth = maxWidth - lineWidth;
                    lineWidth = tokenCanevas.Width;

                    if (notReachEnd)
                    {
                        lineWidth += AObject2DFactory.GetWidthFromTextToken(tokenEnumerator.Current);
                    }

                    if (tokensInLine.Count > 0)
                    {
                        diffWidth += AObject2DFactory.GetWidthFromTextToken(tokensInLine.Last());

                        maxHeight = LineHandler(ref currentCursor, tokensInLine, diffWidth);
                    }
                    else
                    {
                        maxHeight = (int)this.characterSize;
                    }

                    currentCursor.X  = startCursor.X;
                    currentCursor.Y += maxHeight;

                    tokensInLine.Clear();
                }
                else
                {
                    lineWidth += tokenCanevas.Width + AObject2DFactory.GetWidthFromTextToken(tokenEnumerator.Current);
                }

                if (notReachEnd &&
                    tokenEnumerator.Current.FullText != "\n")
                {
                    tokensInLine.Add(tokenEnumerator.Current);
                }
            }
        }