Using Multiple setEventReceiver

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
Belajar
Posts: 15
Joined: Mon Nov 15, 2010 3:50 am

Using Multiple setEventReceiver

Post by Belajar »

Hello..

I just learn irrlicht a few days ago..

For the shake of simplicity :D, i'm using IrrEventManager..
link:
http://irrlicht.sourceforge.net/phpBB2/ ... 510#156510

so everything running well..till i learn the Tutorial 5 User Interface..

So, i've got two setEventReceiver in my code...

This is the code that i've tried to make

Code: Select all

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#include <irrEventManager.h>



#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "EventManager.lib")
#endif

struct nuklir
{
	IrrlichtDevice *device;
	//s32				counter;
	//IGUIListBox*	listbox;
};

enum {GUI_ID_QUIT_BUTTON = 101};


class MyEventReceiver:public IEventReceiver{
public:
	MyEventReceiver(nuklir & rudal) :sapi(rudal) { } //member dari myeventreceiver
	virtual bool OnEvent(const SEvent& event)
	{
		if (event.EventType == EET_GUI_EVENT)
		{	s32 id = event.GUIEvent.Caller->getID();
			IGUIEnvironment* env = sapi.device->getGUIEnvironment();
			switch(event.GUIEvent.EventType)
			{
			case EGET_BUTTON_CLICKED:
				switch(id)
				{
				case GUI_ID_QUIT_BUTTON:
				
					sapi.device->closeDevice();
				return true;
				}
				break;
			}
		}
		return false;
	}
private:
	nuklir & sapi;
};
int main()
{
	IEventManager* enm;

	IrrlichtDevice *device =
		createDevice( video::EDT_DIRECT3D9, dimension2d<u32>(1024, 768), 16,
			false, true, true, 0);
	if (!device)
		return 1;
	enm = createEventManager();
	

//variable
	scene::ISceneNode* bola1 = 0;
	scene::ISceneNode* bola2 = 0;
	scene::ISceneNode* node = 0;
    scene::ITriangleSelector* selector = 0;
	scene::ISceneNode *g_CameraPositionNode;
	scene::ISceneNode *g_CameraTargetNode;
	scene::ICameraSceneNode* camera = 0;
	scene::ISceneNodeAnimator* mot2 =0;
	scene::ISceneNodeAnimator* mot =0;
	video::IVideoDriver* driver = device->getVideoDriver();
	int tambah = 0;
	scene::IAnimatedMesh* mesh = 0;

//Button=============================================================
	IGUIEnvironment* env = device->getGUIEnvironment();
	env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
			L"Quit", L"Keluar");
	nuklir rudal;
	rudal.device = device;

	// Then create the event receiver, giving it that context structure.
	MyEventReceiver receiver(rudal);
	IGUISkin* skin = env->getSkin();
	IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp");
	if (font)
		skin->setFont(font);

	skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP);
	
	
	device->setEventReceiver(enm);      ================================================>PROBLEM 
	device->setEventReceiver(&receiver) ;===============================================>PROBLEM 

	
	//===============================================================
	device->setWindowCaption(L"Just Learn");

	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();
	smgr->addLightSceneNode(0, core::vector3df(200,1000,200),
                video::SColorf(1.0f,1.0f,1.0f),2000);
    smgr->setAmbientLight(video::SColorf(0.3f,0.3f,0.3f));
	device->getCursorControl()->setVisible(true);
	//tambahan untuk parralax
	video::IMaterialRenderer* renderer = 	driver->getMaterialRenderer(video::EMT_PARALLAX_MAP_SOLID);
	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
	
	
	//MESH	
	IAnimatedMesh* kotak1 = smgr->getMesh("Model/beruang.irrmesh");
	ISceneNode* nodekotak1= smgr->addAnimatedMeshSceneNode(kotak1);
	nodekotak1->setScale(vector3df(3.0f,3.0f,3.0f));
	nodekotak1->setPosition(core::vector3df(0,0,30));
	nodekotak1->setMaterialFlag(video::EMF_LIGHTING, true);
	
	
	
while(device->run()&& driver)
	{
		vector3df pos = camera->getPosition();
		if(enm->keyDown(irr::KEY_ESCAPE))
			device->closeDevice();
		else
		if(enm->keyDown(irr::KEY_KEY_W))
			pos.Y += 0.05f;
		else
			if(enm->keyDown(irr::KEY_KEY_S))
			pos.Y -= 0.05f;
		else
			if(enm->keyDown(irr::KEY_KEY_A))
			pos.X -= 0.05f;
		else
			if(enm->keyDown(irr::KEY_KEY_D))
			pos.X += 0.05f;
		camera->setPosition(pos);

		driver->beginScene(true, true, 0);//SColor(255,100,101,140));
		
		smgr->drawAll();
		guienv->drawAll();
		env->drawAll();
		driver->endScene();
	}
	device->drop();
	return 0;
}

i have 2 setEventReceiver in my code...
device->setEventReceiver(enm); From IrrEventManager
device->setEventReceiver(&receiver); From GUI

How to combine both of my setEventReceiver..?

Thank you so much..
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

I don't think that you can set more than one Event Receiver (the method would be named "addEventReceiver" otherwise ;) ). But you can create your own event receiver that just calls both of your others.
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Belajar
Posts: 15
Joined: Mon Nov 15, 2010 3:50 am

Post by Belajar »

Thank's for the advice..

ok, i'll try it..

i want to make multiple input from my keyboard, mouse and GUI button..
so i can move the object through my keyboard..and also i can click the GUI button..

i've been search the sample, but there's seems no example that give me explanation how to do that..:D
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Post Reply