コード例 #1
0
ファイル: DragAndDropManager.cs プロジェクト: LiruJ/GuiCookie
        /// <summary>
        /// Begins dragging the given <paramref name="draggable"/> so long as the <see cref="CurrentDraggable"/> is null. Uses the given <paramref name="offset"/> when keeping the draggable pinned to the mouse.
        /// Calls <see cref="IDraggable.OnDragBegin(Point)"/> with the given <paramref name="offset"/> and sets the <see cref="CurrentDraggable"/> to its return value.
        /// </summary>
        /// <param name="draggable"></param>
        /// <param name="offset"></param>
        public bool BeginDragging(IDraggable draggable, Point offset)
        {
            // Return false if the state is invalid.
            if (draggable == null || CurrentDraggable != null)
            {
                return(false);
            }

            // Begin dragging the given draggable.
            IDraggable newDraggable = draggable.OnDragBegin(offset, out Point newOffset);

            // If the given draggable returned a null value, return false.
            if (newDraggable == null)
            {
                return(false);
            }

            // Set the current draggable and offset.
            CurrentDraggable = newDraggable;
            DraggableOffset  = newOffset;
            DraggableOrigin  = CurrentDraggable.Bounds.AbsoluteTotalPosition;

            // Return true as the dragging was begun.
            return(true);
        }