void SelectAndDrag() { Profiler.BeginSample("[PW] Select and drag"); //rendering the selection rect if (editorEvents.isSelecting) { Rect posiviteSelectionRect = PWUtils.CreateRect(e.mousePosition, editorEvents.selectionStartPoint); Rect decaledSelectionRect = PWUtils.DecalRect(posiviteSelectionRect, -graph.panPosition); //draw selection rect if (e.type == EventType.Repaint) { selectionStyle.Draw(posiviteSelectionRect, false, false, false, false); } //iterate throw all nodes of the graph and check if the selection overlaps graph.nodes.ForEach(n => n.isSelected = decaledSelectionRect.Overlaps(n.rect)); editorEvents.selectedNodeCount = graph.nodes.Count(n => n.isSelected); } //multiple window drag: if (e.type == EventType.MouseDrag && editorEvents.isDraggingSelectedNodes) { graph.nodes.ForEach(n => { if (n.isSelected) { n.rect.position += e.delta; } }); } Profiler.EndSample(); }
void RenderDecaledNode(int id, PWNode node) { //node grid snapping when pressing cmd/crtl if (node.isDragged && e.command) { Vector2 pos = node.rect.position; //aproximative grid cell size float snapPixels = 25.6f; pos.x = Mathf.RoundToInt(Mathf.RoundToInt(pos.x / snapPixels) * snapPixels); pos.y = Mathf.RoundToInt(Mathf.RoundToInt(pos.y / snapPixels) * snapPixels); node.rect.position = pos; } //move the node if panPosition changed: node.rect = PWUtils.DecalRect(node.rect, graph.panPosition); Rect decaledRect = GUILayout.Window(id, node.rect, node.OnWindowGUI, node.name, (node.isSelected) ? nodeSelectedStyle : nodeStyle, GUILayout.Height(node.viewHeight)); node.visualRect = decaledRect; node.rect = PWUtils.DecalRect(decaledRect, -graph.panPosition); //draw node header: //Draw the node header using the color scheme: if (e.type == EventType.Repaint) { float h = nodeStyle.border.top; float w = decaledRect.width - nodeStyle.border.right - nodeStyle.border.left; GUI.color = PWColorTheme.GetNodeColor(node.colorSchemeName); // GUI.DrawTexture(new Rect(0, 0, w, h), nodeHeaderStyle.normal.background); nodeHeaderStyle.Draw(new Rect(decaledRect.x, decaledRect.y, w, h), false, false, false, false); GUI.color = Color.white; } if (node.debug) { Rect debugRect = decaledRect; debugRect.y -= 20; EditorGUI.LabelField(debugRect, "id: " + node.id); debugRect.y -= 20; EditorGUI.LabelField(debugRect, "comp order: " + node.computeOrder + " | can work: " + node.canWork); } }
void RenderNode(int id, PWNode node) { RenderDecaledNode(id, node); //check if the mouse is over this node if (node.rect.Contains(e.mousePosition - graph.panPosition)) { graph.editorEvents.mouseOverNode = node; graph.editorEvents.isMouseOverNodeFrame = true; } //display the process time of the window (if > .1ms) if (node.processTime > .1f) { GUIStyle gs = new GUIStyle(); Rect msRect = PWUtils.DecalRect(node.rect, graph.panPosition); msRect.position += new Vector2(msRect.size.x / 2 - 10, msRect.size.y + 5); gs.normal.textColor = greenRedGradient.Evaluate(node.processTime / 20); //20ms ok, after is red GUI.Label(msRect, node.processTime.ToString("F1") + " ms", gs); } }
public void Render(PWGraph graph, Vector2 screenSize) { var e = Event.current; Rect screen = new Rect(-graph.panPosition, screenSize); //check if ordering group is not visible if (!orderGroupRect.Overlaps(screen)) { return; } //Start GUI frame PWGUI.StartFrame(screen); if (orderingGroupStyle == null) { LoadStyles(); } Rect orderGroupWorldRect = PWUtils.DecalRect(orderGroupRect, graph.panPosition); callbackId = 0; int controlSize = 8; int cornerSize = 14; CreateAnchorRectCallabck( //left resize anchor new Rect(orderGroupWorldRect.x, orderGroupWorldRect.y + cornerSize, controlSize, orderGroupWorldRect.height - cornerSize * 2), MouseCursor.ResizeHorizontal, () => orderGroupRect.xMin += e.delta.x ); CreateAnchorRectCallabck( //right resize anchor new Rect(orderGroupWorldRect.x + orderGroupWorldRect.width - controlSize, orderGroupWorldRect.y + cornerSize, controlSize, orderGroupWorldRect.height - cornerSize * 2), MouseCursor.ResizeHorizontal, () => orderGroupRect.xMax += e.delta.x ); CreateAnchorRectCallabck( //top resize anchor new Rect(orderGroupWorldRect.x + cornerSize, orderGroupWorldRect.y, orderGroupWorldRect.width - cornerSize * 2, controlSize), MouseCursor.ResizeVertical, () => orderGroupRect.yMin += e.delta.y ); CreateAnchorRectCallabck( //down resize anchor new Rect(orderGroupWorldRect.x + cornerSize, orderGroupWorldRect.y + orderGroupWorldRect.height - controlSize, orderGroupWorldRect.width - cornerSize * 2, controlSize), MouseCursor.ResizeVertical, () => orderGroupRect.yMax += e.delta.y ); CreateAnchorRectCallabck( //top left anchor new Rect(orderGroupWorldRect.x, orderGroupWorldRect.y, cornerSize, cornerSize), MouseCursor.ResizeUpLeft, () => { orderGroupRect.yMin += e.delta.y; orderGroupRect.xMin += e.delta.x; } ); CreateAnchorRectCallabck( //top right anchor new Rect(orderGroupWorldRect.x + orderGroupWorldRect.width - cornerSize, orderGroupWorldRect.y, cornerSize, cornerSize), MouseCursor.ResizeUpRight, () => { orderGroupRect.yMin += e.delta.y; orderGroupRect.xMax += e.delta.x; } ); CreateAnchorRectCallabck( //down left anchor new Rect(orderGroupWorldRect.x, orderGroupWorldRect.y + orderGroupWorldRect.height - cornerSize, cornerSize, cornerSize), MouseCursor.ResizeUpRight, () => { orderGroupRect.yMax += e.delta.y; orderGroupRect.xMin += e.delta.x; } ); CreateAnchorRectCallabck( //down right anchor new Rect(orderGroupWorldRect.x + orderGroupWorldRect.width - cornerSize, orderGroupWorldRect.y + orderGroupWorldRect.height - cornerSize, cornerSize, cornerSize), MouseCursor.ResizeUpLeft, () => { orderGroupRect.yMax += e.delta.y; orderGroupRect.xMax += e.delta.x; } ); if (e.rawType == EventType.MouseUp) { resizing = false; } //draw renamable name field orderingGroupNameStyle.normal.textColor = color; PWGUI.TextField(orderGroupWorldRect.position + new Vector2(10, -22), ref name, true, orderingGroupNameStyle); //draw move pad Rect movePadRect = new Rect(orderGroupWorldRect.position + new Vector2(10, 10), new Vector2(50, 30)); GUI.DrawTextureWithTexCoords(movePadRect, movepadTexture, new Rect(0, 0, 5, 4)); EditorGUIUtility.AddCursorRect(movePadRect, MouseCursor.MoveArrow); if (e.type == EventType.MouseDown && e.button == 0) { if (movePadRect.Contains(e.mousePosition)) { innerNodes = graph.nodes.Where(n => n.rect.Overlaps(orderGroupRect)).ToList(); moving = true; e.Use(); } } if (e.rawType == EventType.MouseUp) { moving = false; } if (moving && e.type == EventType.MouseDrag) { orderGroupRect.position += e.delta; innerNodes.ForEach(n => n.rect.position += e.delta); } //draw ordering group GUI.color = color; GUI.Label(orderGroupWorldRect, (string)null, orderingGroupStyle); GUI.color = Color.white; //draw color picker Rect colorPickerRect = new Rect(orderGroupWorldRect.x + orderGroupWorldRect.width - 30, orderGroupWorldRect.y + 10, 20, 20); PWGUI.ColorPicker(colorPickerRect, ref color, false); if (orderGroupWorldRect.Contains(e.mousePosition)) { graph.editorEvents.mouseOverOrderingGroup = this; graph.editorEvents.isMouseOverOrderingGroupFrame = true; } }