Exemplo n.º 1
0
void InformWindow::createButtons(const eButtons &btn)
{

    int b = btn;
    int btnCount = 0;
    //calc number of "1" bits = buttons
    for (;b;)
    {
        btnCount += b & 1;
        b = b >> 1;
    }

    int btnWidth = 75;
    int btnHeight = 25;

    int x = (width/btnCount - btnWidth)/2;
    int y = height - (btnHeight + 15);

    int shiftX = width/btnCount;

    if (btn & BTN_YES)
    {
        Command* c = new IWButtonYES(this);
        Button* button = new Button("Yes", "BTNYES", 0, 0, btnWidth, btnHeight, c);
        addUIElement(button, x, y);
        x += shiftX;
    }

    if (btn & BTN_NO)
    {
        Command* c = new IWButtonNO(this);
        Button* button = new Button("No", "BTNNO", 0, 0, btnWidth, btnHeight, c);
        addUIElement(button, x, y);
        x += shiftX;
    }

    if (btn & BTN_OK)
    {
        Command* c = new IWButtonOK(this);
        Button* button = new Button("OK", "BTNOK", 0, 0, btnWidth, btnHeight, c);
        addUIElement(button, x, y);
        x += shiftX;
    }

    if (btn & BTN_CANCEL)
    {
        Command* c = new IWButtonCANCEL(this);
        Button* button = new Button("Cancel", "BTNCANCEL", 0, 0, btnWidth, btnHeight, c);
        addUIElement(button, x, y);
        x += shiftX;
    }
}
Exemplo n.º 2
0
InformWindow::InformWindow(const QString &n, const QString &t, const int &w, const int &h, const eButtons &btn):
    ModalWindow(n, t, w, h)
{
    createButtons(btn);
    Label* tmpLbl = new Label(t, "Label", 0, 0, w-6, 25);
    tmpLbl->setAlignment(Label::CENTER);
    addUIElement(tmpLbl, 0.0, 0.1);

    buttonYESCommand = NULL;
    buttonNOCommand = NULL;
    buttonOKCommand = NULL;
    buttonCANCELCommand = NULL;
}
Exemplo n.º 3
0
bool CPanel::init()
{   
    Layer::init();    
   
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

    auto cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("khh/HWYJ.plist", "khh/HWYJ.png");

    //--------------------------------------------------------

    TUIParm t_panelbg[] = 
    { 
        { "IMG_ditu2.png",          Point(.5f, 0),   Point(visibleSize.width / 2 , 30 ), 0x10001 },      
        { "IMG_huweixinxi.png",     Point(.5f, .5f), Point(visibleSize.width / 2, visibleSize.height / 2 + 30), 0x10005 },     
        { "TMG_huweitujian.png",    Point(0.5f, .5f),Point(visibleSize.width / 2, visibleSize.height / 2 + 230), 0x10009}
    };

    int uiSize = sizeof(t_panelbg) / sizeof(TUIParm);
    for (int i = 0; i < uiSize; i++)
    {
        addUIElement(t_panelbg[i]);
    }

    //----------------------------------------

    auto pBigIcon = Sprite::createWithSpriteFrameName("IMG_xshouling1.png");
    pBigIcon->setPosition(Point(visibleSize.width / 2 - 150, visibleSize.height / 2));
    pBigIcon->setScale(1.5f);
    addChild(pBigIcon);       
   
    //-----------------------------------------------

    Sprite* pButton1 = Sprite::createWithSpriteFrameName("IMG_fanhui.png");
    Sprite* pButton2 = Sprite::createWithSpriteFrameName("IMG_fanhui3.png");
    Sprite* pButton3 = Sprite::createWithSpriteFrameName("IMG_fanhui3.png");

    //---------------------------------------------------
    //FIXME ´¥ÃþʼþÎÊÌâ
//     auto listener1 = EventListenerTouchOneByOne::create();
// 
//     listener1->setSwallowTouches(true);
//     listener1->onTouchBegan = [](Touch* touch, Event* event){
//         auto target = static_cast<Sprite*>(event->getCurrentTarget());
//         Director::getInstance()->end();
//         return true;
//     }; 
//     _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, pButton1); 

    //---------------------------------------------------------------------

    auto closeItem = MenuItemSprite::create(
        pButton1,
        pButton2,
        pButton3,
        CC_CALLBACK_1(CPanel::menuCloseCallback, this)       
        );
    closeItem->setPosition(Point(50, visibleSize.height / 2 + 240));


    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Point::ZERO);
    addChild(menu, 1);

    //---------------------------------------------------

       
    int listSx = 120, listSy = 100, inval = 20;
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            auto pSpriteIcon = Sprite::createWithSpriteFrameName("IMG_xshouling1.png");
            auto pSpriteItem = Sprite::createWithSpriteFrameName("IMG_xxbj.png");

            int listiconW = pSpriteIcon->getContentSize().width;
            int listiconH = pSpriteIcon->getContentSize().height;
            int x = listSx + (listiconW + inval) * j;
            int y = listSy + (listiconH + inval) * i;

            // pSpriteItem->setScale(0.8f);

            CUIElement* pElement = CUIElement::create();
            pElement->setIcon(pSpriteIcon);
            pElement->setLab(pSpriteItem);
            pElement->setScale(0.8f);
            pElement->setPosition(Point(x, y));           

            menu->addChild(pElement);
        }
    }
  

    log("CPanel init");
    return true;
}