Ejemplo n.º 1
0
        public DocumentElement getElementById(object p)
        {
#if DISABLE
            var id      = p.ToString();
            var xmltags = m_scrObj.GetComponent <xmlTags_html>();

            Debug.Log("id=" + id);
            Debug.Log("m_id[" + id + "]=" + xmltags.m_id[id]);

            string d = "ids=>"; foreach (var k in xmltags.m_id.Keys)
            {
                d += k + "=" + xmltags.m_id[k] + ",";
            }
            Debug.Log(d);


            GameObject o = (GameObject)xmltags.m_id[id];
            if (o == null)
            {
                Debug.LogWarning("getElementById ERROR");
                write("getElementById ERROR:CAN'T FIND ID");
                return(null);
            }
            var de = new DocumentElement();
            de.gameObject = o;
            Debug.LogWarning("getElementById o" + o);
            return(de);
#endif
            var id   = p.ToString();
            var body = ((hglWindowInfo)hgca.FindAscendantComponent(m_scrObj.gameObject, typeof(hglWindowInfo))).m_curBodyElement;


            var elm = hglParser.FindID(id, body);
            if (elm != null && elm.FindBone() != null)
            {
                var de = new DocumentElement();
                de.gameObject = elm.FindBone().gameObject;
                de.xe         = elm;

                var rect = new hgRect(elm.formatBase.doneRealRect);
                var v    = Vector2.zero - (elm.formatBase.doneRealRect.center);
                rect.Move(v);
                de.rect = rect;

                return(de);
            }
            return(null);
        }
Ejemplo n.º 2
0
        public void AddImg(hgMesh.CD_IMAGE cd)
        {
            if (leftList == null)
            {
                leftList = new List <hgRect>();
            }
            if (rightList == null)
            {
                rightList = new List <hgRect>();
            }

            hgRect r = new hgRect(cd.outer_v);

            if (cd.align == hgMesh.CD_IMAGE.ALIGN.LEFT)
            {
                leftList.Add(r);
            }
            else if (cd.align == hgMesh.CD_IMAGE.ALIGN.RIGHT)
            {
                rightList.Add(r);
            }
        }
Ejemplo n.º 3
0
    public void Format(/*hglHtmlRender.BASE tableBlock,*/ ALIGN align, hgRect curRect, out hgRect doneRealRect, out hgRect doneMarginRect)
    {
        foreach (var tr in m_table.trlist)
        {
            foreach (var td in tr.tdlist)
            {
                td.CreatePadWpaddingRect(m_table.cellpadding + m_table.xe.thisStyle.GetFloat(StyleKey.border_width, float.NaN));
                SetTD(td);
            }
        }

        int validWidth  = m_baseTable.Get_max_x() + 1;
        int validHeight = m_baseTable.Get_max_y() + 1;

        m_baseTable.Normalize();

        m_xLenList = new LENVAL[validWidth];   for (int i = 0; i < m_xLenList.Length; i++)
        {
            m_xLenList[i] = new LENVAL()
            {
                len = -1
            }
        }
        ;
        m_yLenList = new LENVAL[validHeight];  for (int i = 0; i < m_yLenList.Length; i++)
        {
            m_yLenList[i] = new LENVAL()
            {
                len = -1
            }
        }
        ;

        bool bNeedUpdate = true;
        int  loopIndex   = 0;

        while (bNeedUpdate)
        {
            if (loopIndex++ > 100)
            {
                Debug.LogError("Too much Loop");  break;
            }
            bNeedUpdate = false;

            for (var y = 0; y < validHeight; y++)
            {
                for (var x = 0; x < validWidth; x++)
                {
                    float w, h;
                    if (GetWH(x, y, out w, out h))
                    {
                        if (w > 0 && w > m_xLenList[x].len)
                        {
                            bNeedUpdate       = true;
                            m_xLenList[x].len = w;
                        }
                        if (h > 0 && h > m_yLenList[y].len)
                        {
                            bNeedUpdate       = true;
                            m_yLenList[y].len = h;
                        }
                    }
                }
            }
        }
        //Relocate

        var tmpDoneRealRect = new hgRect();

        for (int y = 0; y < validHeight; y++)
        {
            for (int x = 0; x < validWidth; x++)
            {
                var dt = m_baseTable.GetPoint(x, y);
                if (dt.mode == Element.Mode.ORIGINAL)
                {
                    if (dt.td == null)
                    {
                        continue;
                    }
                    var w = LENVAL.GetWidth(m_xLenList, x, dt.spanLastCol);
                    var h = LENVAL.GetWidth(m_yLenList, y, dt.spanLastRow);

                    var lx = x > 0 ? LENVAL.GetWidth(m_xLenList, 0, x - 1) : 0;
                    var ly = y > 0 ? LENVAL.GetWidth(m_yLenList, 0, y - 1) : 0;

                    tmpDoneRealRect.Sample(new hgRect(lx, -ly, w, h));

                    Vector2 v = Vector2.zero;

                    {
                        Vector2 center = new Vector2(lx + w / 2, -(ly + h / 2));                         //Debug.LogWarning(dt.td.block.ToString() + ">" + center + " Aligh=" + align);
                        v = center - dt.td.padding_w_padRect.center;
                    }
                    dt.td.block.Relocate(v);

                    //Enlarge td.block.doneRealRect to fit.
                    dt.td.block.doneRealRect.ChangWidth(w);
                    dt.td.block.doneRealRect.ChangHeight(h);
                    dt.td.block.doneMarginRect = new hgRect(dt.td.block.doneRealRect);
                }
            }
        }

        Debug.Log("tmpDoneRealRect = " + tmpDoneRealRect);

        float reltopY = curRect._topY;
        float reltopX = curRect._leftX;

        if (m_table.align == ALIGN.CENTER)
        {
            reltopX = curRect._leftX + curRect.width / 2 - tmpDoneRealRect.width / 2;
        }
        else if (m_table.align == ALIGN.RIGHT)
        {
            reltopX = curRect._rightX - tmpDoneRealRect.width;
        }

        Vector3 v2 = new Vector3(reltopX, reltopY, 0) - hglEtc.toVector3(tmpDoneRealRect.topLeft);

        if (v2 != Vector3.zero)
        {
            foreach (var tr in m_table.trlist)
            {
                foreach (var td in tr.tdlist)
                {
                    td.block.Relocate(v2);
                }
            }
        }
        tmpDoneRealRect.Move(v2);

        //Fix align
        foreach (var tr in m_table.trlist)
        {
            foreach (var td in tr.tdlist)
            {
                td.block.ReAlign();
            }
        }

        // For centering
        if (align == ALIGN.CENTER)
        {
            var v3 = new Vector3(m_table.padRect.center.x - tmpDoneRealRect.center.x, 0, 0);
            tmpDoneRealRect.Move(v3);
            foreach (var tr in m_table.trlist)
            {
                foreach (var td in tr.tdlist)
                {
                    td.block.Relocate(v3);
                }
            }
        }

        doneRealRect          = tmpDoneRealRect;
        doneMarginRect        = new hgRect(doneRealRect);
        doneMarginRect.max_v += new Vector2(m_table.hspace, m_table.vspace);
        doneMarginRect.min_v -= new Vector2(m_table.hspace, m_table.vspace);
    }

    bool GetWH(int x, int y, out float w, out float h)
    {
        w = -1;         // means Unknown
        h = -1;         // means Unknown

        var elm = m_baseTable.GetPoint(x, y);

        if (elm == null)
        {
            w = 0; h = 0;
            return(true);
        }
        //    throw new SystemException("ERROR: TABLE("+x+","+y+")" );
        if (elm.mode == Element.Mode.ORIGINAL)
        {
            if (elm.spanLastCol == x)
            {
                w = (elm.td != null) ? elm.td.padding_w_padRect.width : 0;
            }
            if (elm.spanLastRow == y)
            {
                h = (elm.td != null) ? elm.td.padding_w_padRect.height : 0;
            }
            return(true);
        }
        else if (elm.mode == Element.Mode.SPAN)
        {
            var basedt = elm.original;

            if (basedt.spanLastCol == x)
            {
                var lw = LENVAL.GetWidth(m_xLenList, basedt.x, basedt.spanLastCol - 1);
                if (lw >= 0)
                {
                    w = basedt.td.padding_w_padRect.width - lw;
                }
            }
            if (basedt.spanLastRow == y)
            {
                var lw = LENVAL.GetWidth(m_yLenList, basedt.y, basedt.spanLastRow - 1);
                if (lw >= 0)
                {
                    h = basedt.td.padding_w_padRect.height - lw;
                }
            }
            return(true);
        }
        return(false);
    }