GUI Button Woes

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
gavicus
Posts: 16
Joined: Fri Aug 25, 2006 2:19 pm

GUI Button Woes

Post 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;
            }
        }
gavicus
Posts: 16
Joined: Fri Aug 25, 2006 2:19 pm

Post by gavicus »

So, has no one ever seen this problem?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
Post Reply