#include #include #include using namespace irr; class GUIFormSpecMenu : public gui::IGUIElement { public: GUIFormSpecMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, const core::rect &rect): IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rect) { m_allow_focus_removal = false; setVisible(true); Environment->setFocus(this); core::rect listbox_rect(10, 10, 100, 200); gui::IGUIListBox *listbox = Environment->addListBox( listbox_rect, this, -1, true); listbox->addItem(L"Amazing apple pie"); listbox->addItem(L"Bulky banana cream"); listbox->addItem(L"Cool cherry sushi"); listbox->addItem(L"Duftend Durian juice"); listbox->addItem(L"Eloquent edible grass"); listbox->addItem(L"Fried flaspberries"); listbox->addItem(L"Gigantic gross guanotree grease"); listbox->addItem(L"Heavy hot hippopotamus potato"); listbox->addItem(L"Invisible icecream"); listbox->addItem(L"Juicy juicejunk"); listbox->addItem(L"Kleptomanic ketogenic leprechaunberries"); listbox->addItem(L"Literate limonade"); listbox->addItem(L"Minced melon meat"); listbox->addItem(L"Nitty nutty nuts"); listbox->addItem(L"Ordinary oatmeal"); } virtual ~GUIFormSpecMenu() { } void allowFocusRemoval(bool allow) { m_allow_focus_removal = allow; } bool canTakeFocus(gui::IGUIElement *e) { return (e && (e == this || isMyChild(e))) || m_allow_focus_removal; } void draw() { if(!IsVisible) return; video::IVideoDriver* driver = Environment->getVideoDriver(); video::SColor bgcolor(140,0,0,0); driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); /* Call base class */ gui::IGUIElement::draw(); } virtual bool OnEvent(const SEvent& event) { if(event.EventType==EET_MOUSE_INPUT_EVENT && event.MouseInput.Event != EMIE_MOUSE_MOVED) { // Mouse event other than movement //... } if(event.EventType==EET_GUI_EVENT) { //... if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { if(!canTakeFocus(event.GUIEvent.Element)) { std::cerr<<"GUIFormSpecMenu: Not allowing focus change." <OnEvent(event) : false; } private: bool m_allow_focus_removal; }; class MyEventReceiver : public IEventReceiver { public: MyEventReceiver() { // nothing here currently } virtual bool OnEvent(const SEvent& event) { // nothing here currently return false; } }; int main(int argc, char **argv) { video::E_DRIVER_TYPE driverType=video::EDT_OPENGL; // create device MyEventReceiver receiver; IrrlichtDevice *device = createDevice(driverType, core::dimension2d(512, 384), 16, false, false, false, &receiver); if (device == 0) return 1; // could not create selected driver. device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo"); video::IVideoDriver *driver = device->getVideoDriver(); gui::IGUIEnvironment *guienv = device->getGUIEnvironment(); gui::IGUIFont *font = guienv->getBuiltInFont(); gui::IGUISkin *skin = guienv->getSkin(); //skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0)); skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255)); //skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(0,0,0,0)); //skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(0,0,0,0)); skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0)); skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0)); skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255,70,100,50)); skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255,255,255,255)); core::rect formspec_rect(5, 5, 200, 300); GUIFormSpecMenu *formspec = new GUIFormSpecMenu(guienv, guienv->getRootGUIElement(), -1, formspec_rect); while(device->run() && driver) { if (device->isWindowActive()) { u32 time = device->getTimer()->getTime(); driver->beginScene(true, true, video::SColor(255,120,102,136)); guienv->drawAll(); driver->endScene(); } } device->drop(); return 0; }