本文整理汇总了C++中CAButton::setControlState方法的典型用法代码示例。如果您正苦于以下问题:C++ CAButton::setControlState方法的具体用法?C++ CAButton::setControlState怎么用?C++ CAButton::setControlState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAButton
的用法示例。
在下文中一共展示了CAButton::setControlState方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initWithCenter
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;
}
示例2: buttonBackground
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);
}
示例3: layoutSubviews
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;
}
}
示例4: addButton
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;
}
示例5: buttonCallBack
void SessionsViewController::buttonCallBack(CAControl* btn, DPoint point)
{
if(btn->getTag() == 20)
{
SessionsSearchViewController* vc = new SessionsSearchViewController(0);
vc->init();
vc->autorelease();
RootWindow::getInstance()->getRootNavigationController()->pushViewController(vc, true);
}
else if (btn->getTag() == 100)
{
this->getView()->removeSubview(p_alertView);
p_alertView = NULL;
requestMsg();
{
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(SessionsViewController::initMsgTableView));
}
initMsgTableView();
}
else if (btn->getTag() == 200)
{
if(m_navType == 0) return;
m_navType = 0;
for (int i = 0; i < m_filterViewVec.size(); i++)
{
m_filterViewVec[i]->setVisible(false);
}
m_listView->setVisible(true);
if (m_msgTableView)
{
refreshTableByTime(m_navTimeType);
}
}
else if (btn->getTag() == 201)
{
if(m_navType == 1) return;
m_navType = 1;
m_listView->setVisible(false);
m_filterView->setVisible(true);
m_downView[0]->setVisible(false);
m_downView[0]->setVisible(false);
if (m_msgTableView)
{
refreshTableByFormat(m_navTrackType, m_navFormatType);
}
}
else if (btn->getTag() >= 400 && btn->getTag() < 500)
{
if (btn->getControlState() == CAControlStateNormal)
{
m_navTrackType = 0;
refreshTableByFormat(m_navTrackType, m_navFormatType);
}
else if (btn->getControlState() == CAControlStateSelected)
{
for (int i = 0; i < TrackNum; i++)
{
if (m_trackButtonVec[i] == btn)
continue;
m_trackButtonVec[i]->setControlState(CAControlStateNormal);
}
m_navTrackType = btn->getTag() - 400;
refreshTableByFormat(m_navTrackType, m_navFormatType);
}
if (m_filterBtn[0]) {
if (btn->getTag() == 400)
m_filterBtn[0]->setTitleForState(CAControlStateAll, filterItem[0]);
else
m_filterBtn[0]->setTitleForState(CAControlStateAll, trackFilterItem[btn->getTag() - 400]);
}
}
else if (btn->getTag() >= 500 && btn->getTag() < 600)
{
if (btn->getControlState() == CAControlStateNormal)
{
m_navFormatType = 0;
refreshTableByFormat(m_navTrackType, m_navFormatType);
}
else if (btn->getControlState() == CAControlStateSelected)
{
for (int i = 0; i < FormatNum; i++)
{
if (m_formatButtonVec[i] == btn)
continue;
m_formatButtonVec[i]->setControlState(CAControlStateNormal);
}
m_navFormatType = btn->getTag() - 500;
refreshTableByFormat(m_navTrackType, m_navFormatType);
}
if (m_filterBtn[1]) {
if (btn->getTag() == 500)
m_filterBtn[1]->setTitleForState(CAControlStateAll, filterItem[1]);
else
m_filterBtn[1]->setTitleForState(CAControlStateAll, formatFilterItem[btn->getTag() - 500]);
}
}
//.........这里部分代码省略.........
示例6: buttonBackground
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);
}