public void removeConnectionDrawing(ConnectionDrawing connectionDrawing) { connectionDrawings.Remove(connectionDrawing); }
public void mouseMove(object sender, MouseEventArgs e) { if (mainForm.middleMouseDown && mainForm.toolPanSelected || mainForm.leftMouseDown && mainForm.toolPanSelected) { if (lastMousePoint != Point.Empty) { pan(new Point(lastMousePoint.X - e.X, lastMousePoint.Y - e.Y)); } lastMousePoint = new Point(e.X, e.Y); panelCanvas.Invalidate(); } else { lastMousePoint = Point.Empty; } if (mainForm.nodeBeingDragged != null) { itemPreviewRectangle.X = e.X; itemPreviewRectangle.Y = e.Y; Point absoluteCoordinates = viewport.getAbsoluteCoordinates(new Point(e.X, e.Y)); Rectangle absolutePreviewRectangle = new Rectangle(absoluteCoordinates.X, absoluteCoordinates.Y, 100, 100); if (viewport.checkCollision(absolutePreviewRectangle)) { itemPreviewBrush.Color = Color.FromArgb(128, 255, 0, 0); } else { itemPreviewBrush.Color = Color.FromArgb(32, 127, 127, 127); } panelCanvas.Invalidate(); } if (!(sender is ItemDrawing)) { ConnectionDrawing newClosestConnectionDrawing = null; int? closestConnectionDrawingDistance = null; foreach (ConnectionDrawing connectionDrawing in connectionDrawings) { int distance = connectionDrawing.distanceToPoint(new Point(e.X, e.Y)); if (closestConnectionDrawingDistance == null || distance < closestConnectionDrawingDistance) { closestConnectionDrawingDistance = distance; newClosestConnectionDrawing = connectionDrawing; } } int threshold = viewport.getPixelLength(18); bool refresh = false; if (newClosestConnectionDrawing != null && closestConnectionDrawingDistance < threshold) { if (!newClosestConnectionDrawing.lineHovered) { refresh = true; if (selectedConnectionDrawing != null && selectedConnectionDrawing != newClosestConnectionDrawing) { selectedConnectionDrawing.lineHovered = false; } newClosestConnectionDrawing.lineHovered = true; selectedConnectionDrawing = newClosestConnectionDrawing; } } else { if (selectedConnectionDrawing != null && selectedConnectionDrawing.lineHovered) { refresh = true; selectedConnectionDrawing.lineHovered = false; selectedConnectionDrawing = null; } } if (refresh) { if (newClosestConnectionDrawing != null) { newClosestConnectionDrawing.refresh(); } panelCanvas.Refresh(); } } }
private void addConnectionDrawing(ConnectionDrawing connectionDrawing) { connectionDrawings.Add(connectionDrawing); }
private void refreshConnections() { List<Connection> connectionsThatShouldBeDrawn = viewport.getVisibleConnections(); List<ConnectionDrawing> connectionsThatShouldBeRemoved = new List<ConnectionDrawing>(); Console.WriteLine(connectionsThatShouldBeDrawn.Count.ToString()); foreach (Connection connectionThatShouldBeDrawn in connectionsThatShouldBeDrawn) { ConnectionDrawing connectionDrawing = getConnectionDrawing(connectionThatShouldBeDrawn); if (connectionDrawing == null) { connectionDrawing = new ConnectionDrawing(connectionThatShouldBeDrawn, viewport, mainForm); connectionDrawings.Add(connectionDrawing); } connectionDrawing.IsVisible = true; } foreach (ConnectionDrawing connectionDrawing in connectionDrawings) { if (connectionDrawing.IsVisible && !connectionsThatShouldBeDrawn.Contains(connectionDrawing.Connection)) { connectionsThatShouldBeRemoved.Add(connectionDrawing); //connectionDrawing.IsVisible = false; } else { connectionDrawing.refresh(); } } foreach (ConnectionDrawing connectionThatShouldBeRemoved in connectionsThatShouldBeRemoved) { connectionThatShouldBeRemoved.Disconnect(); connectionDrawings.Remove(connectionThatShouldBeRemoved); } }