Ejemplo n.º 1
0
        /// <summary>
        /// Finds the nearest dock point to the specified point.
        /// </summary>
        /// <param name="p">The point that is being searched</param>
        /// <param name="openInNewWindow"><para>Set to true if the panel should be opened in a new window.</para>
        /// <para>This occurs when the panel is positioned away from any dock points.</para></param>
        /// <returns></returns>
        DockTypes FindNearestDockPoint(Point p, out bool openInNewWindow)
        {
            DockTypes nearestDockType = panelBeingRelocated.DockType;

            int lowestDifference  = 0;
            int currentDifference = 0;

            openInNewWindow = false;

            foreach (var dockType in (DockTypes[])Enum.GetValues(typeof(DockTypes)))
            {
                currentDifference = (int)Math.Pow((dockPoints[dockType].X - p.X), 2) + (int)Math.Pow((dockPoints[dockType].Y - p.Y), 2);

                if ((int)dockType == 0)
                {
                    lowestDifference = currentDifference;
                }

                if (currentDifference <= lowestDifference)
                {
                    lowestDifference = currentDifference;
                    nearestDockType  = dockType;
                }
            }

            //If not near any dock points, the panel will be opened in a new window.
            //The dock point is set to the top left so the panel appears full screen.
            if (lowestDifference >= 65000)
            {
                openInNewWindow = true;
                nearestDockType = DockTypes.TopLeft;
            }

            return(nearestDockType);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds the dock point closest to the specified point.
        /// </summary>
        /// <param name="p">The point that is being searched</param>
        /// <returns>A dock type specifying the type of dock point that is closest to the specified point.</returns>
        DockTypes FindNearestDockPoint(Point p)
        {
            DockTypes nearestDockType = panelBeingRelocated.DockType;

            int lowestDifference  = 0;
            int currentDifference = 0;

            foreach (var dockType in (DockTypes[])Enum.GetValues(typeof(DockTypes)))
            {
                currentDifference = (int)Math.Pow((dockPoints[dockType].X - p.X), 2) + (int)Math.Pow((dockPoints[dockType].Y - p.Y), 2);

                if ((int)dockType == 0)
                {
                    lowestDifference = currentDifference;
                }

                if (currentDifference <= lowestDifference)
                {
                    lowestDifference = currentDifference;
                    nearestDockType  = dockType;
                }
            }

            return(nearestDockType);
        }
Ejemplo n.º 3
0
 public MyToolStripButton(DockTypes dockType)
 {
     thisButtonIndex   = (int)dockType;
     type              = typeof(DockTypes);
     CheckOnClick      = true;
     Click            += GenerateClickEvent;
     this.Width        = 100;
     this.DisplayStyle = ToolStripItemDisplayStyle.Text;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the panel's layout properties to the specified values.
        /// </summary>
        public void SetPanelProperties(DockTypes dockType, AutosizeTypes autosizeType, FillStyles fillStyle, Size size)
        {
            windowDockType = dockType;
            autoSize = autosizeType;
            windowFillStyle = fillStyle;
            originalSize = size;

            SetupContextMenu();
        }
Ejemplo n.º 5
0
        public MyToolbar(WindowFlowPanel parent, PanelControlEvents events)
        {
            SetupToolbar();
            windowFillStyle = FillStyles.FullWidth;
            autoSize        = AutosizeTypes.Constant;
            windowDockType  = DockTypes.TopLeft;

            this.parent = parent;
            removed     = true;

            type = typeof(MyToolbar);

            originalSize = this.Size;

            events.ShowToolStrip   += OnToolStripAdded;
            events.RemoveToolStrip += OnToolStripRemoved;
        }
Ejemplo n.º 6
0
        /// <returns>True if the dock type is associated with the left of the panel</returns>
        public static bool IsDockedAtLeft(DockTypes dockType)
        {
            bool dockedAtLeft;

            if (dockType == DockTypes.TopLeft
                || dockType == DockTypes.Left
                || dockType == DockTypes.BottomLeft
                || dockType == DockTypes.Top
                || dockType == DockTypes.None
                || dockType == DockTypes.Bottom)
            {
                dockedAtLeft = true;
            }
            else
            {
                dockedAtLeft = false;
            }

            return dockedAtLeft;
        }
Ejemplo n.º 7
0
        /// <returns>True if the dock type is associated with the top of the panel</returns>
        public static bool IsDockedAtTop(DockTypes dockType)
        {
            bool dockedAtTop;

            if (dockType == DockTypes.TopLeft
                || dockType == DockTypes.Top
                || dockType == DockTypes.Top2
                || dockType == DockTypes.TopRight
                || dockType == DockTypes.Left
                || dockType == DockTypes.None)
            {
                dockedAtTop = true;
            }
            else
            {
                dockedAtTop = false;
            }

            return dockedAtTop;
        }
Ejemplo n.º 8
0
        public MyToolbar(WindowFlowPanel parent)
        {
            SetupToolbar();
            windowFillStyle = FillStyles.FullWidth;
            autoSize        = AutosizeTypes.Constant;
            windowDockType  = DockTypes.TopLeft;

            _parent = parent;
            form    = _parent._parent;
            removed = true;

            type = typeof(MyToolbar);

            originalSize = this.Size;

            form.PanelAdded += OnPanelAdded;
            FlowLayoutEvents.MainPanelLayoutChanged += GetShownHiddenPanels;
            MyEvents.ShowToolStrip             += OnToolStripAdded;
            MyEvents.RemoveToolStrip           += OnToolStripRemoved;
            MyEvents.FinishedLoadingParameters += OnPaceParametersFinishedLoading;
            MyEvents.FinishedLoadingStrategies += OnStrategiesFinishedLoading;
        }
Ejemplo n.º 9
0
        /// <returns>The location at which to dock the panel at</returns>
        Point GetLocation(IDockableControl c)
        {
            Control controlCopy = (Control)c;

            Point drawPoint = new Point(); //point at which to draw control
            Point dockPoint = new Point(); //point at which control is docked.

            DockTypes DockType = c.DockType;

            dockPoint = dockPointLocations[DockType];

            //set the property of the control to the location at which it is docked.
            c.DockPointLocation = dockPoint;

            //Finding controlCopy.Location:
            //if docked at bottom, drawpoint is higher than dockpoint
            if ((DockType == DockTypes.Bottom) || (DockType == DockTypes.BottomLeft) || (DockType == DockTypes.BottomRight) || (DockType == DockTypes.Bottom2))
            {
                drawPoint.Y = dockPoint.Y - controlCopy.Height;
            }
            else //drawpoint.Y is the same as dockpoint.Y
            {
                drawPoint.Y = dockPoint.Y;
            }

            //if docked at right, drawpoint is to the left of dockpoint
            if ((DockType == DockTypes.TopRight) || (DockType == DockTypes.Right) || (DockType == DockTypes.BottomRight) || (DockType == DockTypes.Bottom2) || (DockType == DockTypes.Top2))
            {
                drawPoint.X = dockPoint.X - controlCopy.Width;
            }
            else
            {
                drawPoint.X = dockPoint.X;
            }

            return(drawPoint);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a width, in pixels, to the x-coordinate of the dock point at the specified dock type
        /// </summary>
        /// <returns>The new point with the width added</returns>

        Point AddWidthToDockPoint(DockTypes dockType, int widthToAdd)
        {
            return(new Point(dockPointLocations[dockType].X + widthToAdd, dockPointLocations[dockType].Y));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Adds a height, in pixels, to the y-coordinate of the dock point at the specified dock type
 /// </summary>
 /// <returns>The new point with the height added</returns>
 Point AddHeightToDockPoint(DockTypes dockType, int heightToAdd)
 {
     return(new Point(dockPointLocations[dockType].X, dockPointLocations[dockType].Y + heightToAdd));
 }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
 void MyEvents_PanelDrag(Point newPoint)
 {
     panelRectangle.Location = new Point(newPoint.X, newPoint.Y);
     dockPointToHighlight    = FindNearestDockPoint(newPoint, false);
     Invalidate();
 }