Exemplo n.º 1
0
            public bool MoveNext()
            {
                if (this.xPos > -1)
                {
                    if (ListViewShared.HasMouseDown(this.ilvState, this.rect))
                    {
                        this.ilvState.state.selectionChanged = true;
                        this.ilvState.state.row       = this.yPos;
                        this.ilvState.state.column    = this.xPos;
                        this.ilvState.state.scrollPos = ListViewShared.ListViewScrollToRow(this.ilvState, this.yPos);
                        if ((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && GUIUtility.hotControl == this.ilvState.state.ID)
                        {
                            ((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID)).mouseDownPosition = Event.current.mousePosition;
                            this.ilvState.dragItem       = this.yPos;
                            ListViewShared.dragControlID = this.ilvState.state.ID;
                        }
                    }
                    if ((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && (GUIUtility.hotControl == this.ilvState.state.ID && Event.current.type == EventType.MouseDrag) && GUIClip.visibleRect.Contains(Event.current.mousePosition))
                    {
                        if (((DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID)).CanStartDrag())
                        {
                            DragAndDrop.PrepareStartDrag();
                            DragAndDrop.objectReferences = new UnityEngine.Object[0];
                            DragAndDrop.paths            = (string[])null;
                            if (this.ilvState.wantsReordering)
                            {
                                this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, 0.0f, this.ilvState.rect.width, (float)(this.ilvState.state.rowHeight * 2));
                                DragAndDrop.StartDrag(this.dragTitle);
                            }
                            else if (this.ilvState.wantsToStartCustomDrag)
                            {
                                DragAndDrop.SetGenericData("CustomDragID", (object)this.ilvState.state.ID);
                                DragAndDrop.StartDrag(this.dragTitle);
                            }
                        }
                        Event.current.Use();
                    }
                }
                ++this.xPos;
                if (this.xPos > this.xTo)
                {
                    this.xPos = 0;
                    ++this.yPos;
                    this.rect.x     = this.firstRect.x;
                    this.rect.width = (float)this.colWidths[0];
                    if (this.yPos > this.yTo)
                    {
                        this.quiting = true;
                    }
                    else
                    {
                        this.rect.y += this.rect.height;
                    }
                }
                else
                {
                    if (this.xPos >= 1)
                    {
                        this.rect.x += (float)this.colWidths[this.xPos - 1];
                    }
                    this.rect.width = (float)this.colWidths[this.xPos];
                }
                this.element.row      = this.yPos;
                this.element.column   = this.xPos;
                this.element.position = this.rect;
                if (this.element.row >= this.ilvState.state.totalRows)
                {
                    this.quiting = true;
                }
                if (this.isLayouted && Event.current.type == EventType.Layout && this.yFrom + 1 == this.yPos)
                {
                    this.quiting = true;
                }
                if (this.isLayouted && this.yPos != this.yFrom)
                {
                    GUILayout.EndHorizontal();
                }
                if (this.quiting)
                {
                    if (this.ilvState.state.drawDropHere && Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.Repaint)
                    {
                        GUIStyle insertion = (GUIStyle)ListViewShared.Constants.insertion;
                        insertion.Draw(insertion.margin.Remove(this.ilvState.state.dropHereRect), false, false, false, false);
                    }
                    if (ListViewShared.ListViewKeyboard(this.ilvState, this.colWidths.Length))
                    {
                        this.ilvState.state.selectionChanged = true;
                    }
                    if (Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.MouseUp)
                    {
                        GUIUtility.hotControl = 0;
                    }
                    if (this.ilvState.wantsReordering && GUIUtility.hotControl == this.ilvState.state.ID)
                    {
                        ListViewState state = this.ilvState.state;
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                            DragAndDrop.visualMode = !this.ilvState.rect.Contains(Event.current.mousePosition) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move;
                            Event.current.Use();
                            if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                            {
                                state.dropHereRect.y = (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight) - 1) * state.rowHeight);
                                if ((double)state.dropHereRect.y >= (double)(state.rowHeight * state.totalRows))
                                {
                                    state.dropHereRect.y = (float)(state.rowHeight * (state.totalRows - 1));
                                }
                                state.drawDropHere = true;
                                break;
                            }
                            break;

                        case EventType.DragPerform:
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                            {
                                this.ilvState.state.draggedFrom = this.ilvState.dragItem;
                                this.ilvState.state.draggedTo   = Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight);
                                if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows)
                                {
                                    this.ilvState.state.draggedTo = this.ilvState.state.totalRows;
                                }
                                this.ilvState.state.row = this.ilvState.state.draggedTo <= this.ilvState.state.draggedFrom ? this.ilvState.state.draggedTo : this.ilvState.state.draggedTo - 1;
                                this.ilvState.state.selectionChanged = true;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                                this.ilvState.wantsReordering    = false;
                                this.ilvState.state.drawDropHere = false;
                            }
                            GUIUtility.hotControl = 0;
                            break;

                        case EventType.DragExited:
                            this.ilvState.wantsReordering    = false;
                            this.ilvState.state.drawDropHere = false;
                            GUIUtility.hotControl            = 0;
                            break;
                        }
                    }
                    else if (this.ilvState.wantsExternalFiles)
                    {
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && DragAndDrop.paths != null && DragAndDrop.paths.Length != 0)
                            {
                                DragAndDrop.visualMode = !this.ilvState.rect.Contains(Event.current.mousePosition) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Copy;
                                Event.current.Use();
                                if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                                {
                                    this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)this.ilvState.state.rowHeight) - 1) * this.ilvState.state.rowHeight), this.ilvState.rect.width, (float)this.ilvState.state.rowHeight);
                                    if ((double)this.ilvState.state.dropHereRect.y >= (double)(this.ilvState.state.rowHeight * this.ilvState.state.totalRows))
                                    {
                                        this.ilvState.state.dropHereRect.y = (float)(this.ilvState.state.rowHeight * (this.ilvState.state.totalRows - 1));
                                    }
                                    this.ilvState.state.drawDropHere = true;
                                    break;
                                }
                                break;
                            }
                            break;

                        case EventType.DragPerform:
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                            {
                                this.ilvState.state.fileNames = DragAndDrop.paths;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                                this.ilvState.wantsExternalFiles = false;
                                this.ilvState.state.drawDropHere = false;
                                this.ilvState.state.draggedTo    = Mathf.RoundToInt(Event.current.mousePosition.y / (float)this.ilvState.state.rowHeight);
                                if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows)
                                {
                                    this.ilvState.state.draggedTo = this.ilvState.state.totalRows;
                                }
                                this.ilvState.state.row = this.ilvState.state.draggedTo;
                            }
                            GUIUtility.hotControl = 0;
                            break;

                        case EventType.DragExited:
                            this.ilvState.wantsExternalFiles = false;
                            this.ilvState.state.drawDropHere = false;
                            GUIUtility.hotControl            = 0;
                            break;
                        }
                    }
                    else if (this.ilvState.wantsToAcceptCustomDrag && ListViewShared.dragControlID != this.ilvState.state.ID)
                    {
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && DragAndDrop.GetGenericData("CustomDragID") != null)
                            {
                                DragAndDrop.visualMode = !this.ilvState.rect.Contains(Event.current.mousePosition) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move;
                                Event.current.Use();
                                break;
                            }
                            break;

                        case EventType.DragPerform:
                            object genericData = DragAndDrop.GetGenericData("CustomDragID");
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && genericData != null)
                            {
                                this.ilvState.state.customDraggedFromID = (int)genericData;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                            }
                            GUIUtility.hotControl = 0;
                            break;

                        case EventType.DragExited:
                            GUIUtility.hotControl = 0;
                            break;
                        }
                    }
                    if (this.ilvState.beganHorizontal)
                    {
                        EditorGUILayout.EndScrollView();
                        GUILayout.EndHorizontal();
                        this.ilvState.beganHorizontal = false;
                    }
                    if (this.isLayouted)
                    {
                        GUILayoutUtility.EndLayoutGroup();
                        EditorGUILayout.EndScrollView();
                    }
                    this.ilvState.wantsReordering    = false;
                    this.ilvState.wantsExternalFiles = false;
                }
                else if (this.isLayouted)
                {
                    if (this.yPos != this.yFrom)
                    {
                        this.ilvStateL.group.ResetCursor();
                        this.ilvStateL.group.AddY();
                    }
                    else
                    {
                        this.ilvStateL.group.AddY((float)(this.ilvState.invisibleRows * this.ilvState.state.rowHeight));
                    }
                }
                if (this.isLayouted)
                {
                    if (!this.quiting)
                    {
                        GUILayout.BeginHorizontal(GUIStyle.none, new GUILayoutOption[0]);
                    }
                    else
                    {
                        GUILayout.EndHorizontal();
                    }
                }
                return(!this.quiting);
            }
Exemplo n.º 2
0
            public bool MoveNext()
            {
                if (xPos > -1)
                {
                    if (ListViewShared.HasMouseDown(ilvState, rect))
                    {
                        var previousRow = ilvState.state.row;
                        ilvState.state.selectionChanged = true;
                        ilvState.state.row       = yPos;
                        ilvState.state.column    = xPos;
                        ilvState.state.scrollPos = ListViewShared.ListViewScrollToRow(ilvState, yPos); // this is about clicking on a row that is partially visible

                        if (ilvState.wantsRowMultiSelection)
                        {
                            MultiSelection(ilvState, previousRow);
                        }

                        if ((ilvState.wantsReordering || ilvState.wantsToStartCustomDrag) && (GUIUtility.hotControl == ilvState.state.ID))
                        {
                            DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), ilvState.state.ID);
                            delay.mouseDownPosition = Event.current.mousePosition;
                            ilvState.dragItem       = yPos;
                            dragControlID           = ilvState.state.ID;
                        }
                    }
                    // On Mouse drag, start drag & drop
                    if (!ListViewShared.isDragging &&
                        (ilvState.wantsReordering || ilvState.wantsToStartCustomDrag) &&
                        GUIUtility.hotControl == ilvState.state.ID &&
                        Event.current.type == EventType.MouseDrag &&
                        GUIClip.visibleRect.Contains(Event.current.mousePosition))
                    {
                        DragAndDropDelay delay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), ilvState.state.ID);

                        if (delay.CanStartDrag())
                        {
                            DragAndDrop.PrepareStartDrag();

                            DragAndDrop.objectReferences = new UnityEngine.Object[] {};  // this IS required for dragging to work
                            DragAndDrop.paths            = null;

                            if (ilvState.wantsReordering)
                            {
                                ilvState.state.dropHereRect = new Rect(ilvState.rect.x, 0, ilvState.rect.width, ilvState.state.rowHeight * 2);
                                DragAndDrop.StartDrag(dragTitle);
                            }
                            else if (ilvState.wantsToStartCustomDrag)
                            {
                                DragAndDrop.SetGenericData("CustomDragID", ilvState.state.ID);
                                DragAndDrop.StartDrag(dragTitle);
                            }

                            ListViewShared.isDragging = true;
                        }

                        Event.current.Use();
                    }
                }

                xPos++;

                if (xPos > xTo)
                {
                    xPos = 0;
                    yPos++;

                    rect.x     = firstRect.x;
                    rect.width = colWidths[0];

                    if (yPos > yTo)
                    {
                        quiting = true;
                    }
                    else // move vertically
                    {
                        rect.y += rect.height;
                    }
                }
                else // move horizontally
                {
                    if (xPos >= 1)
                    {
                        rect.x += colWidths[xPos - 1];
                    }

                    rect.width = colWidths[xPos];
                }

                element.row      = yPos;
                element.column   = xPos;
                element.position = rect;

                if (element.row >= ilvState.state.totalRows)
                {
                    quiting = true;
                }

                if (isLayouted && Event.current.type == EventType.Layout)
                {
                    // this is just "on layout event enumerate just first row" (so we get height of single row)
                    if (yFrom + 1 == yPos)
                    {
                        quiting = true;
                    }
                }

                if (isLayouted && yPos != yFrom)
                {
                    GUILayout.EndHorizontal();
                }

                if (quiting)
                {
                    if (ilvState.state.drawDropHere && Event.current.GetTypeForControl(ilvState.state.ID) == EventType.Repaint)
                    {
                        GUIStyle insertion = Constants.insertion;
                        insertion.Draw(insertion.margin.Remove(ilvState.state.dropHereRect), false, false, false, false);
                    }

                    if (ListViewShared.ListViewKeyboard(ilvState, colWidths.Length))
                    {
                        ilvState.state.selectionChanged = true;
                    }

                    if (Event.current.GetTypeForControl(ilvState.state.ID) == EventType.MouseUp)
                    {
                        GUIUtility.hotControl = 0;
                    }

                    if (ilvState.wantsReordering && (GUIUtility.hotControl == ilvState.state.ID))
                    {
                        ListViewState lv = ilvState.state;

                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                        {
                            DragAndDrop.visualMode = ilvState.rect.Contains(Event.current.mousePosition) ?
                                                     DragAndDropVisualMode.Move : DragAndDropVisualMode.None;

                            Event.current.Use();

                            if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                            {
                                lv.dropHereRect.y = (Mathf.RoundToInt(Event.current.mousePosition.y / lv.rowHeight) - 1) * lv.rowHeight;

                                if (lv.dropHereRect.y >= lv.rowHeight * lv.totalRows)
                                {
                                    lv.dropHereRect.y = lv.rowHeight * (lv.totalRows - 1);
                                }

                                lv.drawDropHere = true;
                            }

                            break;
                        }

                        case EventType.DragPerform:
                        {
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                            {
                                ilvState.state.draggedFrom = ilvState.dragItem;
                                ilvState.state.draggedTo   = Mathf.RoundToInt(Event.current.mousePosition.y / lv.rowHeight);

                                if (ilvState.state.draggedTo > ilvState.state.totalRows)
                                {
                                    ilvState.state.draggedTo = ilvState.state.totalRows;
                                }

                                // the guy handling this would better actually rearrange items...
                                if (ilvState.state.draggedTo > ilvState.state.draggedFrom)
                                {
                                    ilvState.state.row = ilvState.state.draggedTo - 1;
                                }
                                else
                                {
                                    ilvState.state.row = ilvState.state.draggedTo;
                                }

                                ilvState.state.selectionChanged = true;

                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                                ilvState.wantsReordering    = false;
                                ilvState.state.drawDropHere = false;
                            }

                            GUIUtility.hotControl = 0;
                            break;
                        }

                        case EventType.DragExited:
                        {
                            ilvState.wantsReordering    = false;
                            ilvState.state.drawDropHere = false;

                            GUIUtility.hotControl = 0;
                            break;
                        }
                        }
                    }
                    else if (ilvState.wantsExternalFiles)
                    {
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                        {
                            if ((GUIClip.visibleRect.Contains(Event.current.mousePosition)) &&
                                (DragAndDrop.paths != null) && (DragAndDrop.paths.Length != 0))             // dragging files from somewhere
                            {
                                DragAndDrop.visualMode = ilvState.rect.Contains(Event.current.mousePosition) ?
                                                         DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;

                                Event.current.Use();

                                if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                                {
                                    ilvState.state.dropHereRect = new Rect(ilvState.rect.x,
                                                                           (Mathf.RoundToInt(Event.current.mousePosition.y / ilvState.state.rowHeight) - 1) * ilvState.state.rowHeight,
                                                                           ilvState.rect.width, ilvState.state.rowHeight);

                                    if (ilvState.state.dropHereRect.y >= ilvState.state.rowHeight * ilvState.state.totalRows)
                                    {
                                        ilvState.state.dropHereRect.y = ilvState.state.rowHeight * (ilvState.state.totalRows - 1);
                                    }

                                    ilvState.state.drawDropHere = true;
                                }
                            }
                            break;
                        }

                        case EventType.DragPerform:
                        {
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                            {
                                ilvState.state.fileNames = DragAndDrop.paths;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                                ilvState.wantsExternalFiles = false;
                                ilvState.state.drawDropHere = false;
                                ilvState.state.draggedTo    = Mathf.RoundToInt(Event.current.mousePosition.y / ilvState.state.rowHeight);
                                if (ilvState.state.draggedTo > ilvState.state.totalRows)
                                {
                                    ilvState.state.draggedTo = ilvState.state.totalRows;
                                }
                                ilvState.state.row = ilvState.state.draggedTo;
                            }

                            GUIUtility.hotControl = 0;

                            break;
                        }

                        case EventType.DragExited:
                        {
                            ilvState.wantsExternalFiles = false;
                            ilvState.state.drawDropHere = false;

                            GUIUtility.hotControl = 0;
                            break;
                        }
                        }
                    }
                    else if (ilvState.wantsToAcceptCustomDrag && (dragControlID != ilvState.state.ID))
                    {
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                        {
                            object data = DragAndDrop.GetGenericData("CustomDragID");

                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && data != null)
                            {
                                DragAndDrop.visualMode = ilvState.rect.Contains(Event.current.mousePosition) ?
                                                         DragAndDropVisualMode.Move : DragAndDropVisualMode.None;

                                Event.current.Use();
                            }
                            break;
                        }

                        case EventType.DragPerform:
                        {
                            object data = DragAndDrop.GetGenericData("CustomDragID");

                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && data != null)
                            {
                                ilvState.state.customDraggedFromID = (int)data;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                            }

                            GUIUtility.hotControl = 0;
                            break;
                        }

                        case EventType.DragExited:
                        {
                            GUIUtility.hotControl = 0;
                            break;
                        }
                        }
                    }

                    if (ilvState.beganHorizontal)
                    {
                        EditorGUILayout.EndScrollView();
                        GUILayout.EndHorizontal();
                        ilvState.beganHorizontal = false;
                    }

                    if (isLayouted)
                    {
                        GUILayoutUtility.EndLayoutGroup();
                        EditorGUILayout.EndScrollView();
                    }

                    ilvState.wantsReordering    = false;
                    ilvState.wantsExternalFiles = false;
                }
                else if (isLayouted)
                {
                    if (yPos != yFrom)
                    {
                        ilvStateL.group.ResetCursor();
                        ilvStateL.group.AddY();
                    }
                    else
                    {
                        ilvStateL.group.AddY(ilvState.invisibleRows * ilvState.state.rowHeight);
                    }
                }

                if (isLayouted)
                {
                    if (!quiting)
                    {
                        GUILayout.BeginHorizontal(GUIStyle.none); // for each row
                    }
                    else
                    {
                        GUILayout.EndHorizontal(); // the one used for drawing LVs background
                    }
                }

                return(!quiting);
            }