private static void workspaceCanvas_MouseMove(object sender, MouseEventArgs e) { mouseLastPos = new PointF((float)(e.GetPosition(workspaceCanvas).X), (float)(e.GetPosition(workspaceCanvas).Y)); switch (mWInst.workspaceCondition) { case MainWindow.WorkspaceConditions.fromParentToHeirRelationPositioniong: workspaceCanvas.Children.Remove(curDrawingPoyline); Border curManipCanvBorder = (Border)curManipulatingCanvas.Parent; PointF p0 = new PointF((float)(Canvas.GetLeft(curManipCanvBorder) + .5f * curManipCanvBorder.ActualWidth), (float)(Canvas.GetTop(curManipCanvBorder))); PointF p1 = new PointF((float)(Canvas.GetLeft(curManipCanvBorder) + .5f * curManipCanvBorder.ActualWidth), (float)(Canvas.GetTop(curManipCanvBorder) + curManipCanvBorder.ActualHeight)); PointF p2 = mouseLastPos; if (canvasOnHover != null) { Ellipse pivotParentEllipse = GetCanvasNodeData(canvasOnHover).parentPivot; p2 = new PointF((float)(Canvas.GetLeft(pivotParentEllipse) + pivotParentEllipse.ActualWidth * .5f), (float)(Canvas.GetTop(pivotParentEllipse) + pivotParentEllipse.ActualHeight * .5f)); } curDrawingPoyline = RelationsDrawer.ConstructPolyline(p0, p1, p2, new PointF { X = p2.X, Y = p2.Y + 50 }); workspaceCanvas.Children.Add(curDrawingPoyline); break; default: break; } }
static void RepaintNodeShapes(Canvas nodeCanvas) { Border nodeCanvasBorder = (Border)nodeCanvas.Parent; RemoveNodeShapes(nodeCanvas); NodeCanvasData ncDInst = GetCanvasNodeData(nodeCanvas); Node node = ncDInst.node; Border rectBorder = new Border() { CornerRadius = new CornerRadius(2), BorderThickness = new Thickness(1), BorderBrush = System.Windows.Media.Brushes.Black }; System.Windows.Shapes.Rectangle heirsPivotRect = new System.Windows.Shapes.Rectangle() { Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.IndianRed), Width = 25, Height = 25 }; Canvas.SetLeft(rectBorder, Canvas.GetLeft(nodeCanvasBorder) + .5f * nodeCanvasBorder.ActualWidth - 12.5f); Canvas.SetTop(rectBorder, Canvas.GetTop(nodeCanvasBorder) + nodeCanvasBorder.ActualHeight); heirsPivotRect.MouseEnter += new MouseEventHandler(canvasRedRect_MouseEnter); heirsPivotRect.MouseLeave += new MouseEventHandler(canvasRedRect_MouseLeave); heirsPivotRect.MouseLeftButtonDown += new MouseButtonEventHandler(canvasRedRect_LeftMouseDown); heirsPivotRect.MouseRightButtonDown += new MouseButtonEventHandler(canvasRedRect_RightMouseDown); rectBorder.Child = heirsPivotRect; workspaceCanvas.Children.Add(rectBorder); Canvas.SetZIndex(rectBorder, 10000); ncDInst.heirsPivot = heirsPivotRect; Ellipse parentPivotEllipse = new Ellipse() { Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.CadetBlue), Width = 25, Height = 25 }; Canvas.SetLeft(parentPivotEllipse, Canvas.GetLeft(nodeCanvasBorder) + .5f * nodeCanvas.Width - 12.5f); Canvas.SetTop(parentPivotEllipse, Canvas.GetTop(nodeCanvasBorder) - 25); workspaceCanvas.Children.Add(parentPivotEllipse); Canvas.SetZIndex(parentPivotEllipse, 20000); ncDInst.parentPivot = parentPivotEllipse; if (node.heirs != null && node.heirs.Count > 0) { List <Canvas> heirsCanvases = new List <Canvas>(); foreach (Heir heir in node.heirs) { heirsCanvases.Add(curNodesOnLayout.Where(el => el.Value.node.Equals(heir.heirNode)).ToArray()[0].Key); } for (int i = 0; i < heirsCanvases.Count; i++) { Border heirCanvBorder = (Border)heirsCanvases[i].Parent; Polyline newPLine; PointF p0, p1, p2, p3; p1 = new PointF((float)(Canvas.GetLeft(nodeCanvasBorder) + .5f * nodeCanvasBorder.ActualWidth), (float)(Canvas.GetTop(nodeCanvasBorder) + nodeCanvasBorder.ActualHeight + ncDInst.heirsPivot.ActualHeight * .5f)); p2 = new PointF((float)(Canvas.GetLeft(heirCanvBorder) + .5f * (heirCanvBorder).ActualWidth), (float)(Canvas.GetTop(heirCanvBorder) - GetCanvasNodeData(heirsCanvases[i]).parentPivot.ActualHeight * .5f)); if (!nodeCanvasBorder.Equals(heirCanvBorder)) { p0 = new PointF(p1.X, (float)Canvas.GetTop(nodeCanvasBorder)); p3 = new PointF(p2.X, (float)(Canvas.GetTop(heirCanvBorder) + (heirCanvBorder).ActualHeight)); newPLine = RelationsDrawer.ConstructPolyline(p0, p1, p2, p3); } else { p0 = new PointF(p1.X, p1.Y - 100f); p3 = new PointF(p2.X, p2.Y + 100f); newPLine = RelationsDrawer.ConstructPolyline(p0, p1, p2, p3, true); } int midIndex = (int)(newPLine.Points.Count * .5f); AddArrowsToPolyline(newPLine); newPLine.MouseEnter += new MouseEventHandler(relation_MouseEnter); newPLine.MouseLeave += new MouseEventHandler(relation_MouseLeave); System.Windows.Point textBlockPos = newPLine.Points.ToArray()[midIndex]; Border tmpBorder = (Border)GetBranchTextBlock(nodeCanvas, heirsCanvases[i]).Parent; Canvas.SetLeft(tmpBorder, textBlockPos.X - tmpBorder.ActualWidth * .5f); Canvas.SetTop(tmpBorder, textBlockPos.Y); ncDInst.relations.Add(newPLine); workspaceCanvas.Children.Add(newPLine); Canvas.SetZIndex(newPLine, 0); } } }