当前位置: 首页>>代码示例>>C++>>正文


C++ Alert::setBackGroundImageScale9Enabled方法代码示例

本文整理汇总了C++中Alert::setBackGroundImageScale9Enabled方法的典型用法代码示例。如果您正苦于以下问题:C++ Alert::setBackGroundImageScale9Enabled方法的具体用法?C++ Alert::setBackGroundImageScale9Enabled怎么用?C++ Alert::setBackGroundImageScale9Enabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Alert的用法示例。


在下文中一共展示了Alert::setBackGroundImageScale9Enabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: create

Alert* Alert::create()
{
    //usual cocos create, note that I'm skipping handling errors. should fix that
    Alert* alert = new (std::nothrow) Alert();
    if (alert && alert->init())
    {
        alert->autorelease();
    }

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Size node_size = visibleSize*0.80f;
    alert->setContentSize(node_size);
    alert->setLayoutType(ui::Layout::Type::RELATIVE);

    //alert->setBackGroundColor(Color3B::BLACK);
    //alert->setBackGroundColorOpacity(255/1.5);
    //alert->setBackGroundColorType(ui::LayoutBackGroundColorType::SOLID);

    alert->setBackGroundImage("main_UI_export_10_x4.png", TextureResType::PLIST);
    alert->setBackGroundImageScale9Enabled(true);
    alert->setBackGroundImageColor(Color3B(114, 160, 72));
    //alert->setBackGroundImageOpacity(200.0f);
    //layout->setClippingEnabled(true);

    auto create_txt = [&](std::string msg, ui::RelativeLayoutParameter* param) {
        auto txt = ui::Text::create(msg, DEFAULT_FONT, sx(25.0f));
        Label* lbl = (Label*)txt->getVirtualRenderer();
        lbl->getFontAtlas()->setAliasTexParameters();
        txt->setTextColor(Color4B::BLACK);
        //txt->enableOutline(Color4B::BLACK, 2);

        txt->ignoreContentAdaptWithSize(false); //word wrap or something

        alert->addChild(txt);

        txt->setLayoutParameter(param);
        return txt;
    };

    auto header_param = ui::RelativeLayoutParameter::create();
    header_param->setRelativeName("header_param");
    header_param->setAlign(ui::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL);
    header_param->setMargin(ui::Margin(sx(10), sy(30), sx(10), sy(10)));

    alert->header_txt = create_txt("Title Here", header_param);

    auto sub_header_param = ui::RelativeLayoutParameter::create();
    sub_header_param->setRelativeName("sub_header_param");
    sub_header_param->setAlign(ui::RelativeAlign::LOCATION_BELOW_CENTER);
    sub_header_param->setMargin(ui::Margin(sx(10), sy(10), sx(10), sy(10)));

    alert->sub_header_txt = create_txt("Sub header", sub_header_param);
    sub_header_param->setRelativeToWidgetName("header_param");

    auto body_param = ui::RelativeLayoutParameter::create();
    body_param->setAlign(ui::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL);
    body_param->setMargin(ui::Margin(sx(30), sy(10), sx(10), sy(10)));
    alert->body_txt = create_txt("Body content", body_param);

    Size body_size = alert->body_txt->getAutoRenderSize();
    alert->body_txt->setTextAreaSize(Size(
        body_size.width,
        body_size.height
    ));


    auto close_btn = ui::Button::create();
    close_btn->addTouchEventListener([alert](Ref*, TouchEventType type)
    {
        if (type == TouchEventType::ENDED)
        {
            Size visibleSize = Director::getInstance()->getVisibleSize();
            Vec2 origin = Director::getInstance()->getVisibleOrigin();

            Vec2 pos = Vec2(
                origin.x + visibleSize.width - 20,
                origin.y + 20
                );
            alert->shrink_close(pos);
        };

    });

    close_btn->setTitleText("X");
    close_btn->setTitleColor(Color3B::RED);
    close_btn->setTitleFontSize(sx(40.0f));
    close_btn->getTitleRenderer()->enableOutline(Color4B::GRAY, 10);
    close_btn->setScaleX(sx(1.0f));
    close_btn->setScaleY(sy(1.0f));
    alert->close_btn = close_btn;

    ui::RelativeLayoutParameter* close_param = ui::RelativeLayoutParameter::create();
    close_param->setAlign(ui::RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT);
    close_param->setMargin(ui::Margin(sx(30), sy(20), sx(30), sy(30)));
    alert->close_btn->setLayoutParameter(close_param);
    alert->addChild(alert->close_btn);

    auto done_btn = ui::Button::create();
    done_btn->addTouchEventListener([alert](Ref*, TouchEventType type)
    {
//.........这里部分代码省略.........
开发者ID:tankorsmash,项目名称:BuildUpABase,代码行数:101,代码来源:Alert.cpp


注:本文中的Alert::setBackGroundImageScale9Enabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。