void CAPageView::ccTouchMoved(CATouch *pTouch, CAEvent *pEvent) { CC_RETURN_IF(m_pViews.empty()); CAScrollView::ccTouchMoved(pTouch, pEvent); }
void FourthViewController::playAnimation(CAControl* btn, CCPoint point) { CC_RETURN_IF(isDoAction); this->doAction(); }
void CALabel::setText(const string& var) { CC_RETURN_IF(m_nText.compare(var) == 0); m_nText = var; this->updateImageDraw(); }
void CommonUrlImageView::setUrl(const std::string& url) { CC_RETURN_IF(url.empty()); m_sUrl = DecodeURL(url); CommonHttpManager::getInstance()->get_image(m_sUrl, this, CommonHttpImage_selector(CommonUrlImageView::onRequestFinished), m_eType); }
void CAListViewCell::selectedListViewCell() { CC_RETURN_IF(m_pBackgroundView == NULL); m_pBackgroundView->setColor(ccc4(50, 193, 255, 255)); }
void CALabel::onEnterTransitionDidFinish() { CAView::onEnterTransitionDidFinish(); CC_RETURN_IF(m_nText.empty()); this->updateImage(); }
void CATabBarController::setTabBarHidden(bool hidden, bool animated) { CC_RETURN_IF(m_bTabBarHidden == hidden); m_bTabBarHidden = hidden; CC_RETURN_IF(this->getView()->getSuperview() == NULL); CCPoint point = CCPointZero; if (m_bTabBarHidden) { switch (m_eTabBarVerticalAlignment) { case CABarVerticalAlignmentTop: { point.y = -m_pTabBar->getFrame().size.height; } break; case CABarVerticalAlignmentBottom: { point.y = this->getView()->getBounds().size.height; } break; default: break; } } else { switch (m_eTabBarVerticalAlignment) { case CABarVerticalAlignmentTop: { point.y = 0; } break; case CABarVerticalAlignmentBottom: { point.y = this->getView()->getBounds().size.height - m_pTabBar->getFrame().size.height; } break; default: break; } } if (animated) { m_pTabBar->stopAllActions(); CCFrameOrginTo* moveTo = CCFrameOrginTo::create(0.3f, point); CCEaseSineOut* easeBack = CCEaseSineOut::create(moveTo); CCCallFunc* begin = CCCallFunc::create(this, callfunc_selector(CATabBarController::scheduleUpdate)); CCCallFunc* end = CCCallFunc::create(this, callfunc_selector(CATabBarController::unScheduleUpdate)); CCDelayTime* delayTime = CCDelayTime::create(0.1f); CCSequence* actions = CCSequence::create(begin, easeBack, delayTime, end, NULL); m_pTabBar->runAction(actions); } else { m_pTabBar->setFrameOrigin(point); if (this->getView()->getSuperview()) { this->update(0); } } }
void CAScrollView::ccTouchMoved(CATouch *pTouch, CAEvent *pEvent) { CC_RETURN_IF(m_bPCMode); CC_RETURN_IF(m_vTouches.contains(pTouch) == false); DPoint p_container = m_pContainer->getFrameOrigin(); DPoint p_off = DPointZero; if (m_vTouches.size() == 1) { p_off = ccpSub(this->convertToNodeSpace(pTouch->getLocation()), this->convertToNodeSpace(pTouch->getPreviousLocation())); DPoint off = p_off; if (off.getLength() <= 5) { off = DPointZero; } m_tPointOffset.push_back(off); } else if (m_vTouches.size() == 2) { CATouch* touch0 = dynamic_cast<CATouch*>(m_vTouches.at(0)); CATouch* touch1 = dynamic_cast<CATouch*>(m_vTouches.at(1)); DPoint mid_point = ccpMidpoint(this->convertToNodeSpace(touch0->getLocation()), this->convertToNodeSpace(touch1->getLocation())); p_off = ccpSub(mid_point, ccpAdd(p_container, m_pContainer->getAnchorPointInPoints() * m_fZoomScale)); if (m_fMinimumZoomScale < m_fMaximumZoomScale) { float touch_lenght = ccpDistance(this->convertToNodeSpace(touch0->getLocation()) , this->convertToNodeSpace(touch1->getLocation())); float scale_off = (touch_lenght - m_fTouchLength) * 0.0020f; m_fZoomScale = m_pContainer->getScale(); m_fZoomScale += m_fZoomScale * scale_off; m_fZoomScale = MIN(m_fZoomScale, m_fMaximumZoomScale); m_fZoomScale = MAX(m_fZoomScale, m_fMinimumZoomScale); m_pContainer->setScale(m_fZoomScale); m_fTouchLength = touch_lenght; } } if (m_bBounces) { DSize size = this->getBounds().size; DPoint curr_point = m_pContainer->getFrameOrigin(); DPoint relust_point = curr_point; this->getScrollWindowNotOutPoint(relust_point); float lenght_x = fabsf(curr_point.x - relust_point.x); float lenght_y = fabsf(curr_point.y - relust_point.y); DPoint scale = DPoint(1.0f, 1.0f); if (!(lenght_x < FLT_EPSILON)) { scale.x = (0.5f - MIN(lenght_x / size.width, 0.5f)); p_off.x *= scale.x; } if (!(lenght_y < FLT_EPSILON)) { scale.y = (0.5f - MIN(lenght_y / size.height, 0.5f)); p_off.y *= scale.y; } } p_container = ccpAdd(p_container, p_off); if (m_bBounces == false) { this->getScrollWindowNotOutPoint(p_container); } else { if (m_bBounceHorizontal == false) { p_container.x = this->getScrollWindowNotOutHorizontal(p_container.x); } if (m_bBounceVertical == false) { p_container.y = this->getScrollWindowNotOutVertical(p_container.y); } } if (p_container.equals(m_pContainer->getFrameOrigin()) == false) { if (m_bTouchEnabledAtSubviews) { m_pContainer->setTouchEnabled(false); } this->setContainerFrame(p_container); this->showIndicator(); if (m_bTracking == false) { if (m_pScrollViewDelegate) { m_pScrollViewDelegate->scrollViewWillBeginDragging(this); } m_bTracking = true; } if (m_pScrollViewDelegate) { m_pScrollViewDelegate->scrollViewDidScroll(this); m_pScrollViewDelegate->scrollViewDragging(this); m_pScrollViewDelegate->scrollViewDidMoved(this); } } this->changedFromPullToRefreshView(); }
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); } }
void CAIndicator::setIndicator(const DSize& parentSize, const DRect& childrenFrame) { CC_RETURN_IF(!this->isVisible()); CC_RETURN_IF(m_bTouch); CAScale9ImageView* indicator = dynamic_cast<CAScale9ImageView*>(m_pIndicator); if (m_eType == CAIndicatorTypeHorizontal) { float size_scale_x = parentSize.width / childrenFrame.size.width; size_scale_x = MIN(size_scale_x, 1.0f); float lenght_scale_x = parentSize.width / 2 - childrenFrame.origin.x; lenght_scale_x /= childrenFrame.size.width; DRect rect; rect.size = m_obContentSize; rect.size.width *= size_scale_x; if (lenght_scale_x < size_scale_x / 2) { rect.size.width *= lenght_scale_x / (size_scale_x / 2); } if (1 - lenght_scale_x < size_scale_x / 2) { rect.size.width *= (1 - lenght_scale_x) / (size_scale_x / 2); } rect.size.width = MAX(rect.size.height, rect.size.width); rect.origin = m_obContentSize; rect.origin.y *= 0.5f; rect.origin.x *= lenght_scale_x; rect.origin.x = MAX(rect.origin.x, rect.size.width/2); rect.origin.x = MIN(rect.origin.x, m_obContentSize.width - rect.size.width/2); indicator->setCenter(rect); } else if (m_eType == CAIndicatorTypeVertical) { float size_scale_y = parentSize.height / childrenFrame.size.height; size_scale_y = MIN(size_scale_y, 1.0f); float lenght_scale_y = parentSize.height / 2 - childrenFrame.origin.y; lenght_scale_y /= childrenFrame.size.height; DRect rect; rect.size = m_obContentSize; rect.size.height *= size_scale_y; if (lenght_scale_y < size_scale_y / 2) { rect.size.height *= lenght_scale_y / (size_scale_y / 2); } if (1 - lenght_scale_y < size_scale_y / 2) { rect.size.height *= (1 - lenght_scale_y) / (size_scale_y / 2); } rect.size.height = MAX(rect.size.height, rect.size.width); rect.origin = m_obContentSize; rect.origin.x *= 0.5f; rect.origin.y *= lenght_scale_y; rect.origin.y = MAX(rect.origin.y, rect.size.height/2); rect.origin.y = MIN(rect.origin.y, m_obContentSize.height - rect.size.height/2); indicator->setCenter(rect); } }
void CAScrollView::setTouchEnabledAtSubviews(bool var) { CC_RETURN_IF(m_bTouchEnabledAtSubviews == var); m_bTouchEnabledAtSubviews = var; m_pContainer->setTouchEnabled(var); }
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); } }
void CATableView::firstReloadData() { CC_RETURN_IF(!m_pUsedTableCells.empty()); this->reloadData(); }
void CATableView::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent) { CC_RETURN_IF(m_pTouches->containsObject(pTouch) == false); CAScrollView::ccTouchEnded(pTouch, pEvent); if (m_pHighlightedTableCells) { m_pContainer->stopAllActions(); CAIndexPath2E deselectedIndexPath = CAIndexPath2EZero; CAIndexPath2E selectedIndexPath = CAIndexPath2E(m_pHighlightedTableCells->getSection(), m_pHighlightedTableCells->getRow()); m_pHighlightedTableCells = NULL; if (m_pSelectedTableCells.count(selectedIndexPath) > 0 && m_bAllowsMultipleSelection) { deselectedIndexPath = selectedIndexPath; selectedIndexPath = CAIndexPath2EZero; m_pSelectedTableCells.erase(deselectedIndexPath); } else { if (!m_pSelectedTableCells.empty() && m_bAllowsMultipleSelection == false) { deselectedIndexPath = *m_pSelectedTableCells.begin(); m_pSelectedTableCells.clear(); } m_pSelectedTableCells.insert(selectedIndexPath); } if (deselectedIndexPath != CAIndexPath2EZero) { if (CATableViewCell* cell = m_pUsedTableCells[deselectedIndexPath]) { cell->setControlStateNormal(); } if (m_pTableViewDelegate) { m_pTableViewDelegate->tableViewDidDeselectRowAtIndexPath(this, deselectedIndexPath.section, deselectedIndexPath.row); } } if (selectedIndexPath != CAIndexPath2EZero) { if (CATableViewCell* cell = m_pUsedTableCells[selectedIndexPath]) { cell->setControlStateSelected(); } if (m_pTableViewDelegate) { m_pTableViewDelegate->tableViewDidSelectRowAtIndexPath(this, selectedIndexPath.section, selectedIndexPath.row); } } } }
void CATableViewCell::highlightedTableViewCell() { CC_RETURN_IF(m_pBackgroundView == NULL); m_pBackgroundView->setColor(ccc4(50, 193, 255, 255)); }
void CANavigationBar::setTitleColor(CAColor4B color) { m_cTitleColor = color; CC_RETURN_IF(!m_bRunning); this->showTitle(); }
void CAListView::firstReloadData() { CC_RETURN_IF(!m_pUsedListCells.empty()); this->reloadData(); }
void updateImage() { const std::string& sPlaceHolder = m_pTextFieldX->getPlaceHolderText(); CAColor4B cFontColor; std::string text; if (m_sText.empty()) { text = sPlaceHolder; cFontColor = m_pTextFieldX->getPlaceHolderColor(); } else { text = m_sText; cFontColor = m_pTextFieldX->getTextColor(); } if (m_pTextFieldX->isSecureTextEntry()) { std::string password; for (std::string::size_type i = 0; i < m_sText.length(); i++) { password.append("*"); } if (password.empty()) { text = sPlaceHolder; } else { text = password; } } int fontSize = m_pTextFieldX->getFontSize(); m_iFontHeight = CAImage::getFontHeight(m_szFontName.c_str(), fontSize); DSize size = DSize(0, m_iFontHeight); CAImage* image = CAImage::createWithString(text.c_str(), cFontColor, m_szFontName.c_str(), fontSize, size, CATextAlignmentLeft, CAVerticalTextAlignmentCenter, true); DRect rect = DRectZero; if (sPlaceHolder.length() == 0) { this->setImage(image); this->setImageRect(rect); } CC_RETURN_IF(image == NULL); rect.size.height = image->getContentSize().height; rect.size.width = MIN(m_iLabelWidth, image->getContentSize().width); if (text.empty()) { m_cImageSize = DSizeZero; } else { m_cImageSize = image->getContentSize(); } this->setImage(image); rect.origin.x = -m_iString_o_length; this->setImageRect(rect); }
void CAAutoCollectionView::firstReloadData() { CC_RETURN_IF(!m_mpUsedCollectionCells.empty()); this->reloadData(); }
void CANavigationController::setNavigationBarHidden(bool hidden, bool animated) { CC_RETURN_IF(m_bNavigationBarHidden == hidden); m_bNavigationBarHidden = hidden; CC_RETURN_IF(this->getView()->getSuperview() == NULL); CCPoint point = CCPointZero; if (m_bNavigationBarHidden) { switch (m_eNavigationBarVerticalAlignment) { case CABarVerticalAlignmentTop: { point.y = -m_pNavigationBar->getFrame().size.height; } break; case CABarVerticalAlignmentBottom: { point.y = this->getView()->getBounds().size.height; } break; default: break; } } else { switch (m_eNavigationBarVerticalAlignment) { case CABarVerticalAlignmentTop: { point.y = 0; } break; case CABarVerticalAlignmentBottom: { point.y = this->getView()->getBounds().size.height - m_pNavigationBar->getFrame().size.height; } break; default: break; } } if (animated) { CCArray* array = CCArray::create(); array->addObject(CCEaseSineOut::create(CCFrameOrginTo::create(0.2f, point))); array->addObject(CCCallFunc::create(this, callfunc_selector(CANavigationController::scheduleUpdate))); array->addObject(CCCallFunc::create(this, callfunc_selector(CANavigationController::unScheduleUpdate))); array->addObject(CCDelayTime::create(0.1f)); m_pNavigationBar->runAction(CCSequence::create(array)); } else { m_pNavigationBar->setFrameOrigin(point); if (this->getView()->getSuperview()) { this->update(0); } } }
void CommonHttpResponseCallBack::onResponseJson(CAHttpClient* client, CAHttpResponse* response) { CommonHttpManager::getInstance()->stopActivityIndicatorView(); CC_RETURN_IF(!m_pSelectorJson); if (response->isSucceed()) { std::string data(response->getResponseData()->begin(), response->getResponseData()->end()); if (!data.empty()) { localStorageSetItem(MD5(m_sUrl).md5().c_str(), data.c_str()); if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget)) { CC_RETURN_IF(viewController->isViewRunning() == false); } //CCLog("\n \n \n---------HttpResponse--json---------\n<<<\n%s\n>>>\n--------------END--------------\n \n \n",data.c_str()); CSJson::Reader read; CSJson::Value root; bool succ = read.parse(data, root); if (succ == false) { CCLog("GetParseError \n"); } if (m_pTarget) { (m_pTarget->*m_pSelectorJson)(HttpResponseSucceed, root); } } else { if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget)) { CC_RETURN_IF(viewController->isViewRunning() == false); } CSJson::Value root; if (m_pTarget) { (m_pTarget->*m_pSelectorJson)(HttpResponseFaild, root); } } } else { if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget)) { CC_RETURN_IF(viewController->isViewRunning() == false); } const char* data = localStorageGetItem(MD5(m_sUrl).md5().c_str()); do { CC_BREAK_IF(data == NULL); CSJson::Reader read; CSJson::Value root; bool succ = read.parse(data, root); if (succ == false) { CCLog("GetParseError \n"); break; } if (m_pTarget) { (m_pTarget->*m_pSelectorJson)(HttpResponseSucceed, root); } return; } while (0); CSJson::Value root; if (m_pTarget) { (m_pTarget->*m_pSelectorJson)(HttpResponseFaild, root); } } }
void CATabBarController::tabBarSelectedItem(CATabBar* tabBar, CATabBarItem* item, unsigned int index) { CC_RETURN_IF(m_nSelectedIndex == index); this->showSelectedViewControllerAtIndex(index); }
void CAListViewCell::normalListViewCell() { CC_RETURN_IF(m_pBackgroundView == NULL); m_pBackgroundView->setColor(ccc4(255, 255, 255, 255)); }
void CANavigationController::viewDidDisappear() { CC_RETURN_IF(m_pViewControllers.empty()); m_pViewControllers.back()->viewDidDisappear(); }
void CAListViewCell::disabledListViewCell() { CC_RETURN_IF(m_pBackgroundView == NULL); m_pBackgroundView->setColor(ccc4(127, 127, 127, 255)); }
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(); }
void CALabel::updateImage() { int fontHeight = CAImage::getFontHeight(m_nfontName.c_str(), m_nfontSize); int defaultLineSpace = fontHeight / 4; unsigned int linenumber = (int)this->getBounds().size.height / fontHeight; CCSize size = CCSizeZero; if (m_bFitFlag) { float width = CAImage::getStringWidth(m_nfontName.c_str(), m_nfontSize, m_nText); if (width > m_obContentSize.width) { if (m_nNumberOfLine > 1) { size = CCSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * m_nNumberOfLine); } else if (m_nNumberOfLine == 1) { size = CCSize(width, fontHeight); } else { size.width = this->getBounds().size.width; size.height = CAImage::getStringHeight(m_nfontName.c_str(), m_nfontSize, m_nText, size.width, m_iLineSpacing, m_bWordWrap); } } else { size.height = fontHeight; size.width = width; } } else { if (linenumber == 0) { size = this->getBounds().size; } else { if (m_nNumberOfLine > 0) { size = CCSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * MIN(m_nNumberOfLine, linenumber)); } else { size = CCSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * linenumber); } } } CAImage* image = CAImage::createWithString(m_nText.c_str(), m_nfontName.c_str(), m_nfontSize, size, m_nTextAlignment, m_nVerticalTextAlignmet, m_bWordWrap, m_iLineSpacing, m_bBold, m_bItalics, m_bUnderLine); this->setImage(image); CC_RETURN_IF(image == NULL); m_cLabelSize = size; CCRect rect = CCRectZero; rect.size.width = this->getBounds().size.width; rect.size.height = size.height; float width = m_bFitFlag ? image->getContentSize().width : MIN(this->getBounds().size.width, image->getContentSize().width); rect.size.width = width; switch (m_nVerticalTextAlignmet) { case CAVerticalTextAlignmentTop: pTextHeight = 0; break; case CAVerticalTextAlignmentCenter: pTextHeight = (this->getBounds().size.height - rect.size.height) / 2; break; case CAVerticalTextAlignmentBottom: pTextHeight = this->getBounds().size.height - rect.size.height; break; default: break; } if (m_bFitFlag) { if (!size.equals(m_obContentSize)) { if (m_bFrame) { CCRect rect = this->getFrame(); rect.size = size; this->setFrame(rect); } else { CCRect rect = this->getCenter(); rect.size = size; this->setCenter(rect); } } } this->setImageRect(rect); }
void CAButton::setControlState(const CAControlState& var) { CAControl::setControlState(var); CC_RETURN_IF(var == CAControlStateAll); for (int i=0; i<CAControlStateAll; i++) { this->removeSubview(m_pBackGroundView[i]); } m_eControlState = var; if (m_bControlStateLocked) { m_eControlState = CAControlStateNormal; } if (m_pBackGroundView[m_eControlState] && m_eControlState != CAControlStateNormal) { m_pBackGroundView[m_eControlState]->setFrame(this->getBounds()); this->insertSubview(m_pBackGroundView[m_eControlState], -1); } else if (m_pBackGroundView[CAControlStateNormal]) { m_pBackGroundView[CAControlStateNormal]->setFrame(this->getBounds()); this->insertSubview(m_pBackGroundView[CAControlStateNormal], -1); } if (m_eControlState == CAControlStateSelected) { m_bSelected = true; } else if(m_eControlState != CAControlStateHighlighted) { m_bSelected = false; } CAImage* image = NULL; std::string title = ""; CCRect imageViewCenter = CCRectZero; CCRect rect = CCRectZero; CCRect labelCenter = this->getBounds(); float labelSize = 0; image = m_pImage[m_eControlState]; title = m_sTitle[m_eControlState]; if (image == NULL) { image = this->isSelected() ? m_pImage[CAControlStateSelected] : m_pImage[CAControlStateNormal]; } if (strcmp(title.c_str(), "") == 0) { title = this->isSelected() ? m_sTitle[CAControlStateSelected] : m_sTitle[CAControlStateNormal]; } if (image && title.compare("") == 0) { CCSize size = this->getBounds().size; CCSize iSize = image->getContentSize(); float scaleX = size.width / iSize.width * 0.75f; float scaleY = size.height / iSize.height * 0.75f; float scale = MIN(scaleX, scaleY); scale = MIN(scale, 1.0f); iSize = ccpMult(iSize, scale); imageViewCenter.origin = size / 2; imageViewCenter.size = iSize; } else if (image == NULL && title.compare("") != 0) { labelSize = this->getBounds().size.height * 0.4f; labelCenter.origin = this->getBounds().size / 2 ; } else if (image && title.compare("") != 0) { CCSize size = this->getBounds().size; CCSize iSize = image->getContentSize(); float scaleX = size.width / iSize.width * 0.5f; float scaleY = size.height / iSize.height * 0.45f; float scale = MIN(scaleX, scaleY); scale = MIN(scale, 1.0f); iSize = ccpMult(iSize, scale); imageViewCenter.size = iSize; imageViewCenter.origin.x = size.width / 2; imageViewCenter.origin.y = size.height * 0.35f; labelSize = size.height * 0.2f; labelCenter.origin.x = size.width / 2; labelCenter.origin.y = size.height * 0.75f; } m_pImageView->setColor(m_sImageColor[m_eControlState]); m_pImageView->setCenter(imageViewCenter); if (image != m_pImageView->getImage()) { m_pImageView->setImage(image); } m_pLabel->setColor(m_sTitleColor[m_eControlState]); m_pLabel->setCenter(labelCenter); if (!title.empty()) { m_pLabel->setFontSize(labelSize); } if (strcmp(title.c_str(), m_pLabel->getText().c_str())) { m_pLabel->setText(title.c_str()); } }
void CALabel::setLineSpacing(int var) { CC_RETURN_IF(m_iLineSpacing == var); m_iLineSpacing = var; this->updateImageDraw(); }
void CAPageView::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent) { CAScrollView::ccTouchEnded(pTouch, pEvent); CC_RETURN_IF(m_vTouches.size() > 1); if (m_ePageViewDirection == CAPageViewDirectionHorizontal) { float off_x = -m_tInertia.x; if (off_x > 0) { m_ePageViewState = Next; } else if (off_x < 0) { m_ePageViewState = Last; } else { m_ePageViewState = None; } } else { float off_y = -m_tInertia.y; if (off_y > 0) { m_ePageViewState = Next; } else if (off_y < 0) { m_ePageViewState = Last; } else { m_ePageViewState = None; } } int page = this->getCurrPage(); if (m_ePageViewState == Next) { page++; } else if (m_ePageViewState == Last) { page--; } else { if (m_ePageViewDirection == CAPageViewDirectionHorizontal) { float width = this->getBounds().size.width; float off_x = this->getContentOffset().x - this->getCurrPage() * width; if (off_x > width/2) { page++; } else if (off_x < -width/2) { page--; } } else { float height = this->getBounds().size.height; float off_y = this->getContentOffset().y - this->getCurrPage() * height; if (off_y > height/2) { page++; } else if (off_y < -height/2) { page--; } } } if (!pTouch->isDelta()) { if (m_pPageViewDelegate) { DPoint point = this->convertTouchToNodeSpace(pTouch); m_pPageViewDelegate->pageViewDidSelectPageAtIndex(this, this->getCurrPage(), point); } this->runAnimation(true); } else { page = MIN(page, (int)this->getPageCount() - 1); page = MAX(page, 0); this->setCurrPage(page, true, true); } }