void ProcessDragging(Event p_event, Rect p_rect) { // Left drag if (p_event.button == 0 && p_event.alt && p_event.type == EventType.MouseDrag && dragging == DraggingType.NONE) { if (Graph != null) { Graph.viewOffset += p_event.delta * Zoom; DashEditorWindow.SetDirty(true); } } // Right drag start if (p_event.button == 1 && p_event.type == EventType.MouseDown) { _rightDragStart = p_event.mousePosition; } // Right drag if (p_event.button == 1 && p_event.type == EventType.MouseDrag) { if (_rightDrag) { Graph.viewOffset += p_event.delta * Zoom; } else if ((p_event.mousePosition - _rightDragStart).magnitude > 5) { _rightDrag = true; Graph.viewOffset += (p_event.mousePosition - _rightDragStart) * Zoom; } DashEditorWindow.SetDirty(true); } }
void ProcessZoom(Event p_event, Rect p_rect) { if (!p_event.isScrollWheel) { return; } float zoom = DashEditorCore.EditorConfig.zoom; float previousZoom = zoom; zoom += p_event.delta.y / 12; if (zoom < 1) { zoom = 1; } if (zoom > 4) { zoom = 4; } if (previousZoom != zoom && Graph != null) { Graph.viewOffset.x += (zoom - previousZoom) * p_rect.width / 2 + (p_event.mousePosition.x - p_rect.x - p_rect.width / 2) * (zoom - previousZoom); Graph.viewOffset.y += (zoom - previousZoom) * p_rect.height / 2 + (p_event.mousePosition.y - p_rect.y - p_rect.height / 2) * (zoom - previousZoom); } DashEditorCore.EditorConfig.zoom = zoom; DashEditorWindow.SetDirty(true); }
void ProcessRightClick(Event p_event, Rect p_rect) { if (p_event.button != 1) { return; } if (p_event.type == EventType.MouseUp) { if (!_rightDrag) { NodeBase hitNode = Graph.HitsNode(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y)); if (hitNode != null) { NodeContextMenu.Show(hitNode); } else { NodeConnection hitConnection = Graph.HitsConnection( p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y), 12); if (hitConnection != null) { ConnectionContextMenu.Show(hitConnection); } else { GraphBox hitRegion = Graph.HitsBoxDrag(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y)); if (hitRegion != null) { BoxContextMenu.Show(hitRegion); } else { CreateNodeContextMenu.ShowAsPopup(); } } } } else { _rightDrag = false; } p_event.Use(); DashEditorWindow.SetDirty(true); } }
public override void ProcessEvent(Event p_event, Rect p_rect) { if (Graph == null || !p_rect.Contains(p_event.mousePosition)) { return; } ProcessZoom(p_event, p_rect); if (!Application.isPlaying && !DashEditorCore.Previewer.IsPreviewing && Graph != null) { ProcessLeftClick(p_event, p_rect); ProcessRightClick(p_event, p_rect); } ProcessDragging(p_event, p_rect); if (Graph.connectingNode != null) { DashEditorWindow.SetDirty(true); } }
void ProcessLeftClick(Event p_event, Rect p_rect) { if (p_event.button != 0) { return; } if (p_event.type == EventType.MouseDown) { GUI.FocusControl(""); } // Select if (p_event.type == EventType.MouseDown && !p_event.alt && Graph != null && !p_event.control) { DashEditorWindow.SetDirty(true); NodeBase hitNode = Graph.HitsNode(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y)); int hitNodeIndex = Graph.Nodes.IndexOf(hitNode); if (!SelectionManager.IsSelected(hitNodeIndex) && (!p_event.shift || hitNodeIndex == 0)) { SelectionManager.ClearSelection(); } if (hitNodeIndex >= 0) { AddSelectedNode(hitNodeIndex); dragging = DraggingType.NODE_DRAG; } else { GraphBox box = Graph.HitsBoxDrag(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y)); if (box != null) { DashEditorCore.selectedBox = box; DashEditorCore.selectedBox.StartDrag(); dragging = DraggingType.BOX_DRAG; } else { box = Graph.HitsBoxResize(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y)); if (box != null) { DashEditorCore.selectedBox = box; DashEditorCore.selectedBox.StartResize(); dragging = DraggingType.BOX_RESIZE; } else { dragging = DraggingType.SELECTION; DashEditorCore.selectedBox = null; Graph.connectingNode = null; selectedRegion = new Rect(p_event.mousePosition.x, p_event.mousePosition.y, 0, 0); } } } } // Dragging if (p_event.type == EventType.MouseDrag) { switch (dragging) { case DraggingType.NODE_DRAG: Vector2 delta = p_event.alt ? Snapping.Snap(p_event.delta, new Vector2(10, 10)): p_event.delta; SelectionManager.DragSelectedNodes(delta, Graph); break; case DraggingType.BOX_DRAG: DashEditorCore.selectedBox.Drag(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom)); break; case DraggingType.BOX_RESIZE: DashEditorCore.selectedBox.Resize(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom)); break; case DraggingType.SELECTION: selectedRegion.width += p_event.delta.x; selectedRegion.height += p_event.delta.y; Rect fixedRect = FixRect(selectedRegion); SelectionManager.SelectingNodes(Graph.Nodes.FindAll(n => n.IsInsideRect(fixedRect)).Select(n => n.Index).ToList()); break; } DashEditorWindow.SetDirty(true); } if (p_event.type == EventType.MouseUp) { if (dragging == DraggingType.SELECTION) { SelectionManager.SelectingToSelected(); } if (dragging == DraggingType.NODE_DRAG || dragging == DraggingType.BOX_DRAG || dragging == DraggingType.BOX_RESIZE) { DashEditorCore.SetDirty(); } dragging = DraggingType.NONE; selectedRegion = Rect.zero; DashEditorWindow.SetDirty(true); } }