Paste #7nn -- näytä pelkkänä tekstinä -- uusi tämän pohjalta
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | #include <irrlicht.h> #include <irrTypes.h> #include <iostream> using namespace irr; class GUIFormSpecMenu : public gui::IGUIElement { public: GUIFormSpecMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, const core::rect<s32> &rect): IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rect) { m_allow_focus_removal = false; setVisible(true); Environment->setFocus(this); core::rect<s32> 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." <<std::endl; // Returning true disables focus change return true; } } //... if((event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN) || (event.GUIEvent.EventType==gui::EGET_LISTBOX_CHANGED)) { //... return true; } } return Parent ? Parent->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<u32>(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<s32> 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; } |