当前位置: 首页>>代码示例>>C++>>正文


C++ InventoryItem::contentWidth方法代码示例

本文整理汇总了C++中InventoryItem::contentWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ InventoryItem::contentWidth方法的具体用法?C++ InventoryItem::contentWidth怎么用?C++ InventoryItem::contentWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InventoryItem的用法示例。


在下文中一共展示了InventoryItem::contentWidth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: itemWillFitAtLocation

//------------------------------------------------------------------------------//
bool InventoryReceiver::itemWillFitAtLocation(const InventoryItem& item,
                                              int x, int y)
{
    if (x < 0 || y < 0)
        return false;

    if (x + item.contentWidth() > d_content.width() ||
        y + item.contentHeight() > d_content.height())
            return false;

    const bool already_attached = this == item.getParent();
    // if item is already attatched erase its data from the content map so the
    // test result is reliable.
    if (already_attached)
        eraseItemFromContentMap(item);

    bool result = true;
    for (int item_y = 0; item_y < item.contentHeight() && result; ++item_y)
    {
        for (int item_x = 0; item_x < item.contentWidth() && result; ++item_x)
        {
            if (d_content.elementAtLocation(item_x + x, item_y + y) &&
                item.isSolidAtLocation(item_x, item_y))
                    result = false;
        }
    }

    // re-write item into content map if we erased it earlier.
    if (already_attached)
        writeItemToContentMap(item);

    return result;
}
开发者ID:AjaxWang1989,项目名称:cegui,代码行数:34,代码来源:InventoryReceiver.cpp

示例2: addItemAtLocation

//------------------------------------------------------------------------------//
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;
}
开发者ID:AjaxWang1989,项目名称:cegui,代码行数:30,代码来源:InventoryReceiver.cpp

示例3: writeItemToContentMap

//------------------------------------------------------------------------------//
void InventoryReceiver::writeItemToContentMap(const InventoryItem& item)
{
    if (item.locationOnReceiverX() == -1 || item.locationOnReceiverY() == -1)
        return;

    for (int y = 0; y < item.contentHeight(); ++y)
    {
        const int map_y = item.locationOnReceiverY() + y;

        for (int x = 0; x < item.contentWidth(); ++x)
        {
            const int map_x = item.locationOnReceiverX() + x;

            bool val = d_content.elementAtLocation(map_x, map_y) |
                       item.isSolidAtLocation(x, y);
            d_content.setElementAtLocation(map_x, map_y, val);
        }
    }

    invalidate();
}
开发者ID:AjaxWang1989,项目名称:cegui,代码行数:22,代码来源:InventoryReceiver.cpp


注:本文中的InventoryItem::contentWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。