Ejemplo n.º 1
0
bool CATextSelViewEx::init()
{
	if (!CAView::init())
		return false;

	m_pCursorMarkL = CAImageView::createWithImage(CAImage::create("source_material/text_pos_l.png"));
	insertSubview(m_pCursorMarkL, CAWindowZOderTop);
	m_pCursorMarkL->setVisible(false);
    
	m_pCursorMarkR = CAImageView::createWithImage(CAImage::create("source_material/text_pos_r.png"));
	insertSubview(m_pCursorMarkR, CAWindowZOderTop);
	m_pCursorMarkR->setVisible(false);
	return true;
}
Ejemplo n.º 2
0
void CABatchView::insertSubview(CAView *subview, unsigned int uIndex)
{
    subview->setBatch(this);
    subview->setAtlasIndex(uIndex);
    subview->setDirty(true);

    if(m_pobImageAtlas->getTotalQuads() == m_pobImageAtlas->getCapacity())
    {
        increaseAtlasCapacity();
    }

    ccV3F_C4B_T2F_Quad quad = subview->getQuad();
    m_pobImageAtlas->insertQuad(&quad, uIndex);
    m_obDescendants.insert(uIndex, subview);

    
    if (m_obDescendants.size() > uIndex + 1)
    {
        for (CAVector<CAView*>::const_iterator itr=m_obDescendants.begin() + uIndex + 1;
             itr!=m_obDescendants.end();
             itr++)
        {
            (*itr)->setAtlasIndex(subview->getAtlasIndex() + 1);
        }
    }

    for (CAVector<CAView*>::const_iterator itr=subview->getSubviews().begin();
         itr!=subview->getSubviews().end();
         itr++)
    {
        unsigned int idx = atlasIndexForSubview(*itr, (*itr)->getZOrder());
        insertSubview(*itr, idx);
    }
}
Ejemplo n.º 3
0
void CCTransitionFade :: onEnter()
{
    CCTransitionScene::onEnter();

    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    CAView* l = CAView::createWithFrame(CCRect(0, 0, size.width, size.height));
    l->setColor(ccc3(m_tColor.r, m_tColor.g, m_tColor.b));
    l->setOpacity(m_tColor.a);
    m_pInScene->setVisible(false);

    l->setTag(kSceneFade);
    insertSubview(l, 2);
    CAView* f = getSubviewByTag(kSceneFade);

    CCActionInterval* a = (CCActionInterval *)CCSequence::create
        (
            CCFadeIn::create(m_fDuration/2),
            CCCallFunc::create(this, callfunc_selector(CCTransitionScene::hideOutShowIn)),//CCCallFunc::create:self selector:@selector(hideOutShowIn)],
            CCFadeOut::create(m_fDuration/2),
            CCCallFunc::create(this, callfunc_selector(CCTransitionScene::finish)), //:self selector:@selector(finish)],
            NULL
        );
    f->runAction(a);
}
Ejemplo n.º 4
0
void CAAlertView::setLabel(CALabel*& pLabel, std::string& szTitle, CAColor4B col)
{
	if (pLabel == NULL)
	{
		pLabel = new CALabel();
        CC_RETURN_IF(pLabel == NULL);
		pLabel->init();
		pLabel->setTextAlignment(CATextAlignmentCenter);
		pLabel->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
        pLabel->setFontName(m_sMsgFontName.c_str());
        pLabel->setFontSize(36);
		insertSubview(pLabel, 1);
	}
	pLabel->setText(szTitle);
	pLabel->setColor(col);
}
void CACollectionView::reloadData()
{
	CC_RETURN_IF(m_pCollectionViewDataSource == NULL);
    
	this->reloadViewSizeData();
    
	this->removeAllSubviews();
    
	DRect winRect = this->getBounds();
	winRect.origin = getContentOffset();
	float width = winRect.size.width;
	int y = 0;
    
	if (m_nCollectionHeaderHeight > 0 && m_pCollectionHeaderView)
	{
		m_pCollectionHeaderView->setDisplayRange(true);
		m_pCollectionHeaderView->setFrame(DRect(0, y, width, m_nCollectionHeaderHeight));
		addSubview(m_pCollectionHeaderView);
		y += m_nCollectionHeaderHeight;
	}
    
;
    int begin = (int)m_rSectionRects.size();
    m_rSectionRects.resize(m_rSectionRects.size() + m_nSections);
	for (int i = 0; i < m_nSections; i++)
	{
		unsigned int iSectionHeaderHeight = m_nSectionHeaderHeights.at(i);
		DRect sectionHeaderRect = DRect(0, y, width, iSectionHeaderHeight);
		if (iSectionHeaderHeight>0)
		{
			CAView* pSectionHeaderView = m_pCollectionViewDataSource->collectionViewSectionViewForHeaderInSection(this, sectionHeaderRect.size, i);
			if (pSectionHeaderView != NULL)
			{
				pSectionHeaderView->setDisplayRange(true);
				pSectionHeaderView->setFrame(sectionHeaderRect);
				insertSubview(pSectionHeaderView, 1);
				m_pSectionHeaderViews[i] = pSectionHeaderView;
				y += iSectionHeaderHeight;
			}
		}
        
		y += m_nVertInterval;
		unsigned int rowCount = m_nRowsInSections.at(i);
		for (int j = 0; j < rowCount; j++)
		{
			int iHeight = m_nRowHeightss.at(i).at(j);
            
			unsigned int itemCount = m_pCollectionViewDataSource->numberOfItemsInRowsInSection(this, i, j);
            
			unsigned int cellWidth = 0;
			if (itemCount>0)
			{
				cellWidth = (width - m_nHoriInterval) / itemCount - m_nHoriInterval;
			}
			for (int k = 0; k < itemCount; k++)
			{
				CAIndexPath3E indexPath = CAIndexPath3E(i, j, k);
				DRect cellRect = DRect(m_nHoriInterval + (cellWidth + m_nHoriInterval)*k, y, cellWidth, iHeight);
				m_rUsedCollectionCellRects[indexPath] = cellRect;
                
				std::pair<std::map<CAIndexPath3E, CACollectionViewCell*>::iterator, bool> itrResult =
                m_mpUsedCollectionCells.insert(std::make_pair(indexPath, (CACollectionViewCell*)NULL));
                
				CC_CONTINUE_IF(!winRect.intersectsRect(cellRect));
                
				CACollectionViewCell* cell = m_pCollectionViewDataSource->collectionCellAtIndex(this, cellRect.size, i, j, k);
				if (cell)
				{
					addSubview(cell);
					cell->setFrame(cellRect);
					cell->m_nSection = i;
					cell->m_nRow = j;
					cell->m_nItem = k;
					itrResult.first->second = cell;
                    m_vpUsedCollectionCells.pushBack(cell);
                    
                    if (m_pCollectionViewDataSource)
                    {
                        m_pCollectionViewDataSource->collectionViewWillDisplayCellAtIndex(this, cell, i, j, k);
                    }
				}
			}
			y += (iHeight + m_nVertInterval);
		}
        
		unsigned int iSectionFooterHeight = m_nSectionFooterHeights.at(i);
		DRect sectionFooterRect = DRect(0, y, width, iSectionFooterHeight);
		if (iSectionFooterHeight > 0)
		{
			CAView* pSectionFooterView = m_pCollectionViewDataSource->collectionViewSectionViewForFooterInSection(this, sectionFooterRect.size, i);
			if (pSectionFooterView != NULL)
			{
				pSectionFooterView->setDisplayRange(true);
				pSectionFooterView->setFrame(sectionFooterRect);
				insertSubview(pSectionFooterView, 1);
				m_pSectionFooterViews[i] = pSectionFooterView;
				y += iSectionFooterHeight;
			}
		}
        
		DRect sectionRect = sectionHeaderRect;
		sectionRect.size.height = sectionFooterRect.origin.y
        + sectionFooterRect.size.height
        - sectionHeaderRect.origin.y;
        m_rSectionRects[begin + i] = sectionRect;
	}
    
	if (m_nCollectionFooterHeight > 0 && m_pCollectionFooterView)
	{
		m_pCollectionFooterView->setFrame(DRect(0, y, width, m_nCollectionFooterHeight));
		addSubview(m_pCollectionFooterView);
		y += m_nCollectionFooterHeight;
	}
    
	this->updateSectionHeaderAndFooterRects();
	this->layoutPullToRefreshView();
	this->startDeaccelerateScroll();
}
Ejemplo n.º 6
0
int CAAutoCollectionView::calculateAllRects()
{
	int dw = 0, dd = 0, dv = 0;
	if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical)
	{
		dw = this->getBounds().size.width - 2 * m_iHoriMargins;
		dd = m_iVertMargins + m_nCollectionHeaderHeight;
		dv = m_nVertCellInterval;
	}
	else
	{
		dw = this->getBounds().size.height - 2 * m_iVertMargins;
		dd = m_iHoriMargins + m_nCollectionHeaderHeight;
		dv = m_nHoriCellInterval;
	}

	for (int i = 0; i < m_rCollectionViewSection.size(); i++)
	{
		CollectionViewSection& cvs = m_rCollectionViewSection[i];

		unsigned int iSectionHeaderHeight = cvs.nSectionHeaderHeight;

		DRect sectionHeaderRect;
		if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical)
		{
			sectionHeaderRect = DRect(m_iHoriMargins, dd, dw, iSectionHeaderHeight);
		}
		else
		{
			sectionHeaderRect = DRect(dd, m_iVertMargins, iSectionHeaderHeight, dw);
		}

		if (iSectionHeaderHeight > 0)
		{
			CAView* pSectionHeaderView = m_pCollectionViewDataSource->collectionViewSectionViewForHeaderInSection(this, sectionHeaderRect.size, i);
			if (pSectionHeaderView != NULL)
			{
				pSectionHeaderView->setDisplayRange(true);
				pSectionHeaderView->setFrame(sectionHeaderRect);
				insertSubview(pSectionHeaderView, 1);
			}
			dd += (iSectionHeaderHeight + dv);
			cvs.pSectionHeaderView = pSectionHeaderView;
		}

		dd = calculateAllCells(cvs, i, dd, dv, dw);

		unsigned int iSectionFooterHeight = cvs.nSectionFooterHeight;

		DRect sectionFooterRect;
		if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical)
		{
			sectionFooterRect = DRect(m_iHoriMargins, dd, dw, iSectionFooterHeight);
		}
		else
		{
			sectionFooterRect = DRect(dd, m_iVertMargins, iSectionFooterHeight, dw);
		}

		if (iSectionFooterHeight > 0)
		{
			CAView* pSectionFooterView = m_pCollectionViewDataSource->collectionViewSectionViewForFooterInSection(this, sectionFooterRect.size, i);
			if (pSectionFooterView != NULL)
			{
				pSectionFooterView->setDisplayRange(true);
				pSectionFooterView->setFrame(sectionFooterRect);
				insertSubview(pSectionFooterView, 1);
			}
			dd += (iSectionFooterHeight + dv);
			cvs.pSectionFooterView = pSectionFooterView;
		}

		DRect sectionRect = sectionHeaderRect;
		if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical)
		{
			sectionRect.size.height = sectionFooterRect.origin.y + sectionFooterRect.size.height - sectionHeaderRect.origin.y;
		}
		else
		{
			sectionRect.size.width = sectionFooterRect.origin.x + sectionFooterRect.size.width - sectionHeaderRect.origin.x;
		}
		cvs.rSectionRect = sectionRect;
	}
	
	return dd;
}
Ejemplo n.º 7
0
void CAStepper::onEnter()
{
    CAControl::onEnter();

    if (m_value<m_minimumValue) {
        m_value = m_minimumValue;
    }
    // init Background
    if (!m_pBackgroundImageView && m_pBackgroundImage[CAControlStateNormal]) {
        m_pBackgroundImageView = CAScale9ImageView::createWithImage(m_pBackgroundImage[CAControlStateNormal]);
        m_pBackgroundImageView->retain();
        m_pBackgroundImageView->setCenter(DRect(getFrame().size.width/2, getFrame().size.height/2,getFrame().size.width,getFrame().size.height));
        addSubview(m_pBackgroundImageView);
    }
    // init divider
    if (!m_pDividerImageView ) {
        m_pDividerImageView = CAImageView::createWithColor(m_cTintColor);
        m_pDividerImageView->retain();
        if (m_pCAStepperOrientation==CAStepperOrientationHorizontal)
        {
            m_pDividerImageView->setCenter(DRect(getBounds().size.width/2,
                                                  getBounds().size.height/2,
                                                  LINE_WIDTH,
                                                  getBounds().size.height));
        }
        else
        {
            m_pDividerImageView->setCenter(DRect(getBounds().size.width/2,
                                                  getBounds().size.height/2,
                                                  getBounds().size.width,
                                                  LINE_WIDTH));
        }
        
        
        
        addSubview(m_pDividerImageView);
    }
    
    //float div = (m_pDividerImageView) ? m_pDividerImageView->getBounds().size.width/2 : 0;
    
    // init increment
    if (!m_pIncrementImageView && m_pIncrementImage[CAControlStateNormal]) {
        m_pIncrementImageView = CAImageView::createWithImage(m_pIncrementImage[CAControlStateNormal]);
        m_pIncrementImageView->retain();
        if (m_pCAStepperOrientation==CAStepperOrientationHorizontal) {
            int tempw = MIN(getBounds().size.width, getBounds().size.height);
            m_pIncrementImageView->setImageViewScaleType(CAImageViewScaleTypeFitViewByHorizontal);
            m_pIncrementImageView->setCenter(DRect(getBounds().size.width/4*3, getBounds().size.height/2,
                                                   tempw,
                                                   tempw));
        }else{
            int tempw = MIN(getBounds().size.width, getBounds().size.height);
            m_pIncrementImageView->setImageViewScaleType(CAImageViewScaleTypeFitViewByVertical);
            m_pIncrementImageView->setCenter(DRect(getBounds().size.width/2, getBounds().size.height/4,
                                                   tempw,
                                                   tempw));
        }
        
        insertSubview(m_pIncrementImageView,10);
    }
    
    // init decrement
    if (!m_pDecrementImageView && m_pDecrementImage[CAControlStateNormal]) {
        m_pDecrementImageView = CAImageView::createWithImage(m_pDecrementImage[CAControlStateNormal]);
        m_pDecrementImageView->retain();
        if (m_pCAStepperOrientation==CAStepperOrientationHorizontal) {
            int tempw = MIN(getBounds().size.width, getBounds().size.height);
            m_pDecrementImageView->setImageViewScaleType(CAImageViewScaleTypeFitViewByHorizontal);
            m_pDecrementImageView->setCenter(DRect(getBounds().size.width/4, getBounds().size.height/2,
                                                   tempw,
                                                   tempw));
        }else{
            int tempw = MIN(getBounds().size.width, getBounds().size.height);
            m_pDecrementImageView->setImageViewScaleType(CAImageViewScaleTypeFitViewByVertical);
            m_pDecrementImageView->setCenter(DRect(getBounds().size.width/2, getBounds().size.height/4*3,
                                                   tempw,
                                                   tempw));
        }
        
        insertSubview(m_pDecrementImageView,10);
    }
}
Ejemplo n.º 8
0
void CCTransitionCrossFade::onEnter()
{
    CCTransitionScene::onEnter();

    // create a transparent color layer
    // in which we are going to add our rendertextures
    ccColor4B  color = {0,0,0,0};
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CAView* layer = CAView::createWithFrame(CCRect(0, 0, size.width, size.height));
    layer->setColor(ccc3(color.r, color.g, color.b));
    layer->setOpacity(color.a);

    // create the first render texture for inScene
    CCRenderTexture* inTexture = CCRenderTexture::create((int)size.width, (int)size.height);

    if (NULL == inTexture)
    {
        return;
    }

    inTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
    inTexture->setPosition( ccp(size.width/2, size.height/2) );
    inTexture->setAnchorPoint( ccp(0.5f,0.5f) );

    // render inScene to its texturebuffer
    inTexture->begin();
    m_pInScene->visit();
    inTexture->end();

    // create the second render texture for outScene
    CCRenderTexture* outTexture = CCRenderTexture::create((int)size.width, (int)size.height);
    outTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
    outTexture->setPosition( ccp(size.width/2, size.height/2) );
    outTexture->setAnchorPoint( ccp(0.5f,0.5f) );

    // render outScene to its texturebuffer
    outTexture->begin();
    m_pOutScene->visit();
    outTexture->end();

    // create blend functions

    ccBlendFunc blend1 = {GL_ONE, GL_ONE}; // inScene will lay on background and will not be used with alpha
    ccBlendFunc blend2 = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}; // we are going to blend outScene via alpha 

    // set blendfunctions
    inTexture->getSprite()->setBlendFunc(blend1);
    outTexture->getSprite()->setBlendFunc(blend2);    

    // add render textures to the layer
    layer->addSubview(inTexture);
    layer->addSubview(outTexture);

    // initial opacity:
    inTexture->getSprite()->setOpacity(255);
    outTexture->getSprite()->setOpacity(255);

    // create the blend action
    CCAction* layerAction = CCSequence::create
    (
        CCFadeTo::create(m_fDuration, 0),
        CCCallFunc::create(this, callfunc_selector(CCTransitionScene::hideOutShowIn)),
        CCCallFunc::create(this, callfunc_selector(CCTransitionScene::finish)),
        NULL
    );


    // run the blend action
    outTexture->getSprite()->runAction( layerAction );

    // add the layer (which contains our two rendertextures) to the scene
    layer->setTag(kSceneFade);
    insertSubview(layer, 2);
}