//------------------------------------------------------------------------------//
bool InventoryReceiver::addItemAtLocation(InventoryItem& item, int x, int y)
{
    if (itemWillFitAtLocation(item, x, y))
    {
        InventoryReceiver* old_receiver =
            dynamic_cast<InventoryReceiver*>(item.getParent());

        if (old_receiver)
            old_receiver->removeItem(item);

        item.setLocationOnReceiver(x, y);
        writeItemToContentMap(item);
        addChild(&item);

        // set position and size.  This ensures the items visually match the
        // logical content map.


        item.setPosition(UVector2(UDim(static_cast<float>(x) / contentWidth(), 0),
                                  UDim(static_cast<float>(y) / contentHeight(), 0)));
        item.setSize(USize(
            UDim(static_cast<float>(item.contentWidth()) / contentWidth(), 0),
            UDim(static_cast<float>(item.contentHeight()) / contentHeight(), 0)));

        return true;
    }

    return false;
}
//------------------------------------------------------------------------------//
void InventoryReceiver::removeItem(InventoryItem& item)
{
    if (item.getParent() != this ||
        item.locationOnReceiverX() == -1 ||
        item.locationOnReceiverY() == -1)
            return;

    eraseItemFromContentMap(item);
    item.setLocationOnReceiver(-1, -1);
    removeChild(&item);
}