1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>SFML - Simple and Fast Multimedia Library</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="tabs.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="logo">
<img src="./logo.jpg" width="770" height="200" title="SFML home" alt="SFML logo" />
</div>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.htm"><span>Main Page</span></a></li>
<li><a href="namespaces.htm"><span>Namespaces</span></a></li>
<li><a href="annotated.htm"><span>Classes</span></a></li>
<li class="current"><a href="files.htm"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.htm"><span>File List</span></a></li>
</ul>
</div>
<h1>Window.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// SFML - Simple and Fast Multimedia Library</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)</span>
<a name="l00005"></a>00005 <span class="comment">//</span>
<a name="l00006"></a>00006 <span class="comment">// This software is provided 'as-is', without any express or implied warranty.</span>
<a name="l00007"></a>00007 <span class="comment">// In no event will the authors be held liable for any damages arising from the use of this software.</span>
<a name="l00008"></a>00008 <span class="comment">//</span>
<a name="l00009"></a>00009 <span class="comment">// Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00010"></a>00010 <span class="comment">// including commercial applications, and to alter it and redistribute it freely,</span>
<a name="l00011"></a>00011 <span class="comment">// subject to the following restrictions:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// 1. The origin of this software must not be misrepresented;</span>
<a name="l00014"></a>00014 <span class="comment">// you must not claim that you wrote the original software.</span>
<a name="l00015"></a>00015 <span class="comment">// If you use this software in a product, an acknowledgment</span>
<a name="l00016"></a>00016 <span class="comment">// in the product documentation would be appreciated but is not required.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018 <span class="comment">// 2. Altered source versions must be plainly marked as such,</span>
<a name="l00019"></a>00019 <span class="comment">// and must not be misrepresented as being the original software.</span>
<a name="l00020"></a>00020 <span class="comment">//</span>
<a name="l00021"></a>00021 <span class="comment">// 3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00022"></a>00022 <span class="comment">//</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00026"></a>00026 <span class="comment">// Headers</span>
<a name="l00028"></a>00028 <span class="comment"></span><span class="preprocessor">#include <SFML/Window/Window.hpp></span>
<a name="l00029"></a>00029 <span class="preprocessor">#include <SFML/Window/Context.hpp></span>
<a name="l00030"></a>00030 <span class="preprocessor">#include <SFML/Window/WindowImpl.hpp></span>
<a name="l00031"></a>00031 <span class="preprocessor">#include <SFML/System/Sleep.hpp></span>
<a name="l00032"></a>00032 <span class="preprocessor">#include <iostream></span>
<a name="l00033"></a>00033
<a name="l00034"></a>00034
<a name="l00036"></a>00036 <span class="comment">// Private data</span>
<a name="l00038"></a>00038 <span class="comment"></span><span class="keyword">namespace</span>
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040 <span class="keyword">const</span> <a class="code" href="classsf_1_1Window.htm" title="Window is a rendering window ; it can create a new window or connect to an existing...">sf::Window</a>* FullscreenWindow = NULL;
<a name="l00041"></a>00041 }
<a name="l00042"></a>00042
<a name="l00043"></a>00043
<a name="l00044"></a>00044 <span class="keyword">namespace </span>sf
<a name="l00045"></a>00045 {
<a name="l00049"></a><a class="code" href="classsf_1_1Window.htm#5359122166b4dc492c3d25caf08ccfc4">00049</a> <a class="code" href="classsf_1_1Window.htm#5359122166b4dc492c3d25caf08ccfc4" title="Default constructor.">Window::Window</a>() :
<a name="l00050"></a>00050 myWindow (NULL),
<a name="l00051"></a>00051 myLastFrameTime (0.f),
<a name="l00052"></a>00052 myIsExternal (false),
<a name="l00053"></a>00053 myFramerateLimit(0),
<a name="l00054"></a>00054 mySetCursorPosX (0xFFFF),
<a name="l00055"></a>00055 mySetCursorPosY (0xFFFF)
<a name="l00056"></a>00056 {
<a name="l00057"></a>00057
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059
<a name="l00060"></a>00060
<a name="l00064"></a><a class="code" href="classsf_1_1Window.htm#8a89aba8776a4eeb5393522a0e6513c9">00064</a> <a class="code" href="classsf_1_1Window.htm#5359122166b4dc492c3d25caf08ccfc4" title="Default constructor.">Window::Window</a>(<a class="code" href="classsf_1_1VideoMode.htm" title="VideoMode defines a video mode (width, height, bpp, frequency) and provides static...">VideoMode</a> Mode, <span class="keyword">const</span> std::string& Title, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> WindowStyle, <span class="keyword">const</span> <a class="code" href="structsf_1_1WindowSettings.htm" title="Structure defining the creation settings of windows.">WindowSettings</a>& Params) :
<a name="l00065"></a>00065 myWindow (NULL),
<a name="l00066"></a>00066 myLastFrameTime (0.f),
<a name="l00067"></a>00067 myIsExternal (false),
<a name="l00068"></a>00068 myFramerateLimit(0),
<a name="l00069"></a>00069 mySetCursorPosX (0xFFFF),
<a name="l00070"></a>00070 mySetCursorPosY (0xFFFF)
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072 <a class="code" href="classsf_1_1Window.htm#a891f1cbd7d77c4dc02ac950b6e76f61" title="Create (or recreate) the window.">Create</a>(Mode, Title, WindowStyle, Params);
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074
<a name="l00075"></a>00075
<a name="l00079"></a><a class="code" href="classsf_1_1Window.htm#ef6c45b1d53ed4a884ccb9c609d2456a">00079</a> <a class="code" href="classsf_1_1Window.htm#5359122166b4dc492c3d25caf08ccfc4" title="Default constructor.">Window::Window</a>(WindowHandle Handle, <span class="keyword">const</span> <a class="code" href="structsf_1_1WindowSettings.htm" title="Structure defining the creation settings of windows.">WindowSettings</a>& Params) :
<a name="l00080"></a>00080 myWindow (NULL),
<a name="l00081"></a>00081 myLastFrameTime (0.f),
<a name="l00082"></a>00082 myIsExternal (true),
<a name="l00083"></a>00083 myFramerateLimit(0),
<a name="l00084"></a>00084 mySetCursorPosX (0xFFFF),
<a name="l00085"></a>00085 mySetCursorPosY (0xFFFF)
<a name="l00086"></a>00086 {
<a name="l00087"></a>00087 <a class="code" href="classsf_1_1Window.htm#a891f1cbd7d77c4dc02ac950b6e76f61" title="Create (or recreate) the window.">Create</a>(Handle, Params);
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089
<a name="l00090"></a>00090
<a name="l00094"></a><a class="code" href="classsf_1_1Window.htm#6d5a00ce5cc93a2c0bc8ae0e317f5008">00094</a> <a class="code" href="classsf_1_1Window.htm#6d5a00ce5cc93a2c0bc8ae0e317f5008" title="Destructor.">Window::~Window</a>()
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096 <span class="comment">// Close the window</span>
<a name="l00097"></a>00097 <a class="code" href="classsf_1_1Window.htm#b04439f6fb9fdfe40f882676fdb2938c" title="Close (destroy) the window.">Close</a>();
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099
<a name="l00100"></a>00100
<a name="l00104"></a><a class="code" href="classsf_1_1Window.htm#a891f1cbd7d77c4dc02ac950b6e76f61">00104</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#a891f1cbd7d77c4dc02ac950b6e76f61" title="Create (or recreate) the window.">Window::Create</a>(<a class="code" href="classsf_1_1VideoMode.htm" title="VideoMode defines a video mode (width, height, bpp, frequency) and provides static...">VideoMode</a> Mode, <span class="keyword">const</span> std::string& Title, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> WindowStyle, <span class="keyword">const</span> <a class="code" href="structsf_1_1WindowSettings.htm" title="Structure defining the creation settings of windows.">WindowSettings</a>& Params)
<a name="l00105"></a>00105 {
<a name="l00106"></a>00106 <span class="comment">// Destroy the previous window implementation</span>
<a name="l00107"></a>00107 <a class="code" href="classsf_1_1Window.htm#b04439f6fb9fdfe40f882676fdb2938c" title="Close (destroy) the window.">Close</a>();
<a name="l00108"></a>00108
<a name="l00109"></a>00109 <span class="comment">// Fullscreen style requires some tests</span>
<a name="l00110"></a>00110 <span class="keywordflow">if</span> (WindowStyle & <a class="code" href="namespacesf_1_1Style.htm#d001cd87b8aa5669d0eadbb8aab1c1d26288ec86830245cf957e2d234f79f50d" title="Fullscreen mode (this flag and all others are mutually exclusive).">Style::Fullscreen</a>)
<a name="l00111"></a>00111 {
<a name="l00112"></a>00112 <span class="comment">// Make sure there's not already a fullscreen window (only one is allowed)</span>
<a name="l00113"></a>00113 <span class="keywordflow">if</span> (FullscreenWindow)
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115 std::cerr << <span class="stringliteral">"Creating two fullscreen windows is not allowed, switching to windowed mode"</span> << std::endl;
<a name="l00116"></a>00116 WindowStyle &= ~Style::Fullscreen;
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118 <span class="keywordflow">else</span>
<a name="l00119"></a>00119 {
<a name="l00120"></a>00120 <span class="comment">// Make sure the chosen video mode is compatible</span>
<a name="l00121"></a>00121 <span class="keywordflow">if</span> (!Mode.<a class="code" href="classsf_1_1VideoMode.htm#13ccf1d15900d7251659f871ea362c7c" title="Tell whether or not the video mode is supported.">IsValid</a>())
<a name="l00122"></a>00122 {
<a name="l00123"></a>00123 std::cerr << <span class="stringliteral">"The requested video mode is not available, switching to a valid mode"</span> << std::endl;
<a name="l00124"></a>00124 Mode = <a class="code" href="classsf_1_1VideoMode.htm#50e64232abd41b7ee1016948b41ea5a2" title="Get a valid video mode Index must be in range [0, GetModesCount()[ Modes are sorted...">VideoMode::GetMode</a>(0);
<a name="l00125"></a>00125 }
<a name="l00126"></a>00126
<a name="l00127"></a>00127 <span class="comment">// Update the fullscreen window</span>
<a name="l00128"></a>00128 FullscreenWindow = <span class="keyword">this</span>;
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130 }
<a name="l00131"></a>00131
<a name="l00132"></a>00132 <span class="comment">// Check validity of style</span>
<a name="l00133"></a>00133 <span class="keywordflow">if</span> ((WindowStyle & <a class="code" href="namespacesf_1_1Style.htm#d001cd87b8aa5669d0eadbb8aab1c1d2e07a7d411d5acf28f4a9a4b76a3a9493" title="Titlebar + close button.">Style::Close</a>) || (WindowStyle & <a class="code" href="namespacesf_1_1Style.htm#d001cd87b8aa5669d0eadbb8aab1c1d2ccff967648ebcd5db2007eff7352b50f" title="Titlebar + resizable border + maximize button.">Style::Resize</a>))
<a name="l00134"></a>00134 WindowStyle |= <a class="code" href="namespacesf_1_1Style.htm#d001cd87b8aa5669d0eadbb8aab1c1d2b4c8b32b05ed715928513787cb1e85b6" title="Title bar + fixed border.">Style::Titlebar</a>;
<a name="l00135"></a>00135
<a name="l00136"></a>00136 <span class="comment">// Activate the global context</span>
<a name="l00137"></a>00137 <a class="code" href="classsf_1_1Context.htm#2a92bd6864df0f75d33bd38ac1b81692" title="Get the global context.">Context::GetGlobal</a>().<a class="code" href="classsf_1_1Context.htm#b1d95acf0b2e5f1464c3a0471a54a8f7" title="Activate or deactivate the context.">SetActive</a>(<span class="keyword">true</span>);
<a name="l00138"></a>00138
<a name="l00139"></a>00139 mySettings = Params;
<a name="l00140"></a>00140 Initialize(priv::WindowImpl::New(Mode, Title, WindowStyle, mySettings));
<a name="l00141"></a>00141 }
<a name="l00142"></a>00142
<a name="l00143"></a>00143
<a name="l00147"></a><a class="code" href="classsf_1_1Window.htm#58e264c181fd70e67986d26fea69a71d">00147</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#a891f1cbd7d77c4dc02ac950b6e76f61" title="Create (or recreate) the window.">Window::Create</a>(WindowHandle Handle, <span class="keyword">const</span> <a class="code" href="structsf_1_1WindowSettings.htm" title="Structure defining the creation settings of windows.">WindowSettings</a>& Params)
<a name="l00148"></a>00148 {
<a name="l00149"></a>00149 <span class="comment">// Destroy the previous window implementation</span>
<a name="l00150"></a>00150 <a class="code" href="classsf_1_1Window.htm#b04439f6fb9fdfe40f882676fdb2938c" title="Close (destroy) the window.">Close</a>();
<a name="l00151"></a>00151
<a name="l00152"></a>00152 <span class="comment">// Activate the global context</span>
<a name="l00153"></a>00153 <a class="code" href="classsf_1_1Context.htm#2a92bd6864df0f75d33bd38ac1b81692" title="Get the global context.">Context::GetGlobal</a>().<a class="code" href="classsf_1_1Context.htm#b1d95acf0b2e5f1464c3a0471a54a8f7" title="Activate or deactivate the context.">SetActive</a>(<span class="keyword">true</span>);
<a name="l00154"></a>00154
<a name="l00155"></a>00155 mySettings = Params;
<a name="l00156"></a>00156 Initialize(priv::WindowImpl::New(Handle, mySettings));
<a name="l00157"></a>00157 }
<a name="l00158"></a>00158
<a name="l00159"></a>00159
<a name="l00165"></a><a class="code" href="classsf_1_1Window.htm#b04439f6fb9fdfe40f882676fdb2938c">00165</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#b04439f6fb9fdfe40f882676fdb2938c" title="Close (destroy) the window.">Window::Close</a>()
<a name="l00166"></a>00166 {
<a name="l00167"></a>00167 <span class="comment">// Delete the window implementation</span>
<a name="l00168"></a>00168 <span class="keyword">delete</span> myWindow;
<a name="l00169"></a>00169 myWindow = NULL;
<a name="l00170"></a>00170
<a name="l00171"></a>00171 <span class="comment">// Update the fullscreen window</span>
<a name="l00172"></a>00172 <span class="keywordflow">if</span> (<span class="keyword">this</span> == FullscreenWindow)
<a name="l00173"></a>00173 FullscreenWindow = NULL;
<a name="l00174"></a>00174 }
<a name="l00175"></a>00175
<a name="l00176"></a>00176
<a name="l00182"></a><a class="code" href="classsf_1_1Window.htm#5c4c82e1fdb4252108314fcbe462ad8d">00182</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Window.htm#5c4c82e1fdb4252108314fcbe462ad8d" title="Tell whether or not the window is opened (ie.">Window::IsOpened</a>()<span class="keyword"> const</span>
<a name="l00183"></a>00183 <span class="keyword"></span>{
<a name="l00184"></a>00184 <span class="keywordflow">return</span> myWindow != NULL;
<a name="l00185"></a>00185 }
<a name="l00186"></a>00186
<a name="l00187"></a>00187
<a name="l00191"></a><a class="code" href="classsf_1_1Window.htm#c5dfd4d7df394e3638b567352ec69e22">00191</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classsf_1_1Window.htm#c5dfd4d7df394e3638b567352ec69e22" title="Get the width of the rendering region of the window.">Window::GetWidth</a>()<span class="keyword"> const</span>
<a name="l00192"></a>00192 <span class="keyword"></span>{
<a name="l00193"></a>00193 <span class="keywordflow">return</span> myWindow ? myWindow->GetWidth() : 0;
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195
<a name="l00196"></a>00196
<a name="l00200"></a><a class="code" href="classsf_1_1Window.htm#913a7ae79631eaa8ef6a1ad8cd0c5947">00200</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classsf_1_1Window.htm#913a7ae79631eaa8ef6a1ad8cd0c5947" title="Get the height of the rendering region of the window.">Window::GetHeight</a>()<span class="keyword"> const</span>
<a name="l00201"></a>00201 <span class="keyword"></span>{
<a name="l00202"></a>00202 <span class="keywordflow">return</span> myWindow ? myWindow->GetHeight() : 0;
<a name="l00203"></a>00203 }
<a name="l00204"></a>00204
<a name="l00205"></a>00205
<a name="l00209"></a><a class="code" href="classsf_1_1Window.htm#27321006595f9f6a482b26b13800695f">00209</a> <span class="keyword">const</span> <a class="code" href="structsf_1_1WindowSettings.htm" title="Structure defining the creation settings of windows.">WindowSettings</a>& <a class="code" href="classsf_1_1Window.htm#27321006595f9f6a482b26b13800695f" title="Get the creation settings of the window.">Window::GetSettings</a>()<span class="keyword"> const</span>
<a name="l00210"></a>00210 <span class="keyword"></span>{
<a name="l00211"></a>00211 <span class="keywordflow">return</span> mySettings;
<a name="l00212"></a>00212 }
<a name="l00213"></a>00213
<a name="l00214"></a>00214
<a name="l00218"></a><a class="code" href="classsf_1_1Window.htm#65cb14f66a870f459bd66e11e52fbfe8">00218</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Window.htm#65cb14f66a870f459bd66e11e52fbfe8" title="Get the event on top of events stack, if any, and pop it.">Window::GetEvent</a>(<a class="code" href="classsf_1_1Event.htm" title="Event defines a system event and its parameters.">Event</a>& EventReceived)
<a name="l00219"></a>00219 {
<a name="l00220"></a>00220 <span class="comment">// Let the window implementation process incoming events if the events queue is empty</span>
<a name="l00221"></a>00221 <span class="keywordflow">if</span> (myWindow && myEvents.empty())
<a name="l00222"></a>00222 myWindow->DoEvents();
<a name="l00223"></a>00223
<a name="l00224"></a>00224 <span class="comment">// Pop first event of queue, if not empty</span>
<a name="l00225"></a>00225 <span class="keywordflow">if</span> (!myEvents.empty())
<a name="l00226"></a>00226 {
<a name="l00227"></a>00227 EventReceived = myEvents.front();
<a name="l00228"></a>00228 myEvents.pop();
<a name="l00229"></a>00229
<a name="l00230"></a>00230 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232
<a name="l00233"></a>00233 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00234"></a>00234 }
<a name="l00235"></a>00235
<a name="l00236"></a>00236
<a name="l00240"></a><a class="code" href="classsf_1_1Window.htm#cb8391cc93ff730288e2a8dd6b0bb7b5">00240</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#cb8391cc93ff730288e2a8dd6b0bb7b5" title="Enable / disable vertical synchronization.">Window::UseVerticalSync</a>(<span class="keywordtype">bool</span> Enabled)
<a name="l00241"></a>00241 {
<a name="l00242"></a>00242 <span class="keywordflow">if</span> (<a class="code" href="classsf_1_1Window.htm#9fc1e745594d5cf6a30225ec9ea36675" title="Activate of deactivate the window as the current target for rendering.">SetActive</a>())
<a name="l00243"></a>00243 myWindow->UseVerticalSync(Enabled);
<a name="l00244"></a>00244 }
<a name="l00245"></a>00245
<a name="l00246"></a>00246
<a name="l00250"></a><a class="code" href="classsf_1_1Window.htm#6142e38cb60901e6604284425714f3f0">00250</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#6142e38cb60901e6604284425714f3f0" title="Show or hide the mouse cursor.">Window::ShowMouseCursor</a>(<span class="keywordtype">bool</span> Show)
<a name="l00251"></a>00251 {
<a name="l00252"></a>00252 <span class="keywordflow">if</span> (myWindow)
<a name="l00253"></a>00253 myWindow->ShowMouseCursor(Show);
<a name="l00254"></a>00254 }
<a name="l00255"></a>00255
<a name="l00256"></a>00256
<a name="l00260"></a><a class="code" href="classsf_1_1Window.htm#369d1764893c6fde8979fcf04142dc55">00260</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#369d1764893c6fde8979fcf04142dc55" title="Change the position of the mouse cursor.">Window::SetCursorPosition</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Left, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Top)
<a name="l00261"></a>00261 {
<a name="l00262"></a>00262 <span class="keywordflow">if</span> (myWindow)
<a name="l00263"></a>00263 {
<a name="l00264"></a>00264 <span class="comment">// Keep coordinates for later checking (to reject the generated MouseMoved event)</span>
<a name="l00265"></a>00265 mySetCursorPosX = Left;
<a name="l00266"></a>00266 mySetCursorPosY = Top;
<a name="l00267"></a>00267
<a name="l00268"></a>00268 myWindow->SetCursorPosition(Left, Top);
<a name="l00269"></a>00269 }
<a name="l00270"></a>00270 }
<a name="l00271"></a>00271
<a name="l00272"></a>00272
<a name="l00276"></a><a class="code" href="classsf_1_1Window.htm#3a6d2908a624a8afda4b2fdd9ef46058">00276</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#3a6d2908a624a8afda4b2fdd9ef46058" title="Change the position of the window on screen.">Window::SetPosition</a>(<span class="keywordtype">int</span> Left, <span class="keywordtype">int</span> Top)
<a name="l00277"></a>00277 {
<a name="l00278"></a>00278 <span class="keywordflow">if</span> (!myIsExternal)
<a name="l00279"></a>00279 {
<a name="l00280"></a>00280 <span class="keywordflow">if</span> (myWindow)
<a name="l00281"></a>00281 myWindow->SetPosition(Left, Top);
<a name="l00282"></a>00282 }
<a name="l00283"></a>00283 <span class="keywordflow">else</span>
<a name="l00284"></a>00284 {
<a name="l00285"></a>00285 std::cerr << <span class="stringliteral">"Warning : trying to change the position of an external SFML window, which is not allowed"</span> << std::endl;
<a name="l00286"></a>00286 }
<a name="l00287"></a>00287 }
<a name="l00288"></a>00288
<a name="l00289"></a>00289
<a name="l00293"></a><a class="code" href="classsf_1_1Window.htm#dc4461bfaa9b4ff0fd0364a5079a47ef">00293</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#dc4461bfaa9b4ff0fd0364a5079a47ef" title="Change the size of the rendering region of the window.">Window::SetSize</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Width, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Height)
<a name="l00294"></a>00294 {
<a name="l00295"></a>00295 <span class="keywordflow">if</span> (myWindow)
<a name="l00296"></a>00296 myWindow->SetSize(Width, Height);
<a name="l00297"></a>00297 }
<a name="l00298"></a>00298
<a name="l00299"></a>00299
<a name="l00303"></a><a class="code" href="classsf_1_1Window.htm#727c01602c86710fd935f9892946b2de">00303</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#727c01602c86710fd935f9892946b2de" title="Show or hide the window.">Window::Show</a>(<span class="keywordtype">bool</span> State)
<a name="l00304"></a>00304 {
<a name="l00305"></a>00305 <span class="keywordflow">if</span> (!myIsExternal)
<a name="l00306"></a>00306 {
<a name="l00307"></a>00307 <span class="keywordflow">if</span> (myWindow)
<a name="l00308"></a>00308 myWindow->Show(State);
<a name="l00309"></a>00309 }
<a name="l00310"></a>00310 }
<a name="l00311"></a>00311
<a name="l00312"></a>00312
<a name="l00317"></a><a class="code" href="classsf_1_1Window.htm#43ac767f0b7b697b392444d639b909e0">00317</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#43ac767f0b7b697b392444d639b909e0" title="Enable or disable automatic key-repeat.">Window::EnableKeyRepeat</a>(<span class="keywordtype">bool</span> Enabled)
<a name="l00318"></a>00318 {
<a name="l00319"></a>00319 <span class="keywordflow">if</span> (myWindow)
<a name="l00320"></a>00320 myWindow->EnableKeyRepeat(Enabled);
<a name="l00321"></a>00321 }
<a name="l00322"></a>00322
<a name="l00323"></a>00323
<a name="l00327"></a><a class="code" href="classsf_1_1Window.htm#36fa09e52af66878b8b826457b8f1dfa">00327</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#36fa09e52af66878b8b826457b8f1dfa" title="Change the window&#39;s icon.">Window::SetIcon</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Width, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Height, <span class="keyword">const</span> Uint8* Pixels)
<a name="l00328"></a>00328 {
<a name="l00329"></a>00329 <span class="keywordflow">if</span> (myWindow)
<a name="l00330"></a>00330 myWindow->SetIcon(Width, Height, Pixels);
<a name="l00331"></a>00331 }
<a name="l00332"></a>00332
<a name="l00333"></a>00333
<a name="l00338"></a><a class="code" href="classsf_1_1Window.htm#9fc1e745594d5cf6a30225ec9ea36675">00338</a> <span class="keywordtype">bool</span> <a class="code" href="classsf_1_1Window.htm#9fc1e745594d5cf6a30225ec9ea36675" title="Activate of deactivate the window as the current target for rendering.">Window::SetActive</a>(<span class="keywordtype">bool</span> Active)<span class="keyword"> const</span>
<a name="l00339"></a>00339 <span class="keyword"></span>{
<a name="l00340"></a>00340 <span class="keywordflow">if</span> (myWindow)
<a name="l00341"></a>00341 {
<a name="l00342"></a>00342 myWindow->SetActive(Active);
<a name="l00343"></a>00343 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00344"></a>00344 }
<a name="l00345"></a>00345
<a name="l00346"></a>00346 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00347"></a>00347 }
<a name="l00348"></a>00348
<a name="l00349"></a>00349
<a name="l00353"></a><a class="code" href="classsf_1_1Window.htm#ee37843c5c882f7b3a0788b310308435">00353</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#ee37843c5c882f7b3a0788b310308435" title="Display the window on screen.">Window::Display</a>()
<a name="l00354"></a>00354 {
<a name="l00355"></a>00355 <span class="comment">// Limit the framerate if needed</span>
<a name="l00356"></a>00356 <span class="keywordflow">if</span> (myFramerateLimit > 0)
<a name="l00357"></a>00357 {
<a name="l00358"></a>00358 <span class="keywordtype">float</span> RemainingTime = 1.f / myFramerateLimit - myClock.<a class="code" href="classsf_1_1Clock.htm#e9a02135879afbd38d034ac4a357a995" title="Get the time elapsed since last reset.">GetElapsedTime</a>();
<a name="l00359"></a>00359 <span class="keywordflow">if</span> (RemainingTime > 0)
<a name="l00360"></a>00360 Sleep(RemainingTime);
<a name="l00361"></a>00361 }
<a name="l00362"></a>00362
<a name="l00363"></a>00363 <span class="comment">// Measure the time elapsed since last frame</span>
<a name="l00364"></a>00364 myLastFrameTime = myClock.<a class="code" href="classsf_1_1Clock.htm#e9a02135879afbd38d034ac4a357a995" title="Get the time elapsed since last reset.">GetElapsedTime</a>();
<a name="l00365"></a>00365 myClock.<a class="code" href="classsf_1_1Clock.htm#e7d8de6876d51fa16675a64c649570ec" title="Restart the timer.">Reset</a>();
<a name="l00366"></a>00366
<a name="l00367"></a>00367 <span class="comment">// Display the backbuffer on screen</span>
<a name="l00368"></a>00368 <span class="keywordflow">if</span> (<a class="code" href="classsf_1_1Window.htm#9fc1e745594d5cf6a30225ec9ea36675" title="Activate of deactivate the window as the current target for rendering.">SetActive</a>())
<a name="l00369"></a>00369 myWindow->Display();
<a name="l00370"></a>00370 }
<a name="l00371"></a>00371
<a name="l00372"></a>00372
<a name="l00376"></a><a class="code" href="classsf_1_1Window.htm#49db47a79ca98b7d65087adeea06e919">00376</a> <span class="keyword">const</span> <a class="code" href="classsf_1_1Input.htm" title="Input handles real-time input from keyboard and mouse.">Input</a>& <a class="code" href="classsf_1_1Window.htm#49db47a79ca98b7d65087adeea06e919" title="Get the input manager of the window.">Window::GetInput</a>()<span class="keyword"> const</span>
<a name="l00377"></a>00377 <span class="keyword"></span>{
<a name="l00378"></a>00378 <span class="keywordflow">return</span> myInput;
<a name="l00379"></a>00379 }
<a name="l00380"></a>00380
<a name="l00381"></a>00381
<a name="l00385"></a><a class="code" href="classsf_1_1Window.htm#5544031f1d2965c00532fb5660763f33">00385</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#5544031f1d2965c00532fb5660763f33" title="Limit the framerate to a maximum fixed frequency.">Window::SetFramerateLimit</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Limit)
<a name="l00386"></a>00386 {
<a name="l00387"></a>00387 myFramerateLimit = Limit;
<a name="l00388"></a>00388 }
<a name="l00389"></a>00389
<a name="l00390"></a>00390
<a name="l00394"></a><a class="code" href="classsf_1_1Window.htm#63571ef14c9351899bcd605fb101c254">00394</a> <span class="keywordtype">float</span> <a class="code" href="classsf_1_1Window.htm#63571ef14c9351899bcd605fb101c254" title="Get time elapsed since last frame.">Window::GetFrameTime</a>()<span class="keyword"> const</span>
<a name="l00395"></a>00395 <span class="keyword"></span>{
<a name="l00396"></a>00396 <span class="keywordflow">return</span> myLastFrameTime;
<a name="l00397"></a>00397 }
<a name="l00398"></a>00398
<a name="l00399"></a>00399
<a name="l00404"></a><a class="code" href="classsf_1_1Window.htm#d685eed68b85a66c8000a08e9a28aa91">00404</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1Window.htm#d685eed68b85a66c8000a08e9a28aa91" title="Change the joystick threshold, ie.">Window::SetJoystickThreshold</a>(<span class="keywordtype">float</span> Threshold)
<a name="l00405"></a>00405 {
<a name="l00406"></a>00406 <span class="keywordflow">if</span> (myWindow)
<a name="l00407"></a>00407 myWindow->SetJoystickThreshold(Threshold);
<a name="l00408"></a>00408 }
<a name="l00409"></a>00409
<a name="l00410"></a>00410
<a name="l00414"></a>00414 <span class="keywordtype">void</span> Window::OnCreate()
<a name="l00415"></a>00415 {
<a name="l00416"></a>00416 <span class="comment">// Nothing by default</span>
<a name="l00417"></a>00417 }
<a name="l00418"></a>00418
<a name="l00419"></a>00419
<a name="l00423"></a>00423 <span class="keywordtype">void</span> Window::OnEvent(<span class="keyword">const</span> Event& EventReceived)
<a name="l00424"></a>00424 {
<a name="l00425"></a>00425 <span class="comment">// Discard MouseMove events generated by SetCursorPosition</span>
<a name="l00426"></a>00426 <span class="keywordflow">if</span> ((EventReceived.Type == Event::MouseMoved) &&
<a name="l00427"></a>00427 (EventReceived.MouseMove.X == mySetCursorPosX) &&
<a name="l00428"></a>00428 (EventReceived.MouseMove.Y == mySetCursorPosY))
<a name="l00429"></a>00429 {
<a name="l00430"></a>00430 mySetCursorPosX = 0xFFFF;
<a name="l00431"></a>00431 mySetCursorPosY = 0xFFFF;
<a name="l00432"></a>00432 <span class="keywordflow">return</span>;
<a name="l00433"></a>00433 }
<a name="l00434"></a>00434
<a name="l00435"></a>00435 myEvents.push(EventReceived);
<a name="l00436"></a>00436 }
<a name="l00437"></a>00437
<a name="l00438"></a>00438
<a name="l00442"></a>00442 <span class="keywordtype">void</span> Window::Initialize(priv::WindowImpl* Window)
<a name="l00443"></a>00443 {
<a name="l00444"></a>00444 <span class="comment">// Assign and initialize the new window</span>
<a name="l00445"></a>00445 myWindow = Window;
<a name="l00446"></a>00446 myWindow->Initialize();
<a name="l00447"></a>00447
<a name="l00448"></a>00448 <span class="comment">// Clear the event queue</span>
<a name="l00449"></a>00449 <span class="keywordflow">while</span> (!myEvents.empty())
<a name="l00450"></a>00450 myEvents.pop();
<a name="l00451"></a>00451
<a name="l00452"></a>00452 <span class="comment">// Listen to events from the new window</span>
<a name="l00453"></a>00453 myWindow->AddListener(<span class="keyword">this</span>);
<a name="l00454"></a>00454 myWindow->AddListener(&myInput);
<a name="l00455"></a>00455
<a name="l00456"></a>00456 <span class="comment">// Setup default behaviours (to get a consistent behaviour across different implementations)</span>
<a name="l00457"></a>00457 <a class="code" href="classsf_1_1Window.htm#727c01602c86710fd935f9892946b2de" title="Show or hide the window.">Show</a>(<span class="keyword">true</span>);
<a name="l00458"></a>00458 <a class="code" href="classsf_1_1Window.htm#cb8391cc93ff730288e2a8dd6b0bb7b5" title="Enable / disable vertical synchronization.">UseVerticalSync</a>(<span class="keyword">false</span>);
<a name="l00459"></a>00459 <a class="code" href="classsf_1_1Window.htm#6142e38cb60901e6604284425714f3f0" title="Show or hide the mouse cursor.">ShowMouseCursor</a>(<span class="keyword">true</span>);
<a name="l00460"></a>00460 <a class="code" href="classsf_1_1Window.htm#43ac767f0b7b697b392444d639b909e0" title="Enable or disable automatic key-repeat.">EnableKeyRepeat</a>(<span class="keyword">true</span>);
<a name="l00461"></a>00461
<a name="l00462"></a>00462 <span class="comment">// Reset frame time</span>
<a name="l00463"></a>00463 myClock.Reset();
<a name="l00464"></a>00464 myLastFrameTime = 0.f;
<a name="l00465"></a>00465
<a name="l00466"></a>00466 <span class="comment">// Activate the window</span>
<a name="l00467"></a>00467 <a class="code" href="classsf_1_1Window.htm#9fc1e745594d5cf6a30225ec9ea36675" title="Activate of deactivate the window as the current target for rendering.">SetActive</a>(<span class="keyword">true</span>);
<a name="l00468"></a>00468
<a name="l00469"></a>00469 <span class="comment">// Notify the derived class</span>
<a name="l00470"></a>00470 OnCreate();
<a name="l00471"></a>00471 }
<a name="l00472"></a>00472
<a name="l00473"></a>00473 } <span class="comment">// namespace sf</span>
</pre></div></div>
<p id="footer">
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved ::
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen 1.5.2</a> ::
</p>
</body>
</html>
|