Ejemplo n.º 1
0
void CPageView::onScrolling()
{
	if( m_uCellsCount == 0 )
		return;

	CTableView::onScrolling();

	CCPoint tPageIdxOffset;
	switch( m_eDirection )
	{
	case eScrollViewDirectionHorizontal:
		tPageIdxOffset = getContentOffset() - CCPoint(m_obContentSize.width / 2, 0);
		break;
	case eScrollViewDirectionVertical:
		tPageIdxOffset = getContentOffset() + CCPoint(0, m_obContentSize.height / 2);
		break;
	default:
		break;
	}

	unsigned int nPage = cellBeginIndexFromOffset(tPageIdxOffset);
	if( nPage != m_nPageIndex )
	{
		m_nPageIndex = nPage;
		executePageChangedHandler(this, m_nPageIndex);
	}
}
Ejemplo n.º 2
0
void CScrollView::performedDeaccelerateScrolling(float dt)
{
	if( m_bDragging )
	{
		stoppedDeaccelerateScroll();
		return;
	}

	Vec2 tOldOffset;
	Vec2 tNewOffset;
	float fDistance = m_fDragSpeed * dt;
	switch( m_eDirection )
	{
		case eScrollViewDirectionHorizontal:
			fDistance  = m_tScrollDistance.x < 0 ? -fDistance : fDistance;
			tNewOffset = getContentOffset() + Vec2(fDistance, 0);
			break;
		default:
			fDistance  = m_tScrollDistance.y < 0 ? -fDistance : fDistance;
			tNewOffset = getContentOffset() + Vec2(0, fDistance);
			break;
	}
	tOldOffset = tNewOffset;
	bool bOutOfView = validateOffset(tNewOffset);

	if( bOutOfView && !m_bBounceable )
	{
		setContentOffsetWithoutCheck(tNewOffset);
		stoppedDeaccelerateScroll();
		return;
	}

	setContentOffsetWithoutCheck(tOldOffset);

	if( bOutOfView )
	{
		m_fDragSpeed = MIN(CSCROLLVIEW_DEACCELERATE_MAX, m_fDragSpeed);
		m_fDragSpeed = m_fDragSpeed - CSCROLLVIEW_DEACCELERATE_VA * dt;
	}
	else
	{
		m_fDragSpeed = CSCROLLVIEW_DEACCELERATE_PERCENTAGE * m_fDragSpeed - CSCROLLVIEW_DEACCELERATE_VA * dt;
	}

	if( m_fDragSpeed <= 0 )
	{
		stoppedDeaccelerateScroll();
		
		if( bOutOfView )
		{
			relocateContainerWithoutCheck(tNewOffset);
		}
		else
		{
			onDeaccelerateScrollEnded();
		}
	}
}
Ejemplo n.º 3
0
bool CCCGameScrollView::ccTouchBegan( CCTouch *pTouch, CCEvent *pEvent )
{
    CCPoint touchPoint=pTouch->getLocation();
    
    //    将世界坐标转换为当前父View的本地坐标系
    
    CCPoint reallyPoint=this->getParent()->convertToNodeSpace(touchPoint);
    //CCPoint touchPoint = this->convertTouchToNodeSpace(pTouch);
    if (!this->boundingBox().containsPoint(reallyPoint)) {
        return false;
    }
    
	m_BeginOffset = getContentOffset();
    CCPoint m_EndOffset = getContentOffset();
    
	//点击Page的功能
//	if (m_BeginOffset.equals(m_EndOffset))
	{
		int nPage = -1;
		if (m_eDirection == kCCScrollViewDirectionHorizontal)
		{
			nPage = abs(m_EndOffset.x / (int)m_CellSize.width);
		}
		else
		{
			nPage = abs(m_EndOffset.y / (int)m_CellSize.height);
		}
		CCCGameScrollViewDelegate *pDele = (CCCGameScrollViewDelegate *)m_pDelegate;
		CCNode *pPgae = m_pContainer->getChildByTag(nPage);
		CCRect rcContent;
		rcContent.origin = pPgae->getPosition();
        
		rcContent.size = pPgae->getContentSize();
        //		rcContent.origin.x -= rcContent.size.width / 2;
        //	rcContent.origin.y -= rcContent.size.height / 2;
        CCPoint pos1 = this->convertTouchToNodeSpace(pTouch);
		CCPoint pos =pos1;
		if (m_eDirection == kCCScrollViewDirectionHorizontal)
		{
			pos.x += nPage * m_CellSize.width;
		}
		else
		{
			pos.y -= nPage * m_CellSize.height;
		}
        
		if (rcContent.containsPoint(pos))
		{
            pDele->scrollViewTouchBegan(pPgae,pos1);
            
		}
	
	}
    return  CCScrollView::ccTouchBegan(pTouch, pEvent);;
}
Ejemplo n.º 4
0
void CAListView::recoveryCollectionCell()
{
	CCRect rect = this->getBounds();
	rect.origin = getContentOffset();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.size.height *= 1.2f;
    
	std::map<unsigned int, CAListViewCell*>::iterator itr;
	for (itr = m_pUsedListCells.begin(); itr != m_pUsedListCells.end(); itr++)
	{
		CAListViewCell* cell = itr->second;
		CC_CONTINUE_IF(cell == NULL);

		CCRect cellRect = cell->getFrame();
		CC_CONTINUE_IF(rect.intersectsRect(cellRect));

		m_pFreedListCells[cell->getReuseIdentifier()].pushBack(cell);
		cell->removeFromSuperview();
		cell->resetListViewCell();
		itr->second = NULL;
        
        
        CAView* line = m_pUsedLines[itr->first];
        CC_CONTINUE_IF(line == NULL);
        m_pFreedLines.pushBack(line);
        line->removeFromSuperview();
        m_pUsedLines[itr->first] = NULL;
	}
}
Ejemplo n.º 5
0
void CATextView::calculateSelChars(const CCPoint& point, int& l, int& r, int& p)
{
	float y = point.y + getContentOffset().y;
	int iCurLine = getCurrentByPointY(y);
	int iHalfCharSize = 0;
	int iStartPos = 0;
	if (!m_vLinesTextView.empty())
	{
		p = iStartPos = m_vLinesTextView[iCurLine].iStartCharPos;
		std::vector<TextAttribute>& v = m_vLinesTextView[iCurLine].TextAttrVect;
		for (int i = 0, iStringLeftX = 0; i < v.size(); i++)
		{
			TextAttribute& t = v[i];
			if (point.x >= iStringLeftX - iHalfCharSize && point.x < iStringLeftX + t.charlength / 2)
			{
				break;
			}

			iStringLeftX += t.charlength;
			p += t.charSize;
			iHalfCharSize = t.charlength / 2;
		}
	}

	std::string s = m_szText.substr(iStartPos, p - iStartPos);
	if (!s.empty() && s[0] == '\n')
	{
		s.erase(0, 1);
	}
	l = iCurLine;
	r = getStringLength(s);
}
Ejemplo n.º 6
0
void CACollectionView::loadCollectionCell()
{
	CCRect rect = this->getBounds();
	rect.origin = getContentOffset();
	rect.origin.y -= rect.size.height * 0.1f;
	rect.size.height *= 1.2f;

	std::map<CAIndexPath3E, CACollectionViewCell*>::iterator itr;
	for (itr = m_pUsedCollectionCells.begin(); itr != m_pUsedCollectionCells.end(); itr++)
	{
		CC_CONTINUE_IF(itr->second != NULL);

		CAIndexPath3E r = itr->first;
		CCRect cellRect = m_rUsedCollectionCellRects[r];
		CC_CONTINUE_IF(!rect.intersectsRect(cellRect));

		CACollectionViewCell* cell = m_pCollectionViewDataSource->collectionCellAtIndex(this, cellRect.size, r.section, r.row, r.item);
		if (cell)
		{
			cell->m_nSection = r.section;
			cell->m_nRow = r.row;
			cell->m_nItem = r.item;
			cell->updateDisplayedAlpha(this->getAlpha());
			this->addSubview(cell);
			cell->setFrame(cellRect);
			itr->second = cell;

			if (m_pSelectedCollectionCells.count(r))
			{
				cell->setControlStateSelected();
			}
		}
	}
}
Ejemplo n.º 7
0
void CCCGameScrollView::scrollToPage( int nPage )
{
	// 关闭CCScrollView中的自调整
	unscheduleAllSelectors();

	CCPoint oOffset = getContentOffset();
	// 调整位置
	CCPoint adjustPos;
	if (m_eDirection == kCCScrollViewDirectionHorizontal)
	{
		adjustPos = ccp(-m_CellSize.width * nPage, 0);
	}
	else
	{
		adjustPos = ccp(0, m_CellSize.height * nPage);
	}
	// 调整动画时间
	float adjustAnimDelay = ccpDistance(adjustPos, oOffset) / m_fAdjustSpeed;

	// 调整位置
	setContentOffsetInDuration(adjustPos, adjustAnimDelay);

	if (nPage != m_nCurPage)
	{
		m_nCurPage = nPage;
		scheduleOnce(schedule_selector(CCCGameScrollView::onScrollEnd), adjustAnimDelay);
	}
}
Ejemplo n.º 8
0
void CAAutoCollectionView::updateSectionHeaderAndFooterRects()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();

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

		CC_CONTINUE_IF(!rect.intersectsRect(cvs.rSectionRect));

		CAView* header = cvs.pSectionHeaderView;
		CAView* footer = cvs.pSectionFooterView;
		
		float headerHeight = cvs.nSectionHeaderHeight;
		float footerHeight = cvs.nSectionFooterHeight;

		if (header && m_bAlwaysTopSectionHeader)
		{
			DPoint p1 = rect.origin;
			p1.y = MAX(p1.y, cvs.rSectionRect.origin.y);
			p1.y = MIN(p1.y, cvs.rSectionRect.origin.y + cvs.rSectionRect.size.height
				- headerHeight - footerHeight);
			header->setFrameOrigin(p1);
		}
		if (footer && m_bAlwaysBottomSectionFooter)
		{
			DPoint p2 = DPointZero;
			p2.y = MIN(rect.origin.y + this->getBounds().size.height - footerHeight,
				cvs.rSectionRect.origin.y + cvs.rSectionRect.size.height - footerHeight);
			p2.y = MAX(p2.y, cvs.rSectionRect.origin.y + headerHeight);
			footer->setFrameOrigin(p2);
		}
	}
}
Ejemplo n.º 9
0
void LuaTableView::updateScroll(){
	bool vBar = _scrollBar && _scrollBar->isVisible(),
		vNode = _scrollNode && _scrollNode->isVisible();
	if(!vBar || !vNode){
		return;
	}
	bool vert = getDirection() == kCCScrollViewDirectionVertical;
	CCPoint p, cp = getContentOffset();
	CCSize vs = getViewSize(),
		cs = getContentSize();
	float rate = 1 - (vert? abs(cp.y) / (cs.height - vs.height) : abs(cp.x) / (cs.width - vs.width));
	if(vBar){
		CCSize ss = _scrollBar->getPreferredSize();
		p = _scrollBar->getPosition();
		if(vert){	p.y = cs.height - (cs.height - ss.height) * rate - ss.height - _scrollTrackDelta;
		}else{		p.x = cs.width - (cs.width - ss.width) * rate - ss.width - _scrollTrackDelta;
		}
		_scrollBar->setPosition(p);
	}
	if(vNode){
		p = _scrollNode->getPosition();
		if(vert){	p.y = cp.y + vs.height * rate;
		}else{		p.x = cp.x + vs.width * rate;
		}
		_scrollNode->setPosition(p);
	}
	if(_scrollTrack){
		p = _scrollTrack->getPosition();
		if(vert){	p.y = abs(cp.y);
		}else{		p.x = abs(cp.x);
		}
		_scrollTrack->setPosition(p);
	}
//CCLog("LTV.up ss=%d,%d vh=%d cy=%d ch=%d y=%d", (int)ss.width, (int)ss.height, (int)vs.height, (int)p.y, (int)cs.height, (int)_scrollBar->getPositionY());
}
Ejemplo n.º 10
0
void CScrollView::onTouchMoved(Touch *pTouch, float fDuration)
{
    Vec2 tNodePoint = convertToNodeSpace(pTouch->getLocation());
    
    if( m_pSelectedWidget )
    {
        if( m_eSelectedWidgetTouchModel == eWidgetTouchTransient && !m_bTouchMoved )
        {
            float fDistance = tNodePoint.getDistance(m_tTouchBeganPoint);   

            if(!m_bTouchMoved && fabs(ccScrollconvertPointToInch(fDistance)) < CSCROLLVIEW_MOVE_INCH)
            {
                m_pSelectedWidget->executeTouchMovedHandler(pTouch, fDuration);
                return;
            }

            m_bTouchMoved = true;
            m_pSelectedWidget->interruptTouch(pTouch, fDuration);
        }
        
        if(!m_pSelectedWidget->isTouchInterrupted())
        {
            m_pSelectedWidget->executeTouchMovedHandler(pTouch, fDuration);

            if(!m_pSelectedWidget->isTouchInterrupted())
            {
                return;
            }
        }
    }
    
    if( !m_bDragging )
    {
        m_tTouchBeganPoint = tNodePoint;
        m_tLastMovePoint = tNodePoint;
        m_bDragging = true;
		stoppedDeaccelerateScroll();
		stoppedAnimatedScroll();
    }
    
    if( m_bDragable )
    {
        m_tScrollDistance = tNodePoint - m_tLastMovePoint;
        m_tLastMovePoint = tNodePoint;
        
        switch( m_eDirection )
        {
            case eScrollViewDirectionHorizontal:
                m_tScrollDistance.y = 0;
                break;
            case eScrollViewDirectionVertical:
                m_tScrollDistance.x = 0;
                break;
            default:
                break;
        }
        
        setContentOffset( getContentOffset() + m_tScrollDistance );
    }
}
void Pull2RefreshTableView::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
	CCTableView::ccTouchEnded(pTouch, pEvent);

	// calculate the offset if it trigger refresh distance
	CCPoint offset = getContentOffset();

	float fDistance = getPullDistance();

	// set status
	switch(m_nPullType)
	{
		case kPull2RefreshTypeUp:
			if (fDistance > m_fPullUpThreshold)
			{
				m_nPullActionStatus = kPull2RefreshStatusPullUpReleaseToRefresh;
				this->onPullUpRefresh();
			}
			break;
		case kPull2RefreshTypeDown:
			if (fDistance > m_fPullDownThreshold)
			{
				m_nPullActionStatus = kPull2RefreshStatusPullDownReleaseToRefresh;
				this->onPullDownRefresh();
			}
			break;
		default:
			m_nPullActionStatus = kPull2RefreshStatusNormal;
			break;
	}

	m_pointPullStart = CCPointZero;
}
// pull up data is appending at the end,
// so we should set the offset whitch refreshed before
void Pull2RefreshTableView::onPullUpRefreshComplete()
{
	m_nPullActionStatus = kPull2RefreshStatusNormal;
	CCPoint offset = getContentOffset();
	reloadData();
	setContentOffset(offset);
}
Ejemplo n.º 13
0
void CCCGameScrollView::ccTouchCancelled( CCTouch *pTouch, CCEvent *pEvent )
{
	CCScrollView::ccTouchCancelled(pTouch, pEvent);
    
	CCPoint m_EndOffset=getContentOffset();
	adjustScrollView(m_BeginOffset,m_EndOffset);
}
Ejemplo n.º 14
0
void ScrollView::scrollToPage(int nPage)
{
    // 关闭CCScrollView中的自调整
    unscheduleAllCallbacks();
    
    Vec2 oOffset = getContentOffset();
    // 调整位置
    Vec2 adjustPos= Vec2(-_cellSize.width*nPage,0);
    
    // 调整动画时间
    float adjustAnimDelay= adjustPos.getDistance(oOffset)/_adjustSpeed;
    
    // 调整位置
    setContentOffsetInDuration(adjustPos, adjustAnimDelay);
    
    if (nPage!=_prePage)
    {
        this->setTouchEnabled(false);
        schedule(schedule_selector(ScrollView::onScrollEnd),adjustAnimDelay,0,0.0f);
        _prePage=nPage;
        
        if(_delegate)
            _delegate->scrollViewMoveToPage(nPage);
    }
}
Ejemplo n.º 15
0
void CScrollView::relocateContainer()
{
	Vec2 tOffset = getContentOffset();
	if( validateOffset(tOffset) )
	{
		setContentOffsetEaseInWithoutCheck(tOffset, CSCORLLVIEW_RELOCATE_DURATION, CSCROLLVIEW_MOVE_EASEIN_RATE);
	}
}
Ejemplo n.º 16
0
void CCCGameScrollView::ccTouchCancelled( CCTouch *pTouch, CCEvent *pEvent )
{
	CCScrollView::ccTouchCancelled(pTouch, pEvent);
//    CCCGameScrollViewDelegate *pDele = (CCCGameScrollViewDelegate *)m_pDelegate;
//    pDele->scrollViewTouchCancelled(this, CCPointZero);
	CCPoint m_EndOffset = getContentOffset();
	adjustScrollView(m_BeginOffset, m_EndOffset);
}
Ejemplo n.º 17
0
void CAListView::reloadViewSizeData()
{
    DRect winRect = this->getBounds();
    winRect.origin = getContentOffset();
    float width = winRect.size.width;
    float height = winRect.size.height;
    
	clearData();
    
    int iStartPosition = 0;
    if (m_nListHeaderHeight > 0)
    {
        m_rHeaderRect = (m_pListViewOrientation == CAListViewOrientationVertical)
        ? DRect(0, iStartPosition, width, m_nListHeaderHeight)
        : DRect(iStartPosition, 0, m_nListHeaderHeight, height);
        iStartPosition += m_nListHeaderHeight;
    }
    
    m_nIndexs = m_pListViewDataSource->numberOfIndex(this);
    m_rIndexRects.resize(m_nIndexs);
    m_rLineRects.resize(m_nIndexs);
    for (unsigned i = 0; i < m_nIndexs; i++)
    {
        unsigned int cellHeight = m_pListViewDataSource->listViewHeightForIndex(this, i);
        if (cellHeight > 0)
        {
            DRect cellRect = (m_pListViewOrientation == CAListViewOrientationVertical)
            ? DRect(0, iStartPosition, width, cellHeight)
            : DRect(iStartPosition, 0, cellHeight, height);
            m_rIndexRects[i] = cellRect;
            iStartPosition += cellHeight;
        }
        if (m_nSeparatorViewHeight > 0)
        {
            m_rLineRects[i] = (m_pListViewOrientation == CAListViewOrientationVertical)
            ? DRect(0, iStartPosition, width, m_nSeparatorViewHeight)
            : DRect(iStartPosition, 0, m_nSeparatorViewHeight, height);
            iStartPosition += m_nSeparatorViewHeight;
        }
    }
    
    if (m_nListFooterHeight > 0)
    {
        m_rFooterRect = (m_pListViewOrientation == CAListViewOrientationVertical)
        ? DRect(0, iStartPosition, width, m_nListFooterHeight)
        : DRect(iStartPosition, 0, m_nListFooterHeight, height);
        iStartPosition += m_nListFooterHeight;
    }
    
    if (m_pListViewOrientation == CAListViewOrientationVertical)
    {
        this->setViewSize(DSize(width, iStartPosition));
    }
    else
    {
        this->setViewSize(DSize(iStartPosition, height));
    }
}
Ejemplo n.º 18
0
//=============================================================
//=============================================================
void CCScrollLayer::refreshDotPosition()
{
    if(m_bShowHDot)
    {
        m_scrollDotHSprite->setVisible(true);
        float dotWidthPercent = getContentSize().width/m_contentLayer->getContentSize().width;
        float dotWidth = dotWidthPercent* getContentSize().width;
        m_scrollDotHSprite->setScaleX(dotWidth/m_scrollDotVSprite->getContentSize().width);
        
        Point offSetPoint =  getContentOffset();
        float maxSpace = m_contentLayer->getContentSize().width - getContentSize().width;
        
        if(offSetPoint.x!=0)
        {
            float positionPercent = offSetPoint.x/maxSpace;
            float percentwidth = positionPercent* (getContentSize().width - dotWidth);
            m_scrollDotHSprite->setPosition(Point(dotWidth/2+percentwidth,m_scrollDotHSprite->getPosition().y));
        }
    }
    else
    {
        m_scrollDotHSprite->setVisible(false);
    }
    if(m_bShowVDot)
    {
        m_scrollDotVSprite->setVisible(true);
        float dotHeightPercent = getContentSize().height/m_contentLayer->getContentSize().height;
        float dotHeight = dotHeightPercent* getContentSize().height;
        m_scrollDotVSprite->setScaleY(dotHeight/m_scrollDotVSprite->getContentSize().height);
        
        float maxSpace = m_contentLayer->getContentSize().height - getContentSize().height;
        Point offSetPoint =  getContentOffset();
        
        if(offSetPoint.y!=0)
        {
            float positionPercent = offSetPoint.y/maxSpace;
            float percentHeight = positionPercent*(getContentSize().height-dotHeight);
            m_scrollDotVSprite->setPosition(Point(m_scrollDotVSprite->getPosition().x,dotHeight/2+percentHeight));
        }
    }
    else
    {
        m_scrollDotVSprite->setVisible(false);
    }
}
Ejemplo n.º 19
0
void CCCGameScrollView::ccTouchEnded( CCTouch *pTouch, CCEvent *pEvent )
{
	CCPoint touchPoint = this->convertTouchToNodeSpace(pTouch);

	CCScrollView::ccTouchEnded(pTouch, pEvent);

	CCPoint m_EndOffset = getContentOffset();

	//点击Page的功能
	if (m_BeginOffset.equals(m_EndOffset))
	{
		int nPage = -1;
		if (m_eDirection == kCCScrollViewDirectionHorizontal)
		{
			nPage = abs(m_EndOffset.x / (int)m_CellSize.width);
		}
		else
		{
			nPage = abs(m_EndOffset.y / (int)m_CellSize.height);
		}
		CCCGameScrollViewDelegate *pDele = (CCCGameScrollViewDelegate *)m_pDelegate;
		CCNode *pPgae = m_pContainer->getChildByTag(nPage);
		CCRect rcContent;
		rcContent.origin = pPgae->getPosition();
      
		rcContent.size = pPgae->getContentSize();
//		rcContent.origin.x -= rcContent.size.width / 2;
//	rcContent.origin.y -= rcContent.size.height / 2;

		CCPoint pos = touchPoint;
		if (m_eDirection == kCCScrollViewDirectionHorizontal)
		{
			pos.x += nPage * m_CellSize.width;
		}
		else
		{
			pos.y -= nPage * m_CellSize.height;
		}

		if (rcContent.containsPoint(pos))
		{
			pDele->scrollViewClick(m_EndOffset, touchPoint, pPgae, nPage);
            pDele->scrollViewTouchEnded(this,touchPoint);
            
		}
		return ;
	}

	//自动调整
	adjustScrollView(m_BeginOffset, m_EndOffset);
}
Ejemplo n.º 20
0
void CAListView::loadCell()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.origin.x -= rect.size.width * 0.1f;
    rect.size.width *= 1.2f;
    rect.size.height *= 1.2f;
    
	std::map<unsigned int, CAListViewCell*>::iterator itr;
	for (itr = m_mpUsedListCells.begin(); itr != m_mpUsedListCells.end(); itr++)
	{
		CC_CONTINUE_IF(itr->second != NULL);

		unsigned int index = itr->first;
		DRect cellRect = m_rIndexRects[index];
		CC_CONTINUE_IF(!rect.intersectsRect(cellRect));

		CAListViewCell* cell = m_pListViewDataSource->listViewCellAtIndex(this, cellRect.size, index);
		if (cell)
		{
            cell->m_nIndex = index;
            cell->updateDisplayedAlpha(this->getAlpha());
			addSubview(cell);
			cell->setFrame(cellRect);
            m_mpUsedListCells[index] = cell;
            m_vpUsedListCells.pushBack(cell);
		}

		if (m_pSelectedListCells.count(index))
		{
			cell->setControlState(CAControlStateSelected);
		}
        
        if (m_pListViewDataSource)
        {
            m_pListViewDataSource->listViewWillDisplayCellAtIndex(this, cell, index);
        }
        
        CAView* view = this->dequeueReusableLine();
        DRect lineRect = m_rLineRects[index];
        if (view == NULL)
        {
            view = CAView::createWithFrame(lineRect, m_obSeparatorColor);
        }
        m_pUsedLines[index] = view;
        this->insertSubview(view, 1);
		view->setFrame(lineRect);
	}
}
Ejemplo n.º 21
0
void CATextView::moveArrowBtn(const CCPoint& pt)
{
	int iCurLine = 0; int iCurPosX = 0;
	calculateSelChars(convertToNodeSpace(pt), iCurLine, iCurPosX, m_iCurPos);
	m_curSelCharRange = std::make_pair(0, 0);
	calcCursorPosition();

	m_pCursorMark->stopAllActions();
	m_pCursorMark->setCenterOrigin(CCPoint(iCurPosX, m_iLineHeight*1.25f*iCurLine + m_iLineHeight / 2));
	m_pCursorMark->setVisible(true);

	CCPoint ptArr = m_pCursorMark->getCenterOrigin();
	m_pTextArrView->showTextArrView(CCPoint(ptArr.x, ptArr.y + m_iLineHeight*1.2f + getContentOffset().y));
}
Ejemplo n.º 22
0
void CATextView::calcCursorPosition()
{
	int iCurLine = -1, iCurLineCharPos = 0;

	for (int i = 0; i < m_vLinesTextView.size(); i++)
	{
		TextViewLineInfo& t = m_vLinesTextView[i];

		if (m_iCurPos >= t.iStartCharPos && m_iCurPos <= t.iEndCharPos)
		{
			iCurLine = i; iCurLineCharPos = t.iStartCharPos;
			break;
		}
	}

	float fHalfLineHeight = m_iLineHeight / 2.0f;
	float fLineSpaceValue = m_iLineHeight / 4.0f;

	CCPoint cCurPosition;
	if (iCurLine == -1)
	{
		cCurPosition.x = 0;
		cCurPosition.y = fHalfLineHeight;
	}
	else
	{
		std::string s = m_szText.substr(iCurLineCharPos, m_iCurPos - iCurLineCharPos);
		if (!s.empty() && s[0] == '\n')
		{
			s.erase(0, 1);
		}
		cCurPosition.x = getStringLength(s);
		cCurPosition.y = (m_iLineHeight + fLineSpaceValue)*iCurLine + fHalfLineHeight;
	}

	if (m_pCursorMark)
	{
		m_pCursorMark->setCenterOrigin(cCurPosition);
	}

	float w = getBounds().size.height;
	float y = cCurPosition.y - getContentOffset().y;
	if (y < 0 || y > w)
	{
		y = y < 0 ? fHalfLineHeight : w - fHalfLineHeight;
		setContentOffset(CCPointMake(0, cCurPosition.y-y), true);
	}
}
Ejemplo n.º 23
0
void CAAutoCollectionView::reloadData()
{
	if (m_pCollectionViewDataSource == NULL)
		return;
    
	this->reloadViewSizeData();
    
	this->removeAllSubviews();
    
	DRect winRect = this->getBounds();
	winRect.origin = getContentOffset();
	
	int dw = winRect.size.width - 2 * ((m_pCollectionViewOrientation == CACollectionViewOrientationVertical) ? m_iHoriMargins : m_iVertMargins);

	if (m_nCollectionHeaderHeight > 0 && m_pCollectionHeaderView)
	{
		m_pCollectionHeaderView->setDisplayRange(true);
		if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical)
		{
			m_pCollectionHeaderView->setFrame(DRect(m_iHoriMargins, m_iVertMargins, dw, m_nCollectionHeaderHeight));
		}
		else
		{
			m_pCollectionHeaderView->setFrame(DRect(m_iHoriMargins, m_iVertMargins, m_nCollectionHeaderHeight, dw));
		}
		addSubview(m_pCollectionHeaderView);
	}

	int dwValue = calculateAllRects();

	if (m_nCollectionFooterHeight > 0 && m_pCollectionFooterView)
	{
		if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical)
		{
			m_pCollectionFooterView->setFrame(DRect(m_iHoriMargins, dwValue, dw, m_nCollectionFooterHeight));
		}
		else
		{
			m_pCollectionFooterView->setFrame(DRect(dwValue, m_iVertMargins, m_nCollectionFooterHeight, dw));
		}
		addSubview(m_pCollectionFooterView);
	}
    
	this->updateSectionHeaderAndFooterRects();
	this->layoutPullToRefreshView();
	this->startDeaccelerateScroll();
	this->loadCollectionCell();
}
Ejemplo n.º 24
0
GridViewCell* GridView::cellForTouch(Touch *touch)
{
    Vec2 offset = getContentOffset();
    const Size size = getViewSize();
    const float scale = getZoomScale();
    
    Rect viewRect = Rect::ZERO;
    
    if (Direction::Horizontal == _direction)
    {
        if (0 <= offset.x) // right
        {
            offset.x = offset.x + _cellSize.width;
            
        } else // left
        {
            offset.x = offset.x - _cellSize.width;
        }
    } else if (Direction::Vertical == _direction)
    {
        if (0 <= offset.y) // down
        {
            offset.y = offset.y + _cellSize.height;
            
        } else // up
        {
            offset.y = offset.y - _cellSize.height;
        }
    }
    viewRect = Rect(-offset.x/scale, -offset.y/scale, size.width/scale, size.height/scale);
    
    for (int i = 0; i < _container->getChildrenCount(); i++)
    {
        GridViewCell* pCell = dynamic_cast<GridViewCell*>(_container->getChildren().at(i));
        if (!pCell) continue;
        
        if (viewRect.intersectsRect(pCell->boundingBox()))
        {
            if (pCell->boundingBox().containsPoint(_container->convertTouchToNodeSpace(touch)))
            {
                return pCell;
            }
        }
    }
    return nullptr;
}
Ejemplo n.º 25
0
bool ScrollView::onTouchBegan(Touch* touch, Event* event)
{
    if (!this->isVisible() || !this->hasVisibleParents())
    {
        return false;
    }
    
    _beginOffset = getContentOffset();
    
    Rect frame = getViewRect();

    //dispatcher does not know about clipping. reject touches outside visible bounds.
    if (_touches.size() > 2 ||
        _touchMoved          ||
        !frame.containsPoint(touch->getLocation()))
    {
        return false;
    }

    if (std::find(_touches.begin(), _touches.end(), touch) == _touches.end())
    {
        _touches.push_back(touch);
    }

    if (_touches.size() == 1)
    { // scrolling
        _touchPoint     = this->convertTouchToNodeSpace(touch);
        _touchMoved     = false;
        _dragging     = true; //dragging started
        _scrollDistance.setZero();
        _touchLength    = 0.0f;
    }
    else if (_touches.size() == 2)
    {
        _touchPoint = (this->convertTouchToNodeSpace(_touches[0]).getMidpoint(
                        this->convertTouchToNodeSpace(_touches[1])));
        
        _touchLength = _container->convertTouchToNodeSpace(_touches[0]).getDistance(
                       _container->convertTouchToNodeSpace(_touches[1]));
        
        _dragging  = false;
    } 
    return true;
}
Ejemplo n.º 26
0
void ScrollView::onTouchEnded(Touch* touch, Event* event)
{
    if (!this->isVisible())
    {
        return;
    }
    
    auto touchIter = std::find(_touches.begin(), _touches.end(), touch);
    
    if (touchIter != _touches.end())
    {
        if (_touches.size() == 1 && _touchMoved)
        {
            this->schedule(CC_SCHEDULE_SELECTOR(ScrollView::deaccelerateScrolling));
        }
        else if (_touches.size() == 1)
        {
            this->relocateContainer(true);
        }
        _touches.erase(touchIter);
    } 

    if (_touches.size() == 0)
    {
        _dragging = false;    
        _touchMoved = false;
    }
    
    if (_pageEnabled)
    {
        Vec2 endOffset = getContentOffset();
        Vec2 touchPoint = touch->getLocation();
        
        if (_beginOffset.equals(endOffset))
        {
            int page = abs(endOffset.x / (int)_cellSize.width);
            if (_delegate)
                _delegate->scrollViewClick(endOffset, touchPoint, _container->getChildByTag(page), page);
            return;
        }
        
        adjustScrollView(_beginOffset, endOffset);
    }
}
Ejemplo n.º 27
0
void CCCGameScrollView::ccTouchEnded( CCTouch *pTouch, CCEvent *pEvent )
{
	CCPoint touchPoint = pTouch->getLocationInView();
	touchPoint = CCDirector::sharedDirector()->convertToGL( touchPoint );
    
	CCScrollView::ccTouchEnded(pTouch, pEvent);
    
	CCPoint m_EndOffset=getContentOffset();
    
	if (m_BeginOffset.equals(m_EndOffset))
	{
		int nPage = abs(m_EndOffset.x / (int)m_CellSize.width);
		CCNewScrollViewDelegate* pDele=(CCNewScrollViewDelegate*)m_pDelegate;
		pDele->scrollViewClick(m_EndOffset,touchPoint,m_pContainer->getChildByTag(nPage),nPage);
		return ;
	}
    
	adjustScrollView(m_BeginOffset,m_EndOffset);
}
Ejemplo n.º 28
0
void CScrollView::onTouchEnded(Touch *pTouch, float fDuration)
{
    if( m_pSelectedWidget && !m_bTouchMoved && !m_pSelectedWidget->isTouchInterrupted() )
    {
        m_pSelectedWidget->executeTouchEndedHandler(pTouch, fDuration);
		m_bTouchMoved = false;
		m_bDragging = false;
        return;
    }
	
    if( m_bDragable )
    {
        if( m_bDeaccelerateable && m_eDirection != eScrollViewDirectionBoth && fDuration < CSCROLLVIEW_DEACCELERATE_INTERVAL )
        {
            Vec2 tEndPoint = convertToNodeSpace(pTouch->getLocation());
            switch( m_eDirection )
            {
                case eScrollViewDirectionHorizontal:
                    m_fDragSpeed = abs( m_tTouchBeganPoint.x - tEndPoint.x ) / fDuration;
                    break;
                default:
					m_fDragSpeed = abs( m_tTouchBeganPoint.y - tEndPoint.y ) / fDuration;
                    break;
            }
			perpareDeaccelerateScroll();
        }
        else
        {
			Vec2 tOffset = getContentOffset();
			if( validateOffset(tOffset) )
			{
				relocateContainerWithoutCheck(tOffset);
			}
			else
			{
				onDraggingScrollEnded();
			}
        }
    }
    
    m_bTouchMoved = false;
    m_bDragging = false;
}
Ejemplo n.º 29
0
void CATextView::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent)
{
	CAScheduler::unschedule(schedule_selector(CATextView::ccTouchTimer), this);

	if (CATextToolBarView::isTextToolBarShow() || m_pTextSelView->isTextViewShow())
		return;
	
	CCPoint point = this->convertTouchToNodeSpace(pTouch);

	if (!isScrollWindowNotOutSide())
	{
		if (this->getBounds().containsPoint(point))
		{
			becomeFirstResponder();
			if (isFirstResponder())
			{
                this->showCursorMark();

				int iCurLine = 0; int iCurPosX = 0;
				calculateSelChars(point, iCurLine, iCurPosX, m_iCurPos);
				m_pCursorMark->setCenterOrigin(CCPoint(iCurPosX, m_iLineHeight*1.25f*iCurLine + m_iLineHeight / 2));

				CCPoint pt = m_pCursorMark->getCenterOrigin();
				m_pTextArrView->showTextArrView(CCPoint(pt.x, pt.y + m_iLineHeight*1.2f + getContentOffset().y));
			}
		}
		else
		{
			m_pTextArrView->hideTextArrView();
			m_pTextSelView->hideTextSelView();

			if (resignFirstResponder())
			{
                this->hideCursorMark();
			}
		}
	}

	m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos);
	execCurSelCharRange();
	CAScrollView::ccTouchEnded(pTouch, pEvent);
}
void CACollectionView::updateSectionHeaderAndFooterRects()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();

	std::vector<DRect>::iterator itr;
	for (itr = m_rSectionRects.begin(); itr != m_rSectionRects.end(); itr++)
	{
		CC_CONTINUE_IF(!rect.intersectsRect(*itr));
		int i = (int)(itr - m_rSectionRects.begin());
		CAView* header = NULL;
		CAView* footer = NULL;
		float headerHeight = 0;
		float footerHeight = 0;
		if (m_pSectionHeaderViews.find(i) != m_pSectionHeaderViews.end())
		{
			header = m_pSectionHeaderViews[i];
			headerHeight = m_pSectionHeaderViews[i]->getFrame().size.height;
		}
		if (m_pSectionFooterViews.find(i) != m_pSectionFooterViews.end())
		{
			footer = m_pSectionFooterViews[i];
			footerHeight = m_pSectionFooterViews[i]->getFrame().size.height;
		}
		if (header && m_bAlwaysTopSectionHeader)
		{
			DPoint p1 = rect.origin;
			p1.y = MAX(p1.y, itr->origin.y);
			p1.y = MIN(p1.y, itr->origin.y + itr->size.height
				- headerHeight - footerHeight);
			header->setFrameOrigin(p1);
		}
		if (footer && m_bAlwaysBottomSectionFooter)
		{
			DPoint p2 = DPointZero;
			p2.y = MIN(rect.origin.y + this->getBounds().size.height - footerHeight,
				itr->origin.y + itr->size.height - footerHeight);
			p2.y = MAX(p2.y, itr->origin.y + headerHeight);
			footer->setFrameOrigin(p2);
		}
	}
}