Example #1
0
        //----------------------------------------------------------------------------------
        private void ProccessOtherEvents(Event ev, Rect listBox)
        {
            switch (ev.type)
            {
            case EventType.MouseDrag:
            {
                if (listBox.Contains(ev.mousePosition))
                {
                    CustomDragData       receivedDragData = DragAndDrop.GetGenericData(dragDropIdentifier_) as CustomDragData;
                    UnityEngine.Object[] objects          = DragAndDrop.objectReferences;
                    if (receivedDragData != null || (objects != null && objects.Length > 0))
                    {
                        isDragging_ = true;
                        DragAndDrop.StartDrag("Dragging List Element");
                        ev.Use();
                    }
                }
                break;
            }

            case EventType.DragUpdated:
                if (listBox.Contains(ev.mousePosition))
                {
                    if (!dragOverAnyItem_)
                    {
                        CurrentMouseDragItem   = -1;
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                        if (Controller.ListIsValidDragTarget())
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        }
                    }
                    ev.Use();
                }
                break;

            case EventType.DragPerform:
            {
                if (listBox.Contains(ev.mousePosition))
                {
                    CustomDragData receivedDragData = DragAndDrop.GetGenericData(dragDropIdentifier_) as CustomDragData;
                    if (receivedDragData != null)
                    {
                        Controller.MoveDraggedItem(receivedDragData.originalIndex, CurrentMouseDragItem, EdgeDrag);
                        return;
                    }

                    UnityEngine.Object[] objects = DragAndDrop.objectReferences;
                    if (receivedDragData != null || (objects != null && objects.Length > 0))
                    {
                        Controller.AddDraggedObjects(CurrentMouseDragItem, objects);
                    }

                    DragAndDrop.AcceptDrag();
                }

                CleanUp();
                Controller.GUIUpdateRequested();
            }
            break;

            case EventType.DragExited:
                CleanUp();
                Controller.GUIUpdateRequested();
                break;

            case EventType.MouseUp:
                if (listBox.Contains(ev.mousePosition))
                {
                    // Clean up, in case MouseDrag never occurred:
                    CleanUp();
                }

                break;

            case EventType.MouseDown:
                if ((!listBox.Contains(ev.mousePosition) || (listBox.Contains(ev.mousePosition) && !itemEditedClicked_)) && Controller.ItemIdxEditing != -1)
                {
                    Controller.SetItemName(Controller.ItemIdxEditing, Controller.ItemIdxEditingName);
                    Controller.ItemIdxEditing = -1;
                    //CleanUp();
                    Controller.GUIUpdateRequested();
                }
                itemEditedClicked_ = false;
                break;

            case EventType.ContextClick:
                if (listBox.Contains(ev.mousePosition))
                {
                    Controller.OnContextClickList();
                    ev.Use();
                }
                break;
            }
        }
Example #2
0
        //----------------------------------------------------------------------------------
        private void ProcessEventsItemList(Rect listBox, int itemIdx, Rect commandBox, Rect labelBox, Rect toggleBox, Event ev, bool isGroup)
        {
            if (!listBox.Contains(ev.mousePosition))
            {
                return;
            }

            if (Controller.ItemIdxEditing == itemIdx)
            {
                return;
            }

            switch (ev.type)
            {
            case EventType.Used:
                return;

            case EventType.MouseDown:
                if (!Controller.ItemIsSelectable(itemIdx))
                {
                    return;
                }

                if (ev.button == 0)
                {
                    if (isGroup && toggleBox.Contains(ev.mousePosition))
                    {
                        ev.Use();
                        return;
                    }

                    if (commandBox.Contains(ev.mousePosition))
                    {
                        if (itemIdx != Controller.ItemIdxEditing)
                        {
                            if (Controller.ItemIdxEditing != -1)
                            {
                                Controller.SetItemName(Controller.ItemIdxEditing, Controller.ItemIdxEditingName);
                                Controller.ItemIdxEditing = -1;
                            }
                            if (Controller.ItemIsDraggable(itemIdx) && !Controller.BlockEdition)
                            {
                                DragAndDrop.PrepareStartDrag();
                                CustomDragData dragData = new CustomDragData();

                                dragData.originalIndex = itemIdx;
                                dragData.originalList  = this;
                                draggingItemIdx_       = itemIdx;
                                isInternalDrag_        = true;

                                DragAndDrop.objectReferences = new UnityEngine.Object[0];
                                DragAndDrop.SetGenericData(dragDropIdentifier_, dragData);
                            }
                            if (ev.button == 0)
                            {
                                if (ev.clickCount == 1)
                                {
                                    Controller.OnClickItem(itemIdx, ev.control, ev.shift, ev.alt, false);
                                }
                                else if (ev.clickCount == 2)
                                {
                                    Controller.OnDoubleClickItem(itemIdx);
                                }
                            }
                        }
                        else
                        {
                            itemEditedClicked_ = true;
                        }
                        ev.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (isGroup && toggleBox.Contains(ev.mousePosition))
                {
                    ev.Use();
                    return;
                }

                if (!Controller.ItemIsSelectable(itemIdx))
                {
                    return;
                }
                if (commandBox.Contains(ev.mousePosition) && itemIdx != Controller.ItemIdxEditing)
                {
                    if (ev.button == 0)
                    {
                        if (ev.clickCount == 1)
                        {
                            Controller.OnClickItem(itemIdx, ev.control, ev.shift, ev.alt, true);
                        }
                        else if (ev.clickCount == 2)
                        {
                            Controller.OnDoubleClickItem(itemIdx);
                        }
                        ev.Use();
                    }
                }
                break;


            case EventType.DragUpdated:
                Rect edgeBox = new Rect(commandBox.x, commandBox.yMax - 6, commandBox.width, 6);
                if (edgeBox.Contains(ev.mousePosition) && isInternalDrag_)
                {
                    if (Controller.ItemIsValidDragTarget(itemIdx, dragDropIdentifier_))
                    {
                        EdgeDrag               = true;
                        CurrentMouseDragItem   = itemIdx;
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        dragOverAnyItem_       = true;
                        ev.Use();
                    }
                }
                else if (commandBox.Contains(ev.mousePosition))
                {
                    EdgeDrag = false;
                    if (Controller.ItemIsValidDragTarget(itemIdx, dragDropIdentifier_))
                    {
                        CurrentMouseDragItem   = itemIdx;
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        dragOverAnyItem_       = true;
                    }
                    else
                    {
                        CurrentMouseDragItem   = -1;
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                    }
                    ev.Use();
                }
                break;

            case EventType.ContextClick:
                if (!Controller.ItemIsSelectable(itemIdx))
                {
                    return;
                }

                if (commandBox.Contains(ev.mousePosition) && Controller.ItemHasContext(itemIdx) && !Controller.BlockEdition)
                {
                    Controller.OnContextClickItem(itemIdx, ev.control, ev.shift, ev.alt);
                    ev.Use();
                }
                break;
            }
        }