diff options
author | David Walter Seikel | 2014-01-13 19:47:58 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-01-13 19:47:58 +1000 |
commit | f9158592e1478b2013afc7041d9ed041cf2d2f4a (patch) | |
tree | b16e389d7988700e21b4c9741044cefa536dcbae /libraries/irrlicht-1.8.1/examples/Demo/CMainMenu.cpp | |
parent | Libraries readme updated with change markers and more of the Irrlicht changes. (diff) | |
download | SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.zip SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.gz SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.bz2 SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.xz |
Update Irrlicht to 1.8.1. Include actual change markers this time. lol
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8.1/examples/Demo/CMainMenu.cpp | 378 |
1 files changed, 378 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/examples/Demo/CMainMenu.cpp b/libraries/irrlicht-1.8.1/examples/Demo/CMainMenu.cpp new file mode 100644 index 0000000..aa963e5 --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/Demo/CMainMenu.cpp | |||
@@ -0,0 +1,378 @@ | |||
1 | // This is a Demo of the Irrlicht Engine (c) 2005-2009 by N.Gebhardt. | ||
2 | // This file is not documented. | ||
3 | |||
4 | #include "CMainMenu.h" | ||
5 | |||
6 | |||
7 | |||
8 | CMainMenu::CMainMenu() | ||
9 | : startButton(0), MenuDevice(0), selected(2), start(false), fullscreen(true), | ||
10 | music(true), shadows(false), additive(false), transparent(true), vsync(false), aa(false) | ||
11 | { | ||
12 | } | ||
13 | |||
14 | |||
15 | bool CMainMenu::run(bool& outFullscreen, bool& outMusic, bool& outShadows, | ||
16 | bool& outAdditive, bool& outVSync, bool& outAA, | ||
17 | video::E_DRIVER_TYPE& outDriver) | ||
18 | { | ||
19 | //video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9; | ||
20 | //video::E_DRIVER_TYPE driverType = video::EDT_OPENGL; | ||
21 | video::E_DRIVER_TYPE driverType = video::EDT_BURNINGSVIDEO; | ||
22 | //video::E_DRIVER_TYPE driverType = video::EDT_SOFTWARE; | ||
23 | |||
24 | MenuDevice = createDevice(driverType, | ||
25 | core::dimension2d<u32>(512, 384), 16, false, false, false, this); | ||
26 | |||
27 | if (MenuDevice->getFileSystem()->existFile("irrlicht.dat")) | ||
28 | MenuDevice->getFileSystem()->addFileArchive("irrlicht.dat"); | ||
29 | else | ||
30 | MenuDevice->getFileSystem()->addFileArchive("../../media/irrlicht.dat"); | ||
31 | |||
32 | video::IVideoDriver* driver = MenuDevice->getVideoDriver(); | ||
33 | scene::ISceneManager* smgr = MenuDevice->getSceneManager(); | ||
34 | gui::IGUIEnvironment* guienv = MenuDevice->getGUIEnvironment(); | ||
35 | |||
36 | core::stringw str = "Irrlicht Engine Demo v"; | ||
37 | str += MenuDevice->getVersion(); | ||
38 | MenuDevice->setWindowCaption(str.c_str()); | ||
39 | |||
40 | // set new Skin | ||
41 | gui::IGUISkin* newskin = guienv->createSkin(gui::EGST_BURNING_SKIN); | ||
42 | guienv->setSkin(newskin); | ||
43 | newskin->drop(); | ||
44 | |||
45 | // load font | ||
46 | gui::IGUIFont* font = guienv->getFont("../../media/fonthaettenschweiler.bmp"); | ||
47 | if (font) | ||
48 | guienv->getSkin()->setFont(font); | ||
49 | |||
50 | // add images | ||
51 | |||
52 | const s32 leftX = 260; | ||
53 | |||
54 | // add tab control | ||
55 | gui::IGUITabControl* tabctrl = guienv->addTabControl(core::rect<int>(leftX,10,512-10,384-10), | ||
56 | 0, true, true); | ||
57 | gui::IGUITab* optTab = tabctrl->addTab(L"Demo"); | ||
58 | gui::IGUITab* aboutTab = tabctrl->addTab(L"About"); | ||
59 | |||
60 | // add list box | ||
61 | |||
62 | gui::IGUIListBox* box = guienv->addListBox(core::rect<int>(10,10,220,120), optTab, 1); | ||
63 | box->addItem(L"OpenGL 1.5"); | ||
64 | box->addItem(L"Direct3D 8.1"); | ||
65 | box->addItem(L"Direct3D 9.0c"); | ||
66 | box->addItem(L"Burning's Video 0.47"); | ||
67 | box->addItem(L"Irrlicht Software Renderer 1.0"); | ||
68 | box->setSelected(selected); | ||
69 | |||
70 | // add button | ||
71 | |||
72 | startButton = guienv->addButton(core::rect<int>(30,295,200,324), optTab, 2, L"Start Demo"); | ||
73 | |||
74 | // add checkbox | ||
75 | |||
76 | const s32 d = 50; | ||
77 | |||
78 | guienv->addCheckBox(fullscreen, core::rect<int>(20,85+d,130,110+d), | ||
79 | optTab, 3, L"Fullscreen"); | ||
80 | guienv->addCheckBox(music, core::rect<int>(135,85+d,245,110+d), | ||
81 | optTab, 4, L"Music & Sfx"); | ||
82 | guienv->addCheckBox(shadows, core::rect<int>(20,110+d,135,135+d), | ||
83 | optTab, 5, L"Realtime shadows"); | ||
84 | guienv->addCheckBox(additive, core::rect<int>(20,135+d,230,160+d), | ||
85 | optTab, 6, L"Old HW compatible blending"); | ||
86 | guienv->addCheckBox(vsync, core::rect<int>(20,160+d,230,185+d), | ||
87 | optTab, 7, L"Vertical synchronisation"); | ||
88 | guienv->addCheckBox(aa, core::rect<int>(20,185+d,230,210+d), | ||
89 | optTab, 8, L"Antialiasing"); | ||
90 | |||
91 | // add about text | ||
92 | |||
93 | const wchar_t* text2 = L"This is the tech demo of the Irrlicht engine. To start, "\ | ||
94 | L"select a video driver which works best with your hardware and press 'Start Demo'.\n"\ | ||
95 | L"What you currently see is displayed using the Burning Software Renderer (Thomas Alten).\n"\ | ||
96 | L"The Irrlicht Engine was written by me, Nikolaus Gebhardt. The models, "\ | ||
97 | L"maps and textures were placed at my disposal by B.Collins, M.Cook and J.Marton. The music was created by "\ | ||
98 | L"M.Rohde and is played back by irrKlang.\n"\ | ||
99 | L"For more informations, please visit the homepage of the Irrlicht engine:\nhttp://irrlicht.sourceforge.net"; | ||
100 | |||
101 | guienv->addStaticText(text2, core::rect<int>(10, 10, 230, 320), | ||
102 | true, true, aboutTab); | ||
103 | |||
104 | // add md2 model | ||
105 | |||
106 | scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/faerie.md2"); | ||
107 | scene::IAnimatedMeshSceneNode* modelNode = smgr->addAnimatedMeshSceneNode(mesh); | ||
108 | if (modelNode) | ||
109 | { | ||
110 | modelNode->setPosition( core::vector3df(0.f, 0.f, -5.f) ); | ||
111 | modelNode->setMaterialTexture(0, driver->getTexture("../../media/faerie2.bmp")); | ||
112 | modelNode->setMaterialFlag(video::EMF_LIGHTING, true); | ||
113 | modelNode->getMaterial(0).Shininess = 50.f; | ||
114 | modelNode->getMaterial(0).NormalizeNormals = true; | ||
115 | modelNode->setMD2Animation(scene::EMAT_STAND); | ||
116 | } | ||
117 | |||
118 | // set ambient light (no sun light in the catacombs) | ||
119 | smgr->setAmbientLight( video::SColorf(0.2f, 0.2f, 0.2f) ); | ||
120 | |||
121 | scene::ILightSceneNode *light; | ||
122 | scene::ISceneNodeAnimator* anim; | ||
123 | scene::ISceneNode* bill; | ||
124 | |||
125 | enum eLightParticle | ||
126 | { | ||
127 | LIGHT_NONE, | ||
128 | LIGHT_GLOBAL, | ||
129 | LIGHT_RED, | ||
130 | LIGHT_BLUE | ||
131 | }; | ||
132 | core::vector3df lightDir[2] = { | ||
133 | core::vector3df(0.f, 0.1f, 0.4f), | ||
134 | core::vector3df(0.f, 0.1f, -0.4f), | ||
135 | }; | ||
136 | |||
137 | struct SLightParticle | ||
138 | { | ||
139 | eLightParticle type; | ||
140 | u32 dir; | ||
141 | }; | ||
142 | const SLightParticle lightParticle[] = | ||
143 | { | ||
144 | //LIGHT_GLOBAL,0, | ||
145 | {LIGHT_RED,0}, | ||
146 | {LIGHT_BLUE,0}, | ||
147 | {LIGHT_RED,1}, | ||
148 | {LIGHT_BLUE,1}, | ||
149 | {LIGHT_NONE,0} | ||
150 | }; | ||
151 | |||
152 | const SLightParticle *l = lightParticle; | ||
153 | while ( l->type != LIGHT_NONE ) | ||
154 | { | ||
155 | switch ( l->type ) | ||
156 | { | ||
157 | case LIGHT_GLOBAL: | ||
158 | // add illumination from the background | ||
159 | light = smgr->addLightSceneNode(0, core::vector3df(10.f,40.f,-5.f), | ||
160 | video::SColorf(0.2f, 0.2f, 0.2f), 90.f); | ||
161 | break; | ||
162 | case LIGHT_RED: | ||
163 | // add light nearly red | ||
164 | light = smgr->addLightSceneNode(0, core::vector3df(0,1,0), | ||
165 | video::SColorf(0.8f, 0.f, 0.f, 0.0f), 30.0f); | ||
166 | // attach red billboard to the light | ||
167 | bill = smgr->addBillboardSceneNode(light, core::dimension2d<f32>(10, 10)); | ||
168 | if ( bill ) | ||
169 | { | ||
170 | bill->setMaterialFlag(video::EMF_LIGHTING, false); | ||
171 | bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); | ||
172 | bill->setMaterialTexture(0, driver->getTexture("../../media/particlered.bmp")); | ||
173 | } | ||
174 | // add fly circle animator to the light | ||
175 | anim = smgr->createFlyCircleAnimator(core::vector3df(0.f,0.f,-5.f),20.f, | ||
176 | 0.002f, lightDir [l->dir] ); | ||
177 | light->addAnimator(anim); | ||
178 | anim->drop(); | ||
179 | break; | ||
180 | case LIGHT_BLUE: | ||
181 | // add light nearly blue | ||
182 | light = smgr->addLightSceneNode(0, core::vector3df(0,1,0), | ||
183 | video::SColorf(0.f, 0.0f, 0.8f, 0.0f), 30.0f); | ||
184 | // attach blue billboard to the light | ||
185 | bill = smgr->addBillboardSceneNode(light, core::dimension2d<f32>(10, 10)); | ||
186 | if (bill) | ||
187 | { | ||
188 | bill->setMaterialFlag(video::EMF_LIGHTING, false); | ||
189 | bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); | ||
190 | bill->setMaterialTexture(0, driver->getTexture("../../media/portal1.bmp")); | ||
191 | } | ||
192 | // add fly circle animator to the light | ||
193 | anim = smgr->createFlyCircleAnimator(core::vector3df(0.f,0.f,-5.f),20.f, | ||
194 | -0.002f, lightDir [l->dir], 0.5f); | ||
195 | light->addAnimator(anim); | ||
196 | anim->drop(); | ||
197 | break; | ||
198 | case LIGHT_NONE: | ||
199 | break; | ||
200 | } | ||
201 | l += 1; | ||
202 | } | ||
203 | |||
204 | // create a fixed camera | ||
205 | smgr->addCameraSceneNode(0, core::vector3df(45,0,0), core::vector3df(0,0,10)); | ||
206 | |||
207 | |||
208 | // irrlicht logo and background | ||
209 | // add irrlicht logo | ||
210 | bool oldMipMapState = driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); | ||
211 | driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); | ||
212 | |||
213 | guienv->addImage(driver->getTexture("../../media/irrlichtlogo3.png"), | ||
214 | core::position2d<s32>(5,5)); | ||
215 | |||
216 | video::ITexture* irrlichtBack = driver->getTexture("../../media/demoback.jpg"); | ||
217 | |||
218 | driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState); | ||
219 | |||
220 | // query original skin color | ||
221 | getOriginalSkinColor(); | ||
222 | |||
223 | // set transparency | ||
224 | setTransparency(); | ||
225 | |||
226 | // draw all | ||
227 | |||
228 | while(MenuDevice->run()) | ||
229 | { | ||
230 | if (MenuDevice->isWindowActive()) | ||
231 | { | ||
232 | driver->beginScene(false, true, video::SColor(0,0,0,0)); | ||
233 | |||
234 | if (irrlichtBack) | ||
235 | driver->draw2DImage(irrlichtBack, | ||
236 | core::position2d<int>(0,0)); | ||
237 | |||
238 | smgr->drawAll(); | ||
239 | guienv->drawAll(); | ||
240 | driver->endScene(); | ||
241 | } | ||
242 | } | ||
243 | |||
244 | MenuDevice->drop(); | ||
245 | |||
246 | outFullscreen = fullscreen; | ||
247 | outMusic = music; | ||
248 | outShadows = shadows; | ||
249 | outAdditive = additive; | ||
250 | outVSync = vsync; | ||
251 | outAA = aa; | ||
252 | |||
253 | switch(selected) | ||
254 | { | ||
255 | case 0: outDriver = video::EDT_OPENGL; break; | ||
256 | case 1: outDriver = video::EDT_DIRECT3D8; break; | ||
257 | case 2: outDriver = video::EDT_DIRECT3D9; break; | ||
258 | case 3: outDriver = video::EDT_BURNINGSVIDEO; break; | ||
259 | case 4: outDriver = video::EDT_SOFTWARE; break; | ||
260 | } | ||
261 | |||
262 | return start; | ||
263 | } | ||
264 | |||
265 | |||
266 | bool CMainMenu::OnEvent(const SEvent& event) | ||
267 | { | ||
268 | if (event.EventType == EET_KEY_INPUT_EVENT && | ||
269 | event.KeyInput.Key == KEY_F9 && | ||
270 | event.KeyInput.PressedDown == false) | ||
271 | { | ||
272 | video::IImage* image = MenuDevice->getVideoDriver()->createScreenShot(); | ||
273 | if (image) | ||
274 | { | ||
275 | MenuDevice->getVideoDriver()->writeImageToFile(image, "screenshot_main.jpg"); | ||
276 | image->drop(); | ||
277 | } | ||
278 | } | ||
279 | else | ||
280 | if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && | ||
281 | event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP ) | ||
282 | { | ||
283 | core::rect<s32> r(event.MouseInput.X, event.MouseInput.Y, 0, 0); | ||
284 | gui::IGUIContextMenu* menu = MenuDevice->getGUIEnvironment()->addContextMenu(r, 0, 45); | ||
285 | menu->addItem(L"transparent menus", 666, transparent == false); | ||
286 | menu->addItem(L"solid menus", 666, transparent == true); | ||
287 | menu->addSeparator(); | ||
288 | menu->addItem(L"Cancel"); | ||
289 | } | ||
290 | else | ||
291 | if (event.EventType == EET_GUI_EVENT) | ||
292 | { | ||
293 | s32 id = event.GUIEvent.Caller->getID(); | ||
294 | switch(id) | ||
295 | { | ||
296 | case 45: // context menu | ||
297 | if (event.GUIEvent.EventType == gui::EGET_MENU_ITEM_SELECTED) | ||
298 | { | ||
299 | s32 s = ((gui::IGUIContextMenu*)event.GUIEvent.Caller)->getSelectedItem(); | ||
300 | if (s == 0 || s == 1) | ||
301 | { | ||
302 | transparent = !transparent; | ||
303 | setTransparency(); | ||
304 | } | ||
305 | } | ||
306 | break; | ||
307 | case 1: | ||
308 | if (event.GUIEvent.EventType == gui::EGET_LISTBOX_CHANGED || | ||
309 | event.GUIEvent.EventType == gui::EGET_LISTBOX_SELECTED_AGAIN) | ||
310 | { | ||
311 | selected = ((gui::IGUIListBox*)event.GUIEvent.Caller)->getSelected(); | ||
312 | //startButton->setEnabled(selected != 4); | ||
313 | startButton->setEnabled(true); | ||
314 | } | ||
315 | break; | ||
316 | case 2: | ||
317 | if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED ) | ||
318 | { | ||
319 | MenuDevice->closeDevice(); | ||
320 | start = true; | ||
321 | } | ||
322 | case 3: | ||
323 | if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED ) | ||
324 | fullscreen = ((gui::IGUICheckBox*)event.GUIEvent.Caller)->isChecked(); | ||
325 | break; | ||
326 | case 4: | ||
327 | if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED ) | ||
328 | music = ((gui::IGUICheckBox*)event.GUIEvent.Caller)->isChecked(); | ||
329 | break; | ||
330 | case 5: | ||
331 | if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED ) | ||
332 | shadows = ((gui::IGUICheckBox*)event.GUIEvent.Caller)->isChecked(); | ||
333 | break; | ||
334 | case 6: | ||
335 | if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED ) | ||
336 | additive = ((gui::IGUICheckBox*)event.GUIEvent.Caller)->isChecked(); | ||
337 | break; | ||
338 | case 7: | ||
339 | if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED ) | ||
340 | vsync = ((gui::IGUICheckBox*)event.GUIEvent.Caller)->isChecked(); | ||
341 | break; | ||
342 | case 8: | ||
343 | if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED ) | ||
344 | aa = ((gui::IGUICheckBox*)event.GUIEvent.Caller)->isChecked(); | ||
345 | break; | ||
346 | } | ||
347 | } | ||
348 | |||
349 | return false; | ||
350 | } | ||
351 | |||
352 | |||
353 | void CMainMenu::getOriginalSkinColor() | ||
354 | { | ||
355 | irr::gui::IGUISkin * skin = MenuDevice->getGUIEnvironment()->getSkin(); | ||
356 | for (s32 i=0; i<gui::EGDC_COUNT ; ++i) | ||
357 | { | ||
358 | SkinColor[i] = skin->getColor( (gui::EGUI_DEFAULT_COLOR)i ); | ||
359 | } | ||
360 | |||
361 | } | ||
362 | |||
363 | |||
364 | void CMainMenu::setTransparency() | ||
365 | { | ||
366 | irr::gui::IGUISkin * skin = MenuDevice->getGUIEnvironment()->getSkin(); | ||
367 | |||
368 | for (u32 i=0; i<gui::EGDC_COUNT ; ++i) | ||
369 | { | ||
370 | video::SColor col = SkinColor[i]; | ||
371 | |||
372 | if (false == transparent) | ||
373 | col.setAlpha(255); | ||
374 | |||
375 | skin->setColor((gui::EGUI_DEFAULT_COLOR)i, col); | ||
376 | } | ||
377 | } | ||
378 | |||