FairyGUI.GList.HandleArrowKey C# (CSharp) Method

HandleArrowKey() public method

public HandleArrowKey ( int dir ) : void
dir int
return void
        public void HandleArrowKey(int dir)
        {
            int index = this.selectedIndex;
            if (index == -1)
                return;

            switch (dir)
            {
                case 1://up
                    if (_layout == ListLayoutType.SingleColumn || _layout == ListLayoutType.FlowVertical)
                    {
                        index--;
                        if (index >= 0)
                        {
                            ClearSelection();
                            AddSelection(index, true);
                        }
                    }
                    else if (_layout == ListLayoutType.FlowHorizontal || _layout == ListLayoutType.Pagination)
                    {
                        GObject current = _children[index];
                        int k = 0;
                        int i;
                        for (i = index - 1; i >= 0; i--)
                        {
                            GObject obj = _children[i];
                            if (obj.y != current.y)
                            {
                                current = obj;
                                break;
                            }
                            k++;
                        }
                        for (; i >= 0; i--)
                        {
                            GObject obj = _children[i];
                            if (obj.y != current.y)
                            {
                                ClearSelection();
                                AddSelection(i + k + 1, true);
                                break;
                            }
                        }
                    }
                    break;

                case 3://right
                    if (_layout == ListLayoutType.SingleRow || _layout == ListLayoutType.FlowHorizontal || _layout == ListLayoutType.Pagination)
                    {
                        index++;
                        if (index < _children.Count)
                        {
                            ClearSelection();
                            AddSelection(index, true);
                        }
                    }
                    else if (_layout == ListLayoutType.FlowVertical)
                    {
                        GObject current = _children[index];
                        int k = 0;
                        int cnt = _children.Count;
                        int i;
                        for (i = index + 1; i < cnt; i++)
                        {
                            GObject obj = _children[i];
                            if (obj.x != current.x)
                            {
                                current = obj;
                                break;
                            }
                            k++;
                        }
                        for (; i < cnt; i++)
                        {
                            GObject obj = _children[i];
                            if (obj.x != current.x)
                            {
                                ClearSelection();
                                AddSelection(i - k - 1, true);
                                break;
                            }
                        }
                    }
                    break;

                case 5://down
                    if (_layout == ListLayoutType.SingleColumn || _layout == ListLayoutType.FlowVertical)
                    {
                        index++;
                        if (index < _children.Count)
                        {
                            ClearSelection();
                            AddSelection(index, true);
                        }
                    }
                    else if (_layout == ListLayoutType.FlowHorizontal || _layout == ListLayoutType.Pagination)
                    {
                        GObject current = _children[index];
                        int k = 0;
                        int cnt = _children.Count;
                        int i;
                        for (i = index + 1; i < cnt; i++)
                        {
                            GObject obj = _children[i];
                            if (obj.y != current.y)
                            {
                                current = obj;
                                break;
                            }
                            k++;
                        }
                        for (; i < cnt; i++)
                        {
                            GObject obj = _children[i];
                            if (obj.y != current.y)
                            {
                                ClearSelection();
                                AddSelection(i - k - 1, true);
                                break;
                            }
                        }
                    }
                    break;

                case 7://left
                    if (_layout == ListLayoutType.SingleRow || _layout == ListLayoutType.FlowHorizontal || _layout == ListLayoutType.Pagination)
                    {
                        index--;
                        if (index >= 0)
                        {
                            ClearSelection();
                            AddSelection(index, true);
                        }
                    }
                    else if (_layout == ListLayoutType.FlowVertical)
                    {
                        GObject current = _children[index];
                        int k = 0;
                        int i;
                        for (i = index - 1; i >= 0; i--)
                        {
                            GObject obj = _children[i];
                            if (obj.x != current.x)
                            {
                                current = obj;
                                break;
                            }
                            k++;
                        }
                        for (; i >= 0; i--)
                        {
                            GObject obj = _children[i];
                            if (obj.x != current.x)
                            {
                                ClearSelection();
                                AddSelection(i + k + 1, true);
                                break;
                            }
                        }
                    }
                    break;
            }
        }

Usage Example

示例#1
0
 static public int HandleArrowKey(IntPtr l)
 {
     try {
         FairyGUI.GList self = (FairyGUI.GList)checkSelf(l);
         System.Int32   a1;
         checkType(l, 2, out a1);
         self.HandleArrowKey(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
All Usage Examples Of FairyGUI.GList::HandleArrowKey