本文整理汇总了C++中CAButton::setCenter方法的典型用法代码示例。如果您正苦于以下问题:C++ CAButton::setCenter方法的具体用法?C++ CAButton::setCenter怎么用?C++ CAButton::setCenter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAButton
的用法示例。
在下文中一共展示了CAButton::setCenter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: buttonTouchEvent
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);
}
示例3: threeButtonType
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);
}
示例4: threeButtonType
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);
}
示例5: buttonTouchEvent
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);
}
示例6: calcuCtrlsSize
void CAAlertView::calcuCtrlsSize()
{
CCSize winSize = CAApplication::getApplication()->getWinSize();
CCSize ertSize = getAlertWinSize();
bool isHoriBtnArray = m_vAllBtn.size() <= MAX_BUTTON_COUNT_ROW;
if (!isHoriBtnArray)
{
ertSize.height += ertSize.height / 5;
}
if (m_pTitleImage)
{
if (isHoriBtnArray)
{
m_pTitleImage->setCenter(CCRectMake(winSize.width / 2, winSize.height / 2 - ertSize.height * 2 / 5, ertSize.width, ertSize.height / 5));
}
else
{
m_pTitleImage->setCenter(CCRectMake(winSize.width / 2, winSize.height / 2 - ertSize.height * 5 / 12, ertSize.width, ertSize.height / 6));
}
if (m_pTitleLabel)
{
m_pTitleLabel->setBounds(CCRectZero);
}
}
if (m_pTitleLabel)
{
if (isHoriBtnArray)
{
m_pTitleLabel->setCenter(CCRectMake(winSize.width / 2, winSize.height / 2 - ertSize.height * 2 / 5, ertSize.width, ertSize.height / 5));
}
else
{
m_pTitleLabel->setCenter(CCRectMake(winSize.width / 2, winSize.height / 2 - ertSize.height * 5 / 12, ertSize.width, ertSize.height / 6));
}
float size = m_pTitleImage->getBounds().size.height / 2;
m_pTitleLabel->setFontSize(size);
}
if (m_pContentBkImage)
{
if (isHoriBtnArray)
{
m_pContentBkImage->setCenter(CCRectMake(winSize.width / 2, winSize.height / 2, ertSize.width, ertSize.height * 3 / 5));
}
else
{
m_pContentBkImage->setCenter(CCRectMake(winSize.width / 2, winSize.height / 2 - ertSize.height/6, ertSize.width, ertSize.height * 1 / 3));
}
}
if (m_pContentLabel)
{
if (isHoriBtnArray)
{
m_pContentLabel->setCenter(CCRectMake(winSize.width / 2, winSize.height / 2, ertSize.width, ertSize.height * 3 / 5));
}
else
{
m_pContentLabel->setCenter(CCRectMake(winSize.width / 2, winSize.height / 2 - ertSize.height / 6, ertSize.width, ertSize.height * 1 / 3));
}
float size = m_pTitleImage->getBounds().size.height / 2;
m_pContentLabel->setFontSize(size);
}
if (!isHoriBtnArray)
{
m_pBtnTableView = new CATableView();
CCAssert(m_pBtnTableView != NULL, "");
m_pBtnTableView->initWithFrame(CCRectMake(0, 0, 0, 0));
m_pBtnTableView->setCenter(CCRectMake(winSize.width/2, winSize.height/2+ertSize.height/4, ertSize.width, ertSize.height/2));
m_pBtnTableView->setTableViewDataSource(this);
m_pBtnTableView->setTableViewDelegate(this);
addSubview(m_pBtnTableView);
}
for (int i = 0; i < m_vAllBtn.size(); i++)
{
CAButton* pButton = m_vAllBtn[i];
CCAssert(pButton, "");
if (isHoriBtnArray)
{
int iStartPosX = (winSize.width - ertSize.width) / 2;
int iDtBtnWidth = ertSize.width / m_vAllBtn.size();
pButton->setCenter(CCRectMake(iStartPosX + iDtBtnWidth*i + iDtBtnWidth / 2, winSize.height / 2 + ertSize.height * 2 / 5, iDtBtnWidth, ertSize.height / 5));
addSubview(pButton);
}
else
{
pButton->setCenter(CCRectMake(0, 0, ertSize.width, ertSize.height / 6));
}
}
}
示例7: 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);
}