/// <summary> /// Call this after each draggable GUI block, to calculate and draw the current drag state /// (or complete it if the mouse was released). /// Returns TRUE if the drag operation was concluded and accepted. /// </summary> /// <param name="draggableList">List containing the draggable item and all other relative draggable items</param> /// <param name="currDraggableItemIndex">Current index of the draggable item being drawn</param> /// <param name="dragEvidenceColor">Color to use for drag divider and selection</param> static public bool Drag(IList draggableList, int currDraggableItemIndex, Color dragEvidenceColor) { if (_dragData == null || _dragData.draggableList != draggableList) { return(false); } if (_waitingToApplyDrag) { if (Event.current.type == EventType.Repaint) { Event.current.Use(); } if (Event.current.type == EventType.Used) { ApplyDrag(); } return(false); } int listCount = _dragData.draggableList.Count; if (currDraggableItemIndex == 0 && Event.current.type == EventType.Repaint) { _dragData.currDragSet = false; } if (!_dragData.currDragSet) { // Find and store eventual drag position Rect lastRect = GUILayoutUtility.GetLastRect(); float lastRectMiddleY = lastRect.yMin + lastRect.height * 0.5f; float mouseY = Event.current.mousePosition.y; if (currDraggableItemIndex <= listCount - 1 && mouseY <= lastRectMiddleY) { HOGUI.FlatDivider(new Rect(lastRect.xMin, lastRect.yMin - 1, lastRect.width, 2), dragEvidenceColor); _dragData.currDragIndex = currDraggableItemIndex; _dragData.currDragSet = true; } else if (currDraggableItemIndex >= listCount - 1 && mouseY > lastRectMiddleY) { HOGUI.FlatDivider(new Rect(lastRect.xMin, lastRect.yMax - 1, lastRect.width, 2), dragEvidenceColor); _dragData.currDragIndex = listCount; _dragData.currDragSet = true; } } if (_dragData.draggedItemIndex == currDraggableItemIndex) { // Evidence dragged pool Color selectionColor = dragEvidenceColor; selectionColor.a = 0.35f; HOGUI.FlatDivider(GUILayoutUtility.GetLastRect(), selectionColor); } if (GUIUtility.hotControl < 1) { // End drag return(EndDrag(true)); } return(false); }
static bool SetState(Editor editor, EditorWindow editorWindow, IList selectableList, int selectionItemIndex, Color selectionColor) { if (editor != null) { _editor = editor; } else { _editorWindow = editorWindow; } _selectionColor = selectionColor; _selectionColor.a = 0.35f; _unfocusedSelectionColor = new Color(selectionColor.r, selectionColor.g, selectionColor.b, 0.15f); if (_selectData == null || !_selectData.IsStoredList(selectableList)) { _selectData = new GUISelectData(selectableList); } // Check if something was deleted from the list before continuing if (selectionItemIndex == -1 || selectionItemIndex > _selectData.selectableItemsDatas.Count - 1) { return(false); } GUISelectData.ItemData itemData = _selectData.selectableItemsDatas[selectionItemIndex]; if (Event.current.type == EventType.Repaint) { itemData.rect = GUILayoutUtility.GetLastRect(); } bool wasPressed = itemData.isPressed; bool selectionStatusChanged = false; if (Event.current.type == EventType.MouseDown) { itemData.isPressed = itemData.rect.Contains(Event.current.mousePosition); if (wasPressed != itemData.isPressed && !itemData.selected) { selectionStatusChanged = true; if (!itemData.selected) { itemData.canBeDeselected = false; } } } else if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.Used || Event.current.type == EventType.DragExited) { if (!itemData.canBeDeselected) { itemData.canBeDeselected = true; } else if (itemData.isPressed && itemData.selected && itemData.rect.Contains(Event.current.mousePosition)) { selectionStatusChanged = true; } else if (HOGUIUtils.PanelContainsMouse() && itemData.selected && !Event.current.shift && !Event.current.control && !itemData.rect.Contains(Event.current.mousePosition)) { itemData.selected = false; Repaint(); } itemData.isPressed = false; } if (selectionStatusChanged) { itemData.selected = !itemData.selected; if (Event.current.shift) { _selectData.CheckFirstSelectedItem(itemData); SelectRange(_selectData.firstSelectedItemData, itemData); } else if (!Event.current.control) { DeselectAll(itemData.selected ? itemData : null); _selectData.CheckFirstSelectedItem(itemData); } Repaint(); } if (itemData.selected) { HOGUI.FlatDivider(itemData.rect, IsFocusedPanel() ? _selectionColor : _unfocusedSelectionColor); return(true); } return(false); }