Beispiel #1
0
 private void DrawingEnded()
 {
     FGraphEditor.LinkRoot.Remove(FTempPath);
     FTempPathStarted     = false;
     FTempPath            = null;
     FStartingConnectable = null;
     FGraphEditor.NoAwaitingConnections();
 }
Beispiel #2
0
        public override void OnClick(object sender, PInputEventArgs e)
        {
            base.OnClick(sender, e);

            Solid target = FGraphEditor.GetConnectionCandidate(e.Position, FStartingConnectable);

            if ((FTempPathStarted) && (e.Button == MouseButtons.Right))
            {
                // stop drawing path
                DrawingEnded();
            }
            else if ((target == null) && (FTempPath != null))
            {
                //add linkpoint
                FTempPath.AddPoint(e.Position);
            }
            else if (target != null)
            {
                var t = target.Connectable;

                if (FTempPathStarted)
                {
                    // end link
                    var s = FTempPath.StartSolid.Connectable;

                    if ((t.ConnectableType != s.ConnectableType) ||
                        (s.ConnectableType == ConnectableType.CanBeBoth) ||
                        (t.ConnectableType == ConnectableType.CanBeBoth))
                    {
                        if (t.ConnectableType == ConnectableType.StartingPoint)
                        {
                            // end point wants to be starting point
                            // let's invert the temp path, so that the host can rely on
                            // Path.Start is a Connectable with ConnectableType.StartingPoint
                            // Path.End is a Connectable with ConnectableType.EndPoint

                            FTempPath.Revert(target, out target);
                        }

                        FGraphEditor.Host.FinishPath(FTempPath, target.Connectable);
                        DrawingEnded();
                    }
                }
                else
                {
                    // starting link even when mousedown and mouseup positions doesn't match exactly
                    var x = Math.Pow(e.Position.X - FMouseDownPoint.X, 2);
                    var y = Math.Pow(e.Position.Y - FMouseDownPoint.Y, 2);
                    if (Math.Sqrt(x + y) < 5)
                    {
                        // start link
                        FTempPath            = new TempPath(null, target);
                        FTempPathStarted     = true;
                        FStartingConnectable = target.Connectable;
                        t.DecorateStartingPath(FTempPath);
                        FGraphEditor.ShowAwaitingConnections(target.Connectable);

                        FGraphEditor.LinkRoot.Add(FTempPath);
                    }
                }
            }
        }