No GUI events triggered
No GUI events triggered
I have a OnEvent function which can receive mouse and keyboard events perfectly (such as left mouse down/up, right mouse down/up etc).
However, when i check for EET_GUI_EVENT´s by doing this:
bool CGameStateMainMenu::OnEvent(SEvent event)
{
// GUI event
if (event.EventType == irr::EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
...
it never goes into that if statement.
Ive set up 2 buttons in the gui like this:
m_gui->addButton(core::rect<s32>(10, 200, 150, 250), 0, BUTTON_START, L"START");
m_gui->addButton(core::rect<s32>(10, 250, 150, 300), 0, BUTTON_QUIT, L"QUIT");
Any ideas?
However, when i check for EET_GUI_EVENT´s by doing this:
bool CGameStateMainMenu::OnEvent(SEvent event)
{
// GUI event
if (event.EventType == irr::EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
...
it never goes into that if statement.
Ive set up 2 buttons in the gui like this:
m_gui->addButton(core::rect<s32>(10, 200, 150, 250), 0, BUTTON_START, L"START");
m_gui->addButton(core::rect<s32>(10, 250, 150, 300), 0, BUTTON_QUIT, L"QUIT");
Any ideas?
Sure, here is the event function
bool CGameStateMainMenu::OnEvent(SEvent event)
{
// GUI event
if (event.EventType == irr::EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
if (id == BUTTON_START)
{
gameMain.setState(GAME_STATE_GAME);
}
}
// Mouse event
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
// Left mouse button pressed
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
}
// Right mouse button pressed
else if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
{
}
}
return true;
}
----------------------------------------
I think ive just missed something simple here.
I checked my createDevice and its set to use itself as the receiver:
m_device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 32, false, false, false, this);
however, i cant see the buttons pressed down when i click them with this
but if i switch to:
m_device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480));
I can see the buttons pressed down as i click them but still no events are triggered.
I take it i dont need to set m_device->setEventReceiver(this); either but just to make sure i tried with and without that too with no success..
bool CGameStateMainMenu::OnEvent(SEvent event)
{
// GUI event
if (event.EventType == irr::EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
if (id == BUTTON_START)
{
gameMain.setState(GAME_STATE_GAME);
}
}
// Mouse event
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
// Left mouse button pressed
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
}
// Right mouse button pressed
else if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
{
}
}
return true;
}
----------------------------------------
I think ive just missed something simple here.
I checked my createDevice and its set to use itself as the receiver:
m_device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 32, false, false, false, this);
however, i cant see the buttons pressed down when i click them with this
but if i switch to:
m_device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480));
I can see the buttons pressed down as i click them but still no events are triggered.
I take it i dont need to set m_device->setEventReceiver(this); either but just to make sure i tried with and without that too with no success..
I think you have to use it similar to Tutorial number 5: User Interface. So it should look like:
Code: Select all
// GUI event
if (event.EventType == irr::EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
switch(event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
if (id == BUTTON_START)
{
gameMain.setState(GAME_STATE_GAME);
return true;
}
}
}
...
Yes i based it on that tutorial at first, it didnt work either.
Ive checked the other tutorials as well to see if ive missed something but i havent found anything yet. Also i browsed the forums without luck.
Ill do some more research to see what i can come up with.
Anyone else that had this problem before and could share their experiences would be greatly appreciated.
Ive checked the other tutorials as well to see if ive missed something but i havent found anything yet. Also i browsed the forums without luck.
Ill do some more research to see what i can come up with.
Anyone else that had this problem before and could share their experiences would be greatly appreciated.
hmm, I just had that as well, I used:
but I put it in my own spot, then I put it in between the createdevice and getVideoDriver and it worked, but now im having another problem where nothing happens when I click the buttons. The buttons wont even animate. grrrrrrrrrrrr.
EDIT: haha, fixed it, stupid me had return 1 in the end of OnEvent
I hate those tricky errors where you are to blame yourself
Code: Select all
MyEventReceiver receiver;
device->setEventReceiver(&receiver);
EDIT: haha, fixed it, stupid me had return 1 in the end of OnEvent
I hate those tricky errors where you are to blame yourself
-
- Posts: 386
- Joined: Thu Sep 25, 2003 12:43 pm
- Contact:
Another old post I wish to answer.
I had exactly the same problem, and the solution is really the return true; you must put only and always when an event was triggered.
A bad code :
The good Code (compare the "return true;" positions ) :
I had exactly the same problem, and the solution is really the return true; you must put only and always when an event was triggered.
A bad code :
Code: Select all
class MyEventReceiver : public IEventReceiver
{
private:
bool m_key_buffer[KEY_KEY_CODES_COUNT];
public:
virtual bool OnEvent(SEvent event)
{
if(event.EventType == irr::EET_GUI_EVENT )
{
//Your GUI code
return true;
}
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
}
if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
if ( event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN && mouserightpressed==false)
{
mouserightpressed=true;
xmouseoriginemouvement=mousecur->getPosition().X;
ymouseoriginemouvement=mousecur->getPosition().Y;
}
if ( event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP )
mouserightpressed=false;
if ( event.MouseInput.Event == EMIE_MOUSE_WHEEL )
{
if (event.MouseInput.Wheel<0) roulettesouris -= 10;
if (event.MouseInput.Wheel>0) roulettesouris += 10;
}
if ( event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN )
mouseleftpressed=true;
if ( event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP )
mouseleftpressed=false;
return true;
}
return false;
}
};
Code: Select all
class MyEventReceiver : public IEventReceiver
{
private:
bool m_key_buffer[KEY_KEY_CODES_COUNT];
public:
virtual bool OnEvent(SEvent event)
{
if(event.EventType == irr::EET_GUI_EVENT )
{
//rien
return true;
}
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return true;
}
if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
if ( event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN && mouserightpressed==false)
{
mouserightpressed=true;
xmouseoriginemouvement=mousecur->getPosition().X;
ymouseoriginemouvement=mousecur->getPosition().Y;
return true;
}
if ( event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP )
{mouserightpressed=false;return true;}
if ( event.MouseInput.Event == EMIE_MOUSE_WHEEL )
{
if (event.MouseInput.Wheel<0) roulettesouris -= 10;
if (event.MouseInput.Wheel>0) roulettesouris += 10;
return true;
}
if ( event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN )
{mouseleftpressed=true;return true;}
if ( event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP )
{mouseleftpressed=false;return true;}
}
return false;
}
};
There was a last problem with my last code :
Because I send a return true; after the left mouse clic (EMIE_LMOUSE_PRESSED_DOWN and EMIE_LMOUSE_LEFT_UP), the GUI buttons and checkboxes don't working (event clic intercepted before). The solution is to remove return true in the clic detection event.
Replace in my last code the mouse event with this to get final good code :
Because I send a return true; after the left mouse clic (EMIE_LMOUSE_PRESSED_DOWN and EMIE_LMOUSE_LEFT_UP), the GUI buttons and checkboxes don't working (event clic intercepted before). The solution is to remove return true in the clic detection event.
Replace in my last code the mouse event with this to get final good code :
Code: Select all
if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
if ( event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN && mouserightpressed==false)
{
mouserightpressed=true;
xmouseoriginemouvement=mousecur->getPosition().X;
ymouseoriginemouvement=mousecur->getPosition().Y;
return true;
}
if ( event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP )
{mouserightpressed=false;return true;}
if ( event.MouseInput.Event == EMIE_MOUSE_WHEEL )
{
if (event.MouseInput.Wheel<0) roulettesouris -= 10;
if (event.MouseInput.Wheel>0) roulettesouris += 10;
return true;
}
if ( event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN )
{mouseleftpressed=true;}
if ( event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP )
{mouseleftpressed=false;}
}