Event Reciever not recieving GUI buttons

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
remark
Posts: 14
Joined: Wed May 28, 2014 5:02 am

Event Reciever not recieving GUI buttons

Post by remark »

Hi, I recently added key inputs to my event reciever, but now clicking the gui buttons (both of which do the same thing), does not work, and while the keys themself work, the gui event seems to not be acknowledged, any help would be great, I just cant seem to find out what the issue is.

Code: Select all

class MyEventReceiver : public IEventReceiver
{
    int x,y,z;
 
public:
    MyEventReceiver(SAppContext & context) : Context(context)
    {
        for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
            KeyIsDown[i] = false;
    }
 
    // This is used to check whether a key is being held down
    virtual bool IsKeyDown(EKEY_CODE keyCode) const
    {
        return KeyIsDown[keyCode];
    }
 
 
 
    virtual bool OnEvent(const SEvent& event)
    {
 
        if (event.EventType == EET_KEY_INPUT_EVENT)
        {
            KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
        }
 
 
        if (event.EventType == EET_GUI_EVENT)
        {
            #does not print statement, not recieving any gui events
            cout<<"gui_test";
            s32 id = event.GUIEvent.Caller->getID();
            IGUIEnvironment* env = Context.device->getGUIEnvironment();
 
            switch(event.GUIEvent.EventType)
            {
                case EGET_BUTTON_CLICKED:
                switch(id)
                    case GUI_ID_Left_Arrow:
                               .....
 
creating the button

Code: Select all

IGUIButton* Left_Arrow = env ->addButton(rect<s32>(10,10,387-90,630), 0,GUI_ID_Left_Arrow);
    Left_Arrow->setImage(driver->getTexture("left_arrow/Comp 1_00000.png"));
    Left_Arrow->setUseAlphaChannel(true);
    Left_Arrow->setDrawBorder(false);
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Event Reciever not recieving GUI buttons

Post by Seven »

noticed that parent is not set. maybe left_arrow button needs to be child of gui->getrootguielement()

Code: Select all

 
IGUIButton* Left_Arrow = env ->addButton(rect<s32>(10,10,387-90,630), gui->getrootguielement(),GUI_ID_Left_Arrow);
 
remark
Posts: 14
Joined: Wed May 28, 2014 5:02 am

Re: Event Reciever not recieving GUI buttons

Post by remark »

that didnt seem to work, says IGUIEnviroment has not member called getrootguielement(), I assume gui is device->getGuiEnviroment, I hope that i am reading that right, about the parent, I admit i dont know much about it, do all my buttons need a parent linking them together?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Event Reciever not recieving GUI buttons

Post by Seven »

env->getRootGUIElement()
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Event Reciever not recieving GUI buttons

Post by Seven »

i think.........


when gui sends messages, it starts with env->getRootGUIElement()->onEvent() and then works it's way through all of the children. Since your button has no parent, the messages cannot get to it becasue env->addButton() does not assume that the root gui element is the parent if you pass in a 0 for the parent. by setting it to env->getRootGUIElement() it will enter the event stream.

yes, all need a parent, but they do not all have to be env->getRootGUIElement()

for example
----- IGUIWindow* w = addGUIWindow(env->getRootGUIElement(), ID_MAINWINDOW)
--------- IGUIButton* w1 = addGUIButton(w, ID_BUTTON1)
--------- IGUIButton* w2 = addGUIButton(w, ID_BUTTON2)
--------- IGUIButton* w3 = addGUIButton(w, ID_BUTTON3)

creates a window that is a child of the root gui element, and then adds 3 buttons which are all children of the window.....

hope that helps.
remark
Posts: 14
Joined: Wed May 28, 2014 5:02 am

Re: Event Reciever not recieving GUI buttons

Post by remark »

ok, I thought I was doing something wrong, but setting the parent did not fix the problem, the button still doesnt trigger the response even with the parent set, I since it worked before I put in the keyboard keys events, that something i added messed it up, would setting the receiver mess it up?

Code: Select all

MyEventReceiver receiver(context);
    device->setEventReceiver(&receiver);
Also thanks for the help so far.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Event Reciever not recieving GUI buttons

Post by CuteAlien »

Maybe you return true in your eventreceiver. That tells Irrlicht that you have handled the events and it shouldn't process them further (thereby the gui no longer works).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
remark
Posts: 14
Joined: Wed May 28, 2014 5:02 am

Re: Event Reciever not recieving GUI buttons

Post by remark »

ok, I think the problem is this

Code: Select all

virtual bool IsKeyDown(EKEY_CODE keyCode) const
    {
        return KeyIsDown[keyCode];
    }
i tested it with a simple print statement, and it seems to run all the time, so I am guessing I have to change this, probobly to a switch case statement with each key, and do their tasks inside the event reciever, instead of returning the keys and doing them in the main statement, thanks a lot, you really helped me out =D
Post Reply