aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/doc/html/example005.html
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/doc/html/example005.html')
-rw-r--r--libraries/irrlicht-1.8/doc/html/example005.html324
1 files changed, 0 insertions, 324 deletions
diff --git a/libraries/irrlicht-1.8/doc/html/example005.html b/libraries/irrlicht-1.8/doc/html/example005.html
deleted file mode 100644
index 965f00e..0000000
--- a/libraries/irrlicht-1.8/doc/html/example005.html
+++ /dev/null
@@ -1,324 +0,0 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<title>Irrlicht 3D Engine: Tutorial 5: User Interface</title>
6
7<link href="tabs.css" rel="stylesheet" type="text/css"/>
8<link href="doxygen.css" rel="stylesheet" type="text/css" />
9<link href="navtree.css" rel="stylesheet" type="text/css"/>
10<script type="text/javascript" src="jquery.js"></script>
11<script type="text/javascript" src="resize.js"></script>
12<script type="text/javascript" src="navtree.js"></script>
13<script type="text/javascript">
14 $(document).ready(initResizable);
15</script>
16<link href="search/search.css" rel="stylesheet" type="text/css"/>
17<script type="text/javascript" src="search/search.js"></script>
18<script type="text/javascript">
19 $(document).ready(function() { searchBox.OnSelectItem(0); });
20</script>
21
22</head>
23<body>
24<div id="top"><!-- do not remove this div! -->
25
26
27<div id="titlearea">
28<table cellspacing="0" cellpadding="0">
29 <tbody>
30 <tr style="height: 56px;">
31
32 <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
33
34
35 <td style="padding-left: 0.5em;">
36 <div id="projectname">Irrlicht 3D Engine
37
38 </div>
39
40 </td>
41
42
43
44
45 <td> <div id="MSearchBox" class="MSearchBoxInactive">
46 <span class="left">
47 <img id="MSearchSelect" src="search/mag_sel.png"
48 onmouseover="return searchBox.OnSearchSelectShow()"
49 onmouseout="return searchBox.OnSearchSelectHide()"
50 alt=""/>
51 <input type="text" id="MSearchField" value="Search" accesskey="S"
52 onfocus="searchBox.OnSearchFieldFocus(true)"
53 onblur="searchBox.OnSearchFieldFocus(false)"
54 onkeyup="searchBox.OnSearchFieldChange(event)"/>
55 </span><span class="right">
56 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
57 </span>
58 </div>
59</td>
60
61
62 </tr>
63 </tbody>
64</table>
65</div>
66
67<!-- Generated by Doxygen 1.7.5.1 -->
68<script type="text/javascript">
69var searchBox = new SearchBox("searchBox", "search",false,'Search');
70</script>
71<script type="text/javascript" src="dynsections.js"></script>
72</div>
73<div id="side-nav" class="ui-resizable side-nav-resizable">
74 <div id="nav-tree">
75 <div id="nav-tree-contents">
76 </div>
77 </div>
78 <div id="splitbar" style="-moz-user-select:none;"
79 class="ui-resizable-handle">
80 </div>
81</div>
82<script type="text/javascript">
83 initNavTree('example005.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 5: User Interface </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="005shot.jpg" alt="005shot.jpg"/>
93</div>
94 <p>This tutorial shows how to use the built in User Interface of the Irrlicht Engine. It will give a brief overview and show how to create and use windows, buttons, scroll bars, static texts, and list boxes.</p>
95<p>As always, we include the header files, and use the irrlicht namespaces. We also store a pointer to the Irrlicht device, a counter variable for changing the creation position of a window, and a pointer to a listbox. </p>
96<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>
97<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>
98
99<span class="keyword">using namespace </span>irr;
100
101<span class="keyword">using namespace </span>core;
102<span class="keyword">using namespace </span>scene;
103<span class="keyword">using namespace </span>video;
104<span class="keyword">using namespace </span>io;
105<span class="keyword">using namespace </span>gui;
106
107<span class="preprocessor">#ifdef _IRR_WINDOWS_</span>
108<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
109<span class="preprocessor"></span><span class="preprocessor">#endif</span>
110<span class="preprocessor"></span>
111<span class="comment">// Declare a structure to hold some context for the event receiver so that it</span>
112<span class="comment">// has it available inside its OnEvent() method.</span>
113<span class="keyword">struct </span>SAppContext
114{
115 <a class="code" href="classirr_1_1_irrlicht_device.html" title="The Irrlicht device. You can create it with createDevice() or createDeviceEx().">IrrlichtDevice</a> *device;
116 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> counter;
117 IGUIListBox* listbox;
118};
119
120<span class="comment">// Define some values that we&#39;ll use to identify individual GUI controls.</span>
121<span class="keyword">enum</span>
122{
123 GUI_ID_QUIT_BUTTON = 101,
124 GUI_ID_NEW_WINDOW_BUTTON,
125 GUI_ID_FILE_OPEN_BUTTON,
126 GUI_ID_TRANSPARENCY_SCROLL_BAR
127};
128</pre></div><p>The Event Receiver is not only capable of getting keyboard and mouse input events, but also events of the graphical user interface (gui). There are events for almost everything: Button click, Listbox selection change, events that say that a element was hovered and so on. To be able to react to some of these events, we create an event receiver. We only react to gui events, and if it's such an event, we get the id of the caller (the gui element which caused the event) and get the pointer to the gui environment. </p>
129<div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver
130{
131<span class="keyword">public</span>:
132 MyEventReceiver(SAppContext &amp; context) : Context(context) { }
133
134 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
135 {
136 <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0cae85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a>)
137 {
138 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();
139 IGUIEnvironment* env = Context.device-&gt;getGUIEnvironment();
140
141 <span class="keywordflow">switch</span>(event.GUIEvent.EventType)
142 {
143</pre></div><p>If a scrollbar changed its scroll position, and it is 'our' scrollbar (the one with id GUI_ID_TRANSPARENCY_SCROLL_BAR), then we change the transparency of all gui elements. This is a very easy task: There is a skin object, in which all color settings are stored. We simply go through all colors stored in the skin and change their alpha value. </p>
144<div class="fragment"><pre class="fragment"> <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a2eea536494edcde2bb2608bda9d352b2" title="A scrollbar has changed its position.">EGET_SCROLL_BAR_CHANGED</a>:
145 <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_TRANSPARENCY_SCROLL_BAR)
146 {
147 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = ((IGUIScrollBar*)event.GUIEvent.Caller)-&gt;getPos();
148
149 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i&lt;<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aaf340f49e2e0827c0f06fdf65098554af">EGDC_COUNT</a> ; ++i)
150 {
151 SColor col = env-&gt;getSkin()-&gt;getColor((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i);
152 col.setAlpha(pos);
153 env-&gt;getSkin()-&gt;setColor((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i, col);
154 }
155
156 }
157 <span class="keywordflow">break</span>;
158</pre></div><p>If a button was clicked, it could be one of 'our' three buttons. If it is the first, we shut down the engine. If it is the second, we create a little window with some text on it. We also add a string to the list box to log what happened. And if it is the third button, we create a file open dialog, and add also this as string to the list box. That's all for the event receiver. </p>
159<div class="fragment"><pre class="fragment"> <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a308ee345c92444931f83e48354072d98" title="A button was clicked.">EGET_BUTTON_CLICKED</a>:
160 <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>)
161 {
162 <span class="keywordflow">case</span> GUI_ID_QUIT_BUTTON:
163 Context.device-&gt;closeDevice();
164 <span class="keywordflow">return</span> <span class="keyword">true</span>;
165
166 <span class="keywordflow">case</span> GUI_ID_NEW_WINDOW_BUTTON:
167 {
168 Context.listbox-&gt;addItem(L<span class="stringliteral">&quot;Window created&quot;</span>);
169 Context.counter += 30;
170 <span class="keywordflow">if</span> (Context.counter &gt; 200)
171 Context.counter = 0;
172
173 IGUIWindow* window = env-&gt;addWindow(
174 rect&lt;s32&gt;(100 + Context.counter, 100 + Context.counter, 300 + Context.counter, 200 + Context.counter),
175 <span class="keyword">false</span>, <span class="comment">// modal?</span>
176 L<span class="stringliteral">&quot;Test window&quot;</span>);
177
178 env-&gt;addStaticText(L<span class="stringliteral">&quot;Please close me&quot;</span>,
179 rect&lt;s32&gt;(35,35,140,50),
180 <span class="keyword">true</span>, <span class="comment">// border?</span>
181 <span class="keyword">false</span>, <span class="comment">// wordwrap?</span>
182 window);
183 }
184 <span class="keywordflow">return</span> <span class="keyword">true</span>;
185
186 <span class="keywordflow">case</span> GUI_ID_FILE_OPEN_BUTTON:
187 Context.listbox-&gt;addItem(L<span class="stringliteral">&quot;File open&quot;</span>);
188 <span class="comment">// There are some options for the file open dialog</span>
189 <span class="comment">// We set the title, make it a modal window, and make sure</span>
190 <span class="comment">// that the working directory is restored after the dialog</span>
191 <span class="comment">// is finished.</span>
192 env-&gt;addFileOpenDialog(L<span class="stringliteral">&quot;Please choose a file.&quot;</span>, <span class="keyword">true</span>, 0, -1, <span class="keyword">true</span>);
193 <span class="keywordflow">return</span> <span class="keyword">true</span>;
194
195 <span class="keywordflow">default</span>:
196 <span class="keywordflow">return</span> <span class="keyword">false</span>;
197 }
198 <span class="keywordflow">break</span>;
199
200 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a5b6504cf6b541d5ad95407c384632873" title="A file has been selected in the file dialog.">EGET_FILE_SELECTED</a>:
201 {
202 <span class="comment">// show the model filename, selected in the file dialog</span>
203 IGUIFileOpenDialog* dialog =
204 (IGUIFileOpenDialog*)event.GUIEvent.Caller;
205 Context.listbox-&gt;addItem(dialog-&gt;getFileName());
206 }
207 <span class="keywordflow">break</span>;
208
209 <span class="keywordflow">default</span>:
210 <span class="keywordflow">break</span>;
211 }
212 }
213
214 <span class="keywordflow">return</span> <span class="keyword">false</span>;
215 }
216
217<span class="keyword">private</span>:
218 SAppContext &amp; Context;
219};
220</pre></div><p>Ok, now for the more interesting part. First, create the Irrlicht device. As in some examples before, we ask the user which driver he wants to use for this example: </p>
221<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
222{
223 <span class="comment">// ask user for driver</span>
224 <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType=driverChoiceConsole();
225 <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>)
226 <span class="keywordflow">return</span> 1;
227
228 <span class="comment">// create device and exit if creation failed</span>
229
230 IrrlichtDevice * device = <a class="code" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice</a>(driverType, core::dimension2d&lt;u32&gt;(640, 480));
231
232 <span class="keywordflow">if</span> (device == 0)
233 <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
234</pre></div><p> The creation was successful, now we set the event receiver and store pointers to the driver and to the gui environment. </p>
235<div class="fragment"><pre class="fragment"> device-&gt;setWindowCaption(L<span class="stringliteral">&quot;Irrlicht Engine - User Interface Demo&quot;</span>);
236 device-&gt;setResizable(<span class="keyword">true</span>);
237
238 video::IVideoDriver* driver = device-&gt;getVideoDriver();
239 IGUIEnvironment* env = device-&gt;getGUIEnvironment();
240</pre></div><p>To make the font a little bit nicer, we load an external font and set it as the new default font in the skin. To keep the standard font for tool tip text, we set it to the built-in font. </p>
241<div class="fragment"><pre class="fragment"> IGUISkin* skin = env-&gt;getSkin();
242 IGUIFont* font = env-&gt;getFont(<span class="stringliteral">&quot;../../media/fonthaettenschweiler.bmp&quot;</span>);
243 <span class="keywordflow">if</span> (font)
244 skin-&gt;setFont(font);
245
246 skin-&gt;setFont(env-&gt;getBuiltInFont(), <a class="code" href="namespaceirr_1_1gui.html#a9e598ab5e8644d142e55d66e8d308441a9939ed432e179bb20810ee46a82ffcb8" title="Font for tooltips.">EGDF_TOOLTIP</a>);
247</pre></div><p>We add three buttons. The first one closes the engine. The second creates a window and the third opens a file open dialog. The third parameter is the id of the button, with which we can easily identify the button in the event receiver. </p>
248<div class="fragment"><pre class="fragment"> env-&gt;addButton(rect&lt;s32&gt;(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
249 L<span class="stringliteral">&quot;Quit&quot;</span>, L<span class="stringliteral">&quot;Exits Program&quot;</span>);
250 env-&gt;addButton(rect&lt;s32&gt;(10,280,110,280 + 32), 0, GUI_ID_NEW_WINDOW_BUTTON,
251 L<span class="stringliteral">&quot;New Window&quot;</span>, L<span class="stringliteral">&quot;Launches a new Window&quot;</span>);
252 env-&gt;addButton(rect&lt;s32&gt;(10,320,110,320 + 32), 0, GUI_ID_FILE_OPEN_BUTTON,
253 L<span class="stringliteral">&quot;File Open&quot;</span>, L<span class="stringliteral">&quot;Opens a file&quot;</span>);
254</pre></div><p>Now, we add a static text and a scrollbar, which modifies the transparency of all gui elements. We set the maximum value of the scrollbar to 255, because that's the maximal value for a color value. Then we create an other static text and a list box. </p>
255<div class="fragment"><pre class="fragment"> env-&gt;addStaticText(L<span class="stringliteral">&quot;Transparent Control:&quot;</span>, rect&lt;s32&gt;(150,20,350,40), <span class="keyword">true</span>);
256 IGUIScrollBar* scrollbar = env-&gt;addScrollBar(<span class="keyword">true</span>,
257 rect&lt;s32&gt;(150, 45, 350, 60), 0, GUI_ID_TRANSPARENCY_SCROLL_BAR);
258 scrollbar-&gt;setMax(255);
259
260 <span class="comment">// set scrollbar position to alpha value of an arbitrary element</span>
261 scrollbar-&gt;setPos(env-&gt;getSkin()-&gt;getColor(<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aab60eb00de0efde8c5a948ab15d9aa0a7" title="Window background.">EGDC_WINDOW</a>).getAlpha());
262
263 env-&gt;addStaticText(L<span class="stringliteral">&quot;Logging ListBox:&quot;</span>, rect&lt;s32&gt;(50,110,250,130), <span class="keyword">true</span>);
264 IGUIListBox * listbox = env-&gt;addListBox(rect&lt;s32&gt;(50, 140, 250, 210));
265 env-&gt;addEditBox(L<span class="stringliteral">&quot;Editable Text&quot;</span>, rect&lt;s32&gt;(350, 80, 550, 100));
266
267 <span class="comment">// Store the appropriate data in a context structure.</span>
268 SAppContext context;
269 context.device = device;
270 context.counter = 0;
271 context.listbox = listbox;
272
273 <span class="comment">// Then create the event receiver, giving it that context structure.</span>
274 MyEventReceiver receiver(context);
275
276 <span class="comment">// And tell the device to use our custom event receiver.</span>
277 device-&gt;setEventReceiver(&amp;receiver);
278</pre></div><p>And at last, we create a nice Irrlicht Engine logo in the top left corner. </p>
279<div class="fragment"><pre class="fragment"> env-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlichtlogo2.png&quot;</span>),
280 position2d&lt;int&gt;(10,10));
281</pre></div><p>That's all, we only have to draw everything. </p>
282<div class="fragment"><pre class="fragment"> <span class="keywordflow">while</span>(device-&gt;run() &amp;&amp; driver)
283 <span class="keywordflow">if</span> (device-&gt;isWindowActive())
284 {
285 driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, SColor(0,200,200,200));
286
287 env-&gt;drawAll();
288
289 driver-&gt;endScene();
290 }
291
292 device-&gt;drop();
293
294 <span class="keywordflow">return</span> 0;
295}
296</pre></div> </div></div>
297</div>
298 <div id="nav-path" class="navpath">
299 <ul>
300<!-- window showing the filter options -->
301<div id="MSearchSelectWindow"
302 onmouseover="return searchBox.OnSearchSelectShow()"
303 onmouseout="return searchBox.OnSearchSelectHide()"
304 onkeydown="return searchBox.OnSearchSelectKey(event)">
305<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>
306
307<!-- iframe showing the search results (closed by default) -->
308<div id="MSearchResultsWindow">
309<iframe src="javascript:void(0)" frameborder="0"
310 name="MSearchResults" id="MSearchResults">
311</iframe>
312</div>
313
314
315 <li class="footer">
316<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
317Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Tue Nov 6 2012 11:06:01 for Irrlicht 3D Engine by
318<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
319 </ul>
320 </div>
321
322
323</body>
324</html>