void CANavigationBar::showLeftButton() { std::vector<CAButton*>::iterator itr; for (itr = m_pLeftButtons.begin(); itr != m_pLeftButtons.end(); itr++) { (*itr)->removeFromSuperview(); } m_pLeftButtons.clear(); const CAVector<CAObject*>& buttonItems = m_pItem->getLeftButtonItems(); CCRect rect; rect.size.width = _px(80); rect.size.height = this->getBounds().size.height * 0.8f; rect.origin.x = 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 == NULL && m_pItem) { button->setImageForState(CAControlStateNormal, CAImage::create("source_material/btn_left_white.png")); button->setImageColorForState(CAControlStateHighlighted, ccc4(255, 255, 200, 255)); button->addTarget(this, CAControl_selector(CANavigationBar::goBack), CAControlEventTouchUpInSide); } else 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_pLeftButtons.push_back(button); } }
void CATabBar::setTitleColorForSelected(const CAColor4B &var) { m_sSelectedTitleColor = var; if (!m_pButtons.empty()) { for (size_t i=0; i<m_pButtons.size(); i++) { CAButton* btn = m_pButtons.at(i); btn->setTitleColorForState(CAControlStateHighlighted, m_sSelectedTitleColor); btn->setTitleColorForState(CAControlStateSelected, m_sSelectedTitleColor); } } }
void CANavigationBar::showLeftButton() { std::vector<CAButton*>::iterator itr; for (itr = m_pLeftButtons.begin(); itr != m_pLeftButtons.end(); itr++) { (*itr)->removeFromSuperview(); } m_pLeftButtons.clear(); CCArray* buttonItems = m_pItems.back()->getLeftButtonItems(); CCRect rect = this->getBounds(); rect.size.width = rect.size.height * 0.9f; rect.size.height *= 0.8f; rect.origin.x = 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 == NULL && m_pItems.size() > 1) { button->setImageForState(CAControlStateNormal, CAImage::create("source_material/btn_left_white.png")); button->setImageColorForState(CAControlStateHighlighted, ccc4(255, 255, 200, 255)); button->addTarget(this, CAControl_selector(CANavigationBar::goBack), CAControlEventTouchUpInSide); } else 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_pLeftButtons.push_back(button); } }
void ButtonTest::buttonTouchEvent(void) { CADipSize size = eventView->getBounds().size; CALabel* buttonTouch = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.2, size.width*0.4, 50)); buttonTouch->setText("TouchEvent"); buttonTouch->setFontSize(_px(35)); buttonTouch->setTextAlignment(CATextAlignmentCenter); buttonTouch->setColor(CAColor_blueStyle); eventView->addSubview(buttonTouch); CAButton* btnOne = CAButton::create(CAButtonTypeCustom); btnOne->setCenter(CADipRect(size.width*0.25 - 50, size.height*0.5, size.width*0.25, size.height*0.1)); btnOne->setTag(BUTTONONE); btnOne->setTitleForState(CAControlStateAll, "TouchDown"); btnOne->setTitleColorForState(CAControlStateNormal, CAColor_blueStyle); btnOne->setBackGroundViewForState(CAControlStateNormal, CAScale9ImageView::createWithImage(CAImage::create("source_material/round1.png"))); btnOne->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(CAImage::create("source_material/round2.png"))); btnOne->addTarget(this, CAControl_selector(ButtonTest::buttonCallback), CAControlEventTouchDown); eventView->addSubview(btnOne); CAButton* btnTwo = CAButton::create(CAButtonTypeSquareRect); btnTwo->setCenter(CADipRect(size.width*0.5, size.height*0.5, size.width*0.25, size.height*0.1)); btnTwo->setTag(BUTTONTWO); btnTwo->setTitleForState(CAControlStateAll, "TouchMoved"); btnTwo->setTitleColorForState(CAControlStateNormal,CAColor_white); btnTwo->setBackGroundViewForState(CAControlStateNormal, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_square_highlighted.png"))); btnTwo->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_square_selected.png"))); btnTwo->addTarget(this, CAControl_selector(ButtonTest::buttonCallback), CAControlEventTouchMoved); eventView->addSubview(btnTwo); CAButton* btnThree = CAButton::create(CAButtonTypeRoundedRect); btnThree->setCenter(CADipRect(size.width*0.75 + 50, size.height*0.5, size.width*0.25, size.height*0.1)); btnThree->setTag(BUTTONTHREE); btnThree->setTitleForState(CAControlStateAll, "TouchUpInSide"); btnThree->setTitleColorForState(CAControlStateNormal, CAColor_white); btnThree->setBackGroundViewForState(CAControlStateNormal, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_rounded3D_highlighted.png"))); btnThree->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_rounded3D_selected.png"))); btnThree->addTarget(this, CAControl_selector(ButtonTest::buttonCallback), CAControlEventTouchUpInSide); eventView->addSubview(btnThree); descTest = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.8, size.width, 50)); descTest->setText("Display coordinates"); descTest->setFontSize(_px(30)); descTest->setColor(CAColor_blueStyle); descTest->setTextAlignment(CATextAlignmentCenter); eventView->addSubview(descTest); }
void CATabBar::setTitleColorForNormal(const CAColor4B &var) { m_sTitleColor = var; if (!m_pButtons.empty()) { for (size_t i=0; i<m_pButtons.size(); i++) { CAButton* btn = m_pButtons.at(i); btn->setTitleColorForState(CAControlStateNormal, m_sTitleColor); } } }
void ButtonTest::buttonBackground() { CALabel* buttonImage = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.3, size.width*0.4, 50)); buttonImage->setText("ButtonImage"); buttonImage->setFontSize(30 * CROSSAPP_ADPTATION_RATIO); buttonImage->setTextAlignment(CATextAlignmentCenter); buttonImage->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(buttonImage); CAButton* defaultBtn = CAButton::create(CAButtonTypeCustom); defaultBtn->setCenter(CCRect(size.width*0.25 - 50, size.height*0.4, size.width*0.2, size.height*0.05)); defaultBtn->setTitleForState(CAControlStateNormal, "Normal"); defaultBtn->setTitleForState(CAControlStateSelected,"Selected"); defaultBtn->setTitleForState(CAControlStateHighlighted, "Highlighted"); defaultBtn->setBackGroundViewForState(CAControlStateNormal,CAView::createWithColor(CAColor_green)); defaultBtn->setBackGroundViewForState(CAControlStateHighlighted, CAView::createWithColor(CAColor_yellow)); defaultBtn->setTitleColorForState(CAControlStateAll, ccc4(51, 204, 255, 255)); this->getView()->addSubview(defaultBtn); CALabel* custom = CALabel::createWithCenter(CCRect(size.width*0.25 - 50, size.height*0.4 + 80, size.width*0.2, 50)); custom->setText("(BackgroundView)"); 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.4, size.width*0.2, size.height*0.05)); squareRectBtn->setImageForState(CAControlStateNormal,CAImage::create("square_nor.png")); squareRectBtn->setImageForState(CAControlStateHighlighted, CAImage::create("square_sel.png")); this->getView()->addSubview(squareRectBtn); CALabel* square = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.4 + 80, size.width*0.2, 50)); square->setText("(StateImage)"); 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.4, size.width*0.2, size.height*0.05)); roundedRectBtn->setControlState(CAControlStateDisabled); this->getView()->addSubview(roundedRectBtn); CALabel* rounded = CALabel::createWithCenter(CCRect(size.width*0.75 + 50, size.height*0.4 + 80, size.width*0.2, 50)); rounded->setText("(Disabled)"); rounded->setFontSize(20 * CROSSAPP_ADPTATION_RATIO); rounded->setTextAlignment(CATextAlignmentCenter); rounded->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(rounded); }
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 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; }
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 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 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 ButtonTest::buttonTouchEvent() { CALabel* buttonTouch = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.55, size.width*0.4, 50)); buttonTouch->setText("TouchEvent"); buttonTouch->setFontSize(35 * CROSSAPP_ADPTATION_RATIO); buttonTouch->setTextAlignment(CATextAlignmentCenter); buttonTouch->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(buttonTouch); CAButton* btnOne = CAButton::create(CAButtonTypeCustom); btnOne->setCenter(CCRect(size.width*0.25 - 50, size.height*0.65, size.width*0.2, size.height*0.05)); btnOne->setTag(BUTTONONE); btnOne->setTitleForState(CAControlStateNormal, "Normal"); btnOne->setTitleColorForState(CAControlStateNormal, ccc4(51,204,255,255)); btnOne->addTarget(this,CAControl_selector(ButtonTest::buttonCallback),CAControlEventTouchUpInSide); this->getView()->addSubview(btnOne); CAButton* btnTwo = CAButton::create(CAButtonTypeSquareRect); btnTwo->setCenter(CCRect(size.width*0.5, size.height*0.65, size.width*0.2, size.height*0.05)); btnTwo->setTag(BUTTONTWO); btnTwo->addTarget(this, CAControl_selector(ButtonTest::buttonCallback), CAControlEventTouchUpInSide); this->getView()->addSubview(btnTwo); CAButton* btnThree = CAButton::create(CAButtonTypeRoundedRect); btnThree->setCenter(CCRect(size.width*0.75 + 50, size.height*0.65, size.width*0.2, size.height*0.05)); btnThree->setTag(BUTTONTHREE); btnThree->addTarget(this, CAControl_selector(ButtonTest::buttonCallback), CAControlEventTouchUpInSide); this->getView()->addSubview(btnThree); descTest = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.8, size.width*0.9, 50)); descTest->setText("Display coordinates"); descTest->setFontSize(30*CROSSAPP_ADPTATION_RATIO); descTest->setColor(ccc4(51, 204, 255, 255)); descTest->setTextAlignment(CATextAlignmentCenter); this->getView()->addSubview(descTest); }
void SessionsViewController::initMsgTableView() { if (m_msg->empty()) { showAlert(); return; } if (m_msgTableView == NULL) { m_listView = CAListView::createWithFrame(DRect(0,(120),m_winSize.width,(60))); m_listView->setListViewDelegate(this); m_listView->setListViewDataSource(this); m_listView->setAllowsSelection(true); m_listView->setAllowsMultipleSelection(false); m_listView->setListViewOrientation(CAListViewOrientationHorizontal); m_listView->setShowsScrollIndicators(false); m_listView->setSeparatorColor(ccc4(0xf6, 0xf6, 0xf6, 0xff)); m_listView->setBackgroundImage(CAImage::create("common/gray_bg.png")); m_listView->setTag(1); //m_listView->setc this->getView()->addSubview(m_listView); m_msgTableView = CATableView::createWithFrame(DRect(0, (180), m_winSize.width, m_winSize.height - (180))); 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::CAPullToRefreshTypeHeader); refreshDiscount->setLabelColor(CAColor_black); m_msgTableView->setHeaderRefreshView(refreshDiscount); m_filterView = CAView::createWithFrame(DRect(0, (120), m_winSize.width, (60))); CAScale9ImageView* imageView = CAScale9ImageView::createWithImage(CAImage::create("common/gray_bg.png")); imageView->setFrame(DRect(0, 0, m_winSize.width, (60))); m_filterView->addSubview(imageView); this->getView()->addSubview(m_filterView); m_filterViewVec.push_back(m_filterView); for (int i = 0; i < 2; i++) { int cnt = 0; if (i == 0) { cnt = TrackNum; } else if (i == 1) { cnt = FormatNum; } m_filterBtn[i] = CAButton::createWithFrame(DRect(i * m_winSize.width / 2, 0, m_winSize.width / 2, (60)), CAButtonTypeCustom); m_filterBtn[i]->setTitleForState(CAControlStateAll, filterItem[i]); m_filterBtn[i]->setTitleFontName(SAP_FONT_ARIAL); m_filterBtn[i]->setTitleFontSize((30)); m_filterBtn[i]->setTitleColorForState(CAControlStateAll, CAColor_gray); m_filterBtn[i]->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); m_filterBtn[i]->setTag(300 + i); m_filterBtn[i]->setAllowsSelected(true); m_filterView->addSubview(m_filterBtn[i]); m_downView[i] = CAView::createWithFrame(DRect(i * m_winSize.width / 2, (180), m_winSize.width / 2, (50) * cnt + (20))); CAScale9ImageView* imageView = CAScale9ImageView::createWithImage(CAImage::create("common/gray_bg.png")); imageView->setFrame(DRect(0, 0, m_winSize.width / 2, (50) * cnt + (20))); m_downView[i]->addSubview(imageView); this->getView()->addSubview(m_downView[i]); m_filterViewVec.push_back(m_downView[i]); } for (int i = 0; i < m_filterViewVec.size(); i++) { m_filterViewVec[i]->setVisible(false); } for (int i = 0; i < TrackNum; i++) { CAButton* button = CAButton::createWithFrame(DRect((20), (50) * i, m_winSize.width / 2 - (40), (50)), CAButtonTypeCustom); button->setTitleForState(CAControlStateAll, trackFilterItem[i]); button->setTitleFontName(SAP_FONT_ARIAL); button->setTitleColorForState(CAControlStateAll, CAColor_gray); button->setTitleColorForState(CAControlStateSelected, CAColor_white); button->setTitleFontSize((27)); button->setAllowsSelected(true); //CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/white_bg.png")); //button->setBackgroundViewForState(CAControlStateAll, imageView); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/sky_bg.png")); button->setBackgroundViewForState(CAControlStateSelected, imageView); button->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(400 + i); m_downView[0]->addSubview(button); m_trackButtonVec.push_back(button); } for (int i = 0; i < FormatNum; i++) { CAButton* button = CAButton::createWithFrame(DRect((20), (50) * i, m_winSize.width / 2 - (40), (50)), CAButtonTypeCustom); button->setTitleForState(CAControlStateAll, formatFilterItem[i]); button->setTitleFontName(SAP_FONT_ARIAL); button->setTitleColorForState(CAControlStateAll, CAColor_gray); button->setTitleColorForState(CAControlStateSelected, CAColor_white); button->setTitleFontSize((27)); button->setAllowsSelected(true); //CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/white_bg.png")); //button->setBackgroundViewForState(CAControlStateAll, imageView); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/sky_bg.png")); button->setBackgroundViewForState(CAControlStateSelected, imageView); button->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(500 + i); m_downView[1]->addSubview(button); m_formatButtonVec.push_back(button); } } }
void ButtonTest::buttonBackground(void) { CADipSize size = bkgView->getBounds().size; CALabel* buttonImage = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.2, size.width*0.4, 50)); buttonImage->setText("ButtonImage"); buttonImage->setFontSize(_px(30)); buttonImage->setTextAlignment(CATextAlignmentCenter); buttonImage->setColor(ccc4(51, 204, 255, 255)); bkgView->addSubview(buttonImage); 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, "Normal"); defaultBtn->setTitleColorForState(CAControlStateNormal, CAColor_white); defaultBtn->setTitleForState(CAControlStateSelected,"Selected"); defaultBtn->setTitleForState(CAControlStateHighlighted, "Highlighted"); defaultBtn->setBackGroundViewForState(CAControlStateNormal,CAView::createWithColor(CAColor_green)); defaultBtn->setBackGroundViewForState(CAControlStateHighlighted, CAView::createWithColor(CAColor_yellow)); bkgView->addSubview(defaultBtn); CALabel* custom = CALabel::createWithCenter(CADipRect(size.width*0.25 - 50, size.height*0.5 + 80, size.width*0.3, 50)); custom->setText("(BackgroundView)"); custom->setFontSize(_px(20)); custom->setTextAlignment(CATextAlignmentCenter); custom->setColor(CAColor_blueStyle); bkgView->addSubview(custom); CAButton* squareRectBtn = CAButton::create(CAButtonTypeSquareRect); squareRectBtn->setAllowsSelected(true); squareRectBtn->setCenter(CADipRect(size.width*0.5, size.height*0.5, size.width*0.25, size.height*0.1)); squareRectBtn->setTitleForState(CAControlStateNormal, "Normal"); squareRectBtn->setTitleColorForState(CAControlStateNormal, CAColor_white); squareRectBtn->setTitleForState(CAControlStateSelected, "Selected"); squareRectBtn->setTitleForState(CAControlStateHighlighted, "Highlighted"); squareRectBtn->setBackGroundViewForState(CAControlStateNormal, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_rounded3D_normal.png"))); squareRectBtn->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(CAImage::create("source_material/ex4.png"))); squareRectBtn->setBackGroundViewForState(CAControlStateSelected, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_rounded3D_selected.png"))); bkgView->addSubview(squareRectBtn); CALabel* square = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.5 + 80, size.width*0.3, 50)); square->setText("(StateImage)"); square->setFontSize(_px(20)); square->setTextAlignment(CATextAlignmentCenter); square->setColor(CAColor_blueStyle); bkgView->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->setBackGroundViewForState(CAControlStateDisabled, CAScale9ImageView::createWithImage(CAImage::create("source_material/ex5.png"))); roundedRectBtn->setControlState(CAControlStateDisabled); bkgView->addSubview(roundedRectBtn); CALabel* rounded = CALabel::createWithCenter(CADipRect(size.width*0.75 + 50, size.height*0.5 + 80, size.width*0.3, 50)); rounded->setText("(Disabled)"); rounded->setFontSize(_px(20)); rounded->setTextAlignment(CATextAlignmentCenter); rounded->setColor(CAColor_blueStyle); bkgView->addSubview(rounded); }