IMasterReceiver.h (One Event Receiver to Rule Them ALL!)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

IMasterReceiver.h (One Event Receiver to Rule Them ALL!)

Post by Midnight »

Ok we should start by talking a bit about the insecurities or otherwise hidden functionality of this receiver interface.

when you use this in your code someone else could use it against you as keyinput, ect..

you'll need to secure your code if you use this and want to stop someone from hijacking your eventreceiver. you do that by renaming the file.. or by changing the input enumerations in irrlicht.. or something to that effect.

without further adieu I present Lord of the Receivers...

IMasterReceiver.h

Code: Select all

#ifndef _I_MASTER_RECEIVER_H_
#define _I_MASTER_RECEIVER_H_

#include "IEventReceiver.h"
//#include "IReferenceCounted.h"

class IMasterReceiver : public irr::IEventReceiver//, public irr::IReferenceCounted 
{ 
	public:

		/** GUI Element Handling **/

		//Button Push
		virtual bool OnButtonPush(irr::gui::IGUIElement* element) 
		{ return false; } 

		//Focus Lost
		virtual bool OnFocusLost(irr::gui::IGUIElement* element)
		{ return false; } 


		/** Keyboard Input Handling **/

		//Key Pressed
		virtual bool OnKeyDown(irr::EKEY_CODE key)
		{ return false; }

		//Key Let Up
		virtual bool OnKeyUp(irr::EKEY_CODE key)
		{ return false; }


		/** Mouse Input Handling **/

		//Mouse Button Up
		virtual bool OnMouseUp(int IdNum, int x,int y)
		{ return false; }

		//Mouse Button Down
		virtual bool OnMouseDown(int IdNum, int x,int y)
		{ return false; }

		//Mouse Cursor Moved
		virtual bool OnMouseMovement(int x,int y)
		{ return false; }

		//Mouse Wheel Scrolled
		virtual bool OnMouseWheel(float WheelPos)
		{ return false; }


		/** OnEvent **/
		virtual bool OnEvent(const irr::SEvent &e) 
		{  
			switch(e.EventType)
			{
				//GUI Events
				case irr::EET_GUI_EVENT : 
				{
					switch (e.GUIEvent.EventType)
					{
						case irr::gui::EGET_BUTTON_CLICKED :
						{
							return OnButtonPush((irr::gui::IGUIButton*) e.GUIEvent.Caller);
						}
						
						case irr::gui::EGET_ELEMENT_FOCUS_LOST:
						{
							return OnFocusLost((irr::gui::IGUIElement*) e.GUIEvent.Caller);
						}
					}
				}

				//Keyboard Events
				case irr::EET_KEY_INPUT_EVENT : 
				{
					keys[e.KeyInput.Key] = e.KeyInput.PressedDown;
					
					if(e.KeyInput.PressedDown)
						return OnKeyDown(e.KeyInput.Key);
					else
						return OnKeyUp(e.KeyInput.Key);
				}

				//Mouse Events
				case irr::EET_MOUSE_INPUT_EVENT : 
				{
					switch (e.MouseInput.Event)
					{
						case irr::EMIE_LMOUSE_LEFT_UP :
						{return OnMouseUp(0, e.MouseInput.X, e.MouseInput.Y);}

						case irr::EMIE_LMOUSE_PRESSED_DOWN :
						{return OnMouseDown(1, e.MouseInput.X, e.MouseInput.Y);}

						case irr::EMIE_MMOUSE_LEFT_UP :
						{return OnMouseUp(2, e.MouseInput.X, e.MouseInput.Y);}

						case irr::EMIE_MMOUSE_PRESSED_DOWN :
						{return OnMouseDown(3, e.MouseInput.X, e.MouseInput.Y);}

						case irr::EMIE_RMOUSE_LEFT_UP :
						{return OnMouseUp(4, e.MouseInput.X, e.MouseInput.Y);}

						case irr::EMIE_RMOUSE_PRESSED_DOWN :
						{return OnMouseDown(5, e.MouseInput.X, e.MouseInput.Y);}

						case irr::EMIE_MOUSE_MOVED :
						{return OnMouseMovement( e.MouseInput.X, e.MouseInput.Y);}

						case irr::EMIE_MOUSE_WHEEL :
						{return OnMouseWheel( e.MouseInput.Wheel);}

					}
				}

				//Log Events
				case irr::EET_LOG_TEXT_EVENT : 
				{}

			}   
			
			return false;
		}

		private:
		
		// Enumeration keys to boolean
		bool keys[irr::KEY_KEY_CODES_COUNT]; 

};

#endif

the log events aren't finished but this is provided as-is without warrenty no holds barred. don't cry to me if this breaks your $hit and I'm not real thrilled to support this much either for certain personal reasons.

ask your questions if you like but I'll be avoiding the extreamly complex ones in hopes that this thing is as simple as it gets.

I here by release this source to the public domain.
Post Reply