private void AddEllipseToPage(IPAddress ip, IPAddress anotherIP) { //参数中添加 源地址目的地址,在本点是目的地址且没有向源地址发数据时,也添加相应的peertopeer Point thisPosition = new Point(); if (((IList)localIPs).Contains(ip)) { thisPosition.X = canvasWidth / 2; thisPosition.Y = 120 + (canvasHeight - 240) * r.NextDouble(); } else { thisPosition = countPosition(anotherIP); } Ellipse el = new Ellipse(); el.SetValue(Canvas.LeftProperty, thisPosition.X); el.SetValue(Canvas.TopProperty, thisPosition.Y); el.Width = 10; el.Height = 10; EllipseInfo elInfo = new EllipseInfo(el, ip); RadialGradientBrush myRadialGradientBrush = new RadialGradientBrush(); myRadialGradientBrush.GradientOrigin = new Point(0.7, 0.3); myRadialGradientBrush.Center = new Point(0.5, 0.5); myRadialGradientBrush.RadiusX = 1; myRadialGradientBrush.RadiusY = 1; myRadialGradientBrush.GradientStops.Add( new GradientStop(Colors.White, 0.0)); myRadialGradientBrush.GradientStops.Add( new GradientStop(Colors.Black, 0.5)); el.Fill = myRadialGradientBrush; el.MouseEnter += new MouseEventHandler(el_MouseEnter); el.MouseLeave += new MouseEventHandler(el_MouseLeave); canvas1.Children.Add(el); el.Tag = elInfo; el.SetValue(Canvas.ZIndexProperty, 300); el.SetValue(ToolTipService.InitialShowDelayProperty, 0); el.SetValue(ToolTipService.ShowDurationProperty, 100000); ipAndEllipses.Add(ip, el); TextBlock strIP = new TextBlock(); strIP.Text = ip.ToString(); strIP.SetValue(Canvas.ZIndexProperty, 400); canvas1.Children.Add(strIP); strIP.SetBinding(Canvas.LeftProperty, new Binding() { Path = new PropertyPath("TextBlockLeft"), Source = elInfo }); strIP.SetBinding(Canvas.TopProperty, new Binding() { Path = new PropertyPath("TextBlockTop"), Source = elInfo }); }
public WindowShowEllipseInfo(Ellipse e, PeerMapShow _uc) { InitializeComponent(); //this.ShowInTaskbar = false; uc = _uc; el = e; timer = new DispatcherTimer(); timer.Interval = new System.TimeSpan(0, 0, 1); timer.Tick += new EventHandler(timer_Tick); timer.Start(); elInfo = (EllipseInfo)el.Tag; ip = elInfo.ip; peerInfo = uc.ipAndPeerInfos[ip]; tbIP.Text = ip.ToString(); sentPackets.Text = peerInfo.allSendPkNum.ToString(); sentBytes.Text = peerInfo.allSendPkSize.ToString(); sentPercent.Text = ((double)peerInfo.allSendPkSize * 100 / (double)uc.totalPkSize).ToString("0.000"); rcvPackets.Text = peerInfo.allrcvPkNum.ToString(); rcvBytes.Text = peerInfo.allrcvPkSize.ToString(); rcvPercent.Text = ((double)peerInfo.allrcvPkSize * 100 / (double)uc.totalPkSize).ToString("0.000"); peers.Text = peerInfo.peerToPeers.Count.ToString(); protocols.Text = CountProtocols(peerInfo).ToString(); }
private void AddLineToPage(LineSrcDst _lineIP) { //Vector vector = VisualTreeHelper.GetOffset(ipAndEllipses[srcIP]); Ellipse srcEllipse, dstEllipse; _lineIP.daSrcDstX = new DoubleAnimation(); _lineIP.daSrcDstY = new DoubleAnimation(); _lineIP.daDsSrctX = new DoubleAnimation(); _lineIP.daDsSrctY = new DoubleAnimation(); if (ipAndEllipses.ContainsKey(_lineIP._srcip)) { srcEllipse = ipAndEllipses[_lineIP._srcip]; } else { srcEllipse = null; } if (ipAndEllipses.ContainsKey(_lineIP._dstip)) { dstEllipse = ipAndEllipses[_lineIP._dstip]; } else { dstEllipse = null; } EllipseInfo srcEllipseInfo = (EllipseInfo)srcEllipse.Tag; EllipseInfo dstEllipseInfo = (EllipseInfo)dstEllipse.Tag; Duration duration = new Duration(new TimeSpan(0, 0, 1)); _lineIP.daSrcDstX.Duration = duration; _lineIP.daSrcDstY.Duration = duration; _lineIP.daDsSrctX.Duration = duration; _lineIP.daDsSrctY.Duration = duration; _lineIP.raSrcDst = new Rectangle(); _lineIP.raSrcDst.Fill = Brushes.Red; _lineIP.raSrcDst.Width = 6; _lineIP.raSrcDst.Height = 6; _lineIP.raSrcDst.RadiusX = 3; _lineIP.raSrcDst.RadiusY = 3; _lineIP.raDstSrc = new Rectangle(); _lineIP.raDstSrc.Fill = Brushes.Red; _lineIP.raDstSrc.Width = 6; _lineIP.raDstSrc.Height = 6; _lineIP.raDstSrc.RadiusX = 3; _lineIP.raDstSrc.RadiusY = 3; //EllipseInfo tempElinfoSrc = (EllipseInfo)ipAndEllipses[_lineIP._srcip].Tag; //EllipseInfo tempElinfoDst = (EllipseInfo)ipAndEllipses[_lineIP._dstip].Tag; //_lineIP.daSrcDstX.From = tempElinfoSrc.CenterPointX - 3; //_lineIP.daSrcDstY.From = tempElinfoSrc.CenterPointY - 3; //_lineIP.daSrcDstX.To = tempElinfoDst.CenterPointX - 3; //_lineIP.daSrcDstY.To = tempElinfoDst.CenterPointY - 3; //_lineIP.daDsSrctX.From = tempElinfoDst.CenterPointX - 3; //_lineIP.daDsSrctY.From = tempElinfoDst.CenterPointY - 3; //_lineIP.daDsSrctX.To = tempElinfoSrc.CenterPointX - 3; //_lineIP.daDsSrctY.To = tempElinfoSrc.CenterPointY - 3; Storyboard.SetTarget(_lineIP.daSrcDstX, _lineIP.raSrcDst); Storyboard.SetTarget(_lineIP.daSrcDstY, _lineIP.raSrcDst); Storyboard.SetTargetProperty(_lineIP.daSrcDstX, new PropertyPath("(Canvas.Left)")); Storyboard.SetTargetProperty(_lineIP.daSrcDstY, new PropertyPath("(Canvas.Top)")); Storyboard.SetTarget(_lineIP.daDsSrctX, _lineIP.raDstSrc); Storyboard.SetTarget(_lineIP.daDsSrctY, _lineIP.raDstSrc); Storyboard.SetTargetProperty(_lineIP.daDsSrctX, new PropertyPath("(Canvas.Left)")); Storyboard.SetTargetProperty(_lineIP.daDsSrctY, new PropertyPath("(Canvas.Top)")); animationRects.Add(_lineIP.raSrcDst); animationRects.Add(_lineIP.raDstSrc); _lineIP.raSrcDst.SetValue(Canvas.ZIndexProperty, 200); _lineIP.raSrcDst.Visibility = Visibility.Hidden; _lineIP.raSrcDst.IsHitTestVisible = false; _lineIP.raDstSrc.SetValue(Canvas.ZIndexProperty, 200); _lineIP.raDstSrc.Visibility = Visibility.Hidden; _lineIP.raDstSrc.IsHitTestVisible = false; canvas1.Children.Add(_lineIP.raSrcDst); canvas1.Children.Add(_lineIP.raDstSrc); Line l = new Line(); l.SnapsToDevicePixels = true; l.Stroke = new SolidColorBrush(Colors.Blue); l.StrokeThickness = 2; l.Tag = _lineIP; l.SetBinding(Line.X1Property, new Binding() { Path = new PropertyPath("CenterPointX"), Source = srcEllipseInfo }); l.SetBinding(Line.Y1Property, new Binding() { Path = new PropertyPath("CenterPointY"), Source = srcEllipseInfo }); l.SetBinding(Line.X2Property, new Binding() { Path = new PropertyPath("CenterPointX"), Source = dstEllipseInfo }); l.SetBinding(Line.Y2Property, new Binding() { Path = new PropertyPath("CenterPointY"), Source = dstEllipseInfo }); l.MouseEnter += new MouseEventHandler(l_MouseEnter); l.MouseLeave += new MouseEventHandler(l_MouseLeave); l.SetValue(ToolTipService.InitialShowDelayProperty, 0); l.SetValue(ToolTipService.ShowDurationProperty, 100000); canvas1.Children.Add(l); }
void timer_Tick(object sender, EventArgs e) { #region 每次计时器跳时把队列中的点和线画到屏幕上 List <LineSrcDst> tempListIP; List <LineSrcDst> tempDrawLine; lock (tempEllipseLineLock) { tempListIP = listIP; listIP = new List <LineSrcDst>(); tempDrawLine = drawLine; drawLine = new List <LineSrcDst>(); } foreach (var ip in tempListIP) { AddEllipseToPage(ip._srcip, ip._dstip); } foreach (var lineIP in tempDrawLine) { AddLineToPage(lineIP); } #endregion storyBoard.Children.Clear(); //每次跳时根据控件的类型来更新点线的参数,大小,宽度等 foreach (var element in canvas1.Children) { if (element is Ellipse) { tempEllipseInfo = (EllipseInfo)((Ellipse)element).Tag; pointSize = PointSize(ipAndPeerInfos[tempEllipseInfo.ip].allSendPkNum); ipAndEllipses[tempEllipseInfo.ip].Height = pointSize; ipAndEllipses[tempEllipseInfo.ip].Width = pointSize; tempEllipseInfo.TextBlockLeft = tempEllipseInfo.left; tempEllipseInfo.TextBlockTop = tempEllipseInfo.top; //下面两行随便赋值,只是为了激活line端点坐标的重新绑定 // tempEllipseInfo.CenterPointX = 100; // tempEllipseInfo.CenterPointY = 100; tempEllipseInfo.RaiseNotifyPropertyChanged("CenterPointX"); tempEllipseInfo.RaiseNotifyPropertyChanged("CenterPointY"); } if (element is Line) { int allPKNumInLineSrcToDst = 0; int allPKNumInLineDstToSrc = 0; tempLine = (Line)element; tempLineSrcDst = (LineSrcDst)tempLine.Tag; if (ipAndPeerInfos[tempLineSrcDst._srcip].peerToPeers.ContainsKey(tempLineSrcDst._dstip)) { allPKNumInLineSrcToDst = ipAndPeerInfos[tempLineSrcDst._srcip].peerToPeers[tempLineSrcDst._dstip].totalSendPkNum; } if (ipAndPeerInfos[tempLineSrcDst._dstip].peerToPeers.ContainsKey(tempLineSrcDst._srcip)) { allPKNumInLineDstToSrc = ipAndPeerInfos[tempLineSrcDst._dstip].peerToPeers[tempLineSrcDst._srcip].totalSendPkNum; } tempLine.StrokeThickness = LineThickness(allPKNumInLineSrcToDst + allPKNumInLineDstToSrc); if ((bool)cbShowAnimation.IsChecked) { srcEllipseInfo = (EllipseInfo)ipAndEllipses[tempLineSrcDst._srcip].Tag; dstEllipseInfo = (EllipseInfo)ipAndEllipses[tempLineSrcDst._dstip].Tag; if (allPKNumInLineSrcToDst > tempLineSrcDst.oldAllPKNumInLineSrcToDst) { tempLineSrcDst.raSrcDst.Visibility = Visibility.Visible; tempLineSrcDst.daSrcDstX.From = srcEllipseInfo.CenterPointX - 3; tempLineSrcDst.daSrcDstY.From = srcEllipseInfo.CenterPointY - 3; tempLineSrcDst.daSrcDstX.To = dstEllipseInfo.CenterPointX - 3; tempLineSrcDst.daSrcDstY.To = dstEllipseInfo.CenterPointY - 3; //Storyboard.SetTarget(tempLineSrcDst.daSrcDstX, tempLineSrcDst.raSrcDst); //Storyboard.SetTarget(tempLineSrcDst.daSrcDstY, tempLineSrcDst.raSrcDst); //Storyboard.SetTargetProperty(tempLineSrcDst.daSrcDstX, new PropertyPath("(Canvas.Left)")); //Storyboard.SetTargetProperty(tempLineSrcDst.daSrcDstY, new PropertyPath("(Canvas.Top)")); storyBoard.Children.Add(tempLineSrcDst.daSrcDstX); storyBoard.Children.Add(tempLineSrcDst.daSrcDstY); } if (allPKNumInLineDstToSrc > tempLineSrcDst.oldAllPKNumInLineDstToSrc) { tempLineSrcDst.raDstSrc.Visibility = Visibility.Visible; tempLineSrcDst.daDsSrctX.From = dstEllipseInfo.CenterPointX - 3; tempLineSrcDst.daDsSrctY.From = dstEllipseInfo.CenterPointY - 3; tempLineSrcDst.daDsSrctX.To = srcEllipseInfo.CenterPointX - 3; tempLineSrcDst.daDsSrctY.To = srcEllipseInfo.CenterPointY - 3; //Storyboard.SetTarget(tempLineSrcDst.daDsSrctX, tempLineSrcDst.raDstSrc); //Storyboard.SetTarget(tempLineSrcDst.daDsSrctY, tempLineSrcDst.raDstSrc); //Storyboard.SetTargetProperty(tempLineSrcDst.daDsSrctX, new PropertyPath("(Canvas.Left)")); //Storyboard.SetTargetProperty(tempLineSrcDst.daDsSrctY, new PropertyPath("(Canvas.Top)")); storyBoard.Children.Add(tempLineSrcDst.daDsSrctX); storyBoard.Children.Add(tempLineSrcDst.daDsSrctY); } } tempLineSrcDst.oldAllPKNumInLineSrcToDst = allPKNumInLineSrcToDst; tempLineSrcDst.oldAllPKNumInLineDstToSrc = allPKNumInLineDstToSrc; } } storyBoard.Begin(); }