Beispiel #1
0
        /// <summary>
        /// Checks if a <see cref="DragEventArgs.Data"/> is valid to be dropped to the check list box.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.DragEventArgs" /> that contains the event data.</param>
        /// <returns><c>true</c> if the <see cref="DragEventArgs.Data"/> is valid to be dropped to the check list box, <c>false</c> otherwise.</returns>
        private bool CheckListCanDrop(DragEventArgs e)
        {
            var data = (SortText)e.Data.GetData(typeof(SortText));

            if (DragDropOrigin != null && DragDropOrigin.Equals(listCheckSortStyles))
            {
                var checkListBox = listCheckSortStyles;
                int index        = checkListBox.IndexFromPoint(checkListBox.PointToClient(new Point(e.X, e.Y)));
                if (checkListBox.Items.IndexOf(data) == index)
                {
                    return(false);
                }
                return(true);
            }

            if (e.Data.GetDataPresent(typeof(SortText)))
            {
                if (!e.Data.GetDataPresent(typeof(SortText)))
                {
                    return(false);
                }

                if (SortStyleExists(data))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
 //Draw generic cell for drag or drop. Used when dragging items
 void drawCell(DragDropOrigin origin, Rect cellPos, Rect iconPos, int Index)
 {
     if (origin == DragDropOrigin.DragBox)
     {
         drawDragCell(cellPos, iconPos, Index);
     }
     if (origin == DragDropOrigin.DropBox)
     {
         drawDropCell(cellPos, iconPos, Index);
     }
 }
Beispiel #3
0
    //Draw and manage drag and drop icons
    void DrawDragDropIcons()
    {
        Rect cellPos = new Rect();              //Background cell rect

        cellPos.width  = cellSize;
        cellPos.height = cellSize;

        Rect iconPos = new Rect();              //Icon cell rect

        iconPos.width  = cellSize * iconScale;
        iconPos.height = cellSize * iconScale;
        float delta = (cellPos.width - iconPos.width) / 2f;

        for (int i = 0; i < dragRows; i++)
        {
            cellPos.y = dragTitleSize + dragRect.y + cellPadding + (i * (cellSize + cellPadding));
            iconPos.y = cellPos.y + delta;
            for (int j = 0; j < dragCols; j++)
            {
                cellPos.x = dragRect.x + cellPadding + (j * (cellSize + cellPadding));
                iconPos.x = cellPos.x + delta;

                if (cellPos.Contains(Event.current.mousePosition) && Event.current.isMouse && Event.current.type == EventType.mouseUp && draggingItem)
                {
                    dropItemInDrag((i * dragCols) + j);
                    if (autosave)
                    {
                        saveSong(dragDropName);
                    }
                    draggingItem     = false;
                    draggedSlotIndex = -1;
                    draggedIndex     = -1;
                    itemOrigin       = DragDropOrigin.None;
                }

                //If dragging this item => draw empty and continue
                if (draggedSlotIndex == (i * dragCols) + j && itemOrigin == DragDropOrigin.DragBox)
                {
                    GUI.DrawTexture(cellPos, dragEmptySlot);
                    continue;
                }

                //If start dragging set the proper variables
                if (cellPos.Contains(Event.current.mousePosition) && dragSlots[(i * dragCols) + j] != -1)
                {
                    if (Event.current.isMouse && Event.current.button == 0 && Event.current.type == EventType.mouseDrag && !draggingItem)
                    {
                        draggingItem     = true;
                        draggedSlotIndex = (i * dragCols) + j;
                        draggedIndex     = dragSlots[draggedSlotIndex];
                        itemOrigin       = DragDropOrigin.DragBox;

                        //Trigger variables
                    }
                }

                //Draw the drag cell
                drawDragCell(cellPos, iconPos, (i * dragCols) + j);

                if (!draggingItem && cellPos.Contains(Event.current.mousePosition) && dragSlots[(i * dragCols) + j] != -1 && showHints)
                {
                    tooltip     = CreateTooltip(dragDropItems[dragSlots[(i * dragCols) + j]]);
                    showTooltip = true;
                }
                if (tooltip == "")
                {
                    showTooltip = false;
                }
            }
        }

        //Goes for drop slots
        for (int i = 0; i < dropRows; i++)
        {
            cellPos.y = dropTitleSize + dropRect.y + cellPadding + (i * (cellSize + cellPadding));
            iconPos.y = cellPos.y + delta;
            for (int j = 0; j < dropCols; j++)
            {
                cellPos.x = dropRect.x + cellPadding + (j * (cellSize + cellPadding));
                iconPos.x = cellPos.x + delta;

                if (cellPos.Contains(Event.current.mousePosition) && Event.current.isMouse && Event.current.type == EventType.mouseUp && draggingItem)
                {
                    dropItemInDrop((i * dropCols) + j);
                    if (autosave)
                    {
                        saveSong(dragDropName);
                    }
                    draggingItem     = false;
                    draggedSlotIndex = -1;
                    draggedIndex     = -1;
                    itemOrigin       = DragDropOrigin.None;
                }

                //If dragging this item => draw empty and continue
                if (draggedSlotIndex == (i * dropCols) + j && itemOrigin == DragDropOrigin.DropBox)
                {
                    GUI.DrawTexture(cellPos, dropEmptySlot);
                    continue;
                }

                //If start dragging set the proper variables
                if (cellPos.Contains(Event.current.mousePosition) && dropSlots[(i * dragCols) + j] != -1)
                {
                    if (Event.current.isMouse && Event.current.button == 0 && Event.current.type == EventType.mouseDrag && !draggingItem)
                    {
                        draggingItem     = true;
                        draggedSlotIndex = (i * dropCols) + j;
                        draggedIndex     = dropSlots[draggedSlotIndex];
                        itemOrigin       = DragDropOrigin.DropBox;
                    }
                }

                //Draw the drop cell
                drawDropCell(cellPos, iconPos, (i * dropCols) + j);

                if (!draggingItem && cellPos.Contains(Event.current.mousePosition) && dropSlots[(i * dropCols) + j] != -1 && showHints)
                {
                    tooltip     = CreateTooltip(dragDropItems[dropSlots[(i * dropCols) + j]]);
                    showTooltip = true;
                }
                if (tooltip == "")
                {
                    showTooltip = false;
                }
            }
        }

        //Draw the dragged itemS
        if (draggingItem)
        {
            cellPos.x = Event.current.mousePosition.x - (cellSize / 2);
            cellPos.y = Event.current.mousePosition.y - (cellSize / 2);
            iconPos.x = cellPos.x + delta;
            iconPos.y = cellPos.y + delta;
            drawCell(itemOrigin, cellPos, iconPos, draggedSlotIndex);
        }

        //Mouse up in clear area... stops dragging
        if (Event.current.isMouse && Event.current.type == EventType.mouseUp && draggingItem)
        {
            //Setting trigger variables
            originSlot        = draggedSlotIndex;
            destinationSlot   = -1;
            droppedItemIndex  = draggedIndex;
            originIsDrag      = (itemOrigin == DragDropOrigin.DragBox)?true:false;
            destinationIsDrag = false;
            dropErrorCode     = DropErrorCode.notAllowedArea;
            gameObject.SendMessage("DropTrigger", this);

            draggingItem     = false;
            draggedSlotIndex = -1;
            draggedIndex     = -1;
            itemOrigin       = DragDropOrigin.None;
        }
    }