public static HighLevelEvent MultiSelection( Rect rect, Rect[] positions, GUIContent content, Rect[] hitPositions, ref bool[] selections, bool[] readOnly, out int clickedIndex, out Vector2 offset, out float startSelect, out float endSelect, GUIStyle style ) { int id = GUIUtility.GetControlID(41623453, FocusType.Keyboard); Event evt = Event.current; offset = Vector2.zero; clickedIndex = -1; startSelect = endSelect = 0f; if (evt.type == EventType.Used) { return(HighLevelEvent.None); } bool selected = false; if (Event.current.type != EventType.Layout) { if (GUIUtility.keyboardControl == id) { selected = true; } } int selectedIndex; EventType type = evt.GetTypeForControl(id); switch (type) { case EventType.Repaint: // Draw selection rect if (GUIUtility.hotControl == id && s_MultiSelectDragSelection == DragSelectionState.DragSelecting) { float min = Mathf.Min(s_StartSelectPos.x, evt.mousePosition.x); float max = Mathf.Max(s_StartSelectPos.x, evt.mousePosition.x); Rect selRect = new Rect(0, 0, rect.width, rect.height); selRect.x = min; selRect.width = max - min; // Display if bigger than 1 pixel. if (selRect.width > 1) { GUI.Box(selRect, "", ms_Styles.selectionRect); } } // Draw controls Color tempCol = GUI.color; for (int i = 0; i < positions.Length; i++) { if (readOnly != null && readOnly[i]) { GUI.color = tempCol * new Color(0.90f, 0.90f, 0.90f, 0.5f); } else if (selections[i]) { GUI.color = tempCol * new Color(0.30f, 0.55f, 0.95f, 1); } else { GUI.color = tempCol * new Color(0.90f, 0.90f, 0.90f, 1); } style.Draw(positions[i], content, id, selections[i]); } GUI.color = tempCol; break; case EventType.MouseDown: if (evt.button == 0) { GUIUtility.hotControl = id; GUIUtility.keyboardControl = id; s_StartSelectPos = evt.mousePosition; selectedIndex = GetIndexUnderMouse(hitPositions, readOnly); if (Event.current.clickCount == 2) { if (selectedIndex >= 0) { for (int i = 0; i < selections.Length; i++) { selections[i] = false; } selections[selectedIndex] = true; evt.Use(); clickedIndex = selectedIndex; return(HighLevelEvent.DoubleClick); } } if (selectedIndex >= 0) { // Shift click to add to current selection if (!evt.shift && !EditorGUI.actionKey && !selections[selectedIndex]) { for (int i = 0; i < hitPositions.Length; i++) { selections[i] = false; } } if (evt.shift || EditorGUI.actionKey) { selections[selectedIndex] = !selections[selectedIndex]; } else { selections[selectedIndex] = true; } s_MouseDownPos = evt.mousePosition; s_MultiSelectDragSelection = DragSelectionState.None; evt.Use(); clickedIndex = selectedIndex; return(HighLevelEvent.SelectionChanged); } else { // Shift click to add to current selection bool changed = false; if (!evt.shift && !EditorGUI.actionKey) { for (int i = 0; i < hitPositions.Length; i++) { selections[i] = false; } changed = true; } else { changed = false; } s_SelectionBackup = new List <bool>(selections); s_LastFrameSelections = new List <bool>(selections); s_MultiSelectDragSelection = DragSelectionState.DragSelecting; evt.Use(); return(changed ? HighLevelEvent.SelectionChanged : HighLevelEvent.None); } } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { if (s_MultiSelectDragSelection == DragSelectionState.DragSelecting) { float min = Mathf.Min(s_StartSelectPos.x, evt.mousePosition.x); float max = Mathf.Max(s_StartSelectPos.x, evt.mousePosition.x); s_SelectionBackup.CopyTo(selections); for (int i = 0; i < hitPositions.Length; i++) { if (selections[i]) { continue; } float center = hitPositions[i].x + hitPositions[i].width * .5f; if (center >= min && center <= max) { selections[i] = true; } } evt.Use(); startSelect = min; endSelect = max; // Check if the selections _actually_ changed from last call bool changed = false; for (int i = 0; i < selections.Length; i++) { if (selections[i] != s_LastFrameSelections[i]) { changed = true; s_LastFrameSelections[i] = selections[i]; } } return(changed ? HighLevelEvent.SelectionChanged : HighLevelEvent.None); } else { offset = evt.mousePosition - s_MouseDownPos; evt.Use(); if (s_MultiSelectDragSelection == DragSelectionState.None) { s_MultiSelectDragSelection = DragSelectionState.Dragging; return(HighLevelEvent.BeginDrag); } else { return(HighLevelEvent.Drag); } } } break; case EventType.MouseUp: if (GUIUtility.hotControl == id) { GUIUtility.hotControl = 0; if (s_StartSelectPos != evt.mousePosition) { evt.Use(); } // TODO fix magic number for max dragging distance to be ignored if (s_MultiSelectDragSelection == DragSelectionState.None) { clickedIndex = GetIndexUnderMouse(hitPositions, readOnly); if (evt.clickCount == 1) { return(HighLevelEvent.Click); } } else { s_MultiSelectDragSelection = DragSelectionState.None; s_SelectionBackup = null; s_LastFrameSelections = null; return(HighLevelEvent.EndDrag); } } break; case EventType.ValidateCommand: case EventType.ExecuteCommand: if (selected) { bool execute = evt.type == EventType.ExecuteCommand; switch (evt.commandName) { case EventCommandNames.Delete: evt.Use(); if (execute) { return(HighLevelEvent.Delete); } break; } } break; case EventType.KeyDown: if (selected) { if (evt.keyCode == KeyCode.Backspace || evt.keyCode == KeyCode.Delete) { evt.Use(); return(HighLevelEvent.Delete); } } break; case EventType.ContextClick: selectedIndex = GetIndexUnderMouse(hitPositions, readOnly); if (selectedIndex >= 0) { clickedIndex = selectedIndex; GUIUtility.keyboardControl = id; evt.Use(); return(HighLevelEvent.ContextClick); } break; } return(HighLevelEvent.None); }
public static HighLevelEvent MultiSelection(Rect rect, Rect[] positions, GUIContent content, Rect[] hitPositions, ref bool[] selections, bool[] readOnly, out int clickedIndex, out Vector2 offset, out float startSelect, out float endSelect, GUIStyle style) { int controlID = GUIUtility.GetControlID(0x27b1f9d, FocusType.Keyboard); Event current = Event.current; offset = Vector2.zero; clickedIndex = -1; startSelect = endSelect = 0f; if (current.type != EventType.Used) { int indexUnderMouse; bool flag = false; if (Event.current.type != EventType.Layout) { if (GUIUtility.keyboardControl == controlID) { flag = true; } else { selections = new bool[selections.Length]; } } switch (current.GetTypeForControl(controlID)) { case EventType.MouseDown: if (current.button != 0) { break; } GUIUtility.hotControl = controlID; GUIUtility.keyboardControl = controlID; s_StartSelectPos = current.mousePosition; indexUnderMouse = GetIndexUnderMouse(hitPositions, readOnly); if ((Event.current.clickCount != 2) || (indexUnderMouse < 0)) { if (indexUnderMouse >= 0) { if ((!current.shift && !EditorGUI.actionKey) && !selections[indexUnderMouse]) { for (int j = 0; j < hitPositions.Length; j++) { selections[j] = false; } } if (current.shift || EditorGUI.actionKey) { selections[indexUnderMouse] = !selections[indexUnderMouse]; } else { selections[indexUnderMouse] = true; } s_MouseDownPos = current.mousePosition; s_MultiSelectDragSelection = DragSelectionState.None; current.Use(); clickedIndex = indexUnderMouse; return(HighLevelEvent.SelectionChanged); } bool flag2 = false; if (!current.shift && !EditorGUI.actionKey) { for (int k = 0; k < hitPositions.Length; k++) { selections[k] = false; } flag2 = true; } else { flag2 = false; } s_SelectionBackup = new List <bool>(selections); s_LastFrameSelections = new List <bool>(selections); s_MultiSelectDragSelection = DragSelectionState.DragSelecting; current.Use(); return(!flag2 ? HighLevelEvent.None : HighLevelEvent.SelectionChanged); } for (int i = 0; i < selections.Length; i++) { selections[i] = false; } selections[indexUnderMouse] = true; current.Use(); clickedIndex = indexUnderMouse; return(HighLevelEvent.DoubleClick); case EventType.MouseUp: if (GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; if (s_StartSelectPos != current.mousePosition) { current.Use(); } if (s_MultiSelectDragSelection != DragSelectionState.None) { s_MultiSelectDragSelection = DragSelectionState.None; s_SelectionBackup = null; s_LastFrameSelections = null; return(HighLevelEvent.EndDrag); } clickedIndex = GetIndexUnderMouse(hitPositions, readOnly); if (current.clickCount == 1) { return(HighLevelEvent.Click); } } break; case EventType.MouseDrag: { if (GUIUtility.hotControl != controlID) { break; } if (s_MultiSelectDragSelection != DragSelectionState.DragSelecting) { offset = current.mousePosition - s_MouseDownPos; current.Use(); if (s_MultiSelectDragSelection == DragSelectionState.None) { s_MultiSelectDragSelection = DragSelectionState.Dragging; return(HighLevelEvent.BeginDrag); } return(HighLevelEvent.Drag); } float num10 = Mathf.Min(s_StartSelectPos.x, current.mousePosition.x); float num11 = Mathf.Max(s_StartSelectPos.x, current.mousePosition.x); s_SelectionBackup.CopyTo(selections); for (int m = 0; m < hitPositions.Length; m++) { if (!selections[m]) { float num13 = hitPositions[m].x + (hitPositions[m].width * 0.5f); if ((num13 >= num10) && (num13 <= num11)) { selections[m] = true; } } } current.Use(); startSelect = num10; endSelect = num11; bool flag3 = false; for (int n = 0; n < selections.Length; n++) { if (selections[n] != s_LastFrameSelections[n]) { flag3 = true; s_LastFrameSelections[n] = selections[n]; } } return(!flag3 ? HighLevelEvent.None : HighLevelEvent.SelectionChanged); } case EventType.KeyDown: if (!flag || ((current.keyCode != KeyCode.Backspace) && (current.keyCode != KeyCode.Delete))) { break; } current.Use(); return(HighLevelEvent.Delete); case EventType.Repaint: { if ((GUIUtility.hotControl == controlID) && (s_MultiSelectDragSelection == DragSelectionState.DragSelecting)) { float num4 = Mathf.Min(s_StartSelectPos.x, current.mousePosition.x); float num5 = Mathf.Max(s_StartSelectPos.x, current.mousePosition.x); Rect position = new Rect(0f, 0f, rect.width, rect.height) { x = num4, width = num5 - num4 }; if (position.width != 0f) { GUI.Box(position, "", ms_Styles.selectionRect); } } Color color = GUI.color; for (int num6 = 0; num6 < positions.Length; num6++) { if ((readOnly != null) && readOnly[num6]) { GUI.color = color * new Color(0.9f, 0.9f, 0.9f, 0.5f); } else if (selections[num6]) { GUI.color = color * new Color(0.3f, 0.55f, 0.95f, 1f); } else { GUI.color = color * new Color(0.9f, 0.9f, 0.9f, 1f); } style.Draw(positions[num6], content, controlID, selections[num6]); } GUI.color = color; break; } case EventType.ValidateCommand: case EventType.ExecuteCommand: if (flag) { bool flag4 = current.type == EventType.ExecuteCommand; string commandName = current.commandName; if ((commandName != null) && (commandName == "Delete")) { current.Use(); if (flag4) { return(HighLevelEvent.Delete); } break; } } break; case EventType.ContextClick: indexUnderMouse = GetIndexUnderMouse(hitPositions, readOnly); if (indexUnderMouse < 0) { break; } clickedIndex = indexUnderMouse; GUIUtility.keyboardControl = controlID; current.Use(); return(HighLevelEvent.ContextClick); } } return(HighLevelEvent.None); }
public static HighLevelEvent MultiSelection(Rect rect, Rect[] positions, GUIContent content, Rect[] hitPositions, ref bool[] selections, bool[] readOnly, out int clickedIndex, out Vector2 offset, out float startSelect, out float endSelect, GUIStyle style) { int controlID = GUIUtility.GetControlID(0x27b1f9d, FocusType.Keyboard); Event current = Event.current; offset = Vector2.zero; clickedIndex = -1; startSelect = endSelect = 0f; if (current.type != EventType.Used) { int indexUnderMouse; bool flag = false; if (GUIUtility.keyboardControl == controlID) { flag = true; } else { selections = new bool[selections.Length]; } switch (current.GetTypeForControl(controlID)) { case EventType.MouseDown: if (current.button != 0) { break; } GUIUtility.hotControl = controlID; GUIUtility.keyboardControl = controlID; s_StartSelectPos = current.mousePosition; indexUnderMouse = GetIndexUnderMouse(hitPositions, readOnly); if ((Event.current.clickCount != 2) || (indexUnderMouse < 0)) { if (indexUnderMouse >= 0) { if ((!current.shift && !EditorGUI.actionKey) && !selections[indexUnderMouse]) { for (int j = 0; j < hitPositions.Length; j++) { selections[j] = false; } } if (current.shift || EditorGUI.actionKey) { selections[indexUnderMouse] = !selections[indexUnderMouse]; } else { selections[indexUnderMouse] = true; } s_MouseDownPos = current.mousePosition; s_MultiSelectDragSelection = DragSelectionState.None; current.Use(); clickedIndex = indexUnderMouse; return HighLevelEvent.SelectionChanged; } bool flag2 = false; if (!current.shift && !EditorGUI.actionKey) { for (int k = 0; k < hitPositions.Length; k++) { selections[k] = false; } flag2 = true; } else { flag2 = false; } s_SelectionBackup = new List<bool>(selections); s_LastFrameSelections = new List<bool>(selections); s_MultiSelectDragSelection = DragSelectionState.DragSelecting; current.Use(); return (!flag2 ? HighLevelEvent.None : HighLevelEvent.SelectionChanged); } for (int i = 0; i < selections.Length; i++) { selections[i] = false; } selections[indexUnderMouse] = true; current.Use(); clickedIndex = indexUnderMouse; return HighLevelEvent.DoubleClick; case EventType.MouseUp: if (GUIUtility.hotControl != controlID) { break; } GUIUtility.hotControl = 0; if (s_StartSelectPos != current.mousePosition) { current.Use(); } if (s_MultiSelectDragSelection == DragSelectionState.None) { clickedIndex = GetIndexUnderMouse(hitPositions, readOnly); if (current.clickCount == 1) { return HighLevelEvent.Click; } break; } s_MultiSelectDragSelection = DragSelectionState.None; s_SelectionBackup = null; s_LastFrameSelections = null; return HighLevelEvent.EndDrag; case EventType.MouseDrag: { if (GUIUtility.hotControl != controlID) { break; } if (s_MultiSelectDragSelection != DragSelectionState.DragSelecting) { offset = current.mousePosition - s_MouseDownPos; current.Use(); if (s_MultiSelectDragSelection == DragSelectionState.None) { s_MultiSelectDragSelection = DragSelectionState.Dragging; return HighLevelEvent.BeginDrag; } return HighLevelEvent.Drag; } float num9 = Mathf.Min(s_StartSelectPos.x, current.mousePosition.x); float num10 = Mathf.Max(s_StartSelectPos.x, current.mousePosition.x); s_SelectionBackup.CopyTo(selections); for (int m = 0; m < hitPositions.Length; m++) { if (!selections[m]) { float num12 = hitPositions[m].x + (hitPositions[m].width * 0.5f); if ((num12 >= num9) && (num12 <= num10)) { selections[m] = true; } } } current.Use(); startSelect = num9; endSelect = num10; bool flag3 = false; for (int n = 0; n < selections.Length; n++) { if (selections[n] != s_LastFrameSelections[n]) { flag3 = true; s_LastFrameSelections[n] = selections[n]; } } return (!flag3 ? HighLevelEvent.None : HighLevelEvent.SelectionChanged); } case EventType.KeyDown: if (!flag || ((current.keyCode != KeyCode.Backspace) && (current.keyCode != KeyCode.Delete))) { break; } current.Use(); return HighLevelEvent.Delete; case EventType.Repaint: { if ((GUIUtility.hotControl == controlID) && (s_MultiSelectDragSelection == DragSelectionState.DragSelecting)) { float num3 = Mathf.Min(s_StartSelectPos.x, current.mousePosition.x); float num4 = Mathf.Max(s_StartSelectPos.x, current.mousePosition.x); Rect position = new Rect(0f, 0f, rect.width, rect.height) { x = num3, width = num4 - num3 }; if (position.width != 0f) { GUI.Box(position, string.Empty, ms_Styles.selectionRect); } } Color color = GUI.color; for (int num5 = 0; num5 < positions.Length; num5++) { if ((readOnly != null) && readOnly[num5]) { GUI.color = color * new Color(0.9f, 0.9f, 0.9f, 0.5f); } else if (selections[num5]) { GUI.color = color * new Color(0.3f, 0.55f, 0.95f, 1f); } else { GUI.color = color * new Color(0.9f, 0.9f, 0.9f, 1f); } style.Draw(positions[num5], content, controlID, selections[num5]); } GUI.color = color; break; } case EventType.ValidateCommand: case EventType.ExecuteCommand: { int num15; if (!flag) { break; } bool flag4 = current.type == EventType.ExecuteCommand; string commandName = current.commandName; if (commandName == null) { break; } if (<>f__switch$mapC == null) { Dictionary<string, int> dictionary = new Dictionary<string, int>(1); dictionary.Add("Delete", 0); <>f__switch$mapC = dictionary; } if (!<>f__switch$mapC.TryGetValue(commandName, out num15) || (num15 != 0)) { break; } current.Use(); if (!flag4) { break; } return HighLevelEvent.Delete; } case EventType.ContextClick: indexUnderMouse = GetIndexUnderMouse(hitPositions, readOnly); if (indexUnderMouse < 0) { break; } clickedIndex = indexUnderMouse; GUIUtility.keyboardControl = controlID; current.Use(); return HighLevelEvent.ContextClick; } } return HighLevelEvent.None; }