Ejemplo n.º 1
0
        static internal Vector2 ListViewScrollToRow(InternalListViewState ilvState, Vector2 currPos, int row)
        {
            if ((ilvState.invisibleRows < row) && (ilvState.endRow > row))
            {
                return(currPos);
            }

            if (row <= ilvState.invisibleRows)
            {
                currPos.y = ilvState.state.rowHeight * row;
            }
            else
            {
                currPos.y = ilvState.state.rowHeight * (row + 1) - ilvState.rectHeight;
            }

            if (currPos.y < 0)
            {
                currPos.y = 0;
            }
            else if (currPos.y > ilvState.state.totalRows * ilvState.state.rowHeight - ilvState.rectHeight)
            {
                currPos.y = ilvState.state.totalRows * ilvState.state.rowHeight - ilvState.rectHeight;
            }

            return(currPos);
        }
Ejemplo n.º 2
0
        internal static bool ListViewKeyboard(InternalListViewState ilvState, int totalCols)
        {
            int totalRows = ilvState.state.totalRows;

            if ((Event.current.type != EventType.KeyDown) || (totalRows == 0))
            {
                return(false);
            }
            return(((GUIUtility.keyboardControl == ilvState.state.ID) && (Event.current.GetTypeForControl(ilvState.state.ID) == EventType.KeyDown)) && SendKey(ilvState, Event.current.keyCode, totalCols));
        }
Ejemplo n.º 3
0
 internal static bool HasMouseUp(InternalListViewState ilvState, Rect r, int button)
 {
     if (((Event.current.type == EventType.MouseUp) && (Event.current.button == button)) && r.Contains(Event.current.mousePosition))
     {
         GUIUtility.hotControl = 0;
         Event.current.Use();
         return(true);
     }
     return(false);
 }
Ejemplo n.º 4
0
        // Returns if LV selection has changed
        /// *undocumented*
        static bool DoLVPageUpDown(InternalListViewState ilvState, ref int selectedRow, ref Vector2 scrollPos, bool up)
        {
            int visibleRows = ilvState.endRow - ilvState.invisibleRows;

            if (up)
            {
                if (OSX)
                {
                    scrollPos.y -= ilvState.state.rowHeight * visibleRows;

                    if (scrollPos.y < 0)
                    {
                        scrollPos.y = 0;
                    }
                }
                else
                {
                    selectedRow -= visibleRows;

                    if (selectedRow < 0)
                    {
                        selectedRow = 0;
                    }

                    return(true);
                }
            }
            else
            {
                if (OSX)
                {
                    scrollPos.y += ilvState.state.rowHeight * visibleRows;
                    //FIXME: does this need an upper bound check?
                }
                else
                {
                    selectedRow += visibleRows;

                    if (selectedRow >= ilvState.state.totalRows)
                    {
                        selectedRow = ilvState.state.totalRows - 1;
                    }

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        static internal bool HasMouseDown(InternalListViewState ilvState, Rect r, int button)
        {
            if (Event.current.type == EventType.MouseDown && Event.current.button == button)
            {
                if (r.Contains(Event.current.mousePosition))
                {
                    GUIUtility.hotControl      = ilvState.state.ID;
                    GUIUtility.keyboardControl = ilvState.state.ID;
                    ListViewShared.isDragging  = false;
                    Event.current.Use();
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        internal static void MultiSelection(InternalListViewState ilvState, int previousRow)
        {
            var state = ilvState.state;

            // initializing and updating the array if needed
            if (state.selectedItems == null)
            {
                state.selectedItems = new bool[state.totalRows];
            }
            else if (state.selectedItems.Length != state.totalRows)
            {
                System.Array.Resize(ref state.selectedItems, state.totalRows);
            }

            MultiSelection(ilvState, previousRow, state.row, ref state.initialRow, ref state.selectedItems);
        }
Ejemplo n.º 7
0
            internal ListViewElementsEnumerator(InternalListViewState ilvState, int[] colWidths, int yFrom, int yTo, string dragTitle, Rect firstRect)
            {
                this.colWidths = colWidths;
                this.xTo       = colWidths.Length - 1;
                this.yFrom     = yFrom;
                this.yTo       = yTo;
                this.firstRect = firstRect;
                this.rect      = firstRect;
                this.quiting   = ilvState.state.totalRows == 0;

                this.ilvState  = ilvState;
                this.ilvStateL = ilvState as InternalLayoutedListViewState;

                this.isLayouted = ilvStateL != null;

                this.dragTitle = dragTitle;

                ilvState.state.customDraggedFromID = 0;

                Reset();
            }
Ejemplo n.º 8
0
 internal static Vector2 ListViewScrollToRow(InternalListViewState ilvState, Vector2 currPos, int row)
 {
     if ((ilvState.invisibleRows >= row) || (ilvState.endRow <= row))
     {
         if (row <= ilvState.invisibleRows)
         {
             currPos.y = ilvState.state.rowHeight * row;
         }
         else
         {
             currPos.y = (ilvState.state.rowHeight * (row + 1)) - ilvState.rectHeight;
         }
         if (currPos.y < 0f)
         {
             currPos.y = 0f;
         }
         else if (currPos.y > ((ilvState.state.totalRows * ilvState.state.rowHeight) - ilvState.rectHeight))
         {
             currPos.y = (ilvState.state.totalRows * ilvState.state.rowHeight) - ilvState.rectHeight;
         }
     }
     return(currPos);
 }
Ejemplo n.º 9
0
        private static bool DoLVPageUpDown(InternalListViewState ilvState, ref int selectedRow, ref Vector2 scrollPos, bool up)
        {
            int num = ilvState.endRow - ilvState.invisibleRows;

            if (up)
            {
                if (!OSX)
                {
                    selectedRow -= num;
                    if (selectedRow < 0)
                    {
                        selectedRow = 0;
                    }
                    return(true);
                }
                scrollPos.y -= ilvState.state.rowHeight * num;
                if (scrollPos.y < 0f)
                {
                    scrollPos.y = 0f;
                }
            }
            else if (OSX)
            {
                scrollPos.y += ilvState.state.rowHeight * num;
            }
            else
            {
                selectedRow += num;
                if (selectedRow >= ilvState.state.totalRows)
                {
                    selectedRow = ilvState.state.totalRows - 1;
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 10
0
 internal static bool HasMouseUp(InternalListViewState ilvState, Rect r)
 {
     return(HasMouseUp(ilvState, r, 0));
 }
Ejemplo n.º 11
0
        internal static bool SendKey(InternalListViewState ilvState, KeyCode keyCode, int totalCols)
        {
            ListViewState state = ilvState.state;

            switch (keyCode)
            {
            case KeyCode.UpArrow:
                if (state.row > 0)
                {
                    state.row--;
                }
                break;

            case KeyCode.DownArrow:
                if (state.row < (state.totalRows - 1))
                {
                    state.row++;
                }
                break;

            case KeyCode.RightArrow:
                if (state.column < (totalCols - 1))
                {
                    state.column++;
                }
                break;

            case KeyCode.LeftArrow:
                if (state.column > 0)
                {
                    state.column--;
                }
                break;

            case KeyCode.Home:
                state.row = 0;
                break;

            case KeyCode.End:
                state.row = state.totalRows - 1;
                break;

            case KeyCode.PageUp:
                if (DoLVPageUpDown(ilvState, ref state.row, ref state.scrollPos, true))
                {
                    break;
                }
                Event.current.Use();
                return(false);

            case KeyCode.PageDown:
                if (DoLVPageUpDown(ilvState, ref state.row, ref state.scrollPos, false))
                {
                    break;
                }
                Event.current.Use();
                return(false);

            default:
                return(false);
            }
            state.scrollPos = ListViewScrollToRow(ilvState, state.scrollPos, state.row);
            Event.current.Use();
            return(true);
        }
Ejemplo n.º 12
0
        internal static bool MultiSelection(InternalListViewState ilvState, int prevSelected, int currSelected, ref int initialSelected, ref bool[] selectedItems)
        {
            bool shift     = Event.current.shift;
            bool actionKey = EditorGUI.actionKey;
            bool flag3     = false;

            if ((shift || actionKey) && (initialSelected == -1))
            {
                initialSelected = prevSelected;
            }
            if (shift)
            {
                int num  = Math.Min(initialSelected, currSelected);
                int num2 = Math.Max(initialSelected, currSelected);
                if (!actionKey)
                {
                    for (int j = 0; j < num; j++)
                    {
                        if (selectedItems[j])
                        {
                            flag3 = true;
                        }
                        selectedItems[j] = false;
                    }
                    for (int k = num2 + 1; k < selectedItems.Length; k++)
                    {
                        if (selectedItems[k])
                        {
                            flag3 = true;
                        }
                        selectedItems[k] = false;
                    }
                }
                if (num < 0)
                {
                    num = num2;
                }
                for (int i = num; i <= num2; i++)
                {
                    if (!selectedItems[i])
                    {
                        flag3 = true;
                    }
                    selectedItems[i] = true;
                }
            }
            else if (actionKey)
            {
                selectedItems[currSelected] = !selectedItems[currSelected];
                initialSelected             = currSelected;
                flag3 = true;
            }
            else
            {
                if (!selectedItems[currSelected])
                {
                    flag3 = true;
                }
                for (int m = 0; m < selectedItems.Length; m++)
                {
                    if (selectedItems[m] && (currSelected != m))
                    {
                        flag3 = true;
                    }
                    selectedItems[m] = false;
                }
                initialSelected             = -1;
                selectedItems[currSelected] = true;
            }
            if (ilvState != null)
            {
                ilvState.state.scrollPos = ListViewScrollToRow(ilvState, currSelected);
            }
            return(flag3);
        }
Ejemplo n.º 13
0
 internal static bool HasMouseUp(InternalListViewState ilvState, Rect r) =>
 HasMouseUp(ilvState, r, 0);
Ejemplo n.º 14
0
 internal static Vector2 ListViewScrollToRow(InternalListViewState ilvState, int row)
 {
     return(ListViewScrollToRow(ilvState, ilvState.state.scrollPos, row));
 }
Ejemplo n.º 15
0
        // Returns if selection was actually changed
        static internal bool MultiSelection(InternalListViewState ilvState, int prevSelected, int currSelected, ref int initialSelected, ref bool[] selectedItems)
        {
            bool shiftIsDown = Event.current.shift;
            bool ctrlIsDown  = EditorGUI.actionKey;
            bool selChanged  = false;

            if ((shiftIsDown || ctrlIsDown) && (initialSelected == -1))
            {
                initialSelected = prevSelected;
            }

            // Select all : Ctrl + A
            bool selectAll           = ctrlIsDown && Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.A;
            int  prevInitialSelected = initialSelected;

            if (selectAll)
            {
                shiftIsDown = true;

                initialSelected = selectedItems.Length - 1;
                currSelected    = 0;
            }

            // multi selection
            if (shiftIsDown)
            {
                int from = System.Math.Min(initialSelected, currSelected);
                int to   = System.Math.Max(initialSelected, currSelected);

                // shift only: remove the items not between the initial and the current
                if (!ctrlIsDown)
                {
                    for (int i = 0; i < from; i++)
                    {
                        if (selectedItems[i])
                        {
                            selChanged = true;
                        }

                        selectedItems[i] = false;
                    }

                    for (int i = to + 1; i < selectedItems.Length; i++)
                    {
                        if (selectedItems[i])
                        {
                            selChanged = true;
                        }

                        selectedItems[i] = false;
                    }
                }

                if (from < 0)
                {
                    from = to;
                }
                // select the items between the initial and the current
                for (int i = from; i <= to; i++)
                {
                    if (!selectedItems[i])
                    {
                        selChanged = true;
                    }

                    selectedItems[i] = true;
                }
            }
            else if (ctrlIsDown)
            {
                selectedItems[currSelected] = !selectedItems[currSelected];
                initialSelected             = currSelected;
                selChanged = true;
            }
            else
            {
                if (!selectedItems[currSelected])
                {
                    selChanged = true;
                }

                for (int i = 0; i < selectedItems.Length; i++)
                {
                    if (selectedItems[i] && currSelected != i)
                    {
                        selChanged = true;
                    }

                    selectedItems[i] = false;
                }

                initialSelected             = -1;
                selectedItems[currSelected] = true;
            }

            if (selectAll) // revert the value
            {
                initialSelected = prevInitialSelected;
            }

            if (ilvState != null)
            {
                ilvState.state.scrollPos = ListViewScrollToRow(ilvState, currSelected);
            }

            return(selChanged);
        }
Ejemplo n.º 16
0
 static internal bool HasMouseDown(InternalListViewState ilvState, Rect r)
 {
     return(HasMouseDown(ilvState, r, 0));
 }
Ejemplo n.º 17
0
        internal static bool SendKey(InternalListViewState ilvState, KeyCode keyCode, int totalCols)
        {
            var state = ilvState.state;

            int previousRow = state.row;

            //ilvState.state.row, ref ilvState.state.column, ref ilvState.state.scrollPos
            switch (keyCode)
            {
            case KeyCode.UpArrow:
            {
                if (state.row > 0)
                {
                    state.row--;
                }
                // If nothing is selected, upArrow selects the 1st element
                else if (state.row == -1)
                {
                    state.row = 0;
                }
                break;
            }

            case KeyCode.DownArrow:
            {
                if (state.row < state.totalRows - 1)
                {
                    state.row++;
                }
                break;
            }

            case KeyCode.Home:
            {
                state.row = 0;
                break;
            }

            case KeyCode.End:
            {
                state.row = state.totalRows - 1;
                break;
            }

            case KeyCode.LeftArrow:
                if (state.column > 0)
                {
                    state.column--;
                }
                break;

            case KeyCode.RightArrow:
                if (state.column < totalCols - 1)
                {
                    state.column++;
                }
                break;

            case KeyCode.PageUp:
            {
                if (!DoLVPageUpDown(ilvState, ref state.row, ref state.scrollPos, true))
                {
                    Event.current.Use();
                    return(false);
                }
                break;
            }

            case KeyCode.PageDown:
            {
                if (!DoLVPageUpDown(ilvState, ref state.row, ref state.scrollPos, false))
                {
                    Event.current.Use();
                    return(false);
                }
                break;
            }

            case KeyCode.A:     // must evade the return false and be handled by MultiSelection if needed
                if (!(ilvState.wantsRowMultiSelection && EditorGUI.actionKey))
                {
                    return(false);
                }
                break;

            default:
                return(false);
            }

            if (ilvState.wantsRowMultiSelection)
            {
                MultiSelection(ilvState, previousRow); // scrollPos is set during MultiSelection
            }
            else
            {
                state.scrollPos = ListViewScrollToRow(ilvState, state.scrollPos, state.row);
            }
            Event.current.Use();
            return(true);
        }
        // Returns if selection was actually changed
        static internal bool MultiSelection(InternalListViewState ilvState, int prevSelected, int currSelected, ref int initialSelected, ref bool[] selectedItems)
        {
            bool shiftIsDown = Event.current.shift;
            bool ctrlIsDown  = EditorGUI.actionKey;
            bool selChanged  = false;

            if ((shiftIsDown || ctrlIsDown) && (initialSelected == -1))
            {
                initialSelected = prevSelected;
            }

            // multi selection
            if (shiftIsDown)
            {
                int from = System.Math.Min(initialSelected, currSelected);
                int to   = System.Math.Max(initialSelected, currSelected);

                if (!ctrlIsDown)
                {
                    for (int i = 0; i < from; i++)
                    {
                        if (selectedItems[i])
                        {
                            selChanged = true;
                        }

                        selectedItems[i] = false;
                    }

                    for (int i = to + 1; i < selectedItems.Length; i++)
                    {
                        if (selectedItems[i])
                        {
                            selChanged = true;
                        }

                        selectedItems[i] = false;
                    }
                }

                if (from < 0)
                {
                    from = to;
                }

                for (int i = from; i <= to; i++)
                {
                    if (!selectedItems[i])
                    {
                        selChanged = true;
                    }

                    selectedItems[i] = true;
                }
            }
            else if (ctrlIsDown)
            {
                selectedItems[currSelected] = !selectedItems[currSelected];
                initialSelected             = currSelected;
                selChanged = true;
            }
            else
            {
                if (!selectedItems[currSelected])
                {
                    selChanged = true;
                }

                for (int i = 0; i < selectedItems.Length; i++)
                {
                    if (selectedItems[i] && currSelected != i)
                    {
                        selChanged = true;
                    }

                    selectedItems[i] = false;
                }

                initialSelected             = -1;
                selectedItems[currSelected] = true;
            }

            if (ilvState != null)
            {
                ilvState.state.scrollPos = ListViewScrollToRow(ilvState, currSelected);
            }

            return(selChanged);
        }
Ejemplo n.º 19
0
 internal static int ListViewScrollToRow(InternalListViewState ilvState, int currPosY, int row)
 {
     return((int)ListViewScrollToRow(ilvState, new Vector2(0f, (float)currPosY), row).y);
 }
Ejemplo n.º 20
0
        internal static bool SendKey(InternalListViewState ilvState, KeyCode keyCode, int totalCols)
        {
            var state = ilvState.state;

            //ilvState.state.row, ref ilvState.state.column, ref ilvState.state.scrollPos
            switch (keyCode)
            {
            case KeyCode.UpArrow:
            {
                if (state.row > 0)
                {
                    state.row--;
                }
                // If nothing is selected, upArrow selects the 1st element
                else if (state.row == -1)
                {
                    state.row = 0;
                }
                break;
            }

            case KeyCode.DownArrow:
            {
                if (state.row < state.totalRows - 1)
                {
                    state.row++;
                }
                break;
            }

            case KeyCode.Home:
            {
                state.row = 0;
                break;
            }

            case KeyCode.End:
            {
                state.row = state.totalRows - 1;
                break;
            }

            case KeyCode.LeftArrow:
                if (state.column > 0)
                {
                    state.column--;
                }
                break;

            case KeyCode.RightArrow:
                if (state.column < totalCols - 1)
                {
                    state.column++;
                }
                break;

            case KeyCode.PageUp:
            {
                if (!DoLVPageUpDown(ilvState, ref state.row, ref state.scrollPos, true))
                {
                    Event.current.Use();
                    return(false);
                }
                break;
            }

            case KeyCode.PageDown:
            {
                if (!DoLVPageUpDown(ilvState, ref state.row, ref state.scrollPos, false))
                {
                    Event.current.Use();
                    return(false);
                }
                break;
            }

            default:
                return(false);
            }

            state.scrollPos = ListViewScrollToRow(ilvState, state.scrollPos, state.row);
            Event.current.Use();
            return(true);
        }