private void CheckInf(TagBoxSizeInf inf, Size inn, Size outt)
        {
            int delta = 2;

            Assert.IsTrue(inf.InnerBoxSize.Width > inn.Width - delta && inf.InnerBoxSize.Width < inn.Width + delta);
            Assert.IsTrue(inf.InnerBoxSize.Height > inn.Height - delta && inf.InnerBoxSize.Height < inn.Height + delta);

            Assert.IsTrue(inf.OutterBoxSize.Width > outt.Width - delta && inf.OutterBoxSize.Width < outt.Width + delta);
            Assert.IsTrue(inf.OutterBoxSize.Height > outt.Height - delta && inf.OutterBoxSize.Height < outt.Height + delta);
        }
Beispiel #2
0
        public GTagBox(int distance, GUTag tag, double x, double y, int direct)
        {
            //记录展开方向(1:向右 -1:向左)
            Direct = direct;

            //计算大小
            Inf = new TagBoxSizeInf(tag, distance, StaticCfg.Ins.GFontName);

            //*****计算位置*****************
            //计算OutterBox
            OutterBoxLeftTop.X = x;
            OutterBoxLeftTop.Y = y;
            if (Direct == -1)
            {
                OutterBoxLeftTop.X -= Inf.OutterBoxSize.Width;
            }

            //计算InnerBox在:OutterBox的中间
            InnerBoxLeftTop.X = OutterBoxLeftTop.X + (Inf.OutterBoxSize.Width - Inf.InnerBoxSize.Width) / 2;
            InnerBoxLeftTop.Y = OutterBoxLeftTop.Y + (Inf.OutterBoxSize.Height - Inf.InnerBoxSize.Height) / 2;;
        }
Beispiel #3
0
        private static GTagBoxTree ExpandChildCompact(int rootLevel, int MaxLevel, ITagDB db, GTagBoxTree root, GTagBoxTree pre, GUTag ctag, int direct, Size size, TreeLayoutEnv env, LayoutMode mode)
        {
            GTagBoxTree cur;

            Logger.D("ChoosePos:pre:{0}-{1}-{2} cur:{0}-{1},",
                     pre?.GTagBox.Tag,
                     pre == null ? 0 : db.QueryTagChildren(pre.GTagBox.Tag).Count,
                     pre == null ? 0 : pre.totalRange.Right,
                     ctag, db.QueryTagChildren(ctag).Count);

            bool          leftOK = true, rightOK = true;
            TagBoxSizeInf sizeinf      = new TagBoxSizeInf(ctag, rootLevel + 1, StaticCfg.Ins.GFontName);
            int           OneLineChild = GetTagTreeWidth(ctag, db, rootLevel + 1, MaxLevel);

            //右边是否有足够空间(初步预估,用OneLineChild*本节点的宽度预估)
            if (pre != null && direct == 1)
            {
                rightOK = pre.totalRange.Right + sizeinf.OutterBoxSize.Width < size.Width;
            }
            //左边是否有足够空间
            if (pre != null && direct == -1)
            {
                leftOK = sizeinf.OutterBoxSize.Width < pre.totalRange.Left;
            }


            //只有满足严格条件的情况下,才放在兄弟节点的后面,否则在父节点后展开
            if (pre != null && OneLineChild >= 0 &&
                (db.QueryTagChildren(pre.GTagBox.Tag).Count == 0 || rootLevel + 1 == MaxLevel) &&
                rightOK && leftOK)
            {
                Logger.D("Place {0} after {1}:follow", ctag, pre.GTagBox.Tag);
                cur = ExpandNode(ctag, rootLevel + 1, db,
                                 direct == 1 ? pre.totalRange.Right : pre.totalRange.Left,  //X
                                 pre.totalRange.Top,                                        //Y
                                 direct, size, env, mode);
            }

            //第一个节点,没有兄弟节点,放在父节点后面   ==== > 放在父节点的同一行
            //非叶子节点,也直接放在父节点后面 or        ==== > 放在父节点的下一行
            //前一个兄弟已经把这一行占完了               ==== > 放在父节点的下一行
            else
            {
                if (pre == null)
                {
                    Logger.D("Place {0} after {1}:follow", ctag, root.GTagBox.Tag);
                    cur = ExpandNode(ctag, rootLevel + 1, db,
                                     direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left,
                                     root.totalRange.Top, direct, size, env, mode);
                }
                else
                {
                    Logger.D("Place {0} after {1}:newline", ctag, root.GTagBox.Tag);
                    cur = ExpandNode(ctag, rootLevel + 1, db,
                                     direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left,
                                     root.totalRange.Bottom, direct, size, env, mode);
                }
                env.AddLine(root, cur, direct);
            }

            return(cur);
        }