コード例 #1
0
        /// <summary>
        /// Add item to grid at position.
        /// </summary>
        /// <param name="item"><c>GridspaceItem</c> to add.</param>
        /// <param name="position">Position to add.</param>
        /// <returns>true if adding succesfully, otherwise false.</returns>
        public bool AddItemToGrid(GridspaceItem item, GridPosition position)
        {
            if (item == null || position == null || position.X < 0 || position.Y < 0)
            {
                return(false);
            }

            if (item.TypeOfItem != this.AcceptedItemType)
            {
                return(false);
            }

            if (Size.X < position.X + item.Size.X || Size.Y < position.Y + item.Size.Y)
            {
                return(false);
            }

            if (!ValidateGridValues(position, item.Size, false))
            {
                return(false);
            }

            itemsInGrid.Add(item, position);

            SetGridValues(position, item.Size, true);

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Remove item from grid.
        /// </summary>
        /// <param name="item"><c>GridspaceItem</c> to remove.</param>
        /// <returns>true if item is found inside grid and succesfully removed, otherwise false.</returns>
        public bool RemoveItemFromGrid(GridspaceItem item)
        {
            if (!itemsInGrid.ContainsKey(item))
            {
                return(false);
            }

            GridPosition position = itemsInGrid[item];

            itemsInGrid.Remove(item);
            SetGridValues(position, item.Size, false);

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Move item inside grid from old position to new.
        /// </summary>
        /// <param name="item">Item to move.</param>
        /// <param name="newPosition">Position where to move.</param>
        /// <returns>true if move operation succesfull, otherwise false.</returns>
        public bool MoveItemInside(GridspaceItem item, GridPosition newPosition)
        {
            if (newPosition == null || !itemsInGrid.ContainsKey(item))
            {
                return(false);
            }

            var oldPosition = itemsInGrid[item];

            RemoveItemFromGrid(item);

            if (!AddItemToGrid(item, newPosition))
            {
                AddItemToGrid(item, oldPosition);
                return(false);
            }

            return(true);
        }