Esempio n. 1
0
    /// <summary>
    /// Asks Page Logic to try to place a given PageItem.
    /// </summary>
    /// <param name="new_page_item">New page item to place on page.</param>
    public bool AddItem(PageItem new_page_item)
    {
        bool position_found = false;

        // Try to find an AvailableSpace large enough for the new PageItem to fit in it.
        foreach (AvailableSpace space in _available_spaces)
        {
            if (space.CanFit(new_page_item) == true)
            {
                // Big enough space has been found.
                // Set PageItem's origin to found AvailableSpace's origin
                new_page_item.SetOrigin(space.origin);
                // Add the freshly placed PageItem to the list of placed items.
                _page_items.Add(new_page_item);
                position_found = true;
                break;
            }
        }

        if (position_found == true)
        {
            // If item has been placed, recompute available spaces.
            ComputeAvailableSpaces();
        }
        return(position_found);
    }