<td><pre>void showAboutText()<br>{<br><fontcolor="#006600"> // create modal message box with the text<br> // loaded from the xml file</font><fontcolor="#00CC00">.</font><br> Device->getGUIEnvironment()->addMessageBox(<br> Caption.c_str(), MessageText.c_str());<br>}</pre></td>
</tr>
</table>
<p> The second function loadModel() loads a model and displays it using
an addAnimatedMeshSceneNode and the scene manager. Nothing difficult.
It also displays a short message box, if the model could not be loaded.
<td><pre>void loadModel(const c8* filename)<br>{<br><fontcolor="#006600">// load a model into the engine</font><br> if (Model)<br> Model->remove();<br> Model = 0;<br><br> scene::IAnimatedMesh* m = Device->getSceneManager()->getMesh(filename);<br> if (!m) <br> {<br><fontcolor="#006600">// model could not be loaded</font><br> if (StartUpModelFile != filename)<br> Device->getGUIEnvironment()->addMessageBox(<br> Caption.c_str(), L"The model could not be loaded. " \<br> L"Maybe it is not a supported file format.");<br> return;<br> }<br><br><fontcolor="#006600"> // set default material properties</font><br> Model = Device->getSceneManager()->addAnimatedMeshSceneNode(m);<br> Model->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);<br> Model->setMaterialFlag(video::EMF_LIGHTING, false);<br> Model->setDebugDataVisible(true);<br>}</pre></td>
</tr>
</table>
<p> Finally, the third function creates a toolbox window. In this simple
mesh viewer, this toolbox only contains a tab control with three edit
boxes for changing the scale of the displayed model.</p>
<td><pre><fontsize="2">class MyEventReceiver : public IEventReceiver<br>{<br>public:<br> virtual bool OnEvent(const SEvent& event)<br> {<br> if (event.EventType == EET_GUI_EVENT)<br> {<br> s32 id = event.GUIEvent.Caller->getID();<br> IGUIEnvironment* env = Device->getGUIEnvironment();<br> switch(event.GUIEvent.EventType)<br> {<br> case EGET_MENU_ITEM_SELECTED:<br> {<br><fontcolor="#006600"> // a menu item was clicked</font><br> IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;<br> s32 id = menu->getItemCommandId(menu->getSelectedItem());<br><br> switch(id)<br> {<br> case 100<fontcolor="#006600">: // File -> Open Mode</font>l<br> env->addFileOpenDialog(L"Please select a model file to open");<br> break;<br> case 200<fontcolor="#006600">: // File -> Quit</font><br> Device->closeDevice();<br> break;<br> case 300<fontcolor="#006600">: // View -> Skybox</font><br> SkyBox->setVisible(!SkyBox->isVisible());<br> break;<br> case 400<fontcolor="#006600">: // View -> Debug Informatio</font>n<br> if (Model)<br> Model->setDebugDataVisible(!Model->isDebugDataVisible());<br> break;<br> case 500<fontcolor="#006600">: // Help->About</font><br> showAboutText();<br> break;<br> case 610<fontcolor="#006600">: // View -> Material -> Soli</font>d<br> if (Model)<br> Model->setMaterialType(video::EMT_SOLID);<br> break;<br> case 620<fontcolor="#006600">: // View -> Material -> Transparen</font>t<br> if (Model)<br> Model->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);<br> break;<br> case 630<fontcolor="#006600">: // View -> Material -> Reflectio</font>n<br> if (Model)<br> Model->setMaterialType(video::EMT_SPHERE_MAP);<br> break;<br> }<br> break;<br> }<br> case EGET_FILE_SELECTED:<br> {<br><fontcolor="#006600"> // load the model file, selected in the file open dialo</font>g<br> IGUIFileOpenDialog* dialog = <br> (IGUIFileOpenDialog*)event.GUIEvent.Caller;<br> loadModel(core::stringc(dialog->getFilename()).c_str());<br> }<br> case EGET_BUTTON_CLICKED:<br> switch(id)<br> {<br> case 1101:<br> {<br><fontcolor="#006600"> // set scal</font>e<br> gui::IGUIElement* root = env->getRootGUIElement();<br> core::vector3df scale;<br> core::stringc s;<br> s = root->getElementFromId(901, true)->getText();<br> scale.X = (f32)atof(s.c_str());<br> s = root->getElementFromId(902, true)->getText();<br> scale.Y = (f32)atof(s.c_str());<br> s = root->getElementFromId(903, true)->getText();<br> scale.Z = (f32)atof(s.c_str());<br> if (Model)<br> Model->setScale(scale);<br> }<br> break;<br> case 1102:<br> env->addFileOpenDialog(L"Please select a model file to open");<br> break;<br> case 1103:<br> showAboutText();<br> break;<br> case 1104:<br> createToolBox();<br> break;<br> }<br> break;<br> }<br> }<br> return false;<br> }<br>};</font></pre></td>
<td><pre><fontcolor="#006600">// read configuration from xml file</font><br> io::IXMLReader* xml =<br> Device->getFileSystem()->createXMLReader("../../media/config.xml");<br> while(xml && xml->read())<br> {<br> switch(xml->getNodeType())<br> {<br> case io::EXN_TEXT:<br><fontcolor="#006600">// in this xml file, the only text which occurs is the messageText</font><br> MessageText = xml->getNodeData();<br> break;<br> case io::EXN_ELEMENT:<br> {<br> if (core::stringw("startUpModel") == xml->getNodeName())<br> StartUpModelFile = xml->getAttributeValue(L"file");<br> else<br> if (core::stringw("messageText") == xml->getNodeName())<br> Caption = xml->getAttributeValue(L"caption");<br> }<br> break;<br> }<br> }<br> if (xml)<br> xml->drop(); <fontcolor="#006600">// don't forget to delete the xml reader </font><br>
</pre></td>
</tr>
</table>
<p> That wasn't difficult. Now we'll set a nicer font and create the Menu.
It is possible to create submenus for every menu item. The call menu->addItem(L"File",
-1, true, true); for example adds a new menu Item with the name "File"
and the id -1. The following parameter says that the menu item should
be enabled, and the last one says, that there should be a submenu. The
submenu can now be accessed with menu->getSubMenu(0), because the
"File" entry is the menu item with index 0. </p>