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


C++ CCLabelTTF::setCenter方法代码示例

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


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

示例1: showItems

void CATabBar::showItems()
{
    do
    {
        CC_BREAK_IF(m_pViews.empty() == false);
        
        unsigned int count = MIN(m_nMaxShowCount, m_pItems.size());
        
        float width = m_obContentSize.width / count;
        float height = m_obContentSize.height;
        m_cItemSize = CCSize(width, height);
        
        for (unsigned int i=0; i<count; i++)
        {
            CAView* view = CAView::createWithFrame(CCRect(i * width, 0, width, height), ccc4(0, 0, 0, 0));
            this->insertSubview(view, 3);
            view->setDisplayRange(false);
            m_pViews.push_back(view);
            
            CAImageView* imageView = NULL;
            CCLabelTTF* title = NULL;
            
            if (m_pItems.at(i)->getImage())
            {
                imageView = CAImageView::createWithImage(m_pItems.at(i)->getImage());
                imageView->setTag(0xffff);
                view->addSubview(imageView);
            }
            
            
            if (m_pItems.at(i)->getTitle().compare("") != 0)
            {
                int fontSize = this->getContentSize().height / 5.0f;
                title = CCLabelTTF::create(m_pItems.at(i)->getTitle().c_str(), "Arial", fontSize);
                title->setTag(0xfffe);
                view->addSubview(title);
            }
            
            
            if (imageView && title == NULL)
            {
                CCSize imageViewSize = imageView->getBounds().size;
                float scaleX = width / imageViewSize.width * 2/3.0f;
                float scaleY = height / imageViewSize.height * 2/3.0f;
                float scale = MIN(scaleX, scaleY);
                scale = MIN(scale, 1.0f);
                imageViewSize = ccpMult(imageViewSize, scale);
                
                CCRect rect;
                rect.origin = view->getBounds().size/2;
                rect.size = imageViewSize;
                
                imageView->setCenter(rect);
    
            }
            else if (title && imageView == NULL)
            {
                int fontSize = this->getContentSize().height / 2.0f;
                title->setFontSize(fontSize);
                
                CCSize titleSize = title->getBounds().size;
                float titleScale = height / titleSize.height * 1/2.0f;
                titleSize = ccpMult(titleSize, titleScale);
                
                CCRect rect;
                rect.origin = view->getBounds().size/2;
                rect.size = titleSize;
                
                title->setCenter(rect);
            }
            else if (title && imageView)
            {

                CCSize imageViewSize = imageView->getBounds().size;
                float scaleX = width / imageViewSize.width * 1/2.0f;
                float scaleY = height / imageViewSize.height * 1/2.0f;
                float scale = MIN(scaleX, scaleY);
                scale = MIN(scale, 1.0f);
                imageViewSize = ccpMult(imageViewSize, scale);
 
                CCRect rect;
                rect.size = imageViewSize;
                rect.origin = view->getBounds().size;
                rect.origin.x *= 1/2.0f;
                rect.origin.y *= 7/20.0f;
                imageView->setCenter(rect);

                CCSize titleSize = title->getBounds().size;
                float titleScale = height / titleSize.height * 3/10;
                titleSize = ccpMult(titleSize, titleScale);
                
                CCRect rect2;
                rect2.size = titleSize;
                rect2.origin = view->getBounds().size;
                rect2.origin.x *= 1/2.0f;
                rect2.origin.y *= 15/20.0f;
                title->setCenter(rect2);
                
            }
        }
//.........这里部分代码省略.........
开发者ID:Jimlan,项目名称:CrossApp,代码行数:101,代码来源:CABar.cpp


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