public ConnectionPoint(ActivityDesigner associatedDesigner, DesignerEdges designerEdge, int connectionIndex) { if (associatedDesigner == null) { throw new ArgumentNullException("associatedDesigner"); } if ((connectionIndex < 0) || (connectionIndex >= associatedDesigner.GetConnections(designerEdge).Count)) { throw new ArgumentException(DR.GetString("Error_ConnectionPoint", new object[0]), "connectionIndex"); } this.associatedDesigner = associatedDesigner; this.designerEdge = designerEdge; this.connectionIndex = connectionIndex; }
/// <summary> /// Gets the array of rectangles bounding the connectors /// </summary> protected internal virtual Rectangle[] GetConnectors() { if (ActiveDesigner != this) { return new Rectangle[] { } } ; if (!Expanded) { return new Rectangle[] { } } ; CompositeDesignerTheme designerTheme = DesignerTheme as CompositeDesignerTheme; if (designerTheme == null) { return new Rectangle[] { } } ; //Calculate no of connectors for the container; if there is no activityDesigner then we display single connector ReadOnlyCollection <ActivityDesigner> containedDesigners = ContainedDesigners; int connectorCount = (containedDesigners.Count > 0) ? (2 + (containedDesigners.Count - 1)) : 1; Rectangle[] connectorBounds = new Rectangle[connectorCount]; ReadOnlyCollection <Point> containerConnections = GetInnerConnections(DesignerEdges.Top | DesignerEdges.Bottom); Point containerStartConnection = new Point(); Point containerEndConnection = new Point(); if (containerConnections != null && containerConnections.Count > 0) { containerStartConnection = containerConnections[0]; containerEndConnection = containerConnections[containerConnections.Count - 1]; } if (containedDesigners.Count > 0) { //Add the first connector. This will be from bitmap bottom to activityDesigner start ActivityDesigner startDesigner = containedDesigners[0] as ActivityDesigner; ReadOnlyCollection <Point> startDesignerConnections = startDesigner.GetConnections(DesignerEdges.Top | DesignerEdges.Bottom); if (startDesignerConnections.Count == 0) { Rectangle startDesignerBounds = startDesigner.Bounds; List <Point> connections = new List <Point>(); connections.Add(new Point(startDesignerBounds.Left + startDesignerBounds.Width / 2, startDesignerBounds.Top)); connections.Add(new Point(startDesignerBounds.Left + startDesignerBounds.Width / 2, startDesignerBounds.Bottom)); startDesignerConnections = connections.AsReadOnly(); } connectorBounds[0].Location = new Point(containerStartConnection.X - ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) / 2, containerStartConnection.Y); connectorBounds[0].Size = new Size(((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0), startDesignerConnections[0].Y - containerStartConnection.Y); //Add rest of the points for (int i = 0; i < containedDesigners.Count - 1; i++) { ActivityDesigner designerFrom = containedDesigners[i]; ActivityDesigner designerTo = containedDesigners[i + 1]; if (designerFrom != null && designerTo != null) { ReadOnlyCollection <Point> designerFromConnections = designerFrom.GetConnections(DesignerEdges.Top | DesignerEdges.Bottom); int designerFromPointCount = designerFromConnections.Count; ReadOnlyCollection <Point> designerToConnections = designerTo.GetConnections(DesignerEdges.Top | DesignerEdges.Bottom); connectorBounds[i + 1].Location = new Point(designerFromConnections[designerFromPointCount - 1].X - ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) / 2, designerFromConnections[designerFromPointCount - 1].Y); connectorBounds[i + 1].Size = new Size(((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0), designerToConnections[0].Y - designerFromConnections[designerFromPointCount - 1].Y); } } //Add the last connector ActivityDesigner endDesigner = containedDesigners[containedDesigners.Count - 1]; ReadOnlyCollection <Point> endDesignerConnections = endDesigner.GetConnections(DesignerEdges.Top | DesignerEdges.Bottom); if (endDesignerConnections.Count == 0) { Rectangle endDesignerBounds = endDesigner.Bounds; List <Point> connections = new List <Point>(); connections.Add(new Point(endDesignerBounds.Left + endDesignerBounds.Width / 2, endDesignerBounds.Top)); connections.Add(new Point(endDesignerBounds.Left + endDesignerBounds.Width / 2, endDesignerBounds.Bottom)); endDesignerConnections = connections.AsReadOnly(); } connectorBounds[connectorCount - 1].Location = new Point(endDesignerConnections[endDesignerConnections.Count - 1].X - ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) / 2, endDesignerConnections[endDesignerConnections.Count - 1].Y); connectorBounds[connectorCount - 1].Size = new Size(((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0), containerEndConnection.Y - endDesignerConnections[endDesignerConnections.Count - 1].Y); } else { //If there are no activity designers in the container then we show only one connector connectorBounds[0].Location = new Point(containerStartConnection.X - ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) / 2, containerStartConnection.Y); connectorBounds[0].Size = new Size(((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0), containerEndConnection.Y - containerStartConnection.Y); } //extend the targets a little bit for (int i = 0; i < connectorBounds.Length; i++) { connectorBounds[i].Inflate(3 * connectorBounds[i].Width, 0); } return(connectorBounds); }
protected internal virtual Rectangle[] GetConnectors() { if (base.ActiveDesigner != this) { return(new Rectangle[0]); } if (!this.Expanded) { return(new Rectangle[0]); } CompositeDesignerTheme designerTheme = base.DesignerTheme as CompositeDesignerTheme; if (designerTheme == null) { return(new Rectangle[0]); } ReadOnlyCollection <ActivityDesigner> containedDesigners = this.ContainedDesigners; int num = (containedDesigners.Count > 0) ? (2 + (containedDesigners.Count - 1)) : 1; Rectangle[] rectangleArray = new Rectangle[num]; ReadOnlyCollection <Point> innerConnections = this.GetInnerConnections(DesignerEdges.Bottom | DesignerEdges.Top); Point point = new Point(); Point point2 = new Point(); if ((innerConnections != null) && (innerConnections.Count > 0)) { point = innerConnections[0]; point2 = innerConnections[innerConnections.Count - 1]; } if (containedDesigners.Count > 0) { ActivityDesigner designer = containedDesigners[0]; ReadOnlyCollection <Point> connections = designer.GetConnections(DesignerEdges.Bottom | DesignerEdges.Top); if (connections.Count == 0) { Rectangle bounds = designer.Bounds; connections = new List <Point> { new Point(bounds.Left + (bounds.Width / 2), bounds.Top), new Point(bounds.Left + (bounds.Width / 2), bounds.Bottom) }.AsReadOnly(); } rectangleArray[0].Location = new Point(point.X - (((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) / 2), point.Y); Point point3 = connections[0]; rectangleArray[0].Size = new Size((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0, point3.Y - point.Y); for (int j = 0; j < (containedDesigners.Count - 1); j++) { ActivityDesigner designer2 = containedDesigners[j]; ActivityDesigner designer3 = containedDesigners[j + 1]; if ((designer2 != null) && (designer3 != null)) { ReadOnlyCollection <Point> onlys4 = designer2.GetConnections(DesignerEdges.Bottom | DesignerEdges.Top); int count = onlys4.Count; ReadOnlyCollection <Point> onlys5 = designer3.GetConnections(DesignerEdges.Bottom | DesignerEdges.Top); Point point4 = onlys4[count - 1]; Point point5 = onlys4[count - 1]; rectangleArray[j + 1].Location = new Point(point4.X - (((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) / 2), point5.Y); Point point6 = onlys5[0]; Point point7 = onlys4[count - 1]; rectangleArray[j + 1].Size = new Size((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0, point6.Y - point7.Y); } } ActivityDesigner designer4 = containedDesigners[containedDesigners.Count - 1]; ReadOnlyCollection <Point> onlys6 = designer4.GetConnections(DesignerEdges.Bottom | DesignerEdges.Top); if (onlys6.Count == 0) { Rectangle rectangle2 = designer4.Bounds; onlys6 = new List <Point> { new Point(rectangle2.Left + (rectangle2.Width / 2), rectangle2.Top), new Point(rectangle2.Left + (rectangle2.Width / 2), rectangle2.Bottom) }.AsReadOnly(); } Point point8 = onlys6[onlys6.Count - 1]; Point point9 = onlys6[onlys6.Count - 1]; rectangleArray[num - 1].Location = new Point(point8.X - (((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) / 2), point9.Y); Point point10 = onlys6[onlys6.Count - 1]; rectangleArray[num - 1].Size = new Size((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0, point2.Y - point10.Y); } else { rectangleArray[0].Location = new Point(point.X - (((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) / 2), point.Y); rectangleArray[0].Size = new Size((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0, point2.Y - point.Y); } for (int i = 0; i < rectangleArray.Length; i++) { rectangleArray[i].Inflate(3 * rectangleArray[i].Width, 0); } return(rectangleArray); }
private void DrawParallelDropTargets(ActivityDesignerPaintEventArgs e, int index) { Rectangle[] dropTargets = GetDropTargets(Point.Empty); if (index < 0 || index >= dropTargets.Length) { return; } CompositeDesignerTheme compositeDesignerTheme = e.DesignerTheme as CompositeDesignerTheme; if (compositeDesignerTheme == null) { return; } ReadOnlyCollection <ActivityDesigner> containedDesigners = ContainedDesigners; Rectangle dropTargetRectangle = dropTargets[index]; Rectangle bounds = Bounds; int parallelConnectorTop = bounds.Top; parallelConnectorTop += TitleHeight; parallelConnectorTop += (containedDesigners.Count > 0) ? compositeDesignerTheme.ConnectorSize.Height * 3 / 4 : 0; int heightDelta = dropTargetRectangle.Y - parallelConnectorTop; heightDelta += bounds.Bottom - dropTargetRectangle.Bottom; heightDelta -= (containedDesigners.Count > 0) ? compositeDesignerTheme.ConnectorSize.Height * 3 / 4 : 0; dropTargetRectangle.Y = parallelConnectorTop; dropTargetRectangle.Height += heightDelta; DrawConnectors(e.Graphics, e.AmbientTheme.DropIndicatorPen, new Point[] { new Point(dropTargetRectangle.Left + dropTargetRectangle.Width / 2, dropTargetRectangle.Top + 2), new Point(dropTargetRectangle.Left + dropTargetRectangle.Width / 2, dropTargetRectangle.Bottom - 2) }, compositeDesignerTheme.ConnectorStartCap, compositeDesignerTheme.ConnectorEndCap); if (containedDesigners.Count > 0) { if (index == 0) { ActivityDesigner firstDesigner = containedDesigners[0]; ReadOnlyCollection <Point> firstDesignerConnections = firstDesigner.GetConnections(DesignerEdges.Top | DesignerEdges.Bottom); Point[] connectorPoints = new Point[2]; connectorPoints[0].X = dropTargetRectangle.X + dropTargetRectangle.Width / 2; connectorPoints[0].Y = dropTargetRectangle.Y; connectorPoints[1].X = firstDesignerConnections[0].X; connectorPoints[1].Y = dropTargetRectangle.Y; DrawConnectors(e.Graphics, e.AmbientTheme.DropIndicatorPen, connectorPoints, LineAnchor.None, LineAnchor.None); connectorPoints[0].Y = dropTargetRectangle.Bottom; connectorPoints[1].Y = dropTargetRectangle.Bottom; DrawConnectors(e.Graphics, e.AmbientTheme.DropIndicatorPen, connectorPoints, LineAnchor.None, LineAnchor.None); } else if (index == containedDesigners.Count) { ActivityDesigner lastDesigner = containedDesigners[containedDesigners.Count - 1]; ReadOnlyCollection <Point> lastDesignerConnections = lastDesigner.GetConnections(DesignerEdges.Top | DesignerEdges.Bottom); Point[] connectorPoints = new Point[2]; connectorPoints[0].X = lastDesignerConnections[0].X; connectorPoints[0].Y = dropTargetRectangle.Y; connectorPoints[1].X = dropTargetRectangle.X + dropTargetRectangle.Width / 2; connectorPoints[1].Y = dropTargetRectangle.Y; DrawConnectors(e.Graphics, e.AmbientTheme.DropIndicatorPen, connectorPoints, LineAnchor.None, LineAnchor.None); connectorPoints[0].Y = dropTargetRectangle.Bottom; connectorPoints[1].Y = dropTargetRectangle.Bottom; DrawConnectors(e.Graphics, e.AmbientTheme.DropIndicatorPen, connectorPoints, LineAnchor.None, LineAnchor.None); } } }
private void DrawParallelConnectors(ActivityDesignerPaintEventArgs e) { CompositeDesignerTheme compositeDesignerTheme = e.DesignerTheme as CompositeDesignerTheme; if (compositeDesignerTheme == null) { return; } //Get all the information required to calculate the connectors Rectangle bounds = Bounds; int parallelConnectorTop = bounds.Top; parallelConnectorTop += TitleHeight; ReadOnlyCollection <ActivityDesigner> containedDesigners = ContainedDesigners; ActivityDesigner firstDesigner = containedDesigners[0]; ReadOnlyCollection <Point> firstDesignerConnections = firstDesigner.GetConnections(DesignerEdges.Top | DesignerEdges.Bottom); ActivityDesigner lastDesigner = containedDesigners[containedDesigners.Count - 1]; ReadOnlyCollection <Point> lastDesignerConnections = lastDesigner.GetConnections(DesignerEdges.Top | DesignerEdges.Bottom); Point[] parallelLinks = new Point[2]; //Draw small vertical line at the top parallelLinks[0].X = bounds.Left + bounds.Width / 2; parallelLinks[0].Y = parallelConnectorTop; parallelLinks[1].X = bounds.Left + bounds.Width / 2; parallelLinks[1].Y = parallelConnectorTop + compositeDesignerTheme.ConnectorSize.Height * 3 / 4; DrawConnectors(e.Graphics, compositeDesignerTheme.ForegroundPen, parallelLinks, LineAnchor.None, LineAnchor.None); //Draw Horizontal line at the top parallelLinks[0].X = firstDesignerConnections[0].X; parallelLinks[0].Y = parallelConnectorTop + compositeDesignerTheme.ConnectorSize.Height * 3 / 4; parallelLinks[1].X = lastDesignerConnections[0].X; parallelLinks[1].Y = parallelConnectorTop + compositeDesignerTheme.ConnectorSize.Height * 3 / 4; DrawConnectors(e.Graphics, compositeDesignerTheme.ForegroundPen, parallelLinks, LineAnchor.None, LineAnchor.None); //Draw Horizontal line at the bottom parallelLinks[0].X = firstDesignerConnections[firstDesignerConnections.Count - 1].X; parallelLinks[0].Y = bounds.Bottom - compositeDesignerTheme.ConnectorSize.Height * 3 / 4; parallelLinks[1].X = lastDesignerConnections[lastDesignerConnections.Count - 1].X; parallelLinks[1].Y = bounds.Bottom - compositeDesignerTheme.ConnectorSize.Height * 3 / 4; DrawConnectors(e.Graphics, compositeDesignerTheme.ForegroundPen, parallelLinks, LineAnchor.None, LineAnchor.None); //Draw small vertical line at the bottom parallelLinks[0].X = bounds.Left + bounds.Width / 2; parallelLinks[0].Y = bounds.Bottom - compositeDesignerTheme.ConnectorSize.Height * 3 / 4; parallelLinks[1].X = bounds.Left + bounds.Width / 2; parallelLinks[1].Y = bounds.Bottom; DrawConnectors(e.Graphics, compositeDesignerTheme.ForegroundPen, parallelLinks, LineAnchor.None, LineAnchor.None); foreach (ActivityDesigner activityDesigner in containedDesigners) { ReadOnlyCollection <Point> designerConnections = activityDesigner.GetConnections(DesignerEdges.Top | DesignerEdges.Bottom); int connectionCount = designerConnections.Count; Point[] connectingLine = new Point[2]; //Draw connectors for every activityDesigner connectingLine[0].X = designerConnections[0].X; connectingLine[0].Y = parallelConnectorTop + compositeDesignerTheme.ConnectorSize.Height * 3 / 4; connectingLine[1].X = designerConnections[0].X; connectingLine[1].Y = designerConnections[0].Y; DrawConnectors(e.Graphics, compositeDesignerTheme.ForegroundPen, connectingLine, compositeDesignerTheme.ConnectorStartCap, compositeDesignerTheme.ConnectorEndCap); //Draw connectors for every activityDesigner connectingLine[0].X = designerConnections[connectionCount - 1].X; connectingLine[0].Y = designerConnections[connectionCount - 1].Y; connectingLine[1].X = designerConnections[connectionCount - 1].X; connectingLine[1].Y = bounds.Bottom - compositeDesignerTheme.ConnectorSize.Height * 3 / 4; DrawConnectors(e.Graphics, compositeDesignerTheme.ForegroundPen, connectingLine, compositeDesignerTheme.ConnectorStartCap, compositeDesignerTheme.ConnectorEndCap); } }