示例#1
0
        public void FollowMouse(WeightedNodeControl selectedNode)
        {
            nodeToFollow = selectedNode;

            timer.Elapsed += Timer_Elapsed;
            timer.Start();
            IsFollowingMouse = true;
        }
示例#2
0
        public void StopFollowingMouse()
        {
            nodeToFollow = null;

            timer.Stop();
            timer.Elapsed -= Timer_Elapsed;

            IsFollowingMouse = false;
        }
示例#3
0
 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;
     }
 }
示例#4
0
        /// <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;
        }
示例#5
0
        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;
                }
            }
        }
示例#6
0
        /// <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;
        }
示例#7
0
        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;
        }
示例#8
0
        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);
            }
        }