예제 #1
0
            public SortableElementDropper()
            {
                m_Active = false;

                m_DragAndDropDelay = new DragAndDropDelay();

                ActivateButton = MouseButton.LeftMouse;
            }
예제 #2
0
        private void DoRangeSelection(Rect rect)
        {
            int   controlID = GUIUtility.GetControlID(ProfilerTimelineGUI.RangeSelectionInfo.controlIDHint, FocusType.Passive);
            Event current   = Event.current;

            switch (current.type)
            {
            case EventType.MouseDown:
                if (GUIUtility.hotControl == 0 && current.button == 0 && rect.Contains(current.mousePosition))
                {
                    DragAndDropDelay dragAndDropDelay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), controlID);
                    dragAndDropDelay.mouseDownPosition = current.mousePosition;
                    this.m_RangeSelection.mouseDown    = true;
                    this.m_RangeSelection.active       = false;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID && current.button == 0)
                {
                    GUIUtility.hotControl           = 0;
                    this.m_RangeSelection.mouseDown = false;
                    current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == 0 && this.m_RangeSelection.mouseDown)
                {
                    DragAndDropDelay dragAndDropDelay2 = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), controlID);
                    if (dragAndDropDelay2.CanStartDrag())
                    {
                        GUIUtility.hotControl = controlID;
                        this.m_RangeSelection.mouseDownTime = this.m_TimeArea.PixelToTime(dragAndDropDelay2.mouseDownPosition.x, rect);
                        this.m_RangeSelection.startTime     = (this.m_RangeSelection.endTime = this.m_RangeSelection.mouseDownTime);
                        this.ClearSelection();
                        this.m_RangeSelection.active = true;
                        current.Use();
                    }
                }
                else if (GUIUtility.hotControl == controlID)
                {
                    float num = this.m_TimeArea.PixelToTime(current.mousePosition.x, rect);
                    if (num < this.m_RangeSelection.mouseDownTime)
                    {
                        this.m_RangeSelection.startTime = num;
                        this.m_RangeSelection.endTime   = this.m_RangeSelection.mouseDownTime;
                    }
                    else
                    {
                        this.m_RangeSelection.startTime = this.m_RangeSelection.mouseDownTime;
                        this.m_RangeSelection.endTime   = num;
                    }
                    current.Use();
                }
                break;

            case EventType.Repaint:
                if (this.m_RangeSelection.active)
                {
                    float num2 = this.m_TimeArea.TimeToPixel(this.m_RangeSelection.startTime, rect);
                    float num3 = this.m_TimeArea.TimeToPixel(this.m_RangeSelection.endTime, rect);
                    if (num2 <= rect.xMax && num3 >= rect.xMin)
                    {
                        Rect position = Rect.MinMaxRect(Mathf.Max(rect.xMin, num2), rect.yMin, Mathf.Min(rect.xMax, num3), rect.yMax);
                        ProfilerTimelineGUI.styles.rectangleToolSelection.Draw(position, false, false, false, false);
                    }
                }
                break;
            }
        }
예제 #3
0
        public void HandleUnusedMouseEventsForItem(Rect rect, TreeViewItem item, int row)
        {
            int       itemControlID  = TreeViewController.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
                        {
                            List <int> newSelection = this.GetNewSelection(item, true, false);
                            bool       flag         = this.dragging != null && newSelection.Count != 0 && this.dragging.CanStartDrag(item, newSelection, Event.current.mousePosition);
                            if (flag)
                            {
                                this.m_DragSelection = newSelection;
                                DragAndDropDelay dragAndDropDelay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), itemControlID);
                                dragAndDropDelay.mouseDownPosition = Event.current.mousePosition;
                            }
                            else
                            {
                                this.m_DragSelection.Clear();
                                if (this.m_AllowRenameOnMouseUp)
                                {
                                    this.m_AllowRenameOnMouseUp = (this.state.selectedIDs.Count == 1 && this.state.selectedIDs[0] == item.id);
                                }
                                this.SelectionClick(item, false);
                            }
                            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)
                {
                    bool flag2 = this.m_DragSelection.Count > 0;
                    GUIUtility.hotControl = 0;
                    this.m_DragSelection.Clear();
                    current.Use();
                    if (rect.Contains(current.mousePosition))
                    {
                        Rect       renameRect  = this.gui.GetRenameRect(rect, row, item);
                        List <int> selectedIDs = this.state.selectedIDs;
                        if (this.m_AllowRenameOnMouseUp && selectedIDs != null && selectedIDs.Count == 1 && selectedIDs[0] == item.id && renameRect.Contains(current.mousePosition) && !EditorGUIUtility.HasHolddownKeyModifiers(current))
                        {
                            this.BeginNameEditing(0.5f);
                        }
                        else if (flag2)
                        {
                            this.SelectionClick(item, false);
                        }
                    }
                }
                return;

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

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == itemControlID && this.dragging != null && this.m_DragSelection.Count > 0)
                {
                    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_2C;
        }
예제 #4
0
    public void HandleUnusedMouseEventsForItem(Rect rect, TreeViewItem item, bool firstItem)
    {
        int       itemControlId  = 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 = m_KeyboardControlID;
                Repaint();
                if (Event.current.clickCount == 2)
                {
                    if (itemDoubleClickedCallback != null)
                    {
                        itemDoubleClickedCallback(item.id);
                    }
                }
                else
                {
                    if (dragging == null || dragging.CanStartDrag(item, m_DragSelection, Event.current.mousePosition))
                    {
                        m_DragSelection = 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;
            SelectionClick(item, keepMultiSelection);
            break;

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

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

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