Beispiel #1
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);
}
DPoint CAView::convertToNodeSpace(const DPoint& worldPoint)
{
    DPoint ret = worldPoint;//DPointApplyAffineTransform(p, worldToNodeTransform());
    for (CAView* v = this; v; v = v->m_pSuperview)
    {
        ret.x -= v->getFrameOrigin().x;
        ret.y -= v->getFrameOrigin().y;
    }
    return ret;
}
DPoint CAView::convertToWorldSpace(const DPoint& nodePoint)
{
    DPoint p = nodePoint;
    
    DPoint ret = p;//DPointApplyAffineTransform(p, nodeToWorldTransform());
    for (CAView* v = this; v; v = v->m_pSuperview)
    {
        ret.x += v->getFrameOrigin().x;
        ret.y += v->getFrameOrigin().y;
    }
    return ret;
}
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());
    }
}