Page 1 of 1

GUI Button Woes

Posted: Wed Dec 20, 2006 7:20 pm
by gavicus
I have placed a couple of buttons on my project, but am having some problems using them.

When you press button zero, you get an event from that button. The button stays pressed, though, and when you try to click it again, no event is fired.

So, click button one. You get an event from each button. One from button one because you pressed it, and one from button zero because it just became un-pressed. Now, one is pressed and you get no event from that one when clicking it. (some snippets of code below)

Any ideas?

Code: Select all

btnCancelMain = guienv->addButton(rect<s32>(x,y,x+w,y+h),
        0,//parent
        BTN_CANCEL_MAIN_MENU,//id
        L"cancel");//text
//...
btnSave = guienv->addButton(rect<s32>(x,y,x+w,y+h),
        0,//parent
        BTN_SAVE_MAP,//id
        L"save map");//text

Code: Select all

//from my event receiver
switch(id)
        {
            case Game::BTN_CANCEL_MAIN_MENU:
            {
                printf("close window\n");
                game->showWindow(Game::WIN_MAIN_MENU,false);
                game->btnCancelMain->setPressed(false);
                break;
            }
            case Game::BTN_SAVE_MAP:
            {
                printf("save map\n");
                game->btnSave->setPressed(false);
                break;
            }
        }

Posted: Thu Dec 21, 2006 4:41 pm
by gavicus
So, has no one ever seen this problem?

Posted: Thu Dec 21, 2006 4:47 pm
by JP
Normally at the end of each switch case you'd return true or false, not break (in the irrlicht event receiver). Do you actually return a value at the end of the function? If so, what? This could be the problem.

Posted: Thu Dec 21, 2006 5:01 pm
by vitek
I don't think you should be calling setPressed() unless you have a really good reason to be doing so. The button itself manages the pressed and not pressed states internally. You might try commenting those calls out.

Travis

Posted: Thu Dec 21, 2006 5:24 pm
by JP
:lol: yeah good idea Vitek, i didn't notice that in the code, just noticed the breaks!

EDIT: Although looking at it that shouldn't be a problem as all he's doing is setting them to be un-pressed when they're clicked, probably due to having the problem of the buttons remaining pressed he tried that out.