Exemple #1
0
        void AdjustXValues(LingTreeTree tree, int iAdjust)
        {
            // adjust this node
            XCoord += iAdjust;
            XMid   += iAdjust;
            tree.HorizontalOffset = tree.HorizontalOffset + iAdjust;
            // adjust any daughter nodes
            LingTreeNode NextDaughter = Daughter;

            while (NextDaughter != null)
            {
                NextDaughter.AdjustXValues(tree, iAdjust);
                NextDaughter = NextDaughter.Sister;
            }
        }
Exemple #2
0
        ///////////////////////////////////////////////////////////////////////////////
        // NAME
        //    CalculateXCoordinate
        // ARGUMENTS
        //    pTree - pointer to tree this node is in
        //    pDC - pointer to the device context
        //    iMaxColWidth - maximum width of the current column
        // DESCRIPTION
        //    Determine the X-axis coordinate for this node
        //    It assumes that the width of this and all other nodes have
        //      already been established.
        //    It also assumes that higher branching nodes are not wider than the
        //      total width of their daughters (which may not always be true...)
        // RETURN VALUE
        //    The X-axis coordinate at the mid-point of this node
        //
        public int CalculateXCoordinate(LingTreeTree Tree, Graphics grfx, int iMaxColWidth)
        {
            XMid = 0;

            // Determine the width for this node
            CalculateWidth(Tree, grfx);
            if (Daughter != null)
            {                                           // is a non-terminal node
                LingTreeNode NextDaughter = Daughter.Sister;
                if (NextDaughter != null)
                {                                       // node branches
                    if (iMaxColWidth < m_iWidth)
                    {
                        iMaxColWidth = m_iWidth;                         // remember widest node in the column
                    }
                }
                else
                {                                       // only one daughter, so could be in a column
                    if (iMaxColWidth < Width)
                    {
                        iMaxColWidth = Width;                         // remember widest node in the column
                    }
                }
                int iLeftMost = Daughter.CalculateXCoordinate(Tree, grfx,
                                                              iMaxColWidth);
                int iRightMost = iLeftMost;
                while (NextDaughter != null)
                {                                       // calculate coordinates for other daughters
                    iRightMost = NextDaughter.CalculateXCoordinate(Tree, grfx,
                                                                   iMaxColWidth);
                    NextDaughter = NextDaughter.Sister;
                }
                // take mid point between first & last daughter
                XMid = (iLeftMost + iRightMost) / 2;
                if (iRightMost > iLeftMost)
                {
                    if (m_iWidth > (iRightMost - iLeftMost))
                    {
                        int iAdjust = (m_iWidth - (iRightMost - iLeftMost)) / 2;
                        m_iXMid += iAdjust;

                        NextDaughter = Daughter;
                        while (NextDaughter != null)
                        {
                            NextDaughter.AdjustXValues(Tree, iAdjust);
                            NextDaughter = NextDaughter.Sister;
                        }
                    }
                }
            }
            else
            {                                           // is a terminal node
                if (iMaxColWidth < Width)
                {
                    iMaxColWidth = Width;                    // this might be the widest node in the column
                }
                XMid = (int)Tree.HorizontalOffset +          // Offset from last terminal node plus
                       iMaxColWidth / 2;                     // half the width of this column
                Tree.HorizontalOffset = XMid +               // have a new offset for next terminal node
                                        Tree.HorizontalGap + // gap between terminal nodes plus
                                        iMaxColWidth / 2;    // half the width of the widest node in this column
            }
            XCoord = XMid - Width / 2;                       // adjust for width of this node
            int iEnd = XCoord + Width;

            if (Triangle)
            {
                iEnd += Tree.HorizontalGap / 2;
            }
            if (iEnd > Tree.XSize)
            {
                Tree.XSize = iEnd;                      // Keep track of total width for scrolling
            }
#if DoTrace
            Console.WriteLine("{0}\tXSize = {1},\tWidth = {2},\tXCoord = {3},\tYCoord = {4}, \tXMid = {4}", Content, Tree.XSize, Width, XCoord, YCoord, XMid);
#endif
            return(XMid);
        }