Ejemplo n.º 1
0
        public OutputChannel GetOutputChannel(OutputChannelReference chanRef)
        {
            var node = GetNode(chanRef.NodeIdentifier);

            return(node.GetOutputChannel(chanRef.ChannelId));
        }
Ejemplo n.º 2
0
 public void OnLostFocus()
 {
     _doingSelectBox = false;
     SelectedInputChannel = null;
     SelectedOutputChannel = null;
 }
Ejemplo n.º 3
0
 public InputChannel(uint id, string name) : base(id, name)
 {
     IncomingConnection = null;
 }
Ejemplo n.º 4
0
        public void OnGUI()
        {
            if (!_isInstructionCountCached)
                CacheCount();
            GUI.Label(new Rect(5,0,95,45),new GUIContent(_instructionCountDetails,_instructionCountTooltip));

            _reservedArea.Clear();
            _drawArea = new Rect( 0, 0, Screen.width-300, Screen.height-23 );
            _detailsBox = new Rect(Screen.width - 300,0, 300, Screen.height - 40);
            _optionsBox = new Rect(Screen.width - 300,Screen.height - 40, 300 , 25);

            //Mouse clicks in the reserved area do not attemp to select on graph
            _reservedArea.Add( _detailsBox );
            _reservedArea.Add( _optionsBox );

            _currentMousePosition.x = Event.current.mousePosition.x;
            _currentMousePosition.y = Event.current.mousePosition.y;

            // Handle Minimap! (Texel)
            if (_middleMouseDrag) {
                var oldColor = GUI.color;
                var trans = GUI.color * new Vector4(1,1,1,0.3f); // Fairly transparent
                // First, draw the bounds of the graph. This requires min/maxing the graph
                var drawCenter = new Vector2((_drawArea.x + (_drawArea.width * 0.5f)),_drawArea.y + (_drawArea.height * 0.5f));
                drawCenter.x -= _drawArea.width * 0.1f;
                drawCenter.y -= _drawArea.height * 0.1f;

                var redSize = new Vector2(_drawArea.width,_drawArea.height) * 0.2f;

                GUI.color = trans;
                GUI.Box(new Rect(drawCenter.x,drawCenter.y,redSize.x,redSize.y),"");
                GUI.color = oldColor;
                var oldBkg = GUI.backgroundColor;

                // Now we will draw the graph centered around the offset (Scaled down ten times)
                //Rect[] rects = _selectedGraph.CurrentSubGraph.nodePositions;
                foreach(Node node in _selectedGraph.CurrentSubGraph.Nodes) {
                    var rect = node.NodePositionInGraph;

                    var delta = new Vector2(rect.x,rect.y);// - offset;
                    var size = new Vector2(rect.width,rect.height);
                    delta *= 0.2f; size *= 0.2f;
                    delta += drawCenter;

                    switch (node.CurrentState) {
                        case (NodeState.Valid):
                            GUI.color = Color.white;
                            break;
                        case (NodeState.NotConnected):
                            GUI.color = new Color (0.8f, 0.8f, 1f);
                            break;
                        case (NodeState.CircularReferenceInGraph):
                            GUI.color = new Color (0.8f, 0.8f, 0f);
                            break;
                        case (NodeState.Error):
                            GUI.color = Color.red;
                            break;
                    }

                    if( node == _selectedNode )
                        GUI.backgroundColor = Color.Lerp(GUI.backgroundColor,Color.green,0.5f);

                    GUI.Box(new Rect(delta.x,delta.y,size.x,size.y),"");
                    GUI.color = oldColor;
                    GUI.backgroundColor = oldBkg;
                }
            }

            HandleEvents();

            //GUI fixup for changed focus
            GUI.SetNextControlName("FocusFixup");
            EditorGUI.Toggle(new Rect(-100, -100, 1, 1), false);

            if (_focusChangedUpdate)
            {
                GUI.FocusControl("FocusFixup");
                _focusChangedUpdate = false;
            }

            //Update each node and draw them
            _selectedGraph.UpdateErrorState();
            GUILayout.BeginArea( _drawArea );
            _selectedGraph.Draw( this, _showComments, _drawArea );
            UpdateIOChannels();
            DrawIOLines(_drawArea);
            GUILayout.EndArea( );

            if( _doingSelectBox )
            {
                var oldColor = GUI.color;
                var newColor = GUI.color;
                newColor.a = 0.4f;
                GUI.color = newColor;
                GUI.Box( GetSelectionArea(), "" );
                GUI.color = oldColor;
            }

            DrawSettings();

            //Handle node delete / undo and redo
            if( !GUI.changed && Event.current.type == EventType.KeyDown )
            {
                if (Event.current.keyCode == KeyCode.Z
                    && ( Event.current.modifiers == EventModifiers.Alt ) )
                {
                    var graph = _undoChain.Undo();
                    if( graph != null )
                    {
                        _nextGraph = graph;
                        _nextGraph.Initialize( new Rect( 0, 0, Screen.width, Screen.height ), false);
                        _graphNeedsUpdate = true;
                        NextSelectedNode = _nextGraph.FirstSelected;
                        _updateSelection = true;
                        Event.current.Use();
                    }
                    return;
                }
                if (Event.current.keyCode == KeyCode.Z
                    && ( Event.current.modifiers == (EventModifiers.Alt | EventModifiers.Shift ) ) )
                {
                    var graph = _undoChain.Redo();
                    if( graph != null )
                    {
                        _nextGraph = graph;
                        _nextGraph.Initialize( new Rect( 0, 0, Screen.width, Screen.height ), false);
                        _graphNeedsUpdate = true;
                        NextSelectedNode = _nextGraph.FirstSelected;
                        _updateSelection = true;
                        Event.current.Use();
                    }
                    return;
                }

                if (Event.current.keyCode == KeyCode.Delete || Event.current.keyCode == KeyCode.Backspace)
                {
                    _selectedGraph.CurrentSubGraph.DeleteSelected();
                    NextSelectedNode = null;
                    _graphNeedsUpdate = true;
                    _updateSelection = true;

                    SelectedInputChannel = null;
                    SelectedOutputChannel = null;
                    MarkDirty();
                    Event.current.Use();
                }
            }

            //Draw the current subgraph type
            var oldFontSize = GUI.skin.label.fontSize;
            var oldFontStyle = GUI.skin.label.fontStyle;
            GUI.skin.label.fontSize = 30;
            GUI.skin.label.fontStyle = FontStyle.BoldAndItalic;
            GUILayout.BeginArea( _drawArea );
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label( _currentSubGraphType.DisplayName(), GUI.skin.label );
            GUILayout.Space( 10 );
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            GUI.skin.label.fontSize = oldFontSize;
            GUI.skin.label.fontStyle = oldFontStyle;

            DrawOptions();
        }
Ejemplo n.º 5
0
        private void UpdateIOChannels()
        {
            //Update channel selection state
            if (SelectedInputChannel != null && SelectedOutputChannel != null)
            {
                var inputChannel = _selectedGraph.CurrentSubGraph.GetInputChannel(SelectedInputChannel);
                var outputChannel = _selectedGraph.CurrentSubGraph.GetOutputChannel(SelectedOutputChannel);

                if (SelectedInputChannel.NodeIdentifier != SelectedOutputChannel.NodeIdentifier
                    && inputChannel.ChannelType == outputChannel.ChannelType)
                {
                    inputChannel.IncomingConnection = SelectedOutputChannel;
                }
                SelectedInputChannel = null;
                SelectedOutputChannel = null;
                _graphNeedsUpdate = true;
                MarkDirty();
            }
        }
Ejemplo n.º 6
0
 private void SubGraphSelect( object objProperty )
 {
     if( objProperty.GetType() != typeof( SubGraphType ) )
     {
         return;
     }
     _currentSubGraphType = (SubGraphType) objProperty;
     SelectedInputChannel = null;
     SelectedOutputChannel = null;
 }
Ejemplo n.º 7
0
        private bool RightMouseDown()
        {
            if( InsideReservedArea( _currentMousePosition ) )
            {
                return false;
            }

            //First right click clears any lines that are currenly being drawn
            if (SelectedInputChannel != null || SelectedOutputChannel != null)
            {
                SelectedInputChannel = null;
                SelectedOutputChannel = null;
                return false;
            }

            var didDelete = false; // Were we over another node on RMB? - Texel
            //If we clicked on a bezier curve... delete the link!
            foreach (var node in _selectedGraph.CurrentSubGraph.Nodes)
            {
                foreach (var inputChannel in node.GetInputChannels())
                {
                    if (inputChannel.IncomingConnection != null)
                    {
                        var startPos = NodeDrawer.GetAbsoluteInputChannelPosition(node, inputChannel.ChannelId);
                        var endNode = _selectedGraph.CurrentSubGraph.GetNode(inputChannel.IncomingConnection.NodeIdentifier);
                        var endPos = NodeDrawer.GetAbsoluteOutputChannelPosition(endNode, inputChannel.IncomingConnection.ChannelId);

                        var distanceBetweenNodes = Mathf.Abs(startPos.x - endPos.x);

                        var distance = HandleUtility.DistancePointBezier(_currentMousePosition,
                                                            new Vector3(startPos.x, startPos.y, 0.0f),
                                                            new Vector3(endPos.x, endPos.y, 0.0f),
                                                            new Vector3(startPos.x + distanceBetweenNodes / 3.0f, startPos.y, 0.0f),
                                                            new Vector3(endPos.x - distanceBetweenNodes / 3.0f, endPos.y, 0.0f));

                        if (distance < 5.0f)
                        {
                            inputChannel.IncomingConnection = null;
                            _graphNeedsUpdate = true;
                            MarkDirty();
                            didDelete = true;
                        }
                    }
                }
            }

            if( !didDelete )
            {
                _popupMenu.Show( _currentMousePosition, _currentSubGraphType );
            }

            return true;
        }
Ejemplo n.º 8
0
		public InputChannel( uint id, string name ) : base( id, name )
		{
			IncomingConnection = null;
		}