i'm working on some kind of a level editor for my game that i haven't made yet, to improve my skills, but there's a little problemo with my code.
i've created a menubar usin' the built-in gui functionality, but soon as i set an event receiver object for the device, the menus won't work anymore.
i've been searching for answers some time now, and i can't seem to figure it out. the event receiver is based on the one in that mesh viewer tutorial (n° 9) doesn't differs much from my code, but when i compile the tutorial, there is no problemos!!
anyone can see what i'm doin' wrong?
reward is 50,000 $...
here is the freakin' code:
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace std;
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
IrrlichtDevice * device = 0;
class CEventReceiver : public IEventReceiver {
public:
virtual bool OnEvent (const SEvent &event) {
switch (event.EventType) {
case EET_KEY_INPUT_EVENT:
switch (event.KeyInput.Key) {
case KEY_ESCAPE:
device->closeDevice ();
break;
}
break;
case EET_GUI_EVENT:
gui::IGUIEnvironment * guienv = device->getGUIEnvironment ();
switch (event.GUIEvent.EventType) {
case gui::EGET_MENU_ITEM_SELECTED:
gui::IGUIContextMenu * menu = (gui::IGUIContextMenu *)event.GUIEvent.Caller;
s32 id = menu->getItemCommandId (menu->getSelectedItem () );
switch (id) {
case 100:
//new...
break;
case 101:
//open...
break;
case 102:
//save
break;
case 103:
//save as...
break;
case 104:
//close
break;
case 105:
//exit
break;
case 106:
//view toolbar
break;
case 107:
//view list of objects
break;
case 108:
//view map
break;
case 109:
//view settings
break;
case 110:
//tip of the day
break;
case 111:
//contents
break;
case 112:
//visit website
break;
case 113:
//about
break;
} // end switch (id)
break;
}
}
}
} receiver;
video::E_DRIVER_TYPE getDriverType () {
c8 key;
cout << "\n";
cout << " 1 - Direct3D 9.0c\n";
cout << " 2 - Direct3D 8.1\n";
cout << " 3 - OpenGL 2\n";
cout << " 4 - Software\n";
cout << "Please pick a video driver of choise: ";
cin >> key;
switch (key) {
case '1': return (video::EDT_DIRECT3D9);
case '2': return (video::EDT_DIRECT3D8);
case '3': return (video::EDT_OPENGL);
case '4': return (video::EDT_BURNINGSVIDEO);
default: return (getDriverType () );
}
}
int main () {
device = createDevice (getDriverType (), core::dimension2d<s32> (800, 480), 32, false, true,
false, 0, IRRLICHT_SDK_VERSION);
if (!device)
return 1;
device->setResizeAble (true);
device->setEventReceiver (&receiver);
video::IVideoDriver * driver = device->getVideoDriver ();
gui::IGUIEnvironment * guienv = device->getGUIEnvironment ();
scene::ISceneManager * smgr = device->getSceneManager ();
gui::IGUIFont * font = guienv->getFont ("resources\\font.png");
gui::IGUISkin * skin = guienv->getSkin ();
skin->setFont (font);
device->setWindowCaption (L"World Editor v1.0 - Untitled");
gui::IGUIContextMenu * menu = guienv->addMenu (0, 100);
menu->addItem (L"File", -1, true, true, false);
menu->addItem (L"View", -1, true, true, false);
menu->addItem (L"Help", -1, true, true, false);
gui::IGUIContextMenu * submenu;
submenu = menu->getSubMenu (0);
submenu->addItem (L"New...", 100);
submenu->addItem (L"Open...", 101);
submenu->addItem (L"Save", 102);
submenu->addItem (L"Save as...", 103);
submenu->addItem (L"Close", 104);
submenu->addItem (L"Exit", 105);
submenu = menu->getSubMenu (1);
submenu->addItem (L"Toolbar", 106);
submenu->addItem (L"List of Objects", 107);
submenu->addItem (L"Map", 108);
submenu->addItem (L"Settings", 109);
submenu = menu->getSubMenu (2);
submenu->addItem (L"Tip of the day", 110);
submenu->addItem (L"Contents", 111);
submenu->addItem (L"Visit website", 112);
submenu->addItem (L"About", 113);
gui::IGUIStaticText * txtFPS = guienv->addStaticText (L"", core::rect<s32> (256, 2, 360, 18),
true, false, menu, 200, true);
while (device->run () ) {
core::stringw str = L"FPS: ";
str += driver->getFPS ();
txtFPS->setText (str.c_str () );
driver->beginScene (true, true, video::SColor (255, 96, 96, 96) );
smgr->drawAll ();
guienv->drawAll ();
driver->endScene ();
}
device->drop ();
return 0;
}
Code: Select all
device->setEventReceiver (&receiver);
but of course then the event receiver is disabled to!! this is freaking me out!
IDE is Dev-C++ 4.9.9.2 thing (windows version), usin' built-in compiler gcc,
i have the latest version of Irrlicht (1.4)[/code]