CAButton* CAButton::createWithCenter(const CCRect& rect, const CAButtonType& buttonType) { CAButton* btn = new CAButton(buttonType); if (btn && btn->initWithCenter(rect)) { btn->autorelease(); return btn; } CC_SAFE_DELETE(btn); return NULL; }
CAButton* CAButton::create(const CAButtonType& buttonType) { CAButton* btn = new CAButton(buttonType); if (btn && btn->init()) { btn->autorelease(); return btn; } CC_SAFE_DELETE(btn); return NULL; }
void CANavigationBar::showRightButton() { std::vector<CAButton*>::iterator itr; for (itr = m_pRightButtons.begin(); itr != m_pRightButtons.end(); itr++) { (*itr)->removeFromSuperview(); } m_pRightButtons.clear(); const CAVector<CAObject*>& buttonItems = m_pItem->getRightButtonItems(); CCRect rect; rect.size.width = this->getBounds().size.height * 0.9f; rect.size.height = this->getBounds().size.height * 0.8f; rect.origin.x = this->getBounds().size.width - rect.size.width * 0.7f; rect.origin.y = this->getBounds().size.height * 0.5f; for (size_t i=0; i<buttonItems.size(); i++) { CABarButtonItem* item = dynamic_cast<CABarButtonItem*>(buttonItems.at(i)); rect.size.width = item ? item->getItemWidth() : _px(80); rect.origin.x -= i * rect.size.width; CAButton* button = CAButton::createWithCenter(rect, CAButtonTypeCustom); this->addSubview(button); if (item) { if (item->getImage()) { button->setImageForState(CAControlStateNormal, item->getImage()); if (item->getHighlightedImage()) { button->setImageForState(CAControlStateHighlighted, item->getHighlightedImage()); } else { button->setImageColorForState(CAControlStateHighlighted, ccc4(127, 127, 127, 255)); } } else { button->setTitleForState(CAControlStateNormal, item->getTitle()); button->setTitleColorForState(CAControlStateNormal, m_cButtonColor); button->setTitleForState(CAControlStateHighlighted, item->getTitle()); button->setTitleColorForState(CAControlStateHighlighted, ccc4(m_cButtonColor.r/2, m_cButtonColor.g/2, m_cButtonColor.b/2, 255)); } button->addTarget(item->getTarget(), item->getSel(), CAControlEventTouchUpInSide); } m_pRightButtons.push_back(button); } }
void RecipeListViewController::onClickSelectAllButton(CAControl* btn,DPoint point) { CAButton *curBtn = (CAButton*)btn; if(isSelectedAll()) { setAllCheckBoxState(false); curBtn->setTitleForState(CAControlState::CAControlStateAll, "全选"); } else { setAllCheckBoxState(true); curBtn->setTitleForState(CAControlState::CAControlStateAll, "全不选"); } p_TableView->reloadData(); }
bool CASegmentedControl::setTitleColorAtIndex(CAColor4B color, int index, CAControlState controlState) { if (!this->indexIsValid(index)) { return false; } CAButton *btn = m_segments.at(index); if (NULL == btn) { return false; } btn->setTitleColorForState(controlState, color); return true; }
bool CASegmentedControl::setTitleAtIndex(const char* title, int index, CAControlState controlState) { if (!this->indexIsValid(index)) { return false; } CAButton *btn = m_segments.at(index); if (NULL == btn) { return false; } btn->setTitleForState(controlState, title); return true; }
bool CASegmentedControl::setImageAtIndex(CAImage *image, int index, CAControlState controlState) { if (!this->indexIsValid(index)) { return false; } CAButton *btn = m_segments.at(index); if (NULL == btn) { return false; } btn->setImageForState(controlState, image); return true; }
bool CASegmentedControl::setBackgroundImageAtIndex(CAImage *image, int index, CAControlState controlState) { if (!this->indexIsValid(index)) { return false; } CAButton *btn = m_segments.at(index); if (NULL == btn) { return false; } btn->setBackGroundViewForState(controlState, CAScale9ImageView::createWithImage(image)); return true; }
bool CASegmentedControl::setBackgroundViewAtIndex(CAView *view, int index, const CAControlState& controlState) { if (!this->indexIsValid(index)) { return false; } CAButton *btn = m_segments.at(index); if (NULL == btn) { return false; } btn->setBackGroundViewForState(controlState, view); return true; }
void NoticeDetailViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. m_winSize = this->getView()->getBounds().size; CAScale9ImageView* sView = CAScale9ImageView::createWithImage(CAImage::create("common/sky_bg.png")); sView->setFrame(DRect((0), (0), m_winSize.width, (120))); this->getView()->addSubview(sView); CAButton* button = CAButton::createWithFrame(DRect((0), (20), (100), (100)), CAButtonTypeCustom); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/nav_back.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); imageView->setFrame(DRect((20), (20), (80), (80))); button->setBackgroundViewForState(CAControlStateAll, imageView); button->addTarget(this, CAControl_selector(NoticeDetailViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(20); sView->addSubview(button); CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 2, (70), m_winSize.width, (50))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_white); label->setTouchEnabled(false); label->setFontSize((40)); label->setText("Notice"); label->setFontName(SAP_FONT_ARIAL); sView->addSubview(label); label = CALabel::createWithFrame(DRect(0, (200), m_winSize.width, (60))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_gray); label->setTouchEnabled(false); label->setFontSize((40)); label->setText(m_title); label->setFontName(SAP_FONT_ARIAL); this->getView()->addSubview(label); label = CALabel::createWithFrame(DRect(40, (300), m_winSize.width - 80, (800))); label->setTextAlignment(CATextAlignmentLeft); label->setColor(CAColor_gray); label->setTouchEnabled(false); label->setFontSize((30)); label->setText(m_detail); label->setFontName(SAP_FONT_ARIAL); this->getView()->addSubview(label); CCLog("%f", CAApplication::getApplication()->getWinSize().width); }
void ButtonTest::threeButtonType(void) { CADipSize size = typeView->getBounds().size; CALabel* buttonType = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.2, size.width*0.4, 50)); buttonType->setText("DefaultType"); buttonType->setFontSize(_px(30)); buttonType->setTextAlignment(CATextAlignmentCenter); buttonType->setColor(ccc4(51, 204, 255, 255)); typeView->addSubview(buttonType); CAButton* defaultBtn = CAButton::create(CAButtonTypeCustom); defaultBtn->setCenter(CADipRect(size.width*0.25 - 50, size.height*0.5, size.width*0.25, size.height*0.1)); defaultBtn->setTitleForState(CAControlStateNormal, "Noborder"); defaultBtn->setTitleColorForState(CAControlStateNormal, CAColor_blueStyle); typeView->addSubview(defaultBtn); CALabel* custom = CALabel::createWithCenter(CADipRect(size.width*0.25 - 50, size.height*0.5 + 80, size.width*0.3, 50)); custom->setText("(Custom)"); custom->setFontSize(_px(20)); custom->setTextAlignment(CATextAlignmentCenter); custom->setColor(ccc4(51, 204, 255, 255)); typeView->addSubview(custom); CAButton* squareRectBtn = CAButton::create(CAButtonTypeSquareRect); squareRectBtn->setCenter(CADipRect(size.width*0.5, size.height*0.5, size.width*0.25, size.height*0.1)); squareRectBtn->setTitleForState(CAControlStateAll,"SquareRect"); typeView->addSubview(squareRectBtn); CALabel* square = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.5 + 80, size.width*0.3, 50)); square->setText("(SquareRect)"); square->setFontSize(_px(20)); square->setTextAlignment(CATextAlignmentCenter); square->setColor(CAColor_blueStyle); typeView->addSubview(square); CAButton* roundedRectBtn = CAButton::create(CAButtonTypeRoundedRect); roundedRectBtn->setCenter(CADipRect(size.width*0.75 + 50, size.height*0.5, size.width*0.25, size.height*0.1)); roundedRectBtn->setTitleForState(CAControlStateAll, "RoundedRect"); typeView->addSubview(roundedRectBtn); CALabel* rounded = CALabel::createWithCenter(CADipRect(size.width*0.75 + 50, size.height*0.5 + 80, size.width*0.3, 50)); rounded->setText("(RoundedRect)"); rounded->setFontSize(_px(20)); rounded->setTextAlignment(CATextAlignmentCenter); rounded->setColor(CAColor_blueStyle); typeView->addSubview(rounded); }
void MyTableViewCell::initCell() { CADipSize cellSize = this->getFrame().size; CALabel* cellText = CALabel::createWithCenter(CADipRect(cellSize.width*0.1, cellSize.height*0.5, cellSize.width*0.3, cellSize.height*0.8)); cellText->setTag(100); cellText->setFontSize(30 * CROSSAPP_ADPTATION_RATIO); cellText->setColor(CAColor_blueStyle); cellText->setTextAlignment(CATextAlignmentCenter); cellText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); this->addSubview(cellText); CAButton* cellBtn = CAButton::createWithCenter(CADipRect(cellSize.width*0.8, cellSize.height*0.5, cellSize.width*0.2, cellSize.height*0.5), CAButtonTypeRoundedRect); cellBtn->setTag(102); cellBtn->setTitleForState(CAControlStateAll, "Touch"); cellBtn->addTarget(this, CAControl_selector(MyTableViewCell::cellBtnCallback), CAControlEventTouchUpInSide); this->addSubview(cellBtn); }
void CASegmentedControl::layoutSubviews() { const CCSize controlSize = this->getBounds().size; const int totalCount = this->getItemCount(); const float elemWidth = controlSize.width / totalCount; m_itemSize = CCSize(elemWidth, controlSize.height); CCRect elemFrame = CCRect(0, 0, m_itemSize.width, m_itemSize.height); for (int i = 0; i < totalCount; ++i) { CAButton *btn = m_segments.at(i); if (btn) { btn->setFrame(elemFrame); btn->setControlState((m_selectedIndex == i) ? CAControlStateSelected : CAControlStateNormal); } elemFrame.origin.x += elemWidth; } }
void CATabBar::replaceItemAtIndex(size_t index, CATabBarItem* item) { if (index < m_pItems.size()) { m_pItems.replace(index, item); if (!m_pButtons.empty()) { CAButton* btn = m_pButtons.at(index); btn->setTitleForState(CAControlStateAll, item->getTitle()); btn->setImageForState(CAControlStateNormal, item->getImage()); CAImage* selectedImage = item->getSelectedImage() ? item->getSelectedImage() : item->getImage(); btn->setImageForState(CAControlStateHighlighted, selectedImage); btn->setImageForState(CAControlStateSelected, selectedImage); CABadgeView* badgeView = m_pBadgeViews.at(index); badgeView->setBadgeText(item->getBadgeValue()); } } }
bool CASegmentedControl::initWithCenter(const CCRect& rect) { if (!CAControl::init()) { return false; } this->setCenter(rect); m_selectedIndex = 0; this->removeAllSegments(); const float elemWidth = rect.size.width / m_nItemsCount; m_itemSize = CCSize(elemWidth, rect.size.height); CCRect elemFrame = CCRect(0, 0, m_itemSize.width, m_itemSize.height); for (int i = 0; i < m_nItemsCount; ++i) { CAButton *btn = this->createDefaultSegment(); if (btn) { btn->setFrame(elemFrame); char tmp[8] = {0}; snprintf(tmp, 8, "%d", i); btn->setTitleForState(CAControlStateNormal, tmp); btn->setTitleForState(CAControlStateSelected, tmp); btn->setTitleForState(CAControlStateHighlighted, tmp); m_segments.push_back(btn); this->addSubview(btn); btn->setControlState((m_selectedIndex == i) ? CAControlStateSelected : CAControlStateNormal); } elemFrame.origin.x += elemWidth; } return true; }
void FourthViewController::buttonCallback(CrossApp::CAControl *btn, CrossApp::CCPoint point) { point = btn->convertToWorldSpace(point); CAButton* button = (CAButton*)btn; if (button->getTag() == 1) { --action_index; action_index = MAX(action_index, 0); } else { ++action_index; action_index = MIN(action_index, 9); } defaultBtnL->setVisible(action_index > 0); defaultBtnR->setVisible(action_index < 9); if (action_index < 6) { char str[32]; sprintf(str, "play animation %d", action_index+1); defaultLable->setText(str); } else if (action_index < 9) { char str[32]; sprintf(str, "play animation %d", action_index+1 - 6); defaultLable->setText(str); } else { defaultLable->setText("play animation delay"); } flag = true; this->refreshView(false); }
CCObject* CAUIHelper::addButton(CSJson::Value jsonValue, cocos2d::CCRect &uiRect) { CAButton *btn = CAButton::createWithFrame(uiRect, CAButtonTypeRoundedRect); int tag = jsonValue["tag"].asInt(); // bool isEffect = jsonValue["isEffect"].asBool(); // bool isClick = jsonValue["isClick"].asBool(); // bool isTouchSuspend = jsonValue["isTouchSuspend"].asBool(); CAControlState btnState = (CAControlState)jsonValue["btnState"].asInt(); int alpha = jsonValue["alpha"].asInt(); std::string imageRes = jsonValue["backgroundImage"].asString(); mCAButtonType btntype = (mCAButtonType)jsonValue["btnType"].asInt(); btn->setTag(tag); btn->setOpacity(alpha); btn->setControlState(btnState); if (btntype == ButtonColor) { } else if (btntype == ButtonGrid9) { CAScale9ImageView *image = CAScale9ImageView::createWithImage(CAImage::create(imageRes.c_str())); btn->setBackGroundViewForState(CAControlStateNormal, image); } else if (btntype == ButtonImage) { } else if (btntype == ButtonNone) { } return btn; }
void CANavigationBar::showRightButton() { std::vector<CAButton*>::iterator itr; for (itr = m_pRightButtons.begin(); itr != m_pRightButtons.end(); itr++) { (*itr)->removeFromSuperview(); } m_pRightButtons.clear(); CCArray* buttonItems = m_pItems.back()->getRightButtonItems(); CCRect rect = this->getBounds(); rect.size.width = rect.size.height * 0.9f; rect.size.height *= 0.8f; rect.origin.x = this->getBounds().size.width - rect.size.width * 0.7f; rect.origin.y = this->getBounds().size.height / 2; for (int i=0; i<buttonItems->count(); i++) { rect.origin.x -= i * rect.size.width * 1.1f; CAButton* button = CAButton::createWithCenter(rect, CAButtonTypeCustom); this->addSubview(button); CABarButtonItem* item = dynamic_cast<CABarButtonItem*>(buttonItems->objectAtIndex(i)); if (item) { button->setTitleForState(CAControlStateNormal, item->getTitle()); button->setTitleColorForState(CAControlStateNormal, CAColor_white); button->setTitleForState(CAControlStateHighlighted, item->getTitle()); button->setTitleColorForState(CAControlStateHighlighted, ccc4(255, 255, 200, 255)); button->setImageForState(CAControlStateNormal, item->getImage()); if (item->getHighlightedImage()) { button->setImageForState(CAControlStateHighlighted, item->getHighlightedImage()); } else { button->setImageColorForState(CAControlStateHighlighted, ccc4(255, 255, 200, 255)); } button->addTarget(item->getTarget(), item->getSel(), CAControlEventTouchUpInSide); } m_pRightButtons.push_back(button); } }
void SessionsViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. m_winSize = this->getView()->getBounds().size; CAScale9ImageView* sView = CAScale9ImageView::createWithImage(CAImage::create("common/sky_bg.png")); sView->setFrame(DRect(_px(0), _px(0), m_winSize.width, _px(120))); this->getView()->addSubview(sView); CAButton* button = CAButton::createWithFrame(DRect(_px(20), _px(20), _px(100), _px(100)), CAButtonTypeCustom); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("main/nav_notification.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); button->setBackGroundViewForState(CAControlStateAll, imageView); button->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(20); this->getView()->addSubview(button); m_timeNoticeImageView = CAImageView::createWithFrame(DRect(_px(60), _px(30), _px(10), _px(10))); m_timeNoticeImageView->setImage(CAImage::create("common/reddot.png")); button->addSubview(m_timeNoticeImageView); button = CAButton::createWithFrame(DRect(m_winSize.width - _px(120), _px(20), _px(100), _px(100)), CAButtonTypeCustom); imageView = CAImageView::createWithImage(CAImage::create("main/nav_prize.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); button->setBackGroundViewForState(CAControlStateAll, imageView); button->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(30); this->getView()->addSubview(button); CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 2, _px(70), m_winSize.width, _px(40))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_white); label->setFontSize(_px(40)); label->setText("Agenda"); label->setFontName("fonts/arial.ttf"); sView->addSubview(label); if (m_msg.empty()) { requestMsg(); } else { this->initMsgTableView(); } CCLog("%f", CAApplication::getApplication()->getWinSize().width); }
bool CASegmentedControl::initWithCenter(const CCRect& rect) { if (!CAControl::initWithCenter(rect)) { return false; } this->removeAllSegments(); const float elemWidth = this->getBounds().size.width / m_nItemsCount; m_itemSize = CCSizeMake(elemWidth, this->getBounds().size.height); CCRect elemFrame = CCRectMake(0, 0, m_itemSize.width, m_itemSize.height); for (int i = 0; i < m_nItemsCount; ++i) { CAButton *btn = this->createDefaultSegment(); if (btn) { btn->setFrame(elemFrame); m_segments.push_back(btn); this->insertSubview(btn, 1); } elemFrame.origin.x += elemWidth; } return true; }
void CATextToolBarView::show(CAView* pView) { CCSize winSize = CAApplication::getApplication()->getWinSize(); float alertViewButtonHeight = 88; float alertViewWidth = winSize.width * 2 / 3; CCRect rect = CCRect(winSize.width / 2, winSize.height / 2 - alertViewButtonHeight, alertViewWidth, alertViewButtonHeight); m_pBackView = CAClippingView::create(); m_pBackView->setCenter(rect); this->addSubview(m_pBackView); this->setTextTag("CATextToolBarView"); m_pBackView->setAlphaThreshold(0.5f); CAScale9ImageView *backgroundImageView = CAScale9ImageView::createWithFrame(m_pBackView->getBounds()); backgroundImageView->setImage(CAImage::create("source_material/alert_back.png")); m_pBackView->addSubview(backgroundImageView); m_pBackView->setStencil(backgroundImageView->copy()); size_t btnCount = m_CallbackTargets.size(); for (int i = 0; i < btnCount; i++) { CAButton* btn = CAButton::create(CAButtonTypeSquareRect); btn->setTitleForState(CAControlStateAll, m_CallbackTargets[i].cszButtonText.c_str()); btn->setTitleColorForState(CAControlStateAll, ccc4(3, 100, 255, 255)); btn->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(CAColor_clear)); btn->setBackGroundViewForState(CAControlStateHighlighted, CAView::createWithColor(ccc4(226, 226, 226, 225))); btn->setTag(i); btn->addTarget(this, CAControl_selector(CATextToolBarView::alertViewCallback), CAControlEventTouchUpInSide); btn->setFrame(CCRect(i*alertViewWidth / btnCount, 0, alertViewWidth / btnCount, alertViewButtonHeight)); m_pBackView->addSubview(btn); if (i>0) { addGrayLine(alertViewWidth/btnCount * i); } } if (CAWindow *rootWindow = CAApplication::getApplication()->getRootWindow()) { rootWindow->insertSubview(this, CAWindowZOderTop); } becomeFirstResponder(); m_pControlView = pView; }
void FirstViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. CCSize size = this->getView()->getBounds().size; label = CALabel::createWithCenter(CCRect(size.width/2, 60, 200, 50)); label->setTextAlignment(CATextAlignmentCenter); label->setFontSize(size.width/20); label->setText("0.000000"); this->getView()->addSubview(label); float height = size.width * 0.8f * 0.15f; float off_Y = size.width * 0.8f * 0.15f + 10; CCRect progress_rect = CCRect(size.width / 2, off_Y + 60, size.width * 0.8f, 10); progress = CAProgress::create(); progress->setCenter(progress_rect); this->getView()->addSubview(progress); CCRect slider_rect = CCRect(size.width/2, off_Y * 2 + 60, size.width * 0.8f, height); CASlider* slider = CASlider::createWithCenter(slider_rect); this->getView()->addSubview(slider); slider->addTarget(this, CAControl_selector(FirstViewController::updateSlider)); CCRect segmentedControl_rect = CCRect(size.width/2, off_Y * 3 + 60, size.width * 0.8f, height); CASegmentedControl* segmentedControl = CASegmentedControl::createWithCenter(segmentedControl_rect, 2); segmentedControl->insertSegmentWithTitle("2", 2, CAControlStateAll); segmentedControl->insertSegmentWithTitle("3", 3, CAControlStateAll); this->getView()->addSubview(segmentedControl); CAButton* btn = CAButton::createWithCenter(CCRect(size.width/2, size.height - off_Y, 150, 60), CAButtonTypeRoundedRect); btn->setTitleForState(CAControlStateAll, "OK"); this->getView()->addSubview(btn); btn->addTarget(this, CAControl_selector(FirstViewController::diss), CAControlEventTouchUpInSide); }
bool CASegmentedControl::insertSegmentWithImage(CAImage *image, int index, CAControlState controlState) { const int curItemCount = m_segments.size(); if (index < 0) { index = 0; } else if (index >= curItemCount) { index = curItemCount; } CAButton *newBtn = this->createDefaultSegment(); if (NULL == newBtn) { return false; } newBtn->setImageForState(controlState, image); m_segments.insert(m_segments.begin() + index, newBtn); this->addSubview(newBtn); this->layoutSubviews(); return true; }
void ButtonTest::threeButtonType() { CALabel* buttonType = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.05, size.width*0.4, 50)); buttonType->setText("ButtonType"); buttonType->setFontSize(30*CROSSAPP_ADPTATION_RATIO); buttonType->setTextAlignment(CATextAlignmentCenter); buttonType->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(buttonType); CAButton* defaultBtn = CAButton::create(CAButtonTypeCustom); defaultBtn->setCenter(CCRect(size.width*0.25-50, size.height*0.15, size.width*0.2, size.height*0.05)); defaultBtn->setTitleForState(CAControlStateNormal, "Noborder"); defaultBtn->setTitleColorForState(CAControlStateNormal, ccc4(51, 204, 255, 255)); this->getView()->addSubview(defaultBtn); CALabel* custom = CALabel::createWithCenter(CCRect(size.width*0.25-50, size.height*0.15+80, size.width*0.2, 50)); custom->setText("(CAButtonTypeCustom)"); custom->setFontSize(20 * CROSSAPP_ADPTATION_RATIO); custom->setTextAlignment(CATextAlignmentCenter); custom->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(custom); CAButton* squareRectBtn = CAButton::create(CAButtonTypeSquareRect); squareRectBtn->setCenter(CCRect(size.width*0.5, size.height*0.15, size.width*0.2, size.height*0.05)); this->getView()->addSubview(squareRectBtn); CALabel* square = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.15 + 80, size.width*0.2, 50)); square->setText("(CAButtonTypeSquareRect)"); square->setFontSize(20 * CROSSAPP_ADPTATION_RATIO); square->setTextAlignment(CATextAlignmentCenter); square->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(square); CAButton* roundedRectBtn = CAButton::create(CAButtonTypeRoundedRect); roundedRectBtn->setCenter(CCRect(size.width*0.75 + 50, size.height*0.15, size.width*0.2, size.height*0.05)); this->getView()->addSubview(roundedRectBtn); CALabel* rounded = CALabel::createWithCenter(CCRect(size.width*0.75+50, size.height*0.15 + 80, size.width*0.2, 50)); rounded->setText("(CAButtonTypeRoundedRect)"); rounded->setFontSize(20 * CROSSAPP_ADPTATION_RATIO); rounded->setTextAlignment(CATextAlignmentCenter); rounded->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(rounded); }
void SiteViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. m_winSize = this->getView()->getBounds().size; CAScale9ImageView* tabBg = CAScale9ImageView::createWithImage(CAImage::create("common/yellow_bg.png")); tabBg->setCapInsets(DRect(1, 1, 1, 1)); tabBg->setFrame(DRect((0), (0), m_winSize.width, (150))); this->getView()->addSubview(tabBg); CAButton* button = CAButton::createWithFrame(DRect((0), (20), (100), (100)), CAButtonTypeCustom); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/nav_back.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); imageView->setFrame(DRect((20), (20), (80), (80))); button->setBackgroundViewForState(CAControlStateAll, imageView); button->addTarget(this, CAControl_selector(SiteViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(20); this->getView()->addSubview(button); CALabel* mc = CALabel::createWithFrame(DRect((120), (62), (200), (50))); mc->setFontSize((40)); mc->setText("Site"); mc->setColor(CAColor_white); mc->setFontName(SAP_FONT_ARIAL); this->getView()->addSubview(mc); imageView = CAImageView::createWithFrame(DRect(0, (150), m_winSize.width, m_winSize.height - (150))); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop); imageView->setImage(CAImage::create("common/site_map.png")); this->getView()->addSubview(imageView); button = CAButton::createWithFrame(DRect(m_winSize.width - 100, (50), (50), (50)), CAButtonTypeRoundedRect); imageView = CAImageView::createWithImage(CAImage::create("common/share_btn.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitViewByHorizontal); button->setTag(200); button->setBackgroundViewForState(CAControlStateAll, imageView); button->addTarget(this, CAControl_selector(SiteViewController::buttonCallBack), CAControlEventTouchUpInSide); this->getView()->addSubview(button); requestMsg(); m_pLoading = CAActivityIndicatorView::createWithCenter(DRect(m_winSize.width / 2, m_winSize.height / 2, 50, 50)); m_pLoading->setLoadingMinTime(0.5f); this->getView()->addSubview(m_pLoading); CCLog("%f", CAApplication::getApplication()->getWinSize().width); }
void registerViewController::changeButtonView(CAControl*control, CCPoint){ CAView* _view2 = CAScale9ImageView::createWithImage(CAImage::create("image/bg1.png")); CAView* _view3 = CAScale9ImageView::createWithImage(CAImage::create("image/bg1R.png")); CAButton* btn = dynamic_cast<CAButton*>(control); if (btn->getTag() ==99) { btn->setBackGroundViewForState(CAControlStateAll, _view2); // authCodeButton->setBackGroundViewForState(CAControlStateDisabled, CAView::createWithColor(CAColor_gray)); btn->setTag(100); } else if (btn->getTag() == 100) { btn->setBackGroundViewForState(CAControlStateAll, _view3); // authCodeButton->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(CAColor_blue)); btn->setTag(99); } }
CAButton* CASegmentedControl::createDefaultSegment() { CCRect elemFrame = CCRectMake(0, 0, m_itemSize.width, m_itemSize.height); CAButton *newBtn = CAButton::createWithFrame(elemFrame, CAButtonTypeCustom); if (newBtn) { CAView* normalBG = this->getDefaultNormalBackgroundView(); CAView* selectedBG = this->getDefaultSelectedBackgroundView(); CAView* highlightedBG = this->getDefaultHighlightedBackgroundView(); newBtn->setBackGroundViewForState(CAControlStateNormal, normalBG); newBtn->setBackGroundViewForState(CAControlStateSelected, selectedBG); newBtn->setBackGroundViewForState(CAControlStateHighlighted, highlightedBG); newBtn->setAllowsSelected(true); newBtn->setTouchEnabled(false); } return newBtn; }
void MainViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. m_winSize = this->getView()->getBounds().size; // header CAScale9ImageView* header = CAScale9ImageView::createWithImage(CAImage::create("common/sky_bg.png")); if (header) { header->setFrame(DRect((0), (0), m_winSize.width, (120))); header->setTouchEnabled(false); this->getView()->addSubview(header); // title lable CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 2, (80), m_winSize.width, (50))); if (label) { label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_white); label->setFontSize(SAP_TITLE_FONT_SIZE); label->setText("SAP d-kom"); label->setFontName(SAP_FONT_ARIAL); label->setTouchEnabled(false); header->addSubview(label); } } // left notification button CAButton* button = CAButton::createWithFrame(DRect((0), (20), (100), (100)), CAButtonTypeCustom); if (button) { button->addTarget(this, CAControl_selector(MainViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(20); this->getView()->addSubview(button); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("main/nav_notification.png")); if (imageView) { imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); button->setBackGroundViewForState(CAControlStateAll, imageView); } m_timeNoticeImageView = CAImageView::createWithFrame(DRect((60), (30), (20), (20))); if (m_timeNoticeImageView) { m_timeNoticeImageView->setImage(CAImage::create("common/reddot.png")); button->addSubview(m_timeNoticeImageView); } //refreshNoticeRedPoint(); } // notification alert point /* // right survey button button = CAButton::createWithFrame(DRect(m_winSize.width - (100), (20), (100), (100)), CAButtonTypeCustom); if (button) { button->addTarget(this, CAControl_selector(MainViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(30); this->getView()->addSubview(button); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("main/nav_survey.png")); if (imageView) { imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); button->setBackgroundViewForState(CAControlStateAll, imageView); } } // survey lable CALabel * surveylable = CALabel::createWithFrame(DRect(m_winSize.width - (75), (100), (100), (25))); if (surveylable) { surveylable->setTextAlignment(CATextAlignmentLeft); surveylable->setColor(CAColor_white); surveylable->setFontSize(15); surveylable->setText("Survey"); surveylable->setFontName(SAP_FONT_ARIAL); surveylable->setTouchEnabled(false); this->getView()->addSubview(surveylable); } */ int pageViewHeight = m_winSize.height * 0.3; int butViewHeight = m_winSize.height * 0.15; int headerHeight = (120); int buttitleHeight = (40); /* // Page view if (!m_pageView) { m_pageView = CAPageView::createWithFrame(DRect(0, headerHeight, m_winSize.width, pageViewHeight), CAPageViewDirectionHorizontal); if (m_pageView) { m_pageView->setPageViewDelegate(this); m_pageView->setTouchEnabled(true); CAVector<CAView* > viewList; for (int i = 0; i<m_page.size(); i++) { CommonUrlImageView* temImage = CommonUrlImageView::createWithFrame(DRect(0, (0), m_winSize.width, pageViewHeight - headerHeight)); temImage->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop); temImage->setImage(CAImage::create("common/bg.png")); temImage->setUrl(m_page[i].m_imageUrl); temImage->setTouchEnabled(false); viewList.pushBack(temImage); } m_pageView->setViews(viewList); m_pageView->setCurrPage(0, false); this->getView()->addSubview(m_pageView); //headView->addSubview(m_pageView); } } // picture dots bg in page view m_pageControlBG = CAView::createWithColor(ccc4(0, 0, 0, 20)); m_pageControlBG->setFrame(DRect(0, pageViewHeight + headerHeight - (50), m_winSize.width, (50))); m_pageControlBG->setTouchEnabled(false); this->getView()->addSubview(m_pageControlBG); //headView->addSubview(bg); // picture dots m_pageControl = CAPageControl::createWithCenter(DRect(m_winSize.width / 2, pageViewHeight + headerHeight - (25), (120), (50))); if (m_pageControl) { m_pageControl->setNumberOfPages((int)m_page.size()); m_pageControl->setTag(200); m_pageControl->addTarget(this, CAControl_selector(MainViewController::buttonCallBack)); this->getView()->addSubview(m_pageControl); } //headView->addSubview(m_pageControl); */ int buttonHight = (150);//m_winSize.height * 0.15;//(116); // three center button for (int i = 0; i < 3; i++) { DRect r(i * (m_winSize.width / 3), headerHeight + pageViewHeight, m_winSize.width / 3, buttonHight); CAButton* btn = CAButton::createWithFrame(r, CAButtonTypeCustom); btn->setTag(300 + i); CAImageView* imageView = CAImageView::createWithCenter(DRect(m_winSize.width / 3 / 2, (60), (60), (60)));//createWithImage(CAImage::create(crossapp_format_string("main/short_%d.png", i))); imageView->setImage(CAImage::create(crossapp_format_string("main/short_%d.png", i))); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); //imageView->setFrame(DRect(m_winSize.width / 3 / 2, (30), (60), (60))); imageView->setTouchEnabled(false); btn->addSubview(imageView); CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 3 / 2, (140), m_winSize.width / 3, (60))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_gray); label->setFontSize((28)); label->setText(unicode_to_utf8(mainShort[i])); label->setFontName(SAP_FONT_ARIAL); label->setTouchEnabled(false); btn->addSubview(label); btn->addTarget(this, CAControl_selector(MainViewController::buttonCallBack), CAControlEventTouchUpInSide); this->getView()->addSubview(btn); //headView->addSubview(btn); } /* if (m_page.size() > 0) { m_pageViewTitle = CALabel::createWithFrame(DRect(20, m_winSize.width / 2 - 40, m_winSize.width - 50, 50)); m_pageViewTitle->setText(m_page[0].m_title); m_pageViewTitle->setColor(CAColor_white); m_pageViewTitle->setFontSize((28)); m_pageViewTitle->setScrollEnabled(false); m_pageViewTitle->setTouchEnabled(false); this->getView()->addSubview(m_pageViewTitle); //headView->addSubview(m_pageViewTitle); } */ // sub title bar left picture CAView *subViewleft = CAView::createWithCenter(DRect((100), headerHeight + pageViewHeight + buttonHight + (20), m_winSize.width / 4, (20))); //CAView *subViewleft = CAView::createWithFrame(DRect(0, 0, m_winSize.width, (20))); CAImageView* subbarView1 = CAImageView::createWithImage(CAImage::create("main/home_bar.png")); subbarView1->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); subbarView1->setFrame(DRect(0, 0, m_winSize.width / 4, (20))); subbarView1->setTouchEnabled(false); subViewleft->addSubview(subbarView1); this->getView()->addSubview(subViewleft); // sub title CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 2, headerHeight + pageViewHeight + buttonHight + (30), m_winSize.width / 2, (45))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_gray);//ccc4(0x0f, 0xaa, 0xff, 0xff));//CAColor_gray);//CAColor_blue); label->setFontSize((27)); label->setText("My Agenda"); label->setFontName(SAP_FONT_ARIAL);//markerfelt.ttf"); label->setTouchEnabled(false); this->getView()->addSubview(label); // sub title bar right picture CAView *subViewright = CAView::createWithCenter(DRect(m_winSize.width - (100), headerHeight + pageViewHeight +buttonHight + (20), m_winSize.width / 4, (20))); CAImageView* subbarView2 = CAImageView::createWithImage(CAImage::create("main/home_bar.png")); subbarView2->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); subbarView2->setFrame(DRect(0, 0, m_winSize.width / 4, (20))); subbarView2->setTouchEnabled(false); subViewright->addSubview(subbarView2); this->getView()->addSubview(subViewright); //CAView* headView = CAView::createWithFrame(DRect(0, 0, m_winSize.width, m_winSize.width * 0.6 - (120))); //m_msgTableView->setTableHeaderView(headView); //m_msgTableView->setTableHeaderHeight(m_winSize.width / 2 + (130)); int tableStartY = pageViewHeight + butViewHeight + headerHeight + buttitleHeight + (15); m_msgTableView = CATableView::createWithFrame(DRect(0, tableStartY, m_winSize.width, m_winSize.height - tableStartY)); if (m_msgTableView) { m_msgTableView->setTableViewDataSource(this); m_msgTableView->setTableViewDelegate(this); m_msgTableView->setScrollViewDelegate(this); m_msgTableView->setAllowsSelection(true); m_msgTableView->setSeparatorColor(ccc4(200, 200, 200, 80)); //m_msgTableView->setSeparatorViewHeight((2)); this->getView()->addSubview(m_msgTableView); CAPullToRefreshView *refreshDiscount = CAPullToRefreshView::create(CAPullToRefreshView::CAPullToRefreshTypeFooter); if (refreshDiscount) { refreshDiscount->setLabelColor(CAColor_black); m_msgTableView->setFooterRefreshView(refreshDiscount); } // CAPullToRefreshView *refreshDiscount1 = CAPullToRefreshView::create(CAPullToRefreshView::CAPullToRefreshTypeHeader); // if (refreshDiscount1) { // refreshDiscount1->setLabelColor(CAColor_black); // m_msgTableView->setHeaderRefreshView(refreshDiscount1); // } } if (m_msg->empty()) { requestSessionMsg(); p_pLoading = CAActivityIndicatorView::createWithCenter(DRect(m_winSize.width / 2, m_winSize.height / 2, 50, 50)); this->getView()->insertSubview(p_pLoading, CAWindowZOderTop); p_pLoading->setLoadingMinTime(0.5f); // p_pLoading->setTargetOnCancel(this, callfunc_selector(MainViewController::initMsgTableView)); } else { // this->initMsgTableView(); } }
void CATabBar::showSelectedBackGround() { for (size_t i=0; i<m_pButtons.size(); i++) { CAButton* btn = m_pButtons.at(i); btn->setTitleForState(CAControlStateAll, m_pItems.at(i)->getTitle()); btn->setTitleColorForState(CAControlStateAll, m_sTitleColor); btn->setTitleColorForState(CAControlStateHighlighted, m_sSelectedTitleColor); btn->setTitleColorForState(CAControlStateSelected, m_sSelectedTitleColor); btn->setImageForState(CAControlStateNormal, m_pItems.at(i)->getImage()); CAImage* selectedImage = m_pItems.at(i)->getSelectedImage() ? m_pItems.at(i)->getSelectedImage() : m_pItems.at(i)->getImage(); btn->setImageForState(CAControlStateHighlighted, selectedImage); btn->setImageForState(CAControlStateSelected, selectedImage); btn->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(CAColor_clear)); if (m_pSelectedBackGroundImage) { btn->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(m_pSelectedBackGroundImage)); btn->setBackGroundViewForState(CAControlStateSelected, CAScale9ImageView::createWithImage(m_pSelectedBackGroundImage)); } else { btn->setBackGroundViewForState(CAControlStateHighlighted, CAView::createWithColor(m_sSelectedBackGroundColor)); btn->setBackGroundViewForState(CAControlStateSelected, CAView::createWithColor(m_sSelectedBackGroundColor)); } btn->setAllowsSelected(true); CABadgeView* badgeView = m_pBadgeViews.at(i); badgeView->setBadgeText(m_pItems.at(i)->getBadgeValue()); } }
bool CATabBar::init(const CAVector<CATabBarItem*>& items, const CCSize& size) { if (!CAView::init()) { return false; } this->setColor(CAColor_clear); this->setItems(items); CCSize winSize = CAApplication::getApplication()->getWinSize(); CCSize contentSize = size.equals(CCSizeZero) ? CCSize(winSize.width, _px(98)) : size; this->setContentSize(contentSize); CADipRect rect = this->getBounds(); rect.origin = rect.size / 2; rect.size.width = MIN(rect.size.width, 1024); m_pContentView = new CAView(); m_pContentView->setCenter(rect); this->addSubview(m_pContentView); m_pContentView->release(); unsigned int count = (unsigned int)m_pItems.size(); m_cItemSize = m_pContentView->getBounds().size; m_cItemSize.width = rect.size.width/count; if (m_pButtons.empty()) { for (unsigned int i=0; i<count; i++) { CADipRect rect = CADipRectZero; rect.size = m_cItemSize; rect.origin.x = m_cItemSize.width * i; CAButton* btn = CAButton::createWithFrame(rect, CAButtonTypeCustom); m_pContentView->addSubview(btn); btn->setTag(i); btn->addTarget(this, CAControl_selector(CATabBar::setTouchSelected), CAControlEventTouchUpInSide); m_pButtons.pushBack(btn); CABadgeView* badgeView = new CABadgeView(); badgeView->init(); badgeView->setCenter(CADipRect(rect.size.width, 25, 0, 0)); btn->insertSubview(badgeView, 10); m_pBadgeViews.pushBack(badgeView); } } if (m_pBackGroundImage == NULL) { this->setBackGroundImage(CAImage::create("source_material/tabBar_bg.png")); } if (m_pSelectedBackGroundImage == NULL) { this->setSelectedBackGroundImage(CAImage::create("source_material/tabBar_selected_bg.png")); } if (m_pSelectedIndicatorImage == NULL) { this->setSelectedIndicatorImage(CAImage::create("source_material/tabBar_selected_indicator.png")); } return true; }