public void DeselectAll(bool registerUndo, string undoMsg = null) { editor.ResetRunningOutdatedTimer(); foreach (SF_Node n in editor.nodes) { n.Deselect(registerUndo, undoMsg); } }
public void OnLocalGUI(Rect r) { //r = r.PadTop(Mathf.CeilToInt(22*zoom)); editor.mousePosition = Event.current.mousePosition; rect = r; // TOOLBAR //DrawToolbar( new Rect( rect.x, rect.y, rect.width, TOOLBAR_HEIGHT ) ); Rect localRect = new Rect(r); localRect.x = 0; localRect.y = 0; //rect.y += TOOLBAR_HEIGHT; //rect.height -= TOOLBAR_HEIGHT; // VIEW Rect rectInner = new Rect(rect); rectInner.width = float.MaxValue / 2f; rectInner.height = float.MaxValue / 2f; // TEMP: // Rect btn = rectInner; // btn.width = 64; // btn.height = 24; // if(SF_Debug.renderDataNodes){ // if(selection.Selection.Count > 0){ // if(GUI.Button(btn,"NSS")){ // editor.TakeNodePreviewScreenshot(); // } // } // } if (Event.current.type == EventType.Repaint) { nodeSpaceMousePos = ScreenSpaceToZoomSpace(Event.current.mousePosition); } bool mouseOverNode = false; SF_ZoomArea.Begin(zoom, rect, cameraPos); { selection.OnGUI(); // To detect if you press things if (editor.nodeView != null) { editor.nodeView.selection.DrawBoxSelection(); } if (Event.current.type == EventType.Repaint) { viewSpaceMousePos = ZoomSpaceToScreenSpace(Event.current.mousePosition); } // NODES if (editor.nodes != null) { // If we're repainting, draw in reverse to sort properly //if(Event.current.rawType == EventType.repaint){ for (int i = editor.nodes.Count - 1; i >= 0; i--) { if (!editor.nodes[i].Draw()) { break; } } /*} else { * for(int i=0;i<editor.nodes.Count;i++) { * if( !editor.nodes[i].Draw() ) * break; * } * }*/ if (!mouseOverNode) { for (int i = 0; i < editor.nodes.Count; i++) { if (editor.nodes[i].MouseOverNode(world: true)) { mouseOverNode = true; } } } if (Event.current.type == EventType.Repaint) { for (int i = 0; i < editor.nodes.Count; i++) { editor.nodes[i].DrawConnectors(); } } } UpdateCutLine(); UpdateCameraPanning(); } SF_ZoomArea.End(zoom); if (!SF_Node.isEditingAnyNodeTextField) { SF_Editor.instance.UpdateKeyHoldEvents(mouseOverNode); } if (MouseInsideNodeView(false) && Event.current.type == EventType.ScrollWheel) { zoomTarget = ClampZoom(zoomTarget * (1f - Event.current.delta.y * 0.02f)); } SetZoom(Mathf.Lerp(zoom, zoomTarget, 0.2f)); if (Event.current.type == EventType.ContextClick && !SF_GUI.HoldingAlt()) { Vector2 mousePos = Event.current.mousePosition; if (rect.Contains(mousePos)) { // Now create the menu, add items and show it GenericMenu menu = new GenericMenu(); // First item is for creating a comment box //menu.AddItem( new GUIContent("Create comment box"), false, ContextClick, mousePos ); //menu.AddSeparator(""); for (int i = 0; i < editor.nodeTemplates.Count; i++) { if (editor.ps.catLighting.renderPath == SFPSC_Lighting.RenderPath.Deferred && !editor.nodeTemplates[i].availableInDeferredPrePass) { continue; // Skip forward nodes when in deferred } menu.AddItem(new GUIContent(editor.nodeTemplates[i].fullPath), false, ContextClick, editor.nodeTemplates[i]); } editor.ResetRunningOutdatedTimer(); menu.ShowAsContext(); Event.current.Use(); } } if (Event.current.type == EventType.DragPerform) { Object droppedObj = DragAndDrop.objectReferences[0]; if (droppedObj is Texture2D || /*droppedObj is ProceduralTexture ||*/ droppedObj is RenderTexture) { SFN_Tex2d texNode = editor.nodeBrowser.OnStopDrag() as SFN_Tex2d; texNode.TextureAsset = droppedObj as Texture; texNode.OnAssignedTexture(); Event.current.Use(); } //if(droppedObj is ProceduralMaterial){ // OnDroppedSubstance(droppedObj as ProceduralMaterial); //} } if (Event.current.type == EventType.DragUpdated && Event.current.type != EventType.DragPerform) { if (DragAndDrop.objectReferences.Length > 0) { Object dragObj = DragAndDrop.objectReferences[0]; if (dragObj is Texture2D || /*dragObj is ProceduralTexture || */ dragObj is RenderTexture) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (!editor.nodeBrowser.IsPlacing()) { editor.nodeBrowser.OnStartDrag(editor.GetTemplate <SFN_Tex2d>()); } else { editor.nodeBrowser.UpdateDrag(); } } // else if(dragObj is ProceduralMaterial){ // DragAndDrop.visualMode = DragAndDropVisualMode.Link; //} else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } } else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } } // If release if (MouseInsideNodeView(false) && Event.current.type == EventType.MouseUp) { bool ifCursorStayed = Vector2.SqrMagnitude(mousePosStart - Event.current.mousePosition) < SF_Tools.stationaryCursorRadius; if (ifCursorStayed && !SF_GUI.MultiSelectModifierHeld()) { selection.DeselectAll(registerUndo: true); } //editor.Defocus( deselectNodes: ifCursorStayed ); } if (SF_GUI.ReleasedRawLMB()) { SF_NodeConnector.pendingConnectionSource = null; } // If press if (Event.current.type == EventType.MouseDown && MouseInsideNodeView(false)) { //bool ifNotHoldingModifier = !SF_GUI.MultiSelectModifierHeld(); mousePosStart = Event.current.mousePosition; editor.Defocus(); } if (!editor.screenshotInProgress) { Rect logoRect = rect; logoRect.y -= 14; logoRect.x += 1; logoRect.width = SF_GUI.Logo.width; logoRect.height = SF_GUI.Logo.height; GUI.color = new Color(1f, 1f, 1f, 0.5f); GUI.DrawTexture(logoRect, SF_GUI.Logo); logoRect.y += logoRect.height; logoRect.height = 16; GUI.Label(logoRect, "v" + SF_Tools.version, EditorStyles.boldLabel); GUI.color = Color.white; } }
public void DrawButton(SF_EditorNodeData entry, ref Rect btnRect) { GUI.color = entry.isProperty ? SF_Node.colorExposed : Color.white; bool usable = !(!entry.availableInDeferredPrePass && editor.ps.catLighting.renderPath == SFPSC_Lighting.RenderPath.Deferred); if (!usable) { //GUI.color = Color.red; GUI.enabled = false; } bool mouseOver = btnRect.Contains(Event.current.mousePosition); if (usable) { if (dragNode == entry) { GUI.color = SF_GUI.selectionColorBright; } else if (mouseOver && dragNode == null) { GUI.color = SF_GUI.selectionColorBrighter; } } GUI.Label(btnRect, (usable ? string.Empty : " ") + entry.nodeName, styleButton); if (mouseOver && Event.current.type == EventType.MouseDown && Event.current.button == 0 && usable) { OnStartDrag(entry); } else if (Event.current.type == EventType.ContextClick) { Vector2 mousePos = Event.current.mousePosition; if (btnRect.Contains(mousePos)) { // Now create the menu, add items and show it GenericMenu menu = new GenericMenu(); editor.ResetRunningOutdatedTimer(); //menu.AddItem( new GUIContent("Edit Comment"), false, ContextClick, "cmt_edit" ); menu.AddItem(new GUIContent("What does " + entry.nodeName + " do?"), false, ContextClick, entry); menu.ShowAsContext(); Event.current.Use(); } } GUI.color = Color.white; if (entry.isNew || entry.isUnstable) { GUIStyle miniStyle = new GUIStyle(EditorStyles.miniBoldLabel); miniStyle.alignment = TextAnchor.UpperRight; miniStyle.normal.textColor = Color.red; GUI.Label(btnRect, entry.isNew ? "New" : "Unstable", miniStyle); } if (usable) { SF_GUI.AssignCursor(btnRect, MouseCursor.Pan); } else { if (Event.current.type == EventType.Repaint) { GUI.enabled = true; SF_GUI.DrawLock(btnRect.PadTop(4), "Forward rendering only", TextAlignment.Right); //Draw(btnRect.PadTop(4), false, true, true, false); // Draw lock GUI.enabled = false; } } GUI.enabled = true; btnRect.y += btnRect.height; }
public void CheckConnection(SF_Editor editor) { if (ShouldBeInvisible()) { return; } if (conType == ConType.cInput && Event.current.type == EventType.Repaint) { DrawConnection(editor); } if (enableState == EnableState.Disabled || availableState == AvailableState.Unavailable) { return; } if (Clicked()) { SF_NodeConnector.pendingConnectionSource = this; editor.nodeView.selection.DeselectAll(registerUndo: false); foreach (SF_Node iNode in editor.nodes) { foreach (SF_NodeConnector con in iNode.connectors) { con.UpdateCanValidlyConnectToPending(); } } Event.current.Use(); } if (Clicked(1) && SF_GUI.HoldingAlt()) { Disconnect(); } if (!ConnectionInProgress()) { if (Released()) { TryMakeConnection(); } return; } // Active connection: editor.ResetRunningOutdatedTimer(); //if(Event.current.type == EventType.repaint) //node.Repaint(); bool hovering = false; foreach (SF_Node n in editor.nodes) { foreach (SF_NodeConnector con in n.connectors) { if (con.CanConnectToPending() && con.Hovering(false)) { hovering = true; break; } } if (hovering) { break; } } if (Event.current.type == EventType.Repaint) { Color c = hovering ? Color.green : GetConnectionLineColor(); bool input = (conType == ConType.cInput); Vector2 start = input ? GetConnectionPoint() : MousePos(); Vector2 end = input ? MousePos() : GetConnectionPoint();; if (valueType == ValueType.VTm4x4 || valueType == ValueType.VTv4m4x4) { GUILines.DrawMatrixConnection(editor, start, end, c); } else { GUILines.DrawStyledConnection(editor, start, end, GetCompCount(), c); } } //Drawing.DrawLine(rect.center,MousePos(),Color.white,2,true); }