Page 1 of 1

Event Receiver in class

Posted: Tue Dec 13, 2005 4:20 am
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;
}

Posted: Tue Dec 13, 2005 8:15 am
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....

Posted: Wed Dec 14, 2005 8:01 pm
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.