aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/doc/html/example005.html
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/doc/html/example005.html')
-rw-r--r--src/others/irrlicht-1.8.1/doc/html/example005.html329
1 files changed, 329 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/doc/html/example005.html b/src/others/irrlicht-1.8.1/doc/html/example005.html
new file mode 100644
index 0000000..1148a3f
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/doc/html/example005.html
@@ -0,0 +1,329 @@
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>Set the skin transparency by changing the alpha values of all skin-colors </p>
129<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> setSkinTransparency(<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> alpha, <a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html" title="A skin modifies the look of the GUI elements.">irr::gui::IGUISkin</a> * skin)
130{
131 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=0; i&lt;<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aaf340f49e2e0827c0f06fdf65098554af">irr::gui::EGDC_COUNT</a> ; ++i)
132 {
133 video::SColor col = skin-&gt;<a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ad1afa2e5e34c30e0cbfb85b1dee2dbe3" title="returns default color">getColor</a>((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i);
134 col.setAlpha(alpha);
135 skin-&gt;<a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ab9782296ba881872207a0915a81d7807" title="sets a default color">setColor</a>((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i, col);
136 }
137}
138</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>
139<div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver
140{
141<span class="keyword">public</span>:
142 MyEventReceiver(SAppContext &amp; context) : Context(context) { }
143
144 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
145 {
146 <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>)
147 {
148 <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();
149 IGUIEnvironment* env = Context.device-&gt;getGUIEnvironment();
150
151 <span class="keywordflow">switch</span>(event.GUIEvent.EventType)
152 {
153</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>
154<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>:
155 <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_TRANSPARENCY_SCROLL_BAR)
156 {
157 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = ((IGUIScrollBar*)event.GUIEvent.Caller)-&gt;getPos();
158 setSkinTransparency(pos, env-&gt;getSkin());
159 }
160 <span class="keywordflow">break</span>;
161</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>
162<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>:
163 <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>)
164 {
165 <span class="keywordflow">case</span> GUI_ID_QUIT_BUTTON:
166 Context.device-&gt;closeDevice();
167 <span class="keywordflow">return</span> <span class="keyword">true</span>;
168
169 <span class="keywordflow">case</span> GUI_ID_NEW_WINDOW_BUTTON:
170 {
171 Context.listbox-&gt;addItem(L<span class="stringliteral">&quot;Window created&quot;</span>);
172 Context.counter += 30;
173 <span class="keywordflow">if</span> (Context.counter &gt; 200)
174 Context.counter = 0;
175
176 IGUIWindow* window = env-&gt;addWindow(
177 rect&lt;s32&gt;(100 + Context.counter, 100 + Context.counter, 300 + Context.counter, 200 + Context.counter),
178 <span class="keyword">false</span>, <span class="comment">// modal?</span>
179 L<span class="stringliteral">&quot;Test window&quot;</span>);
180
181 env-&gt;addStaticText(L<span class="stringliteral">&quot;Please close me&quot;</span>,
182 rect&lt;s32&gt;(35,35,140,50),
183 <span class="keyword">true</span>, <span class="comment">// border?</span>
184 <span class="keyword">false</span>, <span class="comment">// wordwrap?</span>
185 window);
186 }
187 <span class="keywordflow">return</span> <span class="keyword">true</span>;
188
189 <span class="keywordflow">case</span> GUI_ID_FILE_OPEN_BUTTON:
190 Context.listbox-&gt;addItem(L<span class="stringliteral">&quot;File open&quot;</span>);
191 <span class="comment">// There are some options for the file open dialog</span>
192 <span class="comment">// We set the title, make it a modal window, and make sure</span>
193 <span class="comment">// that the working directory is restored after the dialog</span>
194 <span class="comment">// is finished.</span>
195 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>);
196 <span class="keywordflow">return</span> <span class="keyword">true</span>;
197
198 <span class="keywordflow">default</span>:
199 <span class="keywordflow">return</span> <span class="keyword">false</span>;
200 }
201 <span class="keywordflow">break</span>;
202
203 <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>:
204 {
205 <span class="comment">// show the model filename, selected in the file dialog</span>
206 IGUIFileOpenDialog* dialog =
207 (IGUIFileOpenDialog*)event.GUIEvent.Caller;
208 Context.listbox-&gt;addItem(dialog-&gt;getFileName());
209 }
210 <span class="keywordflow">break</span>;
211
212 <span class="keywordflow">default</span>:
213 <span class="keywordflow">break</span>;
214 }
215 }
216
217 <span class="keywordflow">return</span> <span class="keyword">false</span>;
218 }
219
220<span class="keyword">private</span>:
221 SAppContext &amp; Context;
222};
223</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>
224<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
225{
226 <span class="comment">// ask user for driver</span>
227 <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();
228 <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>)
229 <span class="keywordflow">return</span> 1;
230
231 <span class="comment">// create device and exit if creation failed</span>
232
233 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));
234
235 <span class="keywordflow">if</span> (device == 0)
236 <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
237</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>
238<div class="fragment"><pre class="fragment"> device-&gt;setWindowCaption(L<span class="stringliteral">&quot;Irrlicht Engine - User Interface Demo&quot;</span>);
239 device-&gt;setResizable(<span class="keyword">true</span>);
240
241 video::IVideoDriver* driver = device-&gt;getVideoDriver();
242 IGUIEnvironment* env = device-&gt;getGUIEnvironment();
243</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>
244<div class="fragment"><pre class="fragment"> IGUISkin* skin = env-&gt;getSkin();
245 IGUIFont* font = env-&gt;<a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ab1b2623d04688c4dfe106ca407171d6e" title="returns the default font">getFont</a>(<span class="stringliteral">&quot;../../media/fonthaettenschweiler.bmp&quot;</span>);
246 <span class="keywordflow">if</span> (font)
247 skin-&gt;setFont(font);
248
249 skin-&gt;setFont(env-&gt;getBuiltInFont(), <a class="code" href="namespaceirr_1_1gui.html#a9e598ab5e8644d142e55d66e8d308441a9939ed432e179bb20810ee46a82ffcb8" title="Font for tooltips.">EGDF_TOOLTIP</a>);
250</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>
251<div class="fragment"><pre class="fragment"> env-&gt;addButton(rect&lt;s32&gt;(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
252 L<span class="stringliteral">&quot;Quit&quot;</span>, L<span class="stringliteral">&quot;Exits Program&quot;</span>);
253 env-&gt;addButton(rect&lt;s32&gt;(10,280,110,280 + 32), 0, GUI_ID_NEW_WINDOW_BUTTON,
254 L<span class="stringliteral">&quot;New Window&quot;</span>, L<span class="stringliteral">&quot;Launches a new Window&quot;</span>);
255 env-&gt;addButton(rect&lt;s32&gt;(10,320,110,320 + 32), 0, GUI_ID_FILE_OPEN_BUTTON,
256 L<span class="stringliteral">&quot;File Open&quot;</span>, L<span class="stringliteral">&quot;Opens a file&quot;</span>);
257</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>
258<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>);
259 IGUIScrollBar* scrollbar = env-&gt;addScrollBar(<span class="keyword">true</span>,
260 rect&lt;s32&gt;(150, 45, 350, 60), 0, GUI_ID_TRANSPARENCY_SCROLL_BAR);
261 scrollbar-&gt;setMax(255);
262 scrollbar-&gt;setPos(255);
263 setSkinTransparency( scrollbar-&gt;getPos(), env-&gt;getSkin());
264
265 <span class="comment">// set scrollbar position to alpha value of an arbitrary element</span>
266 scrollbar-&gt;setPos(env-&gt;getSkin()-&gt;getColor(<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aab60eb00de0efde8c5a948ab15d9aa0a7" title="Window background.">EGDC_WINDOW</a>).getAlpha());
267
268 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>);
269 IGUIListBox * listbox = env-&gt;addListBox(rect&lt;s32&gt;(50, 140, 250, 210));
270 env-&gt;addEditBox(L<span class="stringliteral">&quot;Editable Text&quot;</span>, rect&lt;s32&gt;(350, 80, 550, 100));
271
272 <span class="comment">// Store the appropriate data in a context structure.</span>
273 SAppContext context;
274 context.device = device;
275 context.counter = 0;
276 context.listbox = listbox;
277
278 <span class="comment">// Then create the event receiver, giving it that context structure.</span>
279 MyEventReceiver receiver(context);
280
281 <span class="comment">// And tell the device to use our custom event receiver.</span>
282 device-&gt;setEventReceiver(&amp;receiver);
283</pre></div><p>And at last, we create a nice Irrlicht Engine logo in the top left corner. </p>
284<div class="fragment"><pre class="fragment"> env-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlichtlogo2.png&quot;</span>),
285 position2d&lt;int&gt;(10,10));
286</pre></div><p>That's all, we only have to draw everything. </p>
287<div class="fragment"><pre class="fragment"> <span class="keywordflow">while</span>(device-&gt;run() &amp;&amp; driver)
288 <span class="keywordflow">if</span> (device-&gt;isWindowActive())
289 {
290 driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, SColor(0,200,200,200));
291
292 env-&gt;drawAll();
293
294 driver-&gt;endScene();
295 }
296
297 device-&gt;drop();
298
299 <span class="keywordflow">return</span> 0;
300}
301</pre></div> </div></div>
302</div>
303 <div id="nav-path" class="navpath">
304 <ul>
305<!-- window showing the filter options -->
306<div id="MSearchSelectWindow"
307 onmouseover="return searchBox.OnSearchSelectShow()"
308 onmouseout="return searchBox.OnSearchSelectHide()"
309 onkeydown="return searchBox.OnSearchSelectKey(event)">
310<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>
311
312<!-- iframe showing the search results (closed by default) -->
313<div id="MSearchResultsWindow">
314<iframe src="javascript:void(0)" frameborder="0"
315 name="MSearchResults" id="MSearchResults">
316</iframe>
317</div>
318
319
320 <li class="footer">
321<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
322Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:41 for Irrlicht 3D Engine by
323<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
324 </ul>
325 </div>
326
327
328</body>
329</html>