Ejemplo n.º 1
0
        protected virtual void DoNodeGUI(Rect rect, int row, TreeViewItem item, bool selected, bool focused, bool useBoldFont)
        {
            EditorGUIUtility.SetIconSize(new Vector2(this.k_IconWidth, this.k_IconWidth));
            float foldoutIndent = this.GetFoldoutIndent(item);
            int   itemControlID = TreeView.GetItemControlID(item);
            bool  flag          = false;

            if (this.m_TreeView.dragging != null)
            {
                flag = (this.m_TreeView.dragging.GetDropTargetControlID() == itemControlID && this.m_TreeView.data.CanBeParent(item));
            }
            bool flag2 = this.IsRenaming(item.id);
            bool flag3 = this.m_TreeView.data.IsExpandable(item);

            if (flag2 && Event.current.type == EventType.Repaint)
            {
                float num  = (!(item.icon == null)) ? this.k_IconWidth : 0f;
                float num2 = foldoutIndent + this.k_FoldoutWidth + num + this.iconTotalPadding - 1f;
                this.GetRenameOverlay().editFieldRect = new Rect(rect.x + num2, rect.y, rect.width - num2, rect.height);
            }
            if (Event.current.type == EventType.Repaint)
            {
                string label = item.displayName;
                if (flag2)
                {
                    selected = false;
                    label    = string.Empty;
                }
                if (selected)
                {
                    TreeViewGUI.s_Styles.selectionStyle.Draw(rect, false, false, true, focused);
                }
                if (flag)
                {
                    TreeViewGUI.s_Styles.lineStyle.Draw(rect, GUIContent.none, true, true, false, false);
                }
                this.DrawIconAndLabel(rect, item, label, selected, focused, useBoldFont, false);
                if (this.m_TreeView.dragging != null && this.m_TreeView.dragging.GetRowMarkerControlID() == itemControlID)
                {
                    this.m_DraggingInsertionMarkerRect = new Rect(rect.x + foldoutIndent + this.k_FoldoutWidth, rect.y, rect.width - foldoutIndent, rect.height);
                }
            }
            if (flag3)
            {
                this.DoFoldout(rect, item, row);
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
        }
Ejemplo n.º 2
0
        protected virtual void DoNodeGUI(Rect rect, TreeViewItem item, bool selected, bool focused, bool useBoldFont)
        {
            EditorGUIUtility.SetIconSize(new Vector2(this.k_IconWidth, this.k_IconWidth));
            float foldoutIndent = this.GetFoldoutIndent(item);
            Rect  position      = rect;
            int   itemControlID = TreeView.GetItemControlID(item);
            bool  flag          = false;

            if (this.m_TreeView.dragging != null)
            {
                flag = (this.m_TreeView.dragging.GetDropTargetControlID() == itemControlID && this.m_TreeView.data.CanBeParent(item));
            }
            bool flag2 = this.IsRenaming(item.id);
            bool flag3 = this.m_TreeView.data.IsExpandable(item);

            if (flag2 && Event.current.type == EventType.Repaint)
            {
                float num = foldoutIndent + this.k_FoldoutWidth + this.k_IconWidth + this.iconTotalPadding - 1f;
                this.GetRenameOverlay().editFieldRect = new Rect(rect.x + num, rect.y, rect.width - num, rect.height);
            }
            if (Event.current.type == EventType.Repaint)
            {
                string label = item.displayName;
                if (flag2)
                {
                    selected = false;
                    label    = string.Empty;
                }
                if (selected)
                {
                    TreeViewGUI.s_Styles.lineStyle.Draw(rect, false, false, true, focused);
                }
                if (flag)
                {
                    TreeViewGUI.s_Styles.lineStyle.Draw(rect, GUIContent.none, true, true, false, false);
                }
                this.DrawIconAndLabel(rect, item, label, selected, focused, useBoldFont, false);
                if (this.m_TreeView.dragging != null && this.m_TreeView.dragging.GetRowMarkerControlID() == itemControlID)
                {
                    this.m_DraggingInsertionMarkerRect = new Rect(rect.x + foldoutIndent + this.k_FoldoutWidth, rect.y, rect.width - foldoutIndent, rect.height);
                }
            }
            if (flag3)
            {
                position.x     = foldoutIndent;
                position.width = this.k_FoldoutWidth;
                EditorGUI.BeginChangeCheck();
                bool flag4 = GUI.Toggle(position, this.m_TreeView.data.IsExpanded(item), GUIContent.none, TreeViewGUI.s_Styles.foldout);
                if (EditorGUI.EndChangeCheck())
                {
                    if (Event.current.alt)
                    {
                        this.m_TreeView.data.SetExpandedWithChildren(item, flag4);
                    }
                    else
                    {
                        this.m_TreeView.data.SetExpanded(item, flag4);
                    }
                    if (flag4)
                    {
                        this.m_TreeView.UserExpandedNode(item);
                    }
                }
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
        }
Ejemplo n.º 3
0
        public virtual bool DragElement(TreeViewItem targetItem, Rect targetItemRect, bool firstItem)
        {
            DropPosition below;
            TreeViewItem parent;

            if (targetItem == null)
            {
                if (this.m_DropData != null)
                {
                    this.m_DropData.dropTargetControlID = 0;
                    this.m_DropData.rowMarkerControlID  = 0;
                }
                bool perform = Event.current.type == EventType.DragPerform;
                DragAndDrop.visualMode = this.DoDrag(null, null, perform, DropPosition.Below);
                if ((DragAndDrop.visualMode != DragAndDropVisualMode.None) && perform)
                {
                    this.FinalizeDragPerformed(true);
                }
                return(false);
            }
            Vector2 mousePosition     = Event.current.mousePosition;
            bool    flag2             = this.m_TreeView.data.CanBeParent(targetItem);
            Rect    rect              = targetItemRect;
            float   betweenHalfHeight = !flag2 ? (targetItemRect.height * 0.5f) : this.m_TreeView.gui.halfDropBetweenHeight;

            if (firstItem)
            {
                rect.yMin -= betweenHalfHeight;
            }
            rect.yMax += betweenHalfHeight;
            if (!rect.Contains(mousePosition))
            {
                return(false);
            }
            if (!flag2 || (mousePosition.y >= (targetItemRect.yMax - betweenHalfHeight)))
            {
                below = DropPosition.Below;
            }
            else if (!flag2 || (firstItem && (mousePosition.y <= (targetItemRect.yMin + betweenHalfHeight))))
            {
                below = DropPosition.Above;
            }
            else
            {
                below = DropPosition.Upon;
            }
            if (this.m_TreeView.data.IsExpanded(targetItem) && targetItem.hasChildren)
            {
                parent = targetItem;
            }
            else
            {
                parent = targetItem.parent;
            }
            DragAndDropVisualMode none = DragAndDropVisualMode.None;

            if (Event.current.type == EventType.DragPerform)
            {
                if (below == DropPosition.Upon)
                {
                    none = this.DoDrag(targetItem, targetItem, true, below);
                }
                if ((none == DragAndDropVisualMode.None) && (parent != null))
                {
                    none = this.DoDrag(parent, targetItem, true, below);
                }
                if (none != DragAndDropVisualMode.None)
                {
                    this.FinalizeDragPerformed(false);
                }
                else
                {
                    this.DragCleanup(true);
                    this.m_TreeView.NotifyListenersThatDragEnded(null, false);
                }
            }
            else
            {
                if (this.m_DropData == null)
                {
                    this.m_DropData = new DropData();
                }
                this.m_DropData.dropTargetControlID = 0;
                this.m_DropData.rowMarkerControlID  = 0;
                int itemControlID = TreeView.GetItemControlID(targetItem);
                this.HandleAutoExpansion(itemControlID, targetItem, targetItemRect, betweenHalfHeight, mousePosition);
                if (below == DropPosition.Upon)
                {
                    none = this.DoDrag(targetItem, targetItem, false, below);
                }
                if (none != DragAndDropVisualMode.None)
                {
                    this.m_DropData.dropTargetControlID = itemControlID;
                    DragAndDrop.visualMode = none;
                }
                else if ((targetItem != null) && (parent != null))
                {
                    none = this.DoDrag(parent, targetItem, false, below);
                    if (none != DragAndDropVisualMode.None)
                    {
                        this.drawRowMarkerAbove             = below == DropPosition.Above;
                        this.m_DropData.rowMarkerControlID  = itemControlID;
                        this.m_DropData.dropTargetControlID = !this.drawRowMarkerAbove ? TreeView.GetItemControlID(parent) : 0;
                        DragAndDrop.visualMode = none;
                    }
                }
            }
            Event.current.Use();
            return(true);
        }
Ejemplo n.º 4
0
        public virtual bool DragElement(TreeViewItem targetItem, Rect targetItemRect, bool firstItem)
        {
            if (targetItem == null)
            {
                if (this.m_DropData != null)
                {
                    this.m_DropData.dropTargetControlID = 0;
                    this.m_DropData.rowMarkerControlID  = 0;
                }
                bool perform = Event.current.type == EventType.DragPerform;
                DragAndDrop.visualMode = this.DoDrag((TreeViewItem)null, (TreeViewItem)null, perform, TreeViewDragging.DropPosition.Below);
                if (DragAndDrop.visualMode != DragAndDropVisualMode.None && perform)
                {
                    this.FinalizeDragPerformed(true);
                }
                return(false);
            }
            Vector2 mousePosition     = Event.current.mousePosition;
            bool    flag              = this.m_TreeView.data.CanBeParent(targetItem);
            Rect    rect              = targetItemRect;
            float   betweenHalfHeight = !flag ? targetItemRect.height * 0.5f : this.m_TreeView.gui.halfDropBetweenHeight;

            if (firstItem)
            {
                rect.yMin -= betweenHalfHeight;
            }
            rect.yMax += betweenHalfHeight;
            if (!rect.Contains(mousePosition))
            {
                return(false);
            }
            TreeViewDragging.DropPosition dropPosition = (double)mousePosition.y < (double)targetItemRect.yMax - (double)betweenHalfHeight ? (!firstItem || (double)mousePosition.y > (double)targetItemRect.yMin + (double)betweenHalfHeight ? (!flag ? TreeViewDragging.DropPosition.Above : TreeViewDragging.DropPosition.Upon) : TreeViewDragging.DropPosition.Above) : TreeViewDragging.DropPosition.Below;
            TreeViewItem          parentItem           = !this.m_TreeView.data.IsExpanded(targetItem) || !targetItem.hasChildren ? targetItem.parent : targetItem;
            DragAndDropVisualMode andDropVisualMode1   = DragAndDropVisualMode.None;

            if (Event.current.type == EventType.DragPerform)
            {
                if (dropPosition == TreeViewDragging.DropPosition.Upon)
                {
                    andDropVisualMode1 = this.DoDrag(targetItem, targetItem, true, dropPosition);
                }
                if (andDropVisualMode1 == DragAndDropVisualMode.None && parentItem != null)
                {
                    andDropVisualMode1 = this.DoDrag(parentItem, targetItem, true, dropPosition);
                }
                if (andDropVisualMode1 != DragAndDropVisualMode.None)
                {
                    this.FinalizeDragPerformed(false);
                }
                else
                {
                    this.DragCleanup(true);
                    this.m_TreeView.NotifyListenersThatDragEnded((int[])null, false);
                }
            }
            else
            {
                if (this.m_DropData == null)
                {
                    this.m_DropData = new TreeViewDragging.DropData();
                }
                this.m_DropData.dropTargetControlID = 0;
                this.m_DropData.rowMarkerControlID  = 0;
                int itemControlId = TreeView.GetItemControlID(targetItem);
                this.HandleAutoExpansion(itemControlId, targetItem, targetItemRect, betweenHalfHeight, mousePosition);
                if (dropPosition == TreeViewDragging.DropPosition.Upon)
                {
                    andDropVisualMode1 = this.DoDrag(targetItem, targetItem, false, dropPosition);
                }
                if (andDropVisualMode1 != DragAndDropVisualMode.None)
                {
                    this.m_DropData.dropTargetControlID = itemControlId;
                    DragAndDrop.visualMode = andDropVisualMode1;
                }
                else if (targetItem != null && parentItem != null)
                {
                    DragAndDropVisualMode andDropVisualMode2 = this.DoDrag(parentItem, targetItem, false, dropPosition);
                    if (andDropVisualMode2 != DragAndDropVisualMode.None)
                    {
                        this.drawRowMarkerAbove             = dropPosition == TreeViewDragging.DropPosition.Above;
                        this.m_DropData.rowMarkerControlID  = itemControlId;
                        this.m_DropData.dropTargetControlID = !this.drawRowMarkerAbove ? TreeView.GetItemControlID(parentItem) : 0;
                        DragAndDrop.visualMode = andDropVisualMode2;
                    }
                }
            }
            Event.current.Use();
            return(true);
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        public virtual bool DragElement(TreeViewItem targetItem, Rect targetItemRect, bool firstItem)
        {
            if (targetItem == null)
            {
                if (this.m_DropData != null)
                {
                    this.m_DropData.dropTargetControlID = 0;
                    this.m_DropData.rowMarkerControlID  = 0;
                }
                bool flag = Event.current.type == EventType.DragPerform;
                DragAndDrop.visualMode = this.DoDrag(null, null, flag, TreeViewDragging.DropPosition.Below);
                if (DragAndDrop.visualMode != DragAndDropVisualMode.None && flag)
                {
                    this.FinalizeDragPerformed(true);
                }
                return(false);
            }
            Vector2 mousePosition = Event.current.mousePosition;
            bool    flag2         = this.m_TreeView.data.CanBeParent(targetItem);
            Rect    rect          = targetItemRect;
            float   num           = (!flag2) ? (targetItemRect.height * 0.5f) : this.m_TreeView.gui.halfDropBetweenHeight;

            if (firstItem)
            {
                rect.yMin -= num;
            }
            rect.yMax += num;
            if (!rect.Contains(mousePosition))
            {
                return(false);
            }
            TreeViewDragging.DropPosition dropPosition;
            if (mousePosition.y >= targetItemRect.yMax - num)
            {
                dropPosition = TreeViewDragging.DropPosition.Below;
            }
            else if (firstItem && mousePosition.y <= targetItemRect.yMin + num)
            {
                dropPosition = TreeViewDragging.DropPosition.Above;
            }
            else
            {
                dropPosition = ((!flag2) ? TreeViewDragging.DropPosition.Above : TreeViewDragging.DropPosition.Upon);
            }
            TreeViewItem treeViewItem;

            if (this.m_TreeView.data.IsExpanded(targetItem) && targetItem.hasChildren)
            {
                treeViewItem = targetItem;
            }
            else
            {
                treeViewItem = targetItem.parent;
            }
            DragAndDropVisualMode dragAndDropVisualMode = DragAndDropVisualMode.None;

            if (Event.current.type == EventType.DragPerform)
            {
                if (dropPosition == TreeViewDragging.DropPosition.Upon)
                {
                    dragAndDropVisualMode = this.DoDrag(targetItem, targetItem, true, dropPosition);
                }
                if (dragAndDropVisualMode == DragAndDropVisualMode.None && treeViewItem != null)
                {
                    dragAndDropVisualMode = this.DoDrag(treeViewItem, targetItem, true, dropPosition);
                }
                if (dragAndDropVisualMode != DragAndDropVisualMode.None)
                {
                    this.FinalizeDragPerformed(false);
                }
                else
                {
                    this.DragCleanup(true);
                    this.m_TreeView.NotifyListenersThatDragEnded(null, false);
                }
            }
            else
            {
                if (this.m_DropData == null)
                {
                    this.m_DropData = new TreeViewDragging.DropData();
                }
                this.m_DropData.dropTargetControlID = 0;
                this.m_DropData.rowMarkerControlID  = 0;
                int itemControlID = TreeView.GetItemControlID(targetItem);
                this.HandleAutoExpansion(itemControlID, targetItem, targetItemRect, num, mousePosition);
                if (dropPosition == TreeViewDragging.DropPosition.Upon)
                {
                    dragAndDropVisualMode = this.DoDrag(targetItem, targetItem, false, dropPosition);
                }
                if (dragAndDropVisualMode != DragAndDropVisualMode.None)
                {
                    this.m_DropData.dropTargetControlID = itemControlID;
                    DragAndDrop.visualMode = dragAndDropVisualMode;
                }
                else if (targetItem != null && treeViewItem != null)
                {
                    dragAndDropVisualMode = this.DoDrag(treeViewItem, targetItem, false, dropPosition);
                    if (dragAndDropVisualMode != DragAndDropVisualMode.None)
                    {
                        this.drawRowMarkerAbove             = (dropPosition == TreeViewDragging.DropPosition.Above);
                        this.m_DropData.rowMarkerControlID  = itemControlID;
                        this.m_DropData.dropTargetControlID = ((!this.drawRowMarkerAbove) ? TreeView.GetItemControlID(treeViewItem) : 0);
                        DragAndDrop.visualMode = dragAndDropVisualMode;
                    }
                }
            }
            Event.current.Use();
            return(true);
        }
Ejemplo n.º 7
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;
            }
        }