void CC3VertexTextureCoordinates::alignWithTextureCoverage( const CCSize& texCoverage )
{
	CCAssert((texCoverage.width && texCoverage.height), "CC3VertexTextureCoordinates mapsize cannot have zero dimension");

	// Don't waste time adjusting if nothing is changing
	// (eg. POT textures, or new texture has same texture map as old).
	if (texCoverage.equals(m_mapSize)) 
		return;
	
	CC3_TRACE( "[vtx]CC3VertexTextureCoordinates aligning and changing map size from %s to %s but not flipping vertically", 
		stringFromCCSize(m_mapSize).c_str(), stringFromCCSize(texCoverage).c_str() );

	// The scale factor
	CCSize mapRatio = CCSizeMake(texCoverage.width / m_mapSize.width, texCoverage.height / m_mapSize.height);
	
	// The amount by which to translate the image vertically
	GLfloat currVertXln = 1.0f - m_mapSize.height;
	GLfloat newVertXln = 1.0f - texCoverage.height;
	
	for (GLuint i = 0; i < m_vertexCount; i++) 
	{
		ccTex2F* ptc = (ccTex2F*)getAddressOfElement(i);
		ptc->u *= mapRatio.width;
		ptc->v = (ptc->v - currVertXln) * mapRatio.height + newVertXln;
	}
	m_mapSize = texCoverage;	// Remember what we've set the map size to

	updateGLBuffer();
}
Ejemplo n.º 2
0
void UIPageView::addPage(Layout* page)
{
    if (!page)
    {
        return;
    }
    if (page->getWidgetType() != WidgetTypeContainer)
    {
        return;
    }
    if (m_pages->containsObject(page))
    {
        return;
    }
    CCSize pSize = page->getSize();
    CCSize pvSize = getSize();
    if (!pSize.equals(pvSize))
    {
        CCLOG("page size does not match pageview size, it will be force sized!");
        page->setSize(pvSize);
    }
    page->setPosition(ccp(getPositionXByIndex(m_pages->count()), 0));
    m_pages->addObject(page);
    addChild(page);
    updateBoundaryPages();
}
Ejemplo n.º 3
0
void CCNode::setContentSize(const CCSize & size)
{
    if ( ! size.equals(m_obContentSize))
    {
        m_obContentSize = size;

        m_obAnchorPointInPoints = ccp(m_obContentSize.width * m_obAnchorPoint.x, m_obContentSize.height * m_obAnchorPoint.y );
    }
}
Ejemplo n.º 4
0
void CC3Layer::setContentSize( const CCSize& contentSize )
{
	CCSize oldSize = getContentSize();
	super::setContentSize( contentSize );
	if ( !contentSize.equals( oldSize ) ) 
	{
		/// invoke callback
		onContentSizeChanged();
	}
}
Ejemplo n.º 5
0
void CAImageView::setContentSize(const CCSize & size)
{
    if ( ! size.equals(m_obContentSize))
    {
        m_obContentSize = size;
        
        m_obAnchorPointInPoints = ccp(m_obContentSize.width * m_obAnchorPoint.x, m_obContentSize.height * m_obAnchorPoint.y );
        m_obFrameRect.size = CCSize(m_obContentSize.width * m_fScaleX, m_obContentSize.height * m_fScaleY);
        
        this->updateByImageViewScaleType();
        
        arrayMakeObjectsPerformSelector(m_pSubviews, reViewlayout, CAView*);
        
        this->updateDraw();
    }
}
Ejemplo n.º 6
0
void UIPageView::insertPage(Layout* page, int idx)
{
    if (idx < 0)
    {
        return;
    }
    if (!page)
    {
        return;
    }
    if (page->getWidgetType() != WidgetTypeContainer)
    {
        return;
    }
    if (m_pages->containsObject(page))
    {
        return;
    }

    int pageCount = m_pages->count();
    if (idx >= pageCount)
    {
        addPage(page);
    }
    else
    {
        m_pages->insertObject(page, idx);
        page->setPosition(ccp(getPositionXByIndex(idx), 0));
        addChild(page);
        CCSize pSize = page->getSize();
        CCSize pvSize = getSize();
        if (!pSize.equals(pvSize))
        {
            CCLOG("page size does not match pageview size, it will be force sized!");
            page->setSize(pvSize);
        }
        ccArray* arrayPages = m_pages->data;
        int length = arrayPages->num;
        for (int i=(idx+1); i<length; i++) {
            UIWidget* behindPage = dynamic_cast<UIWidget*>(arrayPages->arr[i]);
            CCPoint formerPos = behindPage->getPosition();
            behindPage->setPosition(ccp(formerPos.x+getSize().width, 0));
        }
        updateBoundaryPages();
    }
}
void UISlider::setScale9Size(const CCSize &size)
{
    if (size.equals(CCSizeZero))
    {
        return;
    }
    else
    {
        m_scale9Size = size;
    }
    if (!m_bBarScale9Enable)
    {
        return;
    }
    dynamic_cast<CCScale9Sprite*>(m_pBarNode)->setContentSize(size);
    m_fBarLength = m_pBarNode->getContentSize().width;
    setSlidBallPercent(m_nBarPercent);
}
void UIButton::setScale9Size(const CCSize &size)
{
    if (size.equals(CCSizeZero))
    {
        return;
    }
    else
    {
        m_scale9Size = size;
    }
    if (!m_bScale9Enable)
    {
        return;
    }
    dynamic_cast<CCScale9Sprite*>(m_pButtonNormal)->setContentSize(size);
    dynamic_cast<CCScale9Sprite*>(m_pButtonClicked)->setContentSize(size);
    dynamic_cast<CCScale9Sprite*>(m_pButtonDisable)->setContentSize(size);
}
Ejemplo n.º 9
0
void CAScrollView::setContainerFrame(const CCPoint& point, const CCSize& size)
{
    if (!size.equals(CCSizeZero))
    {
        CCRect rect;
        rect.origin = point;
        rect.size = size;
        m_pContainer->setFrame(rect);
    }
    else
    {
        m_pContainer->setFrameOrigin(point);
    }
    
    CCRect rect = m_pContainer->getFrame();
    
    m_bSlidingMinX = fabsf(rect.getMinX()) < FLT_EPSILON;
    m_bSlidingMaxX = fabsf(rect.getMaxX() - this->getBounds().size.width) < FLT_EPSILON;
    m_bSlidingMinY = fabsf(rect.getMinY()) < FLT_EPSILON;
    m_bSlidingMaxY = fabsf(rect.getMaxY() - this->getBounds().size.height) < FLT_EPSILON;
}
Ejemplo n.º 10
0
bool CATabBar::init(const CAVector<CATabBarItem*>& items, const CCSize& size)
{
    if (!CAView::init())
    {
        return false;
    }
    this->setColor(CAColor_clear);
    this->setItems(items);

    CCSize winSize = CAApplication::getApplication()->getWinSize();
    CCSize contentSize = size.equals(CCSizeZero) ? CCSize(winSize.width, _px(98)) : size;
    this->setContentSize(contentSize);

    CADipRect rect = this->getBounds();
    rect.origin = rect.size / 2;
    rect.size.width = MIN(rect.size.width, 1024);
    
    m_pContentView = new CAView();
    m_pContentView->setCenter(rect);
    this->addSubview(m_pContentView);
    m_pContentView->release();
    
    unsigned int count = (unsigned int)m_pItems.size();
    m_cItemSize = m_pContentView->getBounds().size;
    m_cItemSize.width = rect.size.width/count;

    if (m_pButtons.empty())
    {
        for (unsigned int i=0; i<count; i++)
        {
            CADipRect rect = CADipRectZero;
            rect.size = m_cItemSize;
            rect.origin.x = m_cItemSize.width * i;
            
            CAButton* btn = CAButton::createWithFrame(rect, CAButtonTypeCustom);
            m_pContentView->addSubview(btn);
            btn->setTag(i);
            btn->addTarget(this, CAControl_selector(CATabBar::setTouchSelected), CAControlEventTouchUpInSide);
            m_pButtons.pushBack(btn);
            
            CABadgeView* badgeView = new CABadgeView();
            badgeView->init();
            badgeView->setCenter(CADipRect(rect.size.width, 25, 0, 0));
            btn->insertSubview(badgeView, 10);
            m_pBadgeViews.pushBack(badgeView);
            
        }
    }
    if (m_pBackGroundImage == NULL)
    {
        this->setBackGroundImage(CAImage::create("source_material/tabBar_bg.png"));
    }
    if (m_pSelectedBackGroundImage == NULL)
    {
        this->setSelectedBackGroundImage(CAImage::create("source_material/tabBar_selected_bg.png"));
    }
    if (m_pSelectedIndicatorImage == NULL)
    {
        this->setSelectedIndicatorImage(CAImage::create("source_material/tabBar_selected_indicator.png"));
    }

    return true;
}
Ejemplo n.º 11
0
void CALabel::updateImage()
{
	int fontHeight = CAImage::getFontHeight(m_nfontName.c_str(), m_nfontSize);
	int defaultLineSpace = fontHeight / 4;
 
    unsigned int linenumber = (int)this->getBounds().size.height / fontHeight;

    CCSize size = CCSizeZero;
    if (m_bFitFlag)
    {
        float width = CAImage::getStringWidth(m_nfontName.c_str(), m_nfontSize, m_nText);
        if (width > m_obContentSize.width)
        {
            if (m_nNumberOfLine > 1)
            {
				size = CCSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * m_nNumberOfLine);
            }
            else if (m_nNumberOfLine == 1)
            {
				size = CCSize(width, fontHeight);
            }
            else
            {
                size.width = this->getBounds().size.width;
				size.height = CAImage::getStringHeight(m_nfontName.c_str(), m_nfontSize, m_nText, size.width, m_iLineSpacing, m_bWordWrap);
            }
        }
        else
        {
            size.height = fontHeight;
			size.width = width;
        }
    }
    else
    {
        if (linenumber == 0)
		{
			size = this->getBounds().size;
		}
		else
		{
			if (m_nNumberOfLine > 0)
			{
				size = CCSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * MIN(m_nNumberOfLine, linenumber));
			}
			else
			{
				size = CCSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * linenumber);
			}
		}
    }
    
    
    
	CAImage* image = CAImage::createWithString(m_nText.c_str(),
                                               m_nfontName.c_str(),
                                               m_nfontSize,
                                               size,
                                               m_nTextAlignment,
											   m_nVerticalTextAlignmet, 
											   m_bWordWrap, 
											   m_iLineSpacing, 
											   m_bBold, 
											   m_bItalics,
											   m_bUnderLine);

    this->setImage(image);
	CC_RETURN_IF(image == NULL);

    m_cLabelSize = size;
    
    CCRect rect = CCRectZero;
    rect.size.width = this->getBounds().size.width;
    rect.size.height = size.height;
    
    float width = m_bFitFlag ? image->getContentSize().width : MIN(this->getBounds().size.width, image->getContentSize().width);
    
    rect.size.width = width;

    switch (m_nVerticalTextAlignmet)
    {
        case CAVerticalTextAlignmentTop:
            pTextHeight = 0;
            break;
            
        case CAVerticalTextAlignmentCenter:
            pTextHeight = (this->getBounds().size.height - rect.size.height) / 2;
            break;
            
        case CAVerticalTextAlignmentBottom:
            pTextHeight = this->getBounds().size.height - rect.size.height;
            break;
            
        default:
            break;
    }

    if (m_bFitFlag)
    {
        if (!size.equals(m_obContentSize))
        {
            if (m_bFrame)
            {
                CCRect rect = this->getFrame();
                rect.size = size;
                this->setFrame(rect);
            }
            else
            {
                CCRect rect = this->getCenter();
                rect.size = size;
                this->setCenter(rect);
            }
        }
    }
    this->setImageRect(rect);
}