public void FollowMouse(WeightedNodeControl selectedNode) { nodeToFollow = selectedNode; timer.Elapsed += Timer_Elapsed; timer.Start(); IsFollowingMouse = true; }
public void StopFollowingMouse() { nodeToFollow = null; timer.Stop(); timer.Elapsed -= Timer_Elapsed; IsFollowingMouse = false; }
private void newNodeButton_Click(object sender, RoutedEventArgs e) { if (WeightedNodeControl.IsFollowingMouse == false) { WeightedNodeControl weightedNodeControl = new WeightedNodeControl(); weightedNodeControl.PreviewMouseLeftButtonDown += WeightedNodeControl_PreviewMouseLeftButtonDown; mainCanvas.Children.Add(weightedNodeControl); isNewNode = true; } }
/// <summary> /// Creates a LinkingLine that only has a source and can be linked to a new destination. /// </summary> /// <param name=""></param> public LinkingLine(WeightedNodeControl source) { InitializeComponent(); this.source = source; RequiresDestination = true; source.AddLinkingLine(this); timer.Interval = 5; timer.AutoReset = true; timer.Enabled = true; }
private void LinkingLine_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (RequiresDestination) { if (ParentIsOfType((FrameworkElement)Mouse.DirectlyOver, typeof(WeightedNodeControl))) { WeightedNodeControl node = (WeightedNodeControl)GetParentControl((FrameworkElement)Mouse.DirectlyOver, typeof(WeightedNodeControl)); node.WasLinkedTo = true; node.AddLinkingLine(this); this.destination = node; RequiresDestination = false; ((UIElement)Parent).PreviewMouseLeftButtonDown -= LinkingLine_PreviewMouseLeftButtonDown; } } }
/// <summary> /// Creates a LinkingLine that which already has a destination. /// </summary> /// <param name="source"></param> /// <param name="destination"></param> public LinkingLine(WeightedNodeControl source, WeightedNodeControl destination) { InitializeComponent(); this.source = source; this.destination = destination; source.AddLinkingLine(this); destination.AddLinkingLine(this); destination.PreviewMouseLeftButtonDown += Destination_PreviewMouseLeftButtonDown; timer.Interval = 5; timer.AutoReset = true; timer.Enabled = true; }
private void contextMenuNewPathButton_Click(object sender, RoutedEventArgs e) { WeightedNodeControl newNode = new WeightedNodeControl(); Canvas mainCanvas = (Canvas)this.Parent; LinkingLine line = new LinkingLine(this, newNode); line.X1 = Canvas.GetLeft(this) + (this.Width / 2); line.Y1 = Canvas.GetTop(this) + (this.Height / 2); mainCanvas.Children.Add(line); mainCanvas.Children.Add(newNode); Canvas.SetZIndex(line, 0); Canvas.SetZIndex(newNode, 1); wasContextMenuOptionSelected = true; }
private void WeightedNodeControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (isNewNode == true) { WeightedNodeControl nodeControl = sender as WeightedNodeControl; WeightedNodeControl newNode = new WeightedNodeControl(); isNewNode = false; LinkingLine line = new LinkingLine(nodeControl, newNode); line.X1 = Canvas.GetLeft(nodeControl) + (nodeControl.Width / 2); line.Y1 = Canvas.GetTop(nodeControl) + (nodeControl.Height / 2); mainCanvas.Children.Add(line); mainCanvas.Children.Add(newNode); Canvas.SetZIndex(line, 0); Canvas.SetZIndex(nodeControl, 1); Canvas.SetZIndex(newNode, 1); } }