Example #1
0
        void ValidConnectionMade()
        {
            CurrentStartNode.SetHasConnection(true);
            CurrentEndNode.SetHasConnection(true);

            var connectingSourceNode = GetSourceNode();
            var connectingTargetNode = GetTargetNode();

            var layer = CreateLayer(connectingSourceNode.ColorComponent.GetColor().ToNSColor());

            DrawPathOnLayer(layer);

            var existingConnections = NodeConnectionData.Where(n =>
                                                               n.SourceNodeView.ColorComponent == connectingSourceNode.ColorComponent ||
                                                               n.TargetNodeView.TargetModifier == connectingTargetNode.TargetModifier)
                                      .ToList();

            if (existingConnections.Count >= 0)
            {
                foreach (var existingConnection in existingConnections)
                {
                    var sourceNode = existingConnection.SourceNodeView;
                    var targetNode = existingConnection.TargetNodeView;

                    if (sourceNode.ColorComponent != connectingSourceNode.ColorComponent)
                    {
                        sourceNode.SetHasConnection(false);
                    }
                    if (targetNode.TargetModifier != connectingTargetNode.TargetModifier)
                    {
                        targetNode.SetNodePortColor(NSColor.Black);
                        targetNode.SetHasConnection(false);
                    }

                    existingConnection.ConnectionLayer.RemoveFromSuperLayer();
                    NodeConnectionData.Remove(existingConnection);
                }
            }

            NodeConnectionData.Add(new NodeConnectionData
            {
                SourceNodeView  = connectingSourceNode,
                TargetNodeView  = connectingTargetNode,
                ConnectionLayer = layer
            });

            Layer.AddSublayer(layer);

            SynthSettings.Instance.SetSourceForTarget
                (connectingSourceNode.ColorComponent, connectingTargetNode.TargetModifier);

            SetNodeColors();
        }
Example #2
0
        void SetNodeColors()
        {
            var sourceNode = GetSourceNode();

            var color = NSColor.Black;

            if (sourceNode != null && sourceNode.GetHasConnection())
            {
                color = sourceNode.ColorComponent.GetColor().ToNSColor();
            }

            CurrentStartNode?.SetNodePortColor(color);
            CurrentEndNode?.SetNodePortColor(color);
        }
Example #3
0
        void SetDefaultConnections()
        {
            var settings = SynthSettings.Instance;

            var sourceNodes = Nodes.Where(n => n is SourceNodeView);
            var targetNodes = Nodes.Where(n => n is TargetNodeView);

            foreach (var targetModifier in Enum.GetValues(typeof(TargetModifier)).Cast <TargetModifier>())
            {
                var source = settings.GetSourceForTarget(targetModifier);

                CurrentStartNode = sourceNodes.First(n => (n as SourceNodeView).ColorComponent == source);
                CurrentEndNode   = targetNodes.First(n => (n as TargetNodeView).TargetModifier == targetModifier);

                CurrentStartPosition = CurrentStartNode.GetNodePortMidPoint();
                CurrentEndPosition   = CurrentEndNode.GetNodePortMidPoint();

                ValidConnectionMade();
            }
        }
Example #4
0
        public override void MouseUp(NSEvent theEvent)
        {
            base.MouseUp(theEvent);

            CurrentEndNode = GetInteractingNodePort();

            if (IsDrawing && IsPendingConnectionValid())
            {
                CurrentEndPosition = CurrentEndNode.GetNodePortMidPoint();
                ValidConnectionMade();
            }
            else
            {
                NoConnectionMade();
            }

            SetNodeColors();
            SetDrawingLayerColor();
            ResetDragStates();
        }
Example #5
0
 bool IsPendingConnectionValid()
 {
     return
         (CurrentStartNode.CanConnectToNode(CurrentEndNode) &&
          CurrentEndNode.CanConnectToNode(CurrentStartNode));
 }
Example #6
0
 void NoConnectionMade()
 {
     CurrentStartNode?.SetHasConnection(false);
     CurrentEndNode?.SetHasConnection(false);
 }