Event Receiver in class

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
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Event Receiver in class

Post by AshmenGlue »

I've got an Event Receiver class (CEventReceiver) that I call in my CGame class when I use createDevice.

Now I want to add GUI events in the Event Receiver class. Let's say when a button is clicked, I want to display a text message on the screen. What should I do?

I'm not sure how to write anything to affect the CGame class. I thought about declaring OnEvent(SEvent Event, CGame* world) as such, but OnEvent isn't changable is it?

Code: Select all

// Event handler function
bool CEventReceiver::OnEvent(SEvent Event)
{
	
   if (Event.EventType == EET_KEY_INPUT_EVENT)
   {
      keys[Event.KeyInput.Key] = Event.KeyInput.PressedDown;
   }

   if (Event.EventType == EET_GUI_EVENT) {
		
			s32 id = Event.GUIEvent.Caller->getID();
			
			switch(Event.GUIEvent.EventType) {
				case EGET_BUTTON_CLICKED:
					if (id == 101)
					{
                                                //what do I put here to affect the CGame class?

						return true;
					}
					break;
			}
   }

   return false;
}
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

not sure if i understand your problem...

but try this:
place the CGame Class Object in a Namespace and declare it BEFORE the EventReceiver Class
for example:

Code: Select all

class CGame
{
//Whatever
};
namespace Game
{
     CGame* world
};

class MyEventReceiver : public IEventReceiver
{
public:
	bool CEventReceiver::OnEvent(SEvent Event)
   {
   
   if (Event.EventType == EET_KEY_INPUT_EVENT)
   {
      keys[Event.KeyInput.Key] = Event.KeyInput.PressedDown;
   }

   if (Event.EventType == EET_GUI_EVENT) {
      
         s32 id = Event.GUIEvent.Caller->getID();
         
         switch(Event.GUIEvent.EventType) {
            case EGET_BUTTON_CLICKED:
               if (id == 101)
               {

                  Game::world->dosomething();

                  return true;
               }
               break;
         }
   }

   return false;
   }
};
Hope this helps....
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

The CGame class is written in another file. I've got a solution from a third-party so I'm going to try that. Thanks for helping though.
Post Reply