No GUI events triggered

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
Mace

No GUI events triggered

Post by Mace »

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?
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Could you give your complete OnEvent() code? Are you sure the eventreceiver variable is correct in the createDevice() function?
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Mace

Post by Mace »

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..
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

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;
					}
			}
		} 
...
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Mace

Post by Mace »

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.
killer7
Posts: 14
Joined: Fri Dec 10, 2004 2:42 am
Location: Chicago, USA

Post by killer7 »

Yes, i am still strugling with it, not exactly the same, but, everytime i trigger an event (mouse over, click, ect.) it crashes and askes me to tel microsoft
Json
Posts: 5
Joined: Thu Nov 18, 2004 12:16 pm

Post by Json »

hmm, I just had that as well, I used:

Code: Select all

MyEventReceiver receiver;
device->setEventReceiver(&receiver);
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 :D
I hate those tricky errors where you are to blame yourself :lol:
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Your event receiver should ALWAYS return FALSE unless an event happens. So put "return false;" at the bottom of the OnEvent function.
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
dTb

Post by dTb »

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 :

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;
	}
};
The good Code (compare the "return true;" positions ) :

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;
	}
};
dTb
Posts: 4
Joined: Fri Mar 04, 2005 7:29 pm
Location: Tokyo / Kami-Itabashi
Contact:

Post by dTb »

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 :

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;}
		}
Post Reply