Example #1
0
        // lineX下一行的偏移量
        public virtual void fill(ref Vector2 currentpos, List <Line> lines, float maxWidth, float pixelsPerUnit)
        {
            NextLineX = d_nextLineX * pixelsPerUnit;
            List <Element> TempList;

            UpdateWidthList(out TempList, pixelsPerUnit);
            float height = getHeight();

            AlterX(ref currentpos.x, maxWidth);
            if (TempList.Count == 0)
            {
                return;
            }

            Around around    = owner.around;
            bool   isContain = false; // 当前行是否包含此元素

            for (int i = 0; i < TempList.Count;)
            {
                float totalwidth = TempList[i].totalwidth;
                float newx       = 0f;
                if (((currentpos.x + totalwidth) > maxWidth))
                {
                    currentpos = TempList[i].Next(this, currentpos, lines, maxWidth, NextLineX, height, around, totalwidth, ref isContain);
                    ++i;
                }
                else if (around != null && !around.isContain(currentpos.x, currentpos.y, totalwidth, height, out newx))
                {
                    // 放置不下了
                    currentpos.x = newx;
                }
                else
                {
                    currentpos.x += totalwidth;
                    isContain     = true;
                    ++i;
                }
            }

            Line bl = lines.back();

            bl.x = currentpos.x;
            bl.y = Mathf.Max(height, bl.y);

            if (d_bNewLine)
            {
                lines.Add(new Line(Vector2.zero));
                currentpos.y += height;
                currentpos.x  = NextLineX;
            }
        }
Example #2
0
            void DrawCurrent(bool isnewLine, Around around, float lineX)
            {
                if (sb.Length != 0)
                {
                    var  line      = lines[(int)yline];
                    Rect area_rect = new Rect(pt.x + alignedX, pt.y, x - pt.x + offsetX, node.getHeight());

                    cache.cacheText(line, node, sb.ToString(), area_rect);

                    sb.Remove(0, sb.Length);
                }

                if (isnewLine)
                {
                    // 再换行
                    yline++;
                    x = lineX;

                    pt.x = offsetX;
                    pt.y = offsetY;
                    for (int n = 0; n < yline; ++n)
                    {
                        pt.y += lines[n].y;
                    }

                    if (yline >= lines.Count)
                    {
                        --yline;
                        //Debug.LogError("yline >= vLineSize.Count!yline:" + yline + " vLineSize:" + lines.Count);
                    }

                    alignedX = AlignedFormatting(node.owner, xFormatting, maxWidth, lines[(int)(yline)].x, lineX);

                    float newx;
                    if (!around.isContain(pt.x + alignedX, pt.y, 1, node.getHeight(), out newx))
                    {
                        pt.x = newx - alignedX;
                        x    = pt.x;
                    }
                }
            }
Example #3
0
            public void Draw(TextNode n, float lineX)
            {
                node = n;
                pt   = new Vector2(x + offsetX, offsetY);
                for (int i = 0; i < yline; ++i)
                {
                    pt.y += lines[i].y;
                }

                if (maxWidth == 0)
                {
                    return;
                }

                alignedX = AlignedFormatting(n.owner, xFormatting, maxWidth, lines[(int)(yline)].x, 0);
                fHeight  = node.getHeight();

                sb.Remove(0, sb.Length);

                Around around = n.owner.around;

                int   textindex = 0;
                float newx      = 0f;

                for (int k = 0; k < node.d_widthList.Count; ++k)
                {
                    Element e          = node.d_widthList[k];
                    float   totalwidth = e.totalwidth;
                    if ((x + totalwidth) > maxWidth)
                    {
                        if (x != 0f)
                        {
                            DrawCurrent(true, around, lineX);
                        }

                        if (e.widths == null)
                        {
                            if ((x + e.totalwidth > maxWidth))
                            {
                                DrawCurrent(true, around, lineX);
                            }
                            else
                            {
                                x += e.totalwidth;
                                sb.Append(node.d_text[textindex++]);
                            }
                        }
                        else
                        {
                            for (int m = 0; m < e.widths.Count;)
                            {
                                if (x != 0 && x + e.widths[m] > maxWidth)
                                {
                                    DrawCurrent(true, around, lineX);
                                }
                                else
                                {
                                    x += e.widths[m];
                                    sb.Append(node.d_text[textindex++]);
                                    ++m;
                                }
                            }
                        }
                    }
                    else if (!around.isContain(x, pt.y, totalwidth, fHeight, out newx))
                    {
                        DrawCurrent(false, around, lineX);

                        x    = newx;
                        pt.x = newx;
                        --k;
                    }
                    else
                    {
                        int ec = e.count;
                        sb.Append(node.d_text.Substring(textindex, ec));
                        textindex += ec;
                        x         += totalwidth;
                    }
                }

                if (sb.Length != 0)
                {
                    DrawCurrent(false, around, lineX);
                }

                if (node.d_bNewLine == true)
                {
                    yline++;
                    x = lineX;
                }
            }
Example #4
0
            public Vector2 Next(NodeBase n, Vector2 currentPos, List <Line> lines, float maxWidth, float lineX, float height, Around round, float tw, ref bool currentLineContain)
            {
                if (currentPos.x != 0f)
                {
                    Line bl = lines.back();
                    bl.x = currentPos.x;
                    if (currentLineContain)
                    {
                        bl.y = Mathf.Max(bl.y, height);
                    }

                    // 当前行有数据,在新行里处理
                    currentPos.x       = lineX;
                    currentPos.y      += bl.y;
                    currentLineContain = false;
                    lines.Add(new Line(new Vector2(lineX, 0)));
                }
                else
                {
                    // 当前行没有数据,直接在此行处理
                }

                if (round != null)
                {
                    float newx = 0f;
                    while (!round.isContain(currentPos.x, currentPos.y, tw, height, out newx))
                    {
                        currentPos.x = newx;
                        if (currentPos.x + tw > maxWidth)
                        {
                            currentPos.x = lineX;
                            lines.Add(new Line(new Vector2(lineX, height)));
                            currentPos.y += height;
                        }
                    }
                }

                if (widthList != null)
                {
                    for (int i = 0; i < widthList.Count; ++i)
                    {
                        currentPos = Add(n, currentPos, widthList[i], maxWidth, lineX, lines, height, ref currentLineContain);
                    }
                }
                else
                {
                    currentPos = Add(n, currentPos, totalWidth, maxWidth, lineX, lines, height, ref currentLineContain);
                }

                lines.back().x = currentPos.x;

                return(currentPos);
            }