mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-13 14:00:27 +01:00
631 lines
50 KiB
HTML
631 lines
50 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<title>Irrlicht 3D Engine: Tutorial 24: CursorControl</title>
|
|
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
<link href="navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="resize.js"></script>
|
|
<script type="text/javascript" src="navtree.js"></script>
|
|
<script type="text/javascript">
|
|
$(document).ready(initResizable);
|
|
</script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<script type="text/javascript">
|
|
$(document).ready(function() { searchBox.OnSelectItem(0); });
|
|
</script>
|
|
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div! -->
|
|
|
|
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
|
|
<td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
|
|
|
|
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectname">Irrlicht 3D Engine
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td> <div id="MSearchBox" class="MSearchBoxInactive">
|
|
<span class="left">
|
|
<img id="MSearchSelect" src="search/mag_sel.png"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
alt=""/>
|
|
<input type="text" id="MSearchField" value="Search" accesskey="S"
|
|
onfocus="searchBox.OnSearchFieldFocus(true)"
|
|
onblur="searchBox.OnSearchFieldFocus(false)"
|
|
onkeyup="searchBox.OnSearchFieldChange(event)"/>
|
|
</span><span class="right">
|
|
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
|
|
</span>
|
|
</div>
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Generated by Doxygen 1.7.5.1 -->
|
|
<script type="text/javascript">
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
</script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
</div>
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
initNavTree('example024.html','');
|
|
</script>
|
|
<div id="doc-content">
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">Tutorial 24: CursorControl </div> </div>
|
|
</div>
|
|
<div class="contents">
|
|
<div class="textblock"><div class="image">
|
|
<img src="024shot.jpg" alt="024shot.jpg"/>
|
|
</div>
|
|
<p>Show how to modify cursors and offer some useful tool-functions for creating cursors. It can also be used for experiments with the mouse in general. </p>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>></span>
|
|
<span class="preprocessor">#include "<a class="code" href="driver_choice_8h.html">driverChoice.h</a>"</span>
|
|
|
|
<span class="keyword">using namespace </span>irr;
|
|
<span class="keyword">using namespace </span>core;
|
|
<span class="keyword">using namespace </span>scene;
|
|
<span class="keyword">using namespace </span>video;
|
|
<span class="keyword">using namespace </span>io;
|
|
<span class="keyword">using namespace </span>gui;
|
|
|
|
<span class="preprocessor">#ifdef _IRR_WINDOWS_</span>
|
|
<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span>
|
|
<span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
|
<span class="preprocessor"></span>
|
|
<span class="keyword">const</span> <span class="keywordtype">int</span> DELAY_TIME = 3000;
|
|
|
|
<span class="keyword">enum</span> ETimerAction
|
|
{
|
|
ETA_MOUSE_VISIBLE,
|
|
ETA_MOUSE_INVISIBLE,
|
|
};
|
|
</pre></div><p>Structure to allow delayed execution of some actions. </p>
|
|
<div class="fragment"><pre class="fragment"><span class="keyword">struct </span>TimerAction
|
|
{
|
|
<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> TargetTime;
|
|
ETimerAction Action;
|
|
};
|
|
</pre></div><div class="fragment"><pre class="fragment"><span class="keyword">struct </span>SAppContext
|
|
{
|
|
SAppContext()
|
|
: Device(0), InfoStatic(0), EventBox(0), CursorBox(0), SpriteBox(0)
|
|
, ButtonSetVisible(0), ButtonSetInvisible(0), ButtonSimulateBadFps(0)
|
|
, ButtonChangeIcon(0)
|
|
, SimulateBadFps(false)
|
|
{
|
|
}
|
|
|
|
<span class="keywordtype">void</span> update()
|
|
{
|
|
<span class="keywordflow">if</span> (!Device)
|
|
<span class="keywordflow">return</span>;
|
|
<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> timeNow = Device->getTimer()->getTime();
|
|
<span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i < TimerActions.size(); ++i )
|
|
{
|
|
<span class="keywordflow">if</span> ( timeNow >= TimerActions[i].TargetTime )
|
|
{
|
|
runTimerAction(TimerActions[i]);
|
|
TimerActions.erase(i);
|
|
}
|
|
<span class="keywordflow">else</span>
|
|
{
|
|
++i;
|
|
}
|
|
}
|
|
}
|
|
|
|
<span class="keywordtype">void</span> runTimerAction(<span class="keyword">const</span> TimerAction& action)
|
|
{
|
|
<span class="keywordflow">if</span> (ETA_MOUSE_VISIBLE == action.Action)
|
|
{
|
|
Device->getCursorControl()->setVisible(<span class="keyword">true</span>);
|
|
ButtonSetVisible->setEnabled(<span class="keyword">true</span>);
|
|
}
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> ( ETA_MOUSE_INVISIBLE == action.Action)
|
|
{
|
|
Device->getCursorControl()->setVisible(<span class="keyword">false</span>);
|
|
ButtonSetInvisible->setEnabled(<span class="keyword">true</span>);
|
|
}
|
|
}
|
|
</pre></div><p>Add another icon which the user can click and select as cursor later on. </p>
|
|
<div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> addIcon(<span class="keyword">const</span> <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>& name, <span class="keyword">const</span> SCursorSprite &sprite, <span class="keywordtype">bool</span> addCursor=<span class="keyword">true</span>)
|
|
{
|
|
<span class="comment">// Sprites are just icons - not yet cursors. They can be displayed by Irrlicht sprite functions and be used to create cursors.</span>
|
|
SpriteBox->addItem(name.c_str(), sprite.SpriteId);
|
|
Sprites.push_back(sprite);
|
|
|
|
<span class="comment">// create the cursor together with the icon?</span>
|
|
<span class="keywordflow">if</span> ( addCursor )
|
|
{
|
|
</pre></div><p> Here we create a hardware cursor from a sprite </p>
|
|
<div class="fragment"><pre class="fragment"> Device->getCursorControl()->addIcon(sprite);
|
|
|
|
<span class="comment">// ... and add it to the cursors selection listbox to the other system cursors.</span>
|
|
CursorBox->addItem(name.c_str());
|
|
}
|
|
}
|
|
|
|
IrrlichtDevice * Device;
|
|
gui::IGUIStaticText * InfoStatic;
|
|
gui::IGUIListBox * EventBox;
|
|
gui::IGUIListBox * CursorBox;
|
|
gui::IGUIListBox * SpriteBox;
|
|
gui::IGUIButton * ButtonSetVisible;
|
|
gui::IGUIButton * ButtonSetInvisible;
|
|
gui::IGUIButton * ButtonSimulateBadFps;
|
|
gui::IGUIButton * ButtonChangeIcon;
|
|
array<TimerAction> TimerActions;
|
|
<span class="keywordtype">bool</span> SimulateBadFps;
|
|
array<SCursorSprite> Sprites;
|
|
};
|
|
</pre></div><p>Helper function to print mouse event names into a stringw </p>
|
|
<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> PrintMouseEventName(<span class="keyword">const</span> SEvent& event, <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a> &result)
|
|
{
|
|
<span class="keywordflow">switch</span> ( event.MouseInput.Event )
|
|
{
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fa3f551814f5f38596ea1f3ed7c6c7bad7" title="Left mouse button was pressed down.">EMIE_LMOUSE_PRESSED_DOWN</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_LMOUSE_PRESSED_DOWN"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fab54734344dc9cc7c00b33afcc6443575" title="Right mouse button was pressed down.">EMIE_RMOUSE_PRESSED_DOWN</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_RMOUSE_PRESSED_DOWN"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fa3daff77552ab92abc317afe09b41bc76" title="Middle mouse button was pressed down.">EMIE_MMOUSE_PRESSED_DOWN</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_MMOUSE_PRESSED_DOWN"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fa26d91b99a8912ff622133f02c60f306a" title="Left mouse button was left up.">EMIE_LMOUSE_LEFT_UP</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_LMOUSE_LEFT_UP"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fadb92d5c1011534b2b18065573182d9f4" title="Right mouse button was left up.">EMIE_RMOUSE_LEFT_UP</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_RMOUSE_LEFT_UP"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fa13e6b5b0964334f1dbefae9848dc26df" title="Middle mouse button was left up.">EMIE_MMOUSE_LEFT_UP</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_MMOUSE_LEFT_UP"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fae3288f42ed4b8372853c1822bbc0a7a1" title="The mouse cursor changed its position.">EMIE_MOUSE_MOVED</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_MOUSE_MOVED"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fad091f4f4144d57e46be11b029c3c6720">EMIE_MOUSE_WHEEL</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_MOUSE_WHEEL"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fa689d3c959226829a85d5dc005400c7ce">EMIE_LMOUSE_DOUBLE_CLICK</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_LMOUSE_DOUBLE_CLICK"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fa90865e216488a0a92c030f220a5a69d6">EMIE_RMOUSE_DOUBLE_CLICK</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_RMOUSE_DOUBLE_CLICK"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fa89b46e2e0e79ee26d9c2478ebe1dd9ee">EMIE_MMOUSE_DOUBLE_CLICK</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_MMOUSE_DOUBLE_CLICK"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fa1145828528f7999720df3dd10a3a7de3">EMIE_LMOUSE_TRIPLE_CLICK</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_LMOUSE_TRIPLE_CLICK"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fab24cbd2197b888022531799561c12b49">EMIE_RMOUSE_TRIPLE_CLICK</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_RMOUSE_TRIPLE_CLICK"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fa72b90a632c6063a6f8e2fbf26187c9c6">EMIE_MMOUSE_TRIPLE_CLICK</a>: result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"EMIE_MMOUSE_TRIPLE_CLICK"</span>); <span class="keywordflow">break</span>;
|
|
<span class="keywordflow">default</span>:
|
|
<span class="keywordflow">break</span>;
|
|
}
|
|
}
|
|
</pre></div><p>Helper function to print all the state information which get from a mouse-event into a stringw </p>
|
|
<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> PrintMouseState(<span class="keyword">const</span> SEvent& event, <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a> &result)
|
|
{
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"X: "</span>);
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(event.MouseInput.X);
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"\n"</span>);
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"Y: "</span>);
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(event.MouseInput.Y);
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"\n"</span>);
|
|
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"Wheel: "</span>);
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(event.MouseInput.Wheel);
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"\n"</span>);
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"Shift: "</span>);
|
|
<span class="keywordflow">if</span> ( event.MouseInput.Shift )
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"true\n"</span>);
|
|
<span class="keywordflow">else</span>
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"false\n"</span>);
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"Control: "</span>);
|
|
<span class="keywordflow">if</span> ( event.MouseInput.Control )
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"true\n"</span>);
|
|
<span class="keywordflow">else</span>
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"false\n"</span>);
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"ButtonStates: "</span>);
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(event.MouseInput.ButtonStates);
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"\n"</span>);
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"isLeftPressed: "</span>);
|
|
<span class="keywordflow">if</span> ( event.MouseInput.isLeftPressed() )
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"true\n"</span>);
|
|
<span class="keywordflow">else</span>
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"false\n"</span>);
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"isRightPressed: "</span>);
|
|
<span class="keywordflow">if</span> ( event.MouseInput.isRightPressed() )
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"true\n"</span>);
|
|
<span class="keywordflow">else</span>
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"false\n"</span>);
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"isMiddlePressed: "</span>);
|
|
<span class="keywordflow">if</span> ( event.MouseInput.isMiddlePressed() )
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"true\n"</span>);
|
|
<span class="keywordflow">else</span>
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"false\n"</span>);
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"Event: "</span>);
|
|
|
|
PrintMouseEventName(event, result);
|
|
|
|
result += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>(L<span class="stringliteral">"\n"</span>);
|
|
}
|
|
</pre></div><p>A typical event receiver. </p>
|
|
<div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver
|
|
{
|
|
<span class="keyword">public</span>:
|
|
MyEventReceiver(SAppContext & context) : Context(context) { }
|
|
|
|
<span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent& event)
|
|
{
|
|
<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> )
|
|
{
|
|
<span class="keywordflow">switch</span> ( event.GUIEvent.EventType )
|
|
{
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a308ee345c92444931f83e48354072d98" title="A button was clicked.">EGET_BUTTON_CLICKED</a>:
|
|
{
|
|
<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> timeNow = Context.Device->getTimer()->getTime();
|
|
TimerAction action;
|
|
action.TargetTime = timeNow + DELAY_TIME;
|
|
<span class="keywordflow">if</span> ( event.GUIEvent.Caller == Context.ButtonSetVisible )
|
|
{
|
|
action.Action = ETA_MOUSE_VISIBLE;
|
|
Context.TimerActions.push_back(action);
|
|
Context.ButtonSetVisible->setEnabled(<span class="keyword">false</span>);
|
|
}
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> ( event.GUIEvent.Caller == Context.ButtonSetInvisible )
|
|
{
|
|
action.Action = ETA_MOUSE_INVISIBLE;
|
|
Context.TimerActions.push_back(action);
|
|
Context.ButtonSetInvisible->setEnabled(<span class="keyword">false</span>);
|
|
}
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> ( event.GUIEvent.Caller == Context.ButtonSimulateBadFps )
|
|
{
|
|
Context.SimulateBadFps = Context.ButtonSimulateBadFps->isPressed();
|
|
}
|
|
<span class="keywordflow">else</span> <span class="keywordflow">if</span> ( event.GUIEvent.Caller == Context.ButtonChangeIcon )
|
|
{
|
|
</pre></div><p>Replace an existing cursor icon by another icon. The user has to select both - the icon which should be replaced and the icon which will replace it. </p>
|
|
<div class="fragment"><pre class="fragment"> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> selectedCursor = Context.CursorBox->getSelected();
|
|
<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> selectedSprite = Context.SpriteBox->getSelected();
|
|
<span class="keywordflow">if</span> ( selectedCursor >= 0 && selectedSprite >= 0 )
|
|
{
|
|
</pre></div><p>This does replace the icon. </p>
|
|
<div class="fragment"><pre class="fragment"> Context.Device->getCursorControl()->changeIcon((<a class="code" href="namespaceirr_1_1gui.html#aefee802dd632c5735703e40ef40f879b" title="Default icons for cursors.">ECURSOR_ICON</a>)selectedCursor, Context.Sprites[selectedSprite] );
|
|
</pre></div><p>Do also show the new icon. </p>
|
|
<div class="fragment"><pre class="fragment"> Context.Device->getCursorControl()->setActiveIcon( <a class="code" href="namespaceirr_1_1gui.html#aefee802dd632c5735703e40ef40f879b" title="Default icons for cursors.">ECURSOR_ICON</a>(selectedCursor) );
|
|
}
|
|
}
|
|
}
|
|
<span class="keywordflow">break</span>;
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808ac4834bd158653766be139a322de519aa" title="A new item in a listbox was selected.">EGET_LISTBOX_CHANGED</a>:
|
|
<span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a3f3c374a3c74405ee3eac6973e78345f" title="An item in the listbox was selected, which was already selected.">EGET_LISTBOX_SELECTED_AGAIN</a>:
|
|
{
|
|
<span class="keywordflow">if</span> ( event.GUIEvent.Caller == Context.CursorBox )
|
|
{
|
|
</pre></div><p>Find out which cursor the user selected </p>
|
|
<div class="fragment"><pre class="fragment"> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> selected = Context.CursorBox->getSelected();
|
|
<span class="keywordflow">if</span> ( selected >= 0 )
|
|
{
|
|
</pre></div><p>Here we set the new cursor icon which will now be used within our window. </p>
|
|
<div class="fragment"><pre class="fragment"> Context.Device->getCursorControl()->setActiveIcon( <a class="code" href="namespaceirr_1_1gui.html#aefee802dd632c5735703e40ef40f879b" title="Default icons for cursors.">ECURSOR_ICON</a>(selected) );
|
|
}
|
|
}
|
|
}
|
|
<span class="keywordflow">break</span>;
|
|
<span class="keywordflow">default</span>:
|
|
<span class="keywordflow">break</span>;
|
|
}
|
|
}
|
|
|
|
<span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0caa230b748674e074aa67f661819ad5891" title="A mouse input event.">EET_MOUSE_INPUT_EVENT</a>)
|
|
{
|
|
<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a> infoText;
|
|
PrintMouseState(event, infoText);
|
|
Context.InfoStatic->setText(infoText.c_str());
|
|
<span class="keywordflow">if</span> ( event.MouseInput.Event != <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fae3288f42ed4b8372853c1822bbc0a7a1" title="The mouse cursor changed its position.">EMIE_MOUSE_MOVED</a> && event.MouseInput.Event != <a class="code" href="namespaceirr.html#a2dbf2a247aa17a9eeefbbf36ebd5739fad091f4f4144d57e46be11b029c3c6720">EMIE_MOUSE_WHEEL</a> ) <span class="comment">// no spam</span>
|
|
{
|
|
infoText = L<span class="stringliteral">""</span>;
|
|
PrintMouseEventName(event, infoText);
|
|
Context.EventBox->insertItem(0, infoText.c_str(), -1);
|
|
}
|
|
}
|
|
|
|
<span class="keywordflow">return</span> <span class="keyword">false</span>;
|
|
}
|
|
|
|
<span class="keyword">private</span>:
|
|
SAppContext & Context;
|
|
};
|
|
</pre></div><p>Use several imagefiles as animation frames for a sprite which can be used as cursor icon. The images in those files all need to have the same size. Return sprite index on success or -1 on failure </p>
|
|
<div class="fragment"><pre class="fragment"><a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> AddAnimatedIconToSpriteBank( gui::IGUISpriteBank * spriteBank, video::IVideoDriver* driver, <span class="keyword">const</span> array< io::path >& files, <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> frameTime )
|
|
{
|
|
<span class="keywordflow">if</span> ( !spriteBank || !driver || !files.size() )
|
|
<span class="keywordflow">return</span> -1;
|
|
|
|
video::ITexture * tex = driver->getTexture( files[0] );
|
|
<span class="keywordflow">if</span> ( tex )
|
|
{
|
|
array< rect<s32> >& spritePositions = spriteBank->getPositions();
|
|
<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> idxRect = spritePositions.size();
|
|
spritePositions.push_back( rect<s32>(0,0, tex->getSize().Width, tex->getSize().Height) );
|
|
|
|
SGUISprite sprite;
|
|
sprite.frameTime = frameTime;
|
|
|
|
array< SGUISprite >& sprites = spriteBank->getSprites();
|
|
<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> startIdx = spriteBank->getTextureCount();
|
|
<span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> f=0; f < files.size(); ++f )
|
|
{
|
|
tex = driver->getTexture( files[f] );
|
|
<span class="keywordflow">if</span> ( tex )
|
|
{
|
|
spriteBank->addTexture( driver->getTexture(files[f]) );
|
|
gui::SGUISpriteFrame frame;
|
|
frame.rectNumber = idxRect;
|
|
frame.textureNumber = startIdx+f;
|
|
sprite.Frames.push_back( frame );
|
|
}
|
|
}
|
|
|
|
sprites.push_back( sprite );
|
|
<span class="keywordflow">return</span> sprites.size()-1;
|
|
}
|
|
|
|
<span class="keywordflow">return</span> -1;
|
|
}
|
|
</pre></div><p>Use several images within one imagefile as animation frames for a sprite which can be used as cursor icon The sizes of the icons within that file all need to have the same size Return sprite index on success or -1 on failure </p>
|
|
<div class="fragment"><pre class="fragment"><a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> AddAnimatedIconToSpriteBank( gui::IGUISpriteBank * spriteBank, video::IVideoDriver* driver, <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>& file, <span class="keyword">const</span> array< rect<s32> >& rects, <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> frameTime )
|
|
{
|
|
<span class="keywordflow">if</span> ( !spriteBank || !driver || !rects.size() )
|
|
<span class="keywordflow">return</span> -1;
|
|
|
|
video::ITexture * tex = driver->getTexture( file );
|
|
<span class="keywordflow">if</span> ( tex )
|
|
{
|
|
array< rect<s32> >& spritePositions = spriteBank->getPositions();
|
|
<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> idxRect = spritePositions.size();
|
|
<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> idxTex = spriteBank->getTextureCount();
|
|
spriteBank->addTexture( tex );
|
|
|
|
SGUISprite sprite;
|
|
sprite.frameTime = frameTime;
|
|
|
|
array< SGUISprite >& sprites = spriteBank->getSprites();
|
|
<span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i < rects.size(); ++i )
|
|
{
|
|
spritePositions.push_back( rects[i] );
|
|
|
|
gui::SGUISpriteFrame frame;
|
|
frame.rectNumber = idxRect+i;
|
|
frame.textureNumber = idxTex;
|
|
sprite.Frames.push_back( frame );
|
|
}
|
|
|
|
sprites.push_back( sprite );
|
|
<span class="keywordflow">return</span> sprites.size()-1;
|
|
}
|
|
|
|
<span class="keywordflow">return</span> -1;
|
|
}
|
|
</pre></div><p>Create a non-animated icon from the given file and position and put it into the spritebank. We can use this icon later on in a cursor. </p>
|
|
<div class="fragment"><pre class="fragment"><a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> AddIconToSpriteBank( gui::IGUISpriteBank * spriteBank, video::IVideoDriver* driver, <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>& file, <span class="keyword">const</span> core::rect<s32>& rect )
|
|
{
|
|
<span class="keywordflow">if</span> ( !spriteBank || !driver )
|
|
<span class="keywordflow">return</span> -1;
|
|
|
|
video::ITexture * tex = driver->getTexture( file );
|
|
<span class="keywordflow">if</span> ( tex )
|
|
{
|
|
core::array< core::rect<irr::s32> >& spritePositions = spriteBank->getPositions();
|
|
spritePositions.push_back( rect );
|
|
array< SGUISprite >& sprites = spriteBank->getSprites();
|
|
spriteBank->addTexture( tex );
|
|
|
|
gui::SGUISpriteFrame frame;
|
|
frame.rectNumber = spritePositions.size()-1;
|
|
frame.textureNumber = spriteBank->getTextureCount()-1;
|
|
|
|
SGUISprite sprite;
|
|
sprite.frameTime = 0;
|
|
sprite.Frames.push_back( frame );
|
|
|
|
sprites.push_back( sprite );
|
|
|
|
<span class="keywordflow">return</span> sprites.size()-1;
|
|
}
|
|
|
|
<span class="keywordflow">return</span> -1;
|
|
}
|
|
|
|
<span class="keywordtype">int</span> main()
|
|
{
|
|
<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();
|
|
<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>)
|
|
<span class="keywordflow">return</span> 1;
|
|
|
|
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, dimension2d<u32>(640, 480));
|
|
<span class="keywordflow">if</span> (device == 0)
|
|
<span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
|
|
|
|
<span class="comment">// It's sometimes of interest to know how the mouse behaves after a resize</span>
|
|
device->setResizable(<span class="keyword">true</span>);
|
|
|
|
device->setWindowCaption(L<span class="stringliteral">"Cursor control - Irrlicht engine tutorial"</span>);
|
|
video::IVideoDriver* driver = device->getVideoDriver();
|
|
IGUIEnvironment* env = device->getGUIEnvironment();
|
|
|
|
gui::IGUISpriteBank * SpriteBankIcons;
|
|
|
|
SAppContext context;
|
|
context.Device = device;
|
|
|
|
rect< s32 > rectInfoStatic(10,10, 200, 200);
|
|
env->addStaticText (L<span class="stringliteral">"Cursor state information"</span>, rectInfoStatic, <span class="keyword">true</span>, <span class="keyword">true</span>);
|
|
rectInfoStatic.UpperLeftCorner += <a class="code" href="namespaceirr_1_1core.html#ac79bc3704cf28bc1ab72d7cd1cae78d1" title="Typedef for an integer dimension.">dimension2di</a>(0, 15);
|
|
context.InfoStatic = env->addStaticText (L<span class="stringliteral">""</span>, rectInfoStatic, <span class="keyword">true</span>, <span class="keyword">true</span>);
|
|
rect< s32 > rectEventBox(10,210, 200, 400);
|
|
env->addStaticText (L<span class="stringliteral">"click events (new on top)"</span>, rectEventBox, <span class="keyword">true</span>, <span class="keyword">true</span>);
|
|
rectEventBox.UpperLeftCorner += <a class="code" href="namespaceirr_1_1core.html#ac79bc3704cf28bc1ab72d7cd1cae78d1" title="Typedef for an integer dimension.">dimension2di</a>(0, 15);
|
|
context.EventBox = env->addListBox(rectEventBox);
|
|
rect< s32 > rectCursorBox(210,10, 400, 250);
|
|
env->addStaticText (L<span class="stringliteral">"cursors, click to set the active one"</span>, rectCursorBox, <span class="keyword">true</span>, <span class="keyword">true</span>);
|
|
rectCursorBox.UpperLeftCorner += <a class="code" href="namespaceirr_1_1core.html#ac79bc3704cf28bc1ab72d7cd1cae78d1" title="Typedef for an integer dimension.">dimension2di</a>(0, 15);
|
|
context.CursorBox = env->addListBox(rectCursorBox);
|
|
rect< s32 > rectSpriteBox(210,260, 400, 400);
|
|
env->addStaticText (L<span class="stringliteral">"sprites"</span>, rectSpriteBox, <span class="keyword">true</span>, <span class="keyword">true</span>);
|
|
rectSpriteBox.UpperLeftCorner += <a class="code" href="namespaceirr_1_1core.html#ac79bc3704cf28bc1ab72d7cd1cae78d1" title="Typedef for an integer dimension.">dimension2di</a>(0, 15);
|
|
context.SpriteBox = env->addListBox(rectSpriteBox);
|
|
|
|
context.ButtonSetVisible = env->addButton( rect<s32>( 410, 20, 560, 40 ), 0, -1, L<span class="stringliteral">"set visible (delayed)"</span> );
|
|
context.ButtonSetInvisible = env->addButton( rect<s32>( 410, 50, 560, 70 ), 0, -1, L<span class="stringliteral">"set invisible (delayed)"</span> );
|
|
context.ButtonSimulateBadFps = env->addButton( rect<s32>( 410, 80, 560, 100 ), 0, -1, L<span class="stringliteral">"simulate bad FPS"</span> );
|
|
context.ButtonSimulateBadFps->setIsPushButton(<span class="keyword">true</span>);
|
|
context.ButtonChangeIcon = env->addButton( rect<s32>( 410, 140, 560, 160 ), 0, -1, L<span class="stringliteral">"replace cursor icon\n(cursor+sprite must be selected)"</span> );
|
|
|
|
<span class="comment">// set the names for all the system cursors</span>
|
|
<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i < (int)<a class="code" href="namespaceirr_1_1gui.html#aefee802dd632c5735703e40ef40f879ba4960196a815443cf827e58ca48232583">gui::ECI_COUNT</a>; ++i )
|
|
{
|
|
context.CursorBox->addItem(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a>( <a class="code" href="namespaceirr_1_1gui.html#a33bd57d04dbf92750f64a244df85cd51" title="Names for ECURSOR_ICON.">GUICursorIconNames</a>[i] ).c_str());
|
|
}
|
|
</pre></div><p>Create sprites which then can be used as cursor icons. </p>
|
|
<div class="fragment"><pre class="fragment"> SpriteBankIcons = env->addEmptySpriteBank(<a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"cursor_icons"</span>));
|
|
context.SpriteBox->setSpriteBank(SpriteBankIcons);
|
|
|
|
<span class="comment">// create one animated icon from several files</span>
|
|
array< io::path > files;
|
|
files.push_back( <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"../../media/icon_crosshairs16x16bw1.png"</span>) );
|
|
files.push_back( <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"../../media/icon_crosshairs16x16bw2.png"</span>) );
|
|
files.push_back( <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"../../media/icon_crosshairs16x16bw3.png"</span>) );
|
|
files.push_back( <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"../../media/icon_crosshairs16x16bw3.png"</span>) );
|
|
files.push_back( <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"../../media/icon_crosshairs16x16bw2.png"</span>) );
|
|
SCursorSprite spriteBw; <span class="comment">// the sprite + some additional information needed for cursors</span>
|
|
spriteBw.SpriteId = AddAnimatedIconToSpriteBank( SpriteBankIcons, driver, files, 200 );
|
|
spriteBw.SpriteBank = SpriteBankIcons;
|
|
spriteBw.HotSpot = position2d<s32>(7,7);
|
|
context.addIcon(L<span class="stringliteral">"crosshair_bw"</span>, spriteBw);
|
|
|
|
<span class="comment">// create one animated icon from one file</span>
|
|
array< rect<s32> > iconRects;
|
|
iconRects.push_back( rect<s32>(0,0, 16, 16) );
|
|
iconRects.push_back( rect<s32>(16,0, 32, 16) );
|
|
iconRects.push_back( rect<s32>(0,16, 16, 32) );
|
|
iconRects.push_back( rect<s32>(0,16, 16, 32) );
|
|
iconRects.push_back( rect<s32>(16,0, 32, 16) );
|
|
SCursorSprite spriteCol; <span class="comment">// the sprite + some additional information needed for cursors</span>
|
|
spriteCol.SpriteId = AddAnimatedIconToSpriteBank( SpriteBankIcons, driver, <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"../../media/icon_crosshairs16x16col.png"</span>), iconRects, 200 );
|
|
spriteCol.HotSpot = position2d<s32>(7,7);
|
|
spriteCol.SpriteBank = SpriteBankIcons;
|
|
context.addIcon(L<span class="stringliteral">"crosshair_colored"</span>, spriteCol);
|
|
|
|
<span class="comment">// Create some non-animated icons</span>
|
|
rect<s32> rectIcon;
|
|
SCursorSprite spriteNonAnimated(SpriteBankIcons, 0, position2d<s32>(7,7));
|
|
|
|
rectIcon = rect<s32>(0,0, 16, 16);
|
|
spriteNonAnimated.SpriteId = AddIconToSpriteBank( SpriteBankIcons, driver, <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"../../media/icon_crosshairs16x16col.png"</span>), rectIcon );
|
|
context.addIcon(L<span class="stringliteral">"crosshair_col1"</span>, spriteNonAnimated, <span class="keyword">false</span>);
|
|
|
|
rectIcon = rect<s32>(16,0, 32, 16);
|
|
spriteNonAnimated.SpriteId = AddIconToSpriteBank( SpriteBankIcons, driver, <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"../../media/icon_crosshairs16x16col.png"</span>), rectIcon );
|
|
context.addIcon(L<span class="stringliteral">"crosshair_col2"</span>, spriteNonAnimated, <span class="keyword">false</span>);
|
|
|
|
rectIcon = rect<s32>(0,16, 16, 32);
|
|
spriteNonAnimated.SpriteId = AddIconToSpriteBank( SpriteBankIcons, driver, <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(<span class="stringliteral">"../../media/icon_crosshairs16x16col.png"</span>), rectIcon );
|
|
context.addIcon(L<span class="stringliteral">"crosshair_col3"</span>, spriteNonAnimated, <span class="keyword">false</span>);
|
|
|
|
|
|
MyEventReceiver receiver(context);
|
|
device->setEventReceiver(&receiver);
|
|
|
|
<span class="keywordflow">while</span>(device->run() && driver)
|
|
{
|
|
<span class="comment">// if (device->isWindowActive())</span>
|
|
{
|
|
<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> realTimeNow = device->getTimer()->getRealTime();
|
|
|
|
context.update();
|
|
|
|
driver->beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, SColor(0,200,200,200));
|
|
|
|
env->drawAll();
|
|
|
|
<span class="comment">// draw custom sprite with Irrlicht functions for comparison. It should usually look the same as the cursors.</span>
|
|
<span class="keywordflow">if</span> ( context.SpriteBox )
|
|
{
|
|
<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> selectedSprite = context.SpriteBox->getSelected();
|
|
<span class="keywordflow">if</span> ( selectedSprite >= 0 && context.Sprites[selectedSprite].SpriteId >= 0 )
|
|
{
|
|
SpriteBankIcons->draw2DSprite(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a>(context.Sprites[selectedSprite].SpriteId), <a class="code" href="namespaceirr_1_1core.html#a3643c2cc7820dd78cd87e73a46b92145">position2di</a>(580, 140), 0, video::SColor(255, 255, 255, 255), 0, realTimeNow);
|
|
}
|
|
}
|
|
|
|
driver->endScene();
|
|
}
|
|
|
|
<span class="comment">// By simulating bad fps we can find out if hardware-support for cursors works or not. If it works the cursor will move as usual,while it otherwise will just update with 2 fps now.</span>
|
|
<span class="keywordflow">if</span> ( context.SimulateBadFps )
|
|
{
|
|
device->sleep(500); <span class="comment">// 2 fps</span>
|
|
}
|
|
<span class="keywordflow">else</span>
|
|
{
|
|
device->sleep(10);
|
|
}
|
|
}
|
|
|
|
device->drop();
|
|
|
|
<span class="keywordflow">return</span> 0;
|
|
}
|
|
</pre></div> </div></div>
|
|
</div>
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Defines</a></div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
|
|
<li class="footer">
|
|
<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
|
|
Engine</a> Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on Sat Jul 9 2016 18:18:27 for Irrlicht 3D Engine by
|
|
<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
</body>
|
|
</html>
|