public FlowConnector[] GetConnectorsForLayer(FlowConnector connector, bool isInput) { if (isInput) { return(this.m_Control.Elements .Where(v => v is LayerFlowElement) .Select(v => v as LayerFlowElement) .Where(v => this.m_Layer.Parents.Contains(v.m_Layer)) .Where(v => this.ParentsIndexOf(v.m_Layer).Contains(this.m_InputConnectors.IndexOf(connector))) .Select(v => v.m_OutputConnectors[0]) .ToArray()); } else { IEnumerable <LayerFlowElement> lfe = this.m_Control.Elements .Where(v => v is LayerFlowElement) .Select(v => v as LayerFlowElement) .Where(v => v.m_Layer.Parents.Contains(this.m_Layer)); // TODO: Probably can be moved into LINQ query above. List <FlowConnector> fll = new List <FlowConnector>(); foreach (LayerFlowElement el in lfe) { for (int i = 0; i < el.m_InputConnectors.Count; i++) { if ((el.m_InputConnectors[i] as LayerFlowConnector).ConnectedTo.Contains(this.m_OutputConnectors[0])) { fll.Add(el.m_InputConnectors[i]); } } } return(fll.ToArray()); } }
internal static void RenderTo(FlowElement el, RenderAttributes re, bool selected) { int ex = (int)(el.X * re.Zoom); int ey = (int)(el.Y * re.Zoom); int ew = (int)(el.Width * re.Zoom); int eh = (int)(el.Height * re.Zoom); int eiw = (int)Math.Floor(el.ImageWidth * re.Zoom); int eih = (int)Math.Floor(el.ImageHeight * re.Zoom); int etx = (int)((el.X + 4) * re.Zoom); int ety = (int)((el.Y + 4) * re.Zoom); re.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; re.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; re.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; re.Graphics.FillRectangle(selected ? m_TitleHighlight : SystemBrushes.Control, ex, ey, ew - 1 * re.Zoom, eh - 1 * re.Zoom); re.Graphics.DrawRectangle(Pens.Black, ex, ey, ew - 1 * re.Zoom, eh - 1 * re.Zoom); re.Graphics.DrawString(el.Name, re.Font, SystemBrushes.ControlText, new PointF(etx, ety)); Image img = el.Image; if (img != null) { re.Graphics.DrawImage(img, ex + 1 * re.Zoom, ey + 21 * re.Zoom, eiw, eih); } foreach (FlowConnector fl in el.OutputConnectors) { FlowConnector.RenderTo(fl, re); } foreach (FlowConnector fl in el.InputConnectors) { FlowConnector.RenderTo(fl, re); } }
internal static int GetConnectorIndex(FlowElement el, FlowConnector fl) { if (fl.IsInput) { return(el.InputConnectors.IndexOf(fl)); } else { return(el.OutputConnectors.IndexOf(fl)); } }
internal static void RenderTo(FlowConnector el, RenderAttributes re) { re.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; re.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; // If we are input, we draw on the left hand side of the flow element. int idx = FlowElement.GetConnectorIndex(el.Owner, el); int sx = (int)Math.Ceiling(re.Graphics.MeasureString(el.Name, re.Font).Width); float xx = (el.IsInput ? el.Owner.X - CONNECTOR_PADDING : el.Owner.X + el.Owner.Width + CONNECTOR_PADDING) * re.Zoom; float yy = (el.Owner.Y + idx * (CONNECTOR_SIZE + CONNECTOR_PADDING)) * re.Zoom; if (el.IsInput) { re.Graphics.DrawString(el.Name, re.Font, SystemBrushes.ControlText, new PointF(xx - sx + CONNECTOR_PADDING * re.Zoom, yy)); } else { re.Graphics.DrawString(el.Name, re.Font, SystemBrushes.ControlText, new PointF(xx, yy)); } el.InvalidationWidth = sx; el.m_CenterZoomAdjustment = re.Zoom; sx += CONNECTOR_PADDING; re.Graphics.DrawRectangle(Pens.Black, xx + (el.IsInput ? -sx : sx), yy, CONNECTOR_SIZE * re.Zoom, CONNECTOR_SIZE * re.Zoom); if (el.IsInput && el.ConnectedTo != null) { foreach (FlowConnector ct in el.ConnectedTo) { try { re.Graphics.DrawLine(Pens.Blue, el.Center.Apply(re.Zoom), ct.Center.Apply(re.Zoom)); } catch (OverflowException) { } } } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); // Don't do anything on right-click. if (e.Button == System.Windows.Forms.MouseButtons.Right) { this.m_LastContextMenuOpenLocation = e.Location; return; } // If we are currently dragging, ignore this logic. if (this.m_SelectedElementStillHeldDown || this.m_PanningStillHeldDown) { return; } // Check to see if the mouse is over an element during left press. if (e.Button == System.Windows.Forms.MouseButtons.Left) { this.SelectedElement = null; foreach (FlowElement el in this.m_Elements.Reverse <FlowElement>()) { if (el.Region.Contains(e.Location.Apply(1 / this.Zoom))) { this.SelectedElement = el; this.m_SelectedElementStillHeldDown = true; this.m_SelectedElementDragX = (int)(e.X / this.Zoom) - el.X; this.m_SelectedElementDragY = (int)(e.Y / this.Zoom) - el.Y; break; } } // If we didn't select an element, see if we clicked on a flow // connector. if (this.SelectedElement == null && this.m_ActiveConnection == null) { Rectangle range = new Rectangle( e.X - FlowConnector.CONNECTOR_SIZE / 2, e.Y - FlowConnector.CONNECTOR_SIZE / 2, FlowConnector.CONNECTOR_SIZE * 2, FlowConnector.CONNECTOR_SIZE * 2); foreach (FlowElement el in this.m_Elements.Reverse <FlowElement>()) { // Check input connectors. foreach (FlowConnector ic in el.InputConnectors) { if (range.Contains(ic.Center)) { this.m_ActiveConnection = ic; return; } } // Check output connectors. foreach (FlowConnector ic in el.OutputConnectors) { if (range.Contains(ic.Center)) { this.m_ActiveConnection = ic; return; } } } } // Otherwise if we're clicking on a flow connector and there is an // active connection, we probably want to make the connection. else if (this.m_ActiveConnection != null) { Rectangle range = new Rectangle( e.X - FlowConnector.CONNECTOR_SIZE / 2, e.Y - FlowConnector.CONNECTOR_SIZE / 2, FlowConnector.CONNECTOR_SIZE * 2, FlowConnector.CONNECTOR_SIZE * 2); foreach (FlowElement el in this.m_Elements.Reverse <FlowElement>()) { // Check input connectors. foreach (FlowConnector ic in el.InputConnectors) { if (range.Contains(ic.Center)) { // The user wants to connect this up. Is it possible? if (this.m_ActiveConnection.IsInput) { // Can't connect an input to an input.. this.m_ActiveConnection = null; return; } else { // Set the connection. FlowConnector[] old = this.m_ActiveConnection.ConnectedTo; List <FlowConnector> newFC = new List <FlowConnector>(); foreach (FlowConnector fc in old) { if (!newFC.Contains(fc)) { newFC.Add(fc); } } if (!newFC.Contains(ic)) { newFC.Add(ic); } this.m_ActiveConnection.ConnectedTo = newFC.ToArray(); // Finish up by turning off connection mode. this.m_ActiveConnection = null; return; } } } // Check output connectors. /*foreach (FlowConnector ic in el.OutputConnectors) * { * if (range.Contains(ic.Center)) * { * this.m_ActiveConnection = ic; * return; * } * }*/ } } } // Pan on middle mouse button. if (e.Button == System.Windows.Forms.MouseButtons.Middle || e.Button == System.Windows.Forms.MouseButtons.Left) { this.m_PanningStillHeldDown = true; this.m_AllElementPanX = this.m_AllElementPanOldX = e.X; this.m_AllElementPanY = this.m_AllElementPanOldY = e.Y; } }