示例#1
0
        public void HandleUnusedMouseEventsForItem(Rect rect, TreeViewItem item, bool firstItem)
        {
            int       itemControlID  = TreeView.GetItemControlID(item);
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(itemControlID);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (rect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.button == 0)
                    {
                        GUIUtility.keyboardControl = this.m_KeyboardControlID;
                        this.Repaint();
                        if (Event.current.clickCount == 2)
                        {
                            if (this.itemDoubleClickedCallback != null)
                            {
                                this.itemDoubleClickedCallback(item.id);
                            }
                        }
                        else
                        {
                            if (this.dragging == null || this.dragging.CanStartDrag(item, this.m_DragSelection, Event.current.mousePosition))
                            {
                                this.m_DragSelection = this.GetNewSelection(item, true, false);
                                DragAndDropDelay dragAndDropDelay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlID);
                                dragAndDropDelay.mouseDownPosition = Event.current.mousePosition;
                            }
                            GUIUtility.hotControl = itemControlID;
                        }
                        current.Use();
                    }
                    else if (Event.current.button == 1)
                    {
                        bool keepMultiSelection = true;
                        this.SelectionClick(item, keepMultiSelection);
                    }
                }
                return;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == itemControlID)
                {
                    GUIUtility.hotControl = 0;
                    this.m_DragSelection.Clear();
                    current.Use();
                    if (rect.Contains(current.mousePosition))
                    {
                        float      contentIndent = this.gui.GetContentIndent(item);
                        Rect       rect2         = new Rect(rect.x + contentIndent, rect.y, rect.width - contentIndent, rect.height);
                        List <int> selectedIDs   = this.state.selectedIDs;
                        if (this.m_AllowRenameOnMouseUp && selectedIDs != null && selectedIDs.Count == 1 && selectedIDs[0] == item.id && rect2.Contains(current.mousePosition) && !EditorGUIUtility.HasHolddownKeyModifiers(current))
                        {
                            this.BeginNameEditing(0.5f);
                        }
                        else
                        {
                            this.SelectionClick(item, false);
                        }
                    }
                }
                return;

            case EventType.MouseMove:
IL_2D:
                if (typeForControl == EventType.DragUpdated || typeForControl == EventType.DragPerform)
                {
                    if (this.dragging != null && this.dragging.DragElement(item, rect, firstItem))
                    {
                        GUIUtility.hotControl = 0;
                    }
                    return;
                }
                if (typeForControl != EventType.ContextClick)
                {
                    return;
                }
                if (rect.Contains(current.mousePosition) && this.contextClickItemCallback != null)
                {
                    this.contextClickItemCallback(item.id);
                }
                return;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == itemControlID && this.dragging != null)
                {
                    DragAndDropDelay dragAndDropDelay2 = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlID);
                    if (dragAndDropDelay2.CanStartDrag() && this.dragging.CanStartDrag(item, this.m_DragSelection, dragAndDropDelay2.mouseDownPosition))
                    {
                        this.dragging.StartDrag(item, this.m_DragSelection);
                        GUIUtility.hotControl = 0;
                    }
                    current.Use();
                }
                return;
            }
            goto IL_2D;
        }
示例#2
0
        public void HandleUnusedMouseEventsForNode(Rect rect, TreeViewItem item, bool firstItem)
        {
            int       itemControlId  = TreeView.GetItemControlID(item);
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(itemControlId);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (!rect.Contains(Event.current.mousePosition))
                {
                    break;
                }
                if (Event.current.button == 0)
                {
                    GUIUtility.keyboardControl = this.m_KeyboardControlID;
                    this.Repaint();
                    if (Event.current.clickCount == 2)
                    {
                        if (this.itemDoubleClickedCallback != null)
                        {
                            this.itemDoubleClickedCallback(item.id);
                        }
                    }
                    else
                    {
                        if (this.dragging == null || this.dragging.CanStartDrag(item, this.m_DragSelection, Event.current.mousePosition))
                        {
                            this.m_DragSelection = this.GetNewSelection(item, true, false);
                            ((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlId)).mouseDownPosition = Event.current.mousePosition;
                        }
                        GUIUtility.hotControl = itemControlId;
                    }
                    current.Use();
                    break;
                }
                if (Event.current.button != 1)
                {
                    break;
                }
                bool keepMultiSelection = true;
                this.SelectionClick(item, keepMultiSelection);
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl != itemControlId)
                {
                    break;
                }
                GUIUtility.hotControl = 0;
                this.m_DragSelection.Clear();
                current.Use();
                if (!rect.Contains(current.mousePosition))
                {
                    break;
                }
                float      contentIndent = this.gui.GetContentIndent(item);
                Rect       rect1         = new Rect(rect.x + contentIndent, rect.y, rect.width - contentIndent, rect.height);
                List <int> selectedIds   = this.state.selectedIDs;
                if (this.m_AllowRenameOnMouseUp && selectedIds != null && (selectedIds.Count == 1 && selectedIds[0] == item.id) && (rect1.Contains(current.mousePosition) && !EditorGUIUtility.HasHolddownKeyModifiers(current)))
                {
                    this.BeginNameEditing(0.5f);
                    break;
                }
                this.SelectionClick(item, false);
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != itemControlId || this.dragging == null)
                {
                    break;
                }
                DragAndDropDelay stateObject = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlId);
                if (stateObject.CanStartDrag() && this.dragging.CanStartDrag(item, this.m_DragSelection, stateObject.mouseDownPosition))
                {
                    this.dragging.StartDrag(item, this.m_DragSelection);
                    GUIUtility.hotControl = 0;
                }
                current.Use();
                break;

            default:
                if (typeForControl != EventType.DragUpdated && typeForControl != EventType.DragPerform)
                {
                    if (typeForControl != EventType.ContextClick || !rect.Contains(current.mousePosition) || this.contextClickItemCallback == null)
                    {
                        break;
                    }
                    this.contextClickItemCallback(item.id);
                    break;
                }
                if (this.dragging == null || !this.dragging.DragElement(item, rect, firstItem))
                {
                    break;
                }
                GUIUtility.hotControl = 0;
                break;
            }
        }