Example #1
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);
}
Example #2
0
void CCtrlPage::ccTouchCancelled( cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent )
{
	CCPoint endPoint = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
	float distance = endPoint.x - m_touchPoint.x;

	if(50 <= fabs(distance))
	{
		g_objUIMgr.CleanTouchHandleObj();
	}

	adjustScrollView();
	// 必须要吃掉ScrollView的pTouch,否则ScrollView会自己调整
	if (m_pScrollView)
	{
		m_pScrollView->ccTouchCancelled(pTouch, pEvent);
	}
}
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);
    }
}
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);
}
void ScrollView::onTouchCancelled(Touch* touch, Event* event)
{
    if (!this->isVisible())
    {
        return;
    }
    
    auto touchIter = std::find(_touches.begin(), _touches.end(), touch);
    _touches.erase(touchIter);
    
    if (_touches.size() == 0)
    {
        _dragging = false;    
        _touchMoved = false;
    }
    
    if (_pageEnabled)
    {
        Vec2 endOffset = getContentOffset();
        adjustScrollView(_beginOffset, endOffset);
    }
}
Example #6
0
void CCtrlPage::ccTouchEnded( cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent )
{
	if (m_touchPoint.equals(CCPointZero))
	{
		return;
	}

	CCPoint endPoint = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
	float distance = endPoint.x - m_touchPoint.x;

	if(c_nRemoveHandle * CC_CONTENT_SCALE_FACTOR() <= fabs(distance))
	{
		g_objUIMgr.CleanTouchHandleObj();
	}

	adjustScrollView();

	// 必须要吃掉ScrollView的pTouch,否则ScrollView会自己调整
	if (m_pScrollView)
	{
		m_pScrollView->ccTouchCancelled(pTouch, pEvent);
	}
}