Esempio n. 1
0
        /// <summary>
        /// Inserts a panel into the layout lines system, and updates the lines around it.
        /// </summary>
        /// <param name="p">The control to add to the layout lines system</param>
        /// <param name="DockType">The dock type of the control that is added to the system</param>
        public void AddPanel(Control p, DockTypes DockType)
        {
            int  leftIndex   = 0;
            int  rightIndex  = 0;
            int  topIndex    = 0;
            int  bottomIndex = 0;
            int  indexToInsertPanelLineAt;
            Line panelLineToInsert;

            int[]      lineIndicesRestrictingPanel;
            List <int> lineIndicesToRemove = new List <int>();
            Locations  horizontalLocationToAddLine, verticalLocationToAddLine;

            horizontalLocationToAddLine = (MyPanel.IsDockedAtLeft(DockType) ? Locations.Left : Locations.Right);
            verticalLocationToAddLine   = (MyPanel.IsDockedAtTop(DockType) ? Locations.Top : Locations.Bottom);

            //VERTICAL POSITION
            lineIndicesRestrictingPanel = GetIndicesOfLinesRestrictingPanel(p, verticalLocationToAddLine);

            leftIndex  = lineIndicesRestrictingPanel[0];
            rightIndex = lineIndicesRestrictingPanel[1];

            if (leftIndex == rightIndex)
            {
                lines[verticalLocationToAddLine].Insert(leftIndex + 1, new Line(lines[verticalLocationToAddLine][leftIndex]));
                rightIndex = leftIndex + 1;
            }

            lines[verticalLocationToAddLine][leftIndex].setEndPointX(p.Left);
            lines[verticalLocationToAddLine][rightIndex].setStartPointX(p.Right);

            if (lines[verticalLocationToAddLine][rightIndex].Length == 0)
            {
                lineIndicesToRemove.Add(rightIndex);
            }
            for (int i = rightIndex - 1; i > leftIndex; i--)
            {
                lineIndicesToRemove.Add(i);
            }
            if (lines[verticalLocationToAddLine][leftIndex].Length == 0)
            {
                lineIndicesToRemove.Add(leftIndex);
                indexToInsertPanelLineAt = leftIndex;
            }
            else
            {
                indexToInsertPanelLineAt = leftIndex + 1;
            }

            foreach (int index in lineIndicesToRemove)
            {
                lines[verticalLocationToAddLine].RemoveAt(index);
            }
            lineIndicesToRemove.Clear();

            panelLineToInsert = AddLineFromSideOfPanel(p, (verticalLocationToAddLine == Locations.Top ? Locations.Bottom : Locations.Top));
            lines[verticalLocationToAddLine].Insert(indexToInsertPanelLineAt, panelLineToInsert);


            //HORIZONTAL POSITION
            lineIndicesRestrictingPanel = GetIndicesOfLinesRestrictingPanel(p, horizontalLocationToAddLine);

            topIndex    = lineIndicesRestrictingPanel[0];
            bottomIndex = lineIndicesRestrictingPanel[1];

            //If only one line index, the same layout line covers the whole of the top of the panel
            if (topIndex == bottomIndex)
            {
                //Add a copy of this line
                lines[horizontalLocationToAddLine].Insert(topIndex + 1, new Line(lines[horizontalLocationToAddLine][topIndex]));
                bottomIndex = topIndex + 1;
            }

            //Set the end of the left line and start of the right line to the corners of the panel.
            lines[horizontalLocationToAddLine][topIndex].setEndPointY(p.Top);
            lines[horizontalLocationToAddLine][bottomIndex].setStartPointY(p.Bottom);

            //Remove any zero length lines at the bottom of the panel
            if (lines[horizontalLocationToAddLine][bottomIndex].Length == 0)
            {
                lineIndicesToRemove.Add(bottomIndex);
            }
            //Set a flag to remove any lines contained within the bounds of the panel
            for (int lineIndex = bottomIndex - 1; lineIndex > topIndex; lineIndex--)
            {
                lineIndicesToRemove.Add(lineIndex);
            }
            //Remove zero length lines at the top of the panel
            if (lines[horizontalLocationToAddLine][topIndex].Length == 0)
            {
                lineIndicesToRemove.Add(topIndex);
                indexToInsertPanelLineAt = topIndex;
                //If lines to the left are removed, the insertion index is the top index
            }
            else
            {
                indexToInsertPanelLineAt = topIndex + 1;
                //Else the insertion index is one above the top index
            }

            //Remove the lines marked for removal
            foreach (int index in lineIndicesToRemove)
            {
                lines[horizontalLocationToAddLine].RemoveAt(index);
            }
            lineIndicesToRemove.Clear();

            //Insert the line based on the edge of the panel
            panelLineToInsert = AddLineFromSideOfPanel(p, (horizontalLocationToAddLine == Locations.Left ? Locations.Right : Locations.Left));
            lines[horizontalLocationToAddLine].Insert(indexToInsertPanelLineAt, panelLineToInsert);
        }
Esempio n. 2
0
        void UpdatePoints(IDockableControl controlBeingAdded)
        {
            Control controlCopy = (Control)controlBeingAdded;

            //Depending on how the control fills the screen,
            //update the location of the dock points
            switch (controlBeingAdded.FillStyle)
            {
            case FillStyles.FullWidth:
            {
                //Change the locatoin of the dock points that are affected by the control
                if (MyPanel.IsDockedAtTop(controlBeingAdded.DockType))
                {
                    dockPointLocations[DockTypes.TopLeft]  = AddHeightToDockPoint(DockTypes.TopLeft, controlCopy.Height);
                    dockPointLocations[DockTypes.Left]     = AddHeightToDockPoint(DockTypes.Left, controlCopy.Height);
                    dockPointLocations[DockTypes.Top]      = AddHeightToDockPoint(DockTypes.Top, controlCopy.Height);
                    dockPointLocations[DockTypes.None]     = AddHeightToDockPoint(DockTypes.None, controlCopy.Height);
                    dockPointLocations[DockTypes.TopRight] = AddHeightToDockPoint(DockTypes.TopRight, controlCopy.Height);
                    dockPointLocations[DockTypes.Right]    = AddHeightToDockPoint(DockTypes.Right, controlCopy.Height);
                    dockPointLocations[DockTypes.Top2]     = AddHeightToDockPoint(DockTypes.Top2, controlCopy.Height);
                }
                else
                {
                    dockPointLocations[DockTypes.BottomLeft]  = AddHeightToDockPoint(DockTypes.BottomLeft, -controlCopy.Height);
                    dockPointLocations[DockTypes.Bottom]      = AddHeightToDockPoint(DockTypes.Bottom, -controlCopy.Height);
                    dockPointLocations[DockTypes.BottomRight] = AddHeightToDockPoint(DockTypes.BottomRight, -controlCopy.Height);
                    dockPointLocations[DockTypes.Bottom2]     = AddHeightToDockPoint(DockTypes.Bottom2, -controlCopy.Height);
                }
                break;
            }

            case FillStyles.FullHeight:
            {
                if (MyPanel.IsDockedAtLeft(controlBeingAdded.DockType))
                {
                    dockPointLocations[DockTypes.TopLeft]    = AddWidthToDockPoint(DockTypes.TopLeft, controlCopy.Width);
                    dockPointLocations[DockTypes.Left]       = AddWidthToDockPoint(DockTypes.Left, controlCopy.Width);
                    dockPointLocations[DockTypes.BottomLeft] = AddWidthToDockPoint(DockTypes.BottomLeft, controlCopy.Width);
                    dockPointLocations[DockTypes.Top]        = AddWidthToDockPoint(DockTypes.Top, controlCopy.Width);
                    dockPointLocations[DockTypes.None]       = AddWidthToDockPoint(DockTypes.None, controlCopy.Width);
                    dockPointLocations[DockTypes.Bottom]     = AddWidthToDockPoint(DockTypes.Bottom, controlCopy.Width);
                }
                else
                {
                    dockPointLocations[DockTypes.TopRight]    = AddWidthToDockPoint(DockTypes.TopRight, -controlCopy.Width);
                    dockPointLocations[DockTypes.Right]       = AddWidthToDockPoint(DockTypes.Right, -controlCopy.Width);
                    dockPointLocations[DockTypes.BottomRight] = AddWidthToDockPoint(DockTypes.BottomRight, -controlCopy.Width);
                    dockPointLocations[DockTypes.Top2]        = AddWidthToDockPoint(DockTypes.Top2, -controlCopy.Width);
                    dockPointLocations[DockTypes.Bottom2]     = AddWidthToDockPoint(DockTypes.Bottom2, -controlCopy.Width);
                }
                break;
            }

            case FillStyles.None:
            {
                //If the panel being added will affect the dock point:
                if ((controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.TopLeft]) || (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Left]) || (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.None]))
                {
                    dockPointLocations[DockTypes.TopLeft] = AddHeightToDockPoint(DockTypes.TopLeft, controlCopy.Height);
                    dockPointLocations[DockTypes.Left]    = AddHeightToDockPoint(DockTypes.Left, controlCopy.Height);
                    dockPointLocations[DockTypes.None]    = AddHeightToDockPoint(DockTypes.None, controlCopy.Height);
                }
                if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.BottomLeft])
                {
                    dockPointLocations[DockTypes.BottomLeft] = AddHeightToDockPoint(DockTypes.BottomLeft, -controlCopy.Height);
                }
                if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Top])
                {
                    dockPointLocations[DockTypes.Top] = AddWidthToDockPoint(DockTypes.Top, controlCopy.Width);
                }
                if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Bottom])
                {
                    dockPointLocations[DockTypes.Bottom] = AddWidthToDockPoint(DockTypes.Bottom, controlCopy.Width);
                }
                if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.TopRight])
                {
                    dockPointLocations[DockTypes.TopRight] = AddHeightToDockPoint(DockTypes.TopRight, controlCopy.Height);
                }
                if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Right])
                {
                    dockPointLocations[DockTypes.Right] = AddHeightToDockPoint(DockTypes.Right, controlCopy.Height);
                }
                if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.BottomRight])
                {
                    dockPointLocations[DockTypes.BottomRight] = AddHeightToDockPoint(DockTypes.BottomRight, -controlCopy.Height);
                }
                if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Top2])
                {
                    dockPointLocations[DockTypes.Top2] = AddWidthToDockPoint(DockTypes.Top2, -controlCopy.Width);
                }
                if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Bottom2])
                {
                    dockPointLocations[DockTypes.Bottom2] = AddWidthToDockPoint(DockTypes.Bottom2, -controlCopy.Width);
                }
                break;
            }
            }
        }