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); }
void DMCatalogController::initWithCollectionView() { CADipRect rect = this->getView()->getBounds(); m_uiItems = (unsigned int)(rect.size.width / 300); m_uiItems = MIN(m_uiItems, 5); m_uiItems = MAX(m_uiItems, 3); m_pCollectionView = CACollectionView::createWithFrame(rect); m_pCollectionView->setCollectionViewDataSource(this); m_pCollectionView->setCollectionViewDelegate(this); m_pCollectionView->setScrollViewDelegate(this); CAPullToRefreshView* view = CAPullToRefreshView::create(CAPullToRefreshView::CAPullToRefreshTypeHeader); m_pCollectionView->setHeaderRefreshView(view); m_pCollectionView->setBackGroundColor(CAColor_clear); this->getView()->addSubview(m_pCollectionView); m_pCollectionView->setAllowsSelection(true); m_pCollectionView->setHoriInterval(_px(30)); m_pCollectionView->setVertInterval(_px(10)); float width = this->getView()->getBounds().size.width; m_pCollectionView->setCollectionHeaderHeight(width * 15/32.0f); CAButton* bg = CAButton::createWithFrame(CADipRect(0, 0, rect.size.width, _dip(m_pCollectionView->getCollectionHeaderHeight())), CAButtonTypeCustom); m_pHeaderImageView = CommonUrlImageView::createWithImage(NULL); bg->setBackGroundViewForState(CAControlStateNormal, m_pHeaderImageView); bg->addTarget(this, CAControl_selector(DMCatalogController::onButton), CAControlEventTouchUpInSide); m_pCollectionView->setCollectionHeaderView(bg); CADipRect headerRect = CADipRectZero; headerRect.size = rect.size; headerRect.size.height = 76; headerRect.origin.y = _dip(m_pCollectionView->getCollectionHeaderHeight()) - 76; CAImageView* imageView = CAImageView::createWithFrame(headerRect); imageView->setImage(CAImage::create(title_bg_first)); bg->insertSubview(imageView,1); headerRect.origin.x = 25; headerRect.size.height -= 20; headerRect.size.width -= headerRect.origin.x; headerRect.origin.y = _dip(m_pCollectionView->getCollectionHeaderHeight()) - headerRect.size.height; m_pHeaderLabel = CALabel::createWithFrame(headerRect); m_pHeaderLabel->setFontSize(_px(28)); m_pHeaderLabel->setColor(CAColor_white); m_pHeaderLabel->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); bg->insertSubview(m_pHeaderLabel,1); if (!m_mvData[m_sTitle].empty()) { const DMBriefInfo& info = m_mvData[m_sTitle].front(); m_pHeaderLabel->setText("《" + info.title + "》" + info.subtitle); m_pHeaderImageView->setUrl(info.cover); } }
void UtilManager::toast(string text, string image, bool isSmall) { CAApplication::getApplication()->getRootWindow()->removeSubviewByTag(TOAST_VIEW_TAG); CCSize winSize = CAApplication::getApplication()->getWinSize(); CAImageView *back = CAImageView::create(); if (isSmall == false) { //CAView *back = CAView::createWithCenter(CCRect(winSize.width*0.5, winSize.height*0.5, _dip(winSize.width)*0.3, _dip(winSize.height)*0.3)); back->setCenter(CCRect(winSize.width*0.5, winSize.height*0.55, _px(120), _px(120))); } else { back->setCenter(CCRect(winSize.width*0.5, winSize.height*0.4, _px(120), _px(120))); } back->setTag(TOAST_VIEW_TAG); back->setImage(CAImage::create("image/scape_storage.png")); //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.8), 100, 100)); //title->setText(UTF8ToGBK::transferToGbk(text)); //title->setFontName(getChineseFont()); title->setColor(CAColor_white); title->setTextAlignment(CATextAlignmentCenter); title->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); title->setFontSize(_px(22)); back->addSubview(title); CAImageView *icon = CAImageView::create(); if (isSmall == false) { //CAView *back = CAView::createWithCenter(CCRect(winSize.width*0.5, winSize.height*0.5, _dip(winSize.width)*0.3, _dip(winSize.height)*0.3)); icon->setCenter(CADipRect(_dip(back->getBounds().size.width*0.5), _dip(back->getBounds().size.height*0.4), 90 / 1.5, 68 / 1.5)); } else { icon->setCenter(CADipRect(_dip(back->getBounds().size.width*0.5), _dip(back->getBounds().size.height*0.4), 72 / 1.5, 72 / 1.5)); } //CAImageView *icon = CAImageView::createWithCenter(CADipRect(_dip(back->getBounds().size.width*0.5),_dip(back->getBounds().size.height*0.4), 105/1.5, 95/1.5)); icon->setImage(CAImage::create(image)); back->addSubview(icon); CAApplication::getApplication()->getRootWindow()->addSubview(back); //CCLog("%s", get_date_now().c_str()); icon->runAction(CCSequence::createWithTwoActions(CCDelayTime::create(0.3), CCFadeOut::create(TOAST_TIME / 2.0))); back->runAction(CCSequence::createWithTwoActions(CCDelayTime::create(0.3), CCFadeOut::create(TOAST_TIME))); scheduleOnce(schedule_selector(UtilManager::removeToast), this, TOAST_TIME); }
CADipSize& CADipSize::operator= (const CCPoint& other) { this->width = _dip(other.x); this->height = _dip(other.y); return *this; }
CADipSize& CADipSize::operator= (const CCSize& other) { this->width = _dip(other.width); this->height = _dip(other.height); return *this; }
CADipSize::CADipSize(const CCPoint& other) :width(_dip(other.x)) ,height(_dip(other.y)) { }
CADipSize::CADipSize(const CCSize& other) :width(_dip(other.width)) ,height(_dip(other.height)) { }
CADipPoint& CADipPoint::operator= (const CCSize& other) { this->x = _dip(other.width); this->y = _dip(other.height); return *this; }
CADipPoint& CADipPoint::operator= (const CCPoint& other) { this->x = _dip(other.x); this->y = _dip(other.y); return *this; }
CADipPoint::CADipPoint(const CCSize& other) :x(_dip(other.width)) ,y(_dip(other.height)) { }
CADipPoint::CADipPoint(const CCPoint& other) :x(_dip(other.x)) ,y(_dip(other.y)) { }
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 = _dip(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) { 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(); }