Пример #1
0
void UtilManager::toast(string text, CAViewController* object) {

	CAApplication::getApplication()->getRootWindow()->removeSubviewByTag(TOAST_VIEW_TAG);

	CCSize winSize = CAApplication::getApplication()->getWinSize();
	//CAView *back = CAView::createWithCenter(CCRect(winSize.width*0.5, winSize.height*0.5, _dip(winSize.width)*0.3, _dip(winSize.height)*0.3));
	CAView *back = CAView::createWithCenter(CCRect(winSize.width*0.5, winSize.height*0.5, 180 * getScale(), 30 * getScale()));
	back->setTag(TOAST_VIEW_TAG);
	back->setColor(ccc4(31, 31, 31, 200));//40

	CALabel *title = CALabel::createWithCenter(CADipRect(_dip(back->getBounds().size.width*0.5),
		_dip(back->getBounds().size.height*0.5), 180 * getScale(), 30 * getScale()));
  //	title->setText(UTF8ToGBK::transferToGbk(text));
	title->setText(text);
	//title->setText("sssss");
//	title->setFontName(getChineseFont());
	title->setColor(CAColor_white);
	title->setTextAlignment(CATextAlignmentCenter);
	title->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
	title->setFontSize(_px(15));
	back->addSubview(title);
	//CAApplication::getApplication()->getRootWindow()->getRootViewController()->getView()->addSubview(back);
	back->runAction(CCFadeOut::create(1));

	//CAApplication::getApplication()->getRootWindow()->addSubview(back);
	object->getView()->addSubview(back);
	//CCLog("%s", get_date_now().c_str());
	scheduleOnce(schedule_selector(UtilManager::removeToast), this, TOAST_TIME);
}
Пример #2
0
void CANavigationController::ccTouchMoved(CATouch *pTouch, CAEvent *pEvent)
{
    CC_RETURN_IF(m_pViewControllers.size() <= 1);
    CC_RETURN_IF(m_bTouchMoved == false);
    float offDis = pTouch->getLocation().x - pTouch->getPreviousLocation().x;
    CAView* showContainer = m_pContainers.at(m_pContainers.size() - 2);
    if (!showContainer->getBounds().size.equals(this->getView()->getBounds().size))
    {
        showContainer->setFrame(this->getView()->getBounds());
    }
    showContainer->setVisible(true);
    showContainer->setTouchEnabled(false);
    
    CAView* backContainer = m_pContainers.back();
    
    DPoint point1 = backContainer->getFrameOrigin();
    point1.x += offDis;
    point1.x = MAX(point1.x, 0);
    point1.x = MIN(point1.x, this->getView()->getBounds().size.width);
    backContainer->setFrameOrigin(point1);
    backContainer->setTouchEnabled(false);
    
    DPoint point2 = showContainer->getCenterOrigin();
    point2.x = point1.x/2;
    showContainer->setCenterOrigin(point2);
    
    m_bPopViewController = ((offDis > 10) || point1.x > this->getView()->getBounds().size.width/4);
}
Пример #3
0
void CATouchController::passingTouchesViews(float dt)
{
    CAView* view = dynamic_cast<CAView*>(CAApplication::getApplication()->getTouchDispatcher()->getFirstResponder());
    bool isContainsFirstPoint = view && view->convertRectToWorldSpace(view->getBounds()).containsPoint(m_tFirstPoint);
    if (!isContainsFirstPoint && view)
    {
        view->ccTouchBegan(m_pTouch, m_pEvent);
    }
    
    CC_RETURN_IF(m_vTouchesViews.empty());

    CAResponder* responder = m_vTouchesViews.front();
    while (responder->nextResponder())
    {
        m_vTouchesViews.pushBack(responder->nextResponder());
        responder = responder->nextResponder();
    }
    
    for (int i=0; i<m_vTouchesViews.size();)
    {
        if (!m_vTouchesViews.at(i)->ccTouchBegan(m_pTouch, m_pEvent))
        {
            m_vTouchesViews.erase(i);
        }
        else
        {
            i++;
        }
    }
}
Пример #4
0
void CANavigationController::update(float dt)
{
    CCRect rect = this->getView()->getBounds();
    
    CCPoint point = this->getNavigationBarNowPoint();

    switch (m_eNavigationBarVerticalAlignment)
    {
        case CABarVerticalAlignmentTop:
        {
            rect.origin.y = point.y + m_tNavigationBarSize.height;
            rect.size.height = rect.size.height - rect.origin.y;
        }
            break;
        case CABarVerticalAlignmentBottom:
        {
            rect.size.height = point.y;
        }
            break;
        default:
            break;
    }
    m_pNavigationBars.back()->setFrameOrigin(point);
    
    CAView* secondContainer = m_pSecondContainers.back();
    CAViewController* viewController = m_pViewControllers.back();
    secondContainer->setFrame(rect);
    viewController->getSuperViewRect(secondContainer->getBounds());
}
Пример #5
0
// [email protected]: 2015-03-08
void CANavigationController::popToRootViewControllerAnimated(bool animated)
{
    if (m_pViewControllers.size() == 1)
    {
        return ;
    }
    
    float x = this->getView()->getBounds().size.width;
    
    CAView* backContainer = m_pContainers.back();
    backContainer->setFrameOrigin(DPointZero);
    
    size_t index = 0;
    CAViewController* showViewController = m_pViewControllers.at(index);
    showViewController->viewDidAppear();
    
    CAView* showContainer = m_pContainers.at(index);
    showContainer->setVisible(true);
    showContainer->setFrameOrigin(DPoint(-x/2.0f, 0));
    
    {
        DPoint point = this->getNavigationBarNowPoint(showViewController);
        
        DRect rect = this->getView()->getBounds();
        rect.origin.y = point.y + m_tNavigationBarSize.height;
        rect.size.height = rect.size.height - rect.origin.y;
        m_pNavigationBars.at(index)->setFrameOrigin(point);
        
        CAView* secondContainer = m_pSecondContainers.at(index);
        secondContainer->setFrame(rect);
        
        showViewController->getSuperViewRect(secondContainer->getBounds());
    }
    
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse();
    
    if (animated)
    {
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(0.02f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        showContainer->setFrameOrigin(DPointZero);
        CAViewAnimation::commitAnimations();
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(0.03f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::popToRootViewControllerFinish));
        backContainer->setFrameOrigin(DPoint(x, 0));
        CAViewAnimation::commitAnimations();
    }
    else
    {
        this->popToRootViewControllerFinish();
    }
}
CATableViewCell* ExchangeViewController::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row)
{
    
    CCLog("row = %d , section = %d", row, section);
    CADipSize _size = cellSize;
    CATableViewCell* p_Cell = p_TableView->dequeueReusableCellWithIdentifier("2155");
    if (p_Cell == NULL )
    {
        p_Cell = CATableViewCell::create("2155");
        p_Cell->setAllowsSelected(false);
        
        CAView* itemImage = CAView::createWithFrame(CADipRect(0, 0, _size.width, _size.height));
        itemImage->setColor(ccc4(244, 243, 243, 255));
        itemImage->setTag(99);
        p_Cell->addSubview(itemImage);
        
        CADipSize itemSize = itemImage->getBounds().size;
        CALabel* itemText = CALabel::createWithCenter(CADipRect(itemSize.width/2, itemSize.height/3, itemSize.width,40));
        itemText->setTag(100);
        itemText->setFontSize(_px(35));
        itemText->setTextAlignment(CATextAlignmentCenter);
        itemText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
        p_Cell->addSubview(itemText);
        
        CALabel* itemText2 = CALabel::createWithCenter(CADipRect(itemSize.width/2, itemSize.height/5*4, itemSize.width,40));
        itemText2->setTag(101);
        itemText2->setFontSize(_px(25));
        itemText2->setTextAlignment(CATextAlignmentCenter);
        itemText2->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
        p_Cell->addSubview(itemText2);
        
        CAScale9ImageView* iv = CAScale9ImageView::createWithCenter(CADipRect(itemSize.width-50,itemSize.height/2,50,50));
        iv->setImage(CAImage::create("source_material/cell_btn_right.png"));
        iv->setTag(101);
        p_Cell->addSubview(iv);
        
        CAImageView* icon = CAImageView::createWithCenter(CADipRect(50,itemSize.height/2,64,64));
        icon->setTag(101);
        icon->setScale(0.6f);
        icon->setImage(CAImage::create("source_material/btn_right_blue.png"));
        p_Cell->addSubview(icon);
    }
    
    CALabel * label = (CALabel*)p_Cell->getSubviewByTag(100);
    label->setText( unicode_to_utf8(exChangeMenuTag[row]) );
    label->setColor(CAColor_black);
    
    CALabel* label2 = (CALabel*)p_Cell->getSubviewByTag(101);
    label2->setText(unicode_to_utf8(exChangeMenuTag2[row]));
    label2->setColor(CAColor_gray);
    
    
   
    
    return p_Cell;

}
Пример #7
0
CAResponder* getLastResponder(CATouch* touch, const CAVector<CAView*>& subviews)
{
    CAResponder* lastResponder = NULL;
    
    for (CAVector<CAView*>::const_reverse_iterator itr=subviews.rbegin();
         itr!=subviews.rend();
         itr++)
    {
        CAView* subview = *itr;
        if (subview->isVisible())
        {
            if (CAViewController* viewController = dynamic_cast<CAViewController*>(subview->getContentContainer()))
            {
                CC_CONTINUE_IF(!viewController->isTouchEnabled());
                
                DPoint point = subview->convertTouchToNodeSpace(touch);
                
                if (subview->getBounds().containsPoint(point))
                {
                    lastResponder = viewController;
                    break;
                }
            }
            else
            {
                CC_CONTINUE_IF(!subview->isTouchEnabled());
                
                DPoint point = subview->convertTouchToNodeSpace(touch);
                
                if (subview->getBounds().containsPoint(point))
                {
                    lastResponder = subview;
                    break;
                }
            }
        }
    }
    
    return lastResponder;
}
Пример #8
0
void CANavigationController::update(float dt)
{
    CAViewController* viewController = m_pViewControllers.back();
    
    DPoint point = this->getNavigationBarNowPoint(viewController);

    DRect rect = this->getView()->getBounds();
    rect.origin.y = point.y + m_tNavigationBarSize.height;
    rect.size.height = rect.size.height - rect.origin.y;
    m_pNavigationBars.back()->setFrameOrigin(point);
    
    CAView* secondContainer = m_pSecondContainers.back();
    secondContainer->setFrame(rect);
    
    viewController->getSuperViewRect(secondContainer->getBounds());
}
Пример #9
0
void CATouchController::touchCancelled()
{
    CAScheduler::unschedule(schedule_selector(CATouchController::passingTouchesViews), this);
    
    CAView* view = dynamic_cast<CAView*>(CAApplication::getApplication()->getTouchDispatcher()->getFirstResponder());
    bool isContainsFirstPoint = view && view->convertRectToWorldSpace(view->getBounds()).containsPoint(m_tFirstPoint);
    if (!isContainsFirstPoint && view)
    {
        view->ccTouchCancelled(m_pTouch, m_pEvent);
    }
    
    CAVector<CAResponder*>::iterator itr;
    for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++)
    {
        (*itr)->ccTouchCancelled(m_pTouch, m_pEvent);
    }
}
Пример #10
0
void CATabBarController::scrollViewWillBeginDragging(CAScrollView* view)
{
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse();
    for (int i = MAX((int)m_nSelectedIndex - 1, 0);
         i < MIN((int)m_nSelectedIndex + 2, m_pViewControllers.size());
         i++)
    {
        if (!m_pViewControllers.at(i)->getView()->getSuperview())
        {
            CAView* view = m_pContainer->getSubViewAtIndex(i);
            m_pViewControllers.at(i)->getView()->setFrame(view->getBounds());
            m_pViewControllers.at(i)->addViewFromSuperview(view);
        }
        
        m_pViewControllers.at(i)->getView()->setVisible(true);
    }
}
Пример #11
0
CACollectionViewCell* CDUIShowCollectionView::collectionCellAtIndex(CACollectionView *collectionView, const CCSize& cellSize, unsigned int section, unsigned int row, unsigned int item)
{
    if (row * 3 + item >= m_vTitle.size())
    {
        return NULL;
    }
    
    CADipSize _size = cellSize;
    CACollectionViewCell* p_Cell = collectionView->dequeueReusableCellWithIdentifier("CrossApp");
    if (p_Cell == NULL)
    {
        p_Cell = CACollectionViewCell::create("CrossApp");
        p_Cell->setAllowsSelected(false);
        
        CAView* itemImage = CAView::createWithFrame(CADipRect(0, 0, _size.width, _size.height));
        itemImage->setTag(99);
        p_Cell->addSubview(itemImage);
        
        CADipSize itemSize = itemImage->getBounds().size;
        CALabel* itemText = CALabel::createWithCenter(CADipRect(itemSize.width/2, itemSize.height-40, itemSize.width,40));
        itemText->setTag(100);
        itemText->setFontSize(_px(24));
        itemText->setTextAlignment(CATextAlignmentCenter);
        itemText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
        p_Cell->addSubview(itemText);
        
        CAImageView* icon = CAImageView::createWithCenter(CADipRect(itemSize.width/2,itemSize.height/3,189,123));
        icon->setTag(101);
        icon->setScale(0.6f);
        p_Cell->addSubview(icon);
    }
    
    CAView* itemImageView = p_Cell->getSubviewByTag(99);
    itemImageView->setColor(ccc4(244, 243, 243, 255));
    
    int index = row * 3 + item;
    
    CALabel* itemText = (CALabel*)p_Cell->getSubviewByTag(100);
    itemText->setText(m_vTitle.at(index));
    itemText->setColor(ccc4(34,151,254,255));
    
    CAImageView* icon = (CAImageView*)p_Cell->getSubviewByTag(101);
    icon->setImage(CAImage::create(iconTag[index]));
    
    return p_Cell;
}
Пример #12
0
void CATabBarController::renderingSelectedViewController()
{
    if (m_nLastSelectedIndex < m_pViewControllers.size())
    {
        m_pViewControllers.at(m_nLastSelectedIndex)->getView()->setVisible(false);
        m_pViewControllers.at(m_nLastSelectedIndex)->viewDidDisappear();
    }
    
    if (!m_pViewControllers.at(m_nSelectedIndex)->getView()->getSuperview())
    {
        CAView* view = m_pContainer->getSubViewAtIndex(m_nSelectedIndex);
        m_pViewControllers.at(m_nSelectedIndex)->getView()->setFrame(view->getBounds());
        m_pViewControllers.at(m_nSelectedIndex)->addViewFromSuperview(view);
    }
    
    m_pViewControllers.at(m_nSelectedIndex)->getView()->setVisible(true);
    m_pViewControllers.at(m_nSelectedIndex)->viewDidAppear();
}
Пример #13
0
void CATabBarController::renderingSelectedViewController(float dt)
{
    std::vector<CAViewController*>::iterator itr;
    for (itr=m_pViewControllers.begin(); itr!=m_pViewControllers.end(); itr++)
    {
        (*itr)->getView()->setVisible(false);
    }

    m_pViewControllers.at(m_nSelectedIndex)->getView()->setVisible(true);

    if (m_pViewControllers.at(m_nSelectedIndex)->getView()->getSuperview() == NULL)
    {
        CCRect rect = m_pContainer->getFrame();
        rect.origin.x = m_nSelectedIndex * rect.size.width;
        rect.origin.y = 0;
        CAView* view = CAView::createWithFrame(rect);
        m_pContainer->addSubview(view);
        m_pViewControllers.at(m_nSelectedIndex)->getView()->setFrame(view->getBounds());
        m_pViewControllers.at(m_nSelectedIndex)->addViewFromSuperview(view);
    }
}
Пример #14
0
void CATabBarController::update(float dt)
{
    CCRect rect = m_pContainer->getFrame();
    CCSize size = m_pContainer->getViewSize();

    switch (m_eTabBarVerticalAlignment)
    {
    case CABarVerticalAlignmentTop:
    {
        rect.origin.y = m_pTabBar->getFrame().origin.y + m_pTabBar->getFrame().size.height;
        rect.size.height = this->getView()->getBounds().size.height - rect.origin.y;
    }
    break;
    case CABarVerticalAlignmentBottom:
    {
        rect.size.height = m_pTabBar->getFrame().origin.y;
    }
    break;
    default:
        break;
    }
    size.height = rect.size.height;

    m_pContainer->setFrame(rect);
    CCPoint point = m_pContainer->getContentOffset();
    m_pContainer->setViewSize(size);
    m_pContainer->setContentOffset(point, false);

    for (unsigned int i=0; i<m_pViewControllers.size(); i++)
    {
        CAViewController* viewController = m_pViewControllers.at(i);
        CAView* superview = viewController->getView()->getSuperview();
        CC_CONTINUE_IF(superview == NULL);
        rect.origin.x = superview->getFrameOrigin().x;
        rect.origin.y = 0;
        superview->setFrame(rect);
        viewController->getSuperViewRect(superview->getBounds());
    }
}
Пример #15
0
void CATouchController::touchBegan()
{
    m_tFirstPoint = m_pTouch->getLocation();
    
    std::vector<CAResponder*> vector;
    
    CAView* view = dynamic_cast<CAView*>(CAApplication::getApplication()->getTouchDispatcher()->getFirstResponder());
    bool isContainsFirstPoint = view && view->convertRectToWorldSpace(view->getBounds()).containsPoint(m_tFirstPoint);
    if (isContainsFirstPoint)
    {
        vector = this->getEventListener(m_pTouch, view);
    }
    else
    {
        vector = this->getEventListener(m_pTouch, CAApplication::getApplication()->getRootWindow());
    }

    std::vector<CAResponder*>::iterator itr;
    for (itr=vector.begin(); itr!=vector.end(); itr++)
    {
        if ((*itr)->isTouchMovedStopSubviews())
        {
            m_vTouchMovedsViewCache.pushBack((*itr));
        }
    }
    m_vTouchesViews.pushBack(vector.back());
    
    if (!m_vTouchMovedsViewCache.empty())
    {
        CAScheduler::schedule(schedule_selector(CATouchController::passingTouchesViews), this, 0, 0, 0.05f);
    }
    else
    {
        this->passingTouchesViews();
    }
}
Пример #16
0
CAViewController* CANavigationController::popViewControllerAnimated(bool animated)
{
    if (m_pViewControllers.size() == 1)
    {
        return NULL;
    }

    float x = this->getView()->getBounds().size.width;
    
    CAViewController* backViewController = m_pViewControllers.back();
    CAView* backContainer = m_pContainers.back();
    {
        backContainer->setFrameOrigin(CCPointZero);
    }
    
    size_t index = m_pViewControllers.size() - 2;
    CAViewController* showViewController = m_pViewControllers.at(index);
    showViewController->viewDidAppear();
    
    CAView* showContainer = m_pContainers.at(index);
    showContainer->setVisible(true);
    
    
    {
        CCRect rect = this->getView()->getBounds();
        
        CCPoint point = this->getNavigationBarNowPoint(showViewController);
        
        switch (m_eNavigationBarVerticalAlignment)
        {
            case CABarVerticalAlignmentTop:
            {
                rect.origin.y = point.y + m_tNavigationBarSize.height;
                rect.size.height = rect.size.height - rect.origin.y;
            }
                break;
            case CABarVerticalAlignmentBottom:
            {
                rect.size.height = point.y;
            }
                break;
            default:
                break;
        }
        m_pNavigationBars.at(index)->setFrameOrigin(point);
        
        CAView* secondContainer = m_pSecondContainers.at(index);
        secondContainer->setFrame(rect);
        
        showViewController->getSuperViewRect(secondContainer->getBounds());
    }
    
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse();
    
    if (animated)
    {
        showContainer->setFrameOrigin(CCPoint(-x/2.0f, 0));
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/30.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        showContainer->setFrameOrigin(CCPointZero);
        CAViewAnimation::commitAnimations();
        
        CAViewAnimation::beginAnimations("", NULL);
        CAViewAnimation::setAnimationDuration(0.25f);
        CAViewAnimation::setAnimationDelay(1/60.0f);
        CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut);
        CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::popViewControllerFinish));
        backContainer->setFrameOrigin(CCPoint(x, 0));
        CAViewAnimation::commitAnimations();
    }
    else
    {
        this->popViewControllerFinish();
    }
    return backViewController;
}
Пример #17
0
void CATouchController::touchMoved()
{
    CC_RETURN_IF(ccpDistance(m_tFirstPoint, m_pTouch->getLocation()) < _px(32));
    
    m_tFirstPoint = CCPointZero;
    
    if (!m_vTouchMovedsViewCache.empty())
    {
        bool isScheduledPassing = CAScheduler::isScheduled(schedule_selector(CATouchController::passingTouchesViews), this);
        
        CAScheduler::unschedule(schedule_selector(CATouchController::passingTouchesViews), this);
        
        while (!m_vTouchMovedsViewCache.empty())
        {
            CAResponder* responder = m_vTouchMovedsViewCache.back();
            CCPoint pointOffSet = CCPointZero;
            if (CAView* v = dynamic_cast<CAView*>(responder))
            {
                pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()),
                                     v->convertToNodeSpace(m_pTouch->getPreviousLocation()));
            }
            else if (CAViewController* c = dynamic_cast<CAViewController*>(responder))
            {
                pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()),
                                     c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation()));
            }
            else
            {
                pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation());
            }
            
            pointOffSet.x = fabsf(pointOffSet.x);
            pointOffSet.y = fabsf(pointOffSet.y);
            
            do
            {
                CC_BREAK_IF(!responder->isTouchMovedListenHorizontal() && pointOffSet.x >= pointOffSet.y);
                CC_BREAK_IF(!responder->isTouchMovedListenVertical() && pointOffSet.x < pointOffSet.y);
                m_vTouchMovedsView.pushBack(m_vTouchMovedsViewCache.back());
            }
            while (0);
            
            m_vTouchMovedsViewCache.popBack();
        }
        
        
        CAVector<CAResponder * > tTouchesViews = m_vTouchesViews;
        if (!m_vTouchMovedsView.empty())
        {
            if (!isScheduledPassing)
            {
                
                CAVector<CAResponder*>::iterator itr;
                //
                for (itr = m_vTouchMovedsView.begin(); itr != m_vTouchMovedsView.end(); itr++)
                {
                    m_vTouchesViews.eraseObject(*itr, true);
                }
                //
                
                for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++)
                {
                    (*itr)->ccTouchCancelled(m_pTouch, m_pEvent);
                }
            }
            
            {
                m_vTouchesViews.clear();
                
                for (int i=0; i<m_vTouchMovedsView.size(); i++)
                {
                    CAResponder* responder = m_vTouchMovedsView.at(i);
                    CCPoint pointOffSet = CCPointZero;
                    if (CAView* v = dynamic_cast<CAView*>(responder))
                    {
                        pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()),
                                             v->convertToNodeSpace(m_pTouch->getPreviousLocation()));
                    }
                    else if (CAViewController* c = dynamic_cast<CAViewController*>(responder))
                    {
                        pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()),
                                             c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation()));
                    }
                    else
                    {
                        pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation());
                    }
                    
                    if (responder->isTouchMovedListenHorizontal()
                        && fabsf(pointOffSet.x) >= fabsf(pointOffSet.y))
                    {
                        CC_CONTINUE_IF(responder->isSlidingMinX() && pointOffSet.x > 0);
                        CC_CONTINUE_IF(responder->isSlidingMaxX() && pointOffSet.x < 0);
                    }
                    
                    if (responder->isTouchMovedListenVertical()
                        && fabsf(pointOffSet.x) < fabsf(pointOffSet.y))
                    {
                        CC_CONTINUE_IF(responder->isSlidingMinY() && pointOffSet.y > 0);
                        CC_CONTINUE_IF(responder->isSlidingMaxY() && pointOffSet.y < 0);
                    }
                    
                    m_vTouchesViews.pushBack(responder);
                    
                    
                    if (tTouchesViews.contains(responder)==false)
                    {
                        responder->ccTouchBegan(m_pTouch, m_pEvent);
                    }
                    break;
                }
                
                if (m_vTouchesViews.empty())
                {
                    m_vTouchesViews.pushBack(m_vTouchMovedsView.front());
                    if (tTouchesViews.contains(m_vTouchesViews.back())==false)
                    {
                        m_vTouchesViews.back()->ccTouchBegan(m_pTouch, m_pEvent);//
                    }
                    
                }
            }
        }
        
    }
    
    CAView* view = dynamic_cast<CAView*>(CAApplication::getApplication()->getTouchDispatcher()->getFirstResponder());
    bool isContainsFirstPoint = view && view->convertRectToWorldSpace(view->getBounds()).containsPoint(m_tFirstPoint);
    if (!isContainsFirstPoint && view)
    {
        view->ccTouchMoved(m_pTouch, m_pEvent);
    }
    
    CAVector<CAResponder*>::iterator itr;
    for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++)
    {
        (*itr)->ccTouchMoved(m_pTouch, m_pEvent);
    }
    
}
Пример #18
0
std::vector<CAResponder*> CATouchController::getEventListener(CATouch* touch, CAView* view)
{
    CAResponder* responder = view;
    
    std::vector<CAResponder*> vector;
    
    do
    {
        vector.push_back(responder);
        
        CAResponder* nextResponder = NULL;
        
        if (CAView* view = dynamic_cast<CAView*>(responder))
        {
            if (view->getViewDelegate())
            {
                nextResponder = view->nextResponder();
            }
            else
            {
                view->sortAllSubviews();
                
                CAVector<CAView*>::const_reverse_iterator itr;
                for (itr=view->getSubviews().rbegin(); itr!=view->getSubviews().rend(); itr++)
                {
                    CAView* subview = *itr;
                    if (subview->isVisible() && subview->isTouchEnabled())
                    {
                        CCPoint point = subview->convertTouchToNodeSpace(touch);
                        
                        if (subview->getBounds().containsPoint(point))
                        {
                            nextResponder = subview;
                            break;
                        }
                    }
                }
            }
        }
        else if (CAViewController* viewController = dynamic_cast<CAViewController*>(responder))
        {
            CAVector<CAView*>::const_reverse_iterator itr;
            for (itr=viewController->getView()->getSubviews().rbegin();
                 itr!=viewController->getView()->getSubviews().rend();
                 itr++)
            {
                CAView* subview = *itr;
                if (subview->isVisible() && subview->isTouchEnabled())
                {
                    CCPoint point = subview->convertTouchToNodeSpace(touch);
                    
                    if (subview->getBounds().containsPoint(point))
                    {
                        nextResponder = subview;
                        break;
                    }
                }
            }
        }
        
        responder = nextResponder;
    }
    while (responder);

    return vector;
}
Пример #19
0
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);
                
            }
        }
    }
    while (0);
}
Пример #20
0
void CATouchController::touchMoved()
{
    CC_RETURN_IF(ccpDistance(m_tFirstPoint, m_pTouch->getLocation()) < 16);
    
    m_tFirstPoint = DPointZero;

    if (!m_vTouchMovedsViewCache.empty())
    {
        bool isScheduledPassing = CAScheduler::isScheduled(schedule_selector(CATouchController::passingTouchesViews), this);
        
        bool isTouchEventScrollHandOverToSuperview = true;
        
        for (CAVector<CAResponder*>::iterator itr=m_vTouchesViews.begin();
             itr!=m_vTouchesViews.end(); itr++)
        {
            CC_CONTINUE_IF((*itr)->isTouchEventScrollHandOverToSuperview());
            isTouchEventScrollHandOverToSuperview = false;
            break;
        }
        
        
        if (isScheduledPassing || isTouchEventScrollHandOverToSuperview)
        {
            CAScheduler::unschedule(schedule_selector(CATouchController::passingTouchesViews), this);
            
            while (!m_vTouchMovedsViewCache.empty())
            {
                CAResponder* responder = m_vTouchMovedsViewCache.back();
                DPoint pointOffSet = DPointZero;
                if (CAView* v = dynamic_cast<CAView*>(responder))
                {
                    pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()),
                                         v->convertToNodeSpace(m_pTouch->getPreviousLocation()));
                }
                else if (CAViewController* c = dynamic_cast<CAViewController*>(responder))
                {
                    pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()),
                                         c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation()));
                }
                else
                {
                    pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation());
                }
                
                pointOffSet.x = fabsf(pointOffSet.x);
                pointOffSet.y = fabsf(pointOffSet.y);
                
                do
                {
                    CC_BREAK_IF(!responder->isHorizontalScrollEnabled() && pointOffSet.x >= pointOffSet.y);
                    CC_BREAK_IF(!responder->isVerticalScrollEnabled() && pointOffSet.x < pointOffSet.y);
                    m_vTouchMovedsView.pushBack(m_vTouchMovedsViewCache.back());
                }
                while (0);
                
                m_vTouchMovedsViewCache.popBack();
            }
            
            if (!m_vTouchMovedsView.empty())
            {
                bool isTouchCancelled = true;
                CAVector<CAResponder*>::iterator itr;
                for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++)
                {
                    CAResponder* responder = (*itr);
                    if (responder->isPriorityScroll())
                    {
                        DPoint pointOffSet = DPointZero;
                        if (CAView* v = dynamic_cast<CAView*>(responder))
                        {
                            pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()),
                                                 v->convertToNodeSpace(m_pTouch->getPreviousLocation()));
                        }
                        else if (CAViewController* c = dynamic_cast<CAViewController*>(responder))
                        {
                            pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()),
                                                 c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation()));
                        }
                        else
                        {
                            pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation());
                        }
                        
                        if (!responder->isReachBoundaryHandOverToSuperview())
                        {
                            isTouchCancelled = false;
                            break;
                        }
                        
                        if (responder->isHorizontalScrollEnabled()
                            && fabsf(pointOffSet.x) >= fabsf(pointOffSet.y))
                        {
                            if (!responder->isReachBoundaryLeft() && pointOffSet.x >= 0)
                            {
                                isTouchCancelled = false;
                                break;
                            }
                            if (!responder->isReachBoundaryRight() && pointOffSet.x <= 0)
                            {
                                isTouchCancelled = false;
                                break;
                            }
                            
                        }
                        
                        if (responder->isVerticalScrollEnabled()
                            && fabsf(pointOffSet.x) < fabsf(pointOffSet.y))
                        {
                            if (!responder->isReachBoundaryUp() && pointOffSet.y >= 0)
                            {
                                isTouchCancelled = false;
                                break;
                            }
                            if (!responder->isReachBoundaryDown() && pointOffSet.y <= 0)
                            {
                                isTouchCancelled = false;
                                break;
                            }
                        }
                    }
                }
                
                if (isTouchCancelled)
                {
                    if (!isScheduledPassing)
                    {
                        CAVector<CAResponder*>::iterator itr;
                        for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++)
                        {
                            this->touchCancelledWithResponder(*itr);
                        }
                    }
                    m_vTouchesViews.clear();
                }
                
                if (isScheduledPassing || m_vTouchesViews.empty())
                {
                    for (int i=0; i<m_vTouchMovedsView.size(); i++)
                    {
                        CAResponder* responder = m_vTouchMovedsView.at(i);
                        DPoint pointOffSet = DPointZero;
                        if (CAView* v = dynamic_cast<CAView*>(responder))
                        {
                            pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()),
                                                 v->convertToNodeSpace(m_pTouch->getPreviousLocation()));
                        }
                        else if (CAViewController* c = dynamic_cast<CAViewController*>(responder))
                        {
                            pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()),
                                                 c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation()));
                        }
                        else
                        {
                            pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation());
                        }
                        
                        if (responder->isReachBoundaryHandOverToSuperview())
                        {
                            if (responder->isHorizontalScrollEnabled()
                                && fabsf(pointOffSet.x) >= fabsf(pointOffSet.y))
                            {
                                CC_CONTINUE_IF(responder->isReachBoundaryLeft() && pointOffSet.x > 0);
                                CC_CONTINUE_IF(responder->isReachBoundaryRight() && pointOffSet.x < 0);
                            }
                            else if (responder->isVerticalScrollEnabled()
                                     && fabsf(pointOffSet.x) < fabsf(pointOffSet.y))
                            {
                                CC_CONTINUE_IF(responder->isReachBoundaryUp() && pointOffSet.y > 0);
                                CC_CONTINUE_IF(responder->isReachBoundaryDown() && pointOffSet.y < 0);
                            }
                        }

                        if (this->touchBeganWithResponder(responder))
                        {
                            m_vTouchesViews.pushBack(responder);
                        }
                        
                        break;
                    }
                    
                    if (m_vTouchesViews.empty())
                    {
                        m_vTouchesViews.pushBack(m_vTouchMovedsView.front());
                        
                        while (m_vTouchesViews.back())
                        {
                            if (this->touchBeganWithResponder(m_vTouchesViews.back()))
                            {
                                break;
                            }
                            m_vTouchesViews.popBack();
                        }
                        
                    }
                }
            }
        }

    }

    CAView* view = dynamic_cast<CAView*>(CAApplication::getApplication()->getTouchDispatcher()->getFirstResponder());
    bool isContainsFirstPoint = view && view->convertRectToWorldSpace(view->getBounds()).containsPoint(m_tFirstPoint);
    if (!isContainsFirstPoint && view && view->isScrollEnabled())
    {
        this->touchMovedWithResponder(view);
    }
    
    CAVector<CAResponder*>::iterator itr;
    for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++)
    {
        CC_CONTINUE_IF(!(*itr)->isScrollEnabled());
        this->touchMovedWithResponder(*itr);
    }
    
}