diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWinCE.cpp | 868 |
1 files changed, 868 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWinCE.cpp b/libraries/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWinCE.cpp new file mode 100644 index 0000000..e6eb27d --- /dev/null +++ b/libraries/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWinCE.cpp | |||
@@ -0,0 +1,868 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | #include "IrrCompileConfig.h" | ||
6 | |||
7 | #ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ | ||
8 | |||
9 | #include "CIrrDeviceWinCE.h" | ||
10 | #include "IEventReceiver.h" | ||
11 | #include "irrList.h" | ||
12 | #include "os.h" | ||
13 | |||
14 | #include "CTimer.h" | ||
15 | #include "irrString.h" | ||
16 | #include "COSOperator.h" | ||
17 | #include "dimension2d.h" | ||
18 | #include <winuser.h> | ||
19 | #include "irrlicht.h" | ||
20 | |||
21 | #ifdef _MSC_VER | ||
22 | #pragma comment (lib, "aygshell.lib") | ||
23 | #endif | ||
24 | |||
25 | |||
26 | namespace irr | ||
27 | { | ||
28 | namespace video | ||
29 | { | ||
30 | #ifdef _IRR_COMPILE_WITH_DIRECT3D_8_ | ||
31 | IVideoDriver* createDirectX8Driver(const irr::SIrrlichtCreationParameters& params, | ||
32 | io::IFileSystem* io, HWND window); | ||
33 | #endif | ||
34 | |||
35 | #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_ | ||
36 | IVideoDriver* createDirectX9Driver(const irr::SIrrlichtCreationParameters& params, | ||
37 | io::IFileSystem* io, HWND window); | ||
38 | #endif | ||
39 | |||
40 | #ifdef _IRR_COMPILE_WITH_OPENGL_ | ||
41 | IVideoDriver* createOpenGLDriver(const irr::SIrrlichtCreationParameters& params, io::IFileSystem* io, this); | ||
42 | #endif | ||
43 | } | ||
44 | } // end namespace irr | ||
45 | |||
46 | |||
47 | |||
48 | struct SEnvMapper | ||
49 | { | ||
50 | HWND hWnd; | ||
51 | irr::CIrrDeviceWinCE* irrDev; | ||
52 | }; | ||
53 | |||
54 | irr::core::list<SEnvMapper> EnvMap; | ||
55 | |||
56 | SEnvMapper* getEnvMapperFromHWnd(HWND hWnd) | ||
57 | { | ||
58 | irr::core::list<SEnvMapper>::Iterator it = EnvMap.begin(); | ||
59 | for (; it!= EnvMap.end(); ++it) | ||
60 | if ((*it).hWnd == hWnd) | ||
61 | return &(*it); | ||
62 | |||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | irr::CIrrDeviceWinCE* getDeviceFromHWnd(HWND hWnd) | ||
67 | { | ||
68 | irr::core::list<SEnvMapper>::Iterator it = EnvMap.begin(); | ||
69 | for (; it!= EnvMap.end(); ++it) | ||
70 | if ((*it).hWnd == hWnd) | ||
71 | return (*it).irrDev; | ||
72 | |||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | |||
77 | LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | ||
78 | { | ||
79 | #ifndef WM_MOUSEWHEEL | ||
80 | #define WM_MOUSEWHEEL 0x020A | ||
81 | #endif | ||
82 | #ifndef WHEEL_DELTA | ||
83 | #define WHEEL_DELTA 120 | ||
84 | #endif | ||
85 | |||
86 | irr::CIrrDeviceWinCE* dev = 0; | ||
87 | irr::SEvent event; | ||
88 | SEnvMapper* envm = 0; | ||
89 | |||
90 | //BYTE allKeys[256]; | ||
91 | |||
92 | static irr::s32 ClickCount=0; | ||
93 | if (GetCapture() != hWnd && ClickCount > 0) | ||
94 | ClickCount = 0; | ||
95 | |||
96 | switch (message) | ||
97 | { | ||
98 | case WM_PAINT: | ||
99 | { | ||
100 | PAINTSTRUCT ps; | ||
101 | BeginPaint(hWnd, &ps); | ||
102 | EndPaint(hWnd, &ps); | ||
103 | } | ||
104 | return 0; | ||
105 | |||
106 | case WM_ERASEBKGND: | ||
107 | return 0; | ||
108 | |||
109 | case WM_SETCURSOR: | ||
110 | envm = getEnvMapperFromHWnd(hWnd); | ||
111 | if (envm && !envm->irrDev->getWin32CursorControl()->isVisible()) | ||
112 | { | ||
113 | SetCursor(NULL); | ||
114 | return 0; | ||
115 | } | ||
116 | break; | ||
117 | |||
118 | case WM_MOUSEWHEEL: | ||
119 | event.EventType = irr::EET_MOUSE_INPUT_EVENT; | ||
120 | event.MouseInput.Wheel = ((irr::f32)((short)HIWORD(wParam))) / (irr::f32)WHEEL_DELTA; | ||
121 | event.MouseInput.Event = irr::EMIE_MOUSE_WHEEL; | ||
122 | |||
123 | POINT p; // fixed by jox | ||
124 | p.x = 0; p.y = 0; | ||
125 | ClientToScreen(hWnd, &p); | ||
126 | event.MouseInput.X = LOWORD(lParam) - p.x; | ||
127 | event.MouseInput.Y = HIWORD(lParam) - p.y; | ||
128 | event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0); | ||
129 | event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0); | ||
130 | // left and right mouse buttons | ||
131 | event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON); | ||
132 | // middle and extra buttons | ||
133 | if (wParam & MK_MBUTTON) | ||
134 | event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE; | ||
135 | |||
136 | dev = getDeviceFromHWnd(hWnd); | ||
137 | if (dev) | ||
138 | dev->postEventFromUser(event); | ||
139 | break; | ||
140 | |||
141 | case WM_LBUTTONDOWN: | ||
142 | ClickCount++; | ||
143 | SetCapture(hWnd); | ||
144 | event.EventType = irr::EET_MOUSE_INPUT_EVENT; | ||
145 | event.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN; | ||
146 | event.MouseInput.X = (short)LOWORD(lParam); | ||
147 | event.MouseInput.Y = (short)HIWORD(lParam); | ||
148 | event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0); | ||
149 | event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0); | ||
150 | // left and right mouse buttons | ||
151 | event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON); | ||
152 | // middle and extra buttons | ||
153 | if (wParam & MK_MBUTTON) | ||
154 | event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE; | ||
155 | |||
156 | dev = getDeviceFromHWnd(hWnd); | ||
157 | if (dev) | ||
158 | dev->postEventFromUser(event); | ||
159 | return 0; | ||
160 | |||
161 | case WM_LBUTTONUP: | ||
162 | ClickCount--; | ||
163 | if (ClickCount<1) | ||
164 | { | ||
165 | ClickCount=0; | ||
166 | ReleaseCapture(); | ||
167 | } | ||
168 | event.EventType = irr::EET_MOUSE_INPUT_EVENT; | ||
169 | event.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP; | ||
170 | event.MouseInput.X = (short)LOWORD(lParam); | ||
171 | event.MouseInput.Y = (short)HIWORD(lParam); | ||
172 | event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0); | ||
173 | event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0); | ||
174 | // left and right mouse buttons | ||
175 | event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON); | ||
176 | // middle and extra buttons | ||
177 | if (wParam & MK_MBUTTON) | ||
178 | event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE; | ||
179 | |||
180 | dev = getDeviceFromHWnd(hWnd); | ||
181 | if (dev) | ||
182 | dev->postEventFromUser(event); | ||
183 | return 0; | ||
184 | |||
185 | case WM_RBUTTONDOWN: | ||
186 | ClickCount++; | ||
187 | SetCapture(hWnd); | ||
188 | event.EventType = irr::EET_MOUSE_INPUT_EVENT; | ||
189 | event.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN; | ||
190 | event.MouseInput.X = (short)LOWORD(lParam); | ||
191 | event.MouseInput.Y = (short)HIWORD(lParam); | ||
192 | event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0); | ||
193 | event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0); | ||
194 | // left and right mouse buttons | ||
195 | event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON); | ||
196 | // middle and extra buttons | ||
197 | if (wParam & MK_MBUTTON) | ||
198 | event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE; | ||
199 | |||
200 | dev = getDeviceFromHWnd(hWnd); | ||
201 | if (dev) | ||
202 | dev->postEventFromUser(event); | ||
203 | return 0; | ||
204 | |||
205 | case WM_RBUTTONUP: | ||
206 | ClickCount--; | ||
207 | if (ClickCount<1) | ||
208 | { | ||
209 | ClickCount=0; | ||
210 | ReleaseCapture(); | ||
211 | } | ||
212 | event.EventType = irr::EET_MOUSE_INPUT_EVENT; | ||
213 | event.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP; | ||
214 | event.MouseInput.X = (short)LOWORD(lParam); | ||
215 | event.MouseInput.Y = (short)HIWORD(lParam); | ||
216 | event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0); | ||
217 | event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0); | ||
218 | // left and right mouse buttons | ||
219 | event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON); | ||
220 | // middle and extra buttons | ||
221 | if (wParam & MK_MBUTTON) | ||
222 | event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE; | ||
223 | |||
224 | dev = getDeviceFromHWnd(hWnd); | ||
225 | if (dev) | ||
226 | dev->postEventFromUser(event); | ||
227 | return 0; | ||
228 | |||
229 | case WM_MBUTTONDOWN: | ||
230 | ClickCount++; | ||
231 | SetCapture(hWnd); | ||
232 | event.EventType = irr::EET_MOUSE_INPUT_EVENT; | ||
233 | event.MouseInput.Event = irr::EMIE_MMOUSE_PRESSED_DOWN; | ||
234 | event.MouseInput.X = (short)LOWORD(lParam); | ||
235 | event.MouseInput.Y = (short)HIWORD(lParam); | ||
236 | event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0); | ||
237 | event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0); | ||
238 | // left and right mouse buttons | ||
239 | event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON); | ||
240 | // middle and extra buttons | ||
241 | if (wParam & MK_MBUTTON) | ||
242 | event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE; | ||
243 | |||
244 | dev = getDeviceFromHWnd(hWnd); | ||
245 | if (dev) | ||
246 | dev->postEventFromUser(event); | ||
247 | return 0; | ||
248 | |||
249 | case WM_MBUTTONUP: | ||
250 | ClickCount--; | ||
251 | if (ClickCount<1) | ||
252 | { | ||
253 | ClickCount=0; | ||
254 | ReleaseCapture(); | ||
255 | } | ||
256 | event.EventType = irr::EET_MOUSE_INPUT_EVENT; | ||
257 | event.MouseInput.Event = irr::EMIE_MMOUSE_LEFT_UP; | ||
258 | event.MouseInput.X = (short)LOWORD(lParam); | ||
259 | event.MouseInput.Y = (short)HIWORD(lParam); | ||
260 | event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0); | ||
261 | event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0); | ||
262 | // left and right mouse buttons | ||
263 | event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON); | ||
264 | // middle and extra buttons | ||
265 | if (wParam & MK_MBUTTON) | ||
266 | event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE; | ||
267 | |||
268 | dev = getDeviceFromHWnd(hWnd); | ||
269 | if (dev) | ||
270 | dev->postEventFromUser(event); | ||
271 | return 0; | ||
272 | |||
273 | case WM_MOUSEMOVE: | ||
274 | event.EventType = irr::EET_MOUSE_INPUT_EVENT; | ||
275 | event.MouseInput.Event = irr::EMIE_MOUSE_MOVED; | ||
276 | event.MouseInput.X = (short)LOWORD(lParam); | ||
277 | event.MouseInput.Y = (short)HIWORD(lParam); | ||
278 | event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0); | ||
279 | event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0); | ||
280 | // left and right mouse buttons | ||
281 | event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON); | ||
282 | // middle and extra buttons | ||
283 | if (wParam & MK_MBUTTON) | ||
284 | event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE; | ||
285 | |||
286 | dev = getDeviceFromHWnd(hWnd); | ||
287 | if (dev) | ||
288 | dev->postEventFromUser(event); | ||
289 | |||
290 | return 0; | ||
291 | |||
292 | case WM_SYSKEYDOWN: | ||
293 | case WM_SYSKEYUP: | ||
294 | case WM_KEYDOWN: | ||
295 | case WM_KEYUP: | ||
296 | { | ||
297 | event.EventType = irr::EET_KEY_INPUT_EVENT; | ||
298 | event.KeyInput.Key = (irr::EKEY_CODE)wParam; | ||
299 | event.KeyInput.PressedDown = (message==WM_KEYDOWN || message == WM_SYSKEYDOWN); | ||
300 | dev = getDeviceFromHWnd(hWnd); | ||
301 | /* | ||
302 | WORD KeyAsc=0; | ||
303 | GetKeyboardState(allKeys); | ||
304 | ToAscii(wParam,lParam,allKeys,&KeyAsc,0); | ||
305 | */ | ||
306 | // event.KeyInput.Shift = ((allKeys[VK_SHIFT] & 0x80)!=0); | ||
307 | // event.KeyInput.Control = ((allKeys[VK_CONTROL] & 0x80)!=0); | ||
308 | // event.KeyInput.Char = (KeyAsc & 0x00ff); //KeyAsc >= 0 ? KeyAsc : 0; | ||
309 | |||
310 | if (dev) | ||
311 | dev->postEventFromUser(event); | ||
312 | |||
313 | return 0; | ||
314 | } | ||
315 | |||
316 | case WM_SIZE: | ||
317 | { | ||
318 | // resize | ||
319 | dev = getDeviceFromHWnd(hWnd); | ||
320 | if (dev) | ||
321 | dev->OnResized(); | ||
322 | } | ||
323 | return 0; | ||
324 | |||
325 | case WM_DESTROY: | ||
326 | PostQuitMessage(0); | ||
327 | return 0; | ||
328 | |||
329 | } | ||
330 | |||
331 | return DefWindowProc(hWnd, message, wParam, lParam); | ||
332 | } | ||
333 | |||
334 | namespace irr | ||
335 | { | ||
336 | |||
337 | //! constructor | ||
338 | CIrrDeviceWinCE::CIrrDeviceWinCE(const SIrrlichtCreationParameters& params) | ||
339 | : CIrrDeviceStub(params), HWnd(0), | ||
340 | Win32CursorControl(0), ChangedToFullScreen(false), Resized(false), | ||
341 | ExternalWindow(false) | ||
342 | { | ||
343 | #ifdef _DEBUG | ||
344 | setDebugName("CIrrDeviceWinCE"); | ||
345 | #endif | ||
346 | |||
347 | core::stringc winversion; | ||
348 | getWindowsVersion(winversion); | ||
349 | Operator = new COSOperator(winversion); | ||
350 | os::Printer::log(winversion.c_str(), ELL_INFORMATION); | ||
351 | |||
352 | HINSTANCE hInstance = GetModuleHandle(0); | ||
353 | |||
354 | // create the window only if we do not use the null device | ||
355 | if (!CreationParams.WindowId && (CreationParams.DriverType != video::EDT_NULL)) | ||
356 | { | ||
357 | const wchar_t* ClassName = L"CIrrDeviceWinCE"; | ||
358 | |||
359 | // Register Class | ||
360 | WNDCLASS wc; | ||
361 | wc.style = CS_HREDRAW | CS_VREDRAW; | ||
362 | wc.lpfnWndProc = WndProc; | ||
363 | wc.cbClsExtra = 0; | ||
364 | wc.cbWndExtra = 0; | ||
365 | wc.hInstance = hInstance; | ||
366 | wc.hIcon = NULL; | ||
367 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); | ||
368 | wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | ||
369 | wc.lpszMenuName = 0; | ||
370 | wc.lpszClassName = ClassName; | ||
371 | |||
372 | // if there is an icon, load it | ||
373 | wc.hIcon = (HICON)LoadImageW(hInstance, L"irrlicht.ico", IMAGE_ICON, 0,0, 0); | ||
374 | |||
375 | RegisterClass(&wc); | ||
376 | |||
377 | // calculate client size | ||
378 | |||
379 | RECT clientSize; | ||
380 | clientSize.top = 0; | ||
381 | clientSize.left = 0; | ||
382 | clientSize.right = CreationParams.WindowSize.Width; | ||
383 | clientSize.bottom = CreationParams.WindowSize.Height; | ||
384 | |||
385 | DWORD style = WS_POPUP; | ||
386 | |||
387 | if (!CreationParams.Fullscreen) | ||
388 | style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; | ||
389 | |||
390 | AdjustWindowRectEx(&clientSize, style, FALSE, 0); | ||
391 | |||
392 | const s32 realWidth = clientSize.right - clientSize.left; | ||
393 | const s32 realHeight = clientSize.bottom - clientSize.top; | ||
394 | |||
395 | const s32 windowLeft = core::s32_max ( 0, (GetSystemMetrics(SM_CXSCREEN) - realWidth) >> 1 ); | ||
396 | const s32 windowTop = core::s32_max ( 0, (GetSystemMetrics(SM_CYSCREEN) - realHeight) >> 1 ); | ||
397 | |||
398 | // create window | ||
399 | |||
400 | HWnd = CreateWindowW( ClassName, L"", style, windowLeft, windowTop, | ||
401 | realWidth, realHeight, NULL, NULL, hInstance, NULL); | ||
402 | |||
403 | ShowWindow(HWnd , SW_SHOW); | ||
404 | UpdateWindow(HWnd); | ||
405 | |||
406 | // fix ugly ATI driver bugs. Thanks to ariaci | ||
407 | MoveWindow(HWnd, windowLeft, windowTop, realWidth, realHeight, TRUE); | ||
408 | } | ||
409 | else if (CreationParams.WindowId) | ||
410 | { | ||
411 | // attach external window | ||
412 | HWnd = static_cast<HWND>(CreationParams.WindowId); | ||
413 | RECT r; | ||
414 | GetWindowRect(HWnd, &r); | ||
415 | CreationParams.WindowSize.Width = r.right - r.left; | ||
416 | CreationParams.WindowSize.Height = r.bottom - r.top; | ||
417 | CreationParams.Fullscreen = false; | ||
418 | ExternalWindow = true; | ||
419 | } | ||
420 | |||
421 | // create cursor control | ||
422 | |||
423 | Win32CursorControl = new CCursorControl(CreationParams.WindowSize, HWnd, CreationParams.Fullscreen); | ||
424 | CursorControl = Win32CursorControl; | ||
425 | |||
426 | // create driver | ||
427 | |||
428 | createDriver(); | ||
429 | |||
430 | if (VideoDriver) | ||
431 | createGUIAndScene(); | ||
432 | |||
433 | // register environment | ||
434 | |||
435 | SEnvMapper em; | ||
436 | em.irrDev = this; | ||
437 | em.hWnd = HWnd; | ||
438 | EnvMap.push_back(em); | ||
439 | |||
440 | // set this as active window | ||
441 | SetActiveWindow(HWnd); | ||
442 | SetForegroundWindow(HWnd); | ||
443 | } | ||
444 | |||
445 | |||
446 | //! destructor | ||
447 | CIrrDeviceWinCE::~CIrrDeviceWinCE() | ||
448 | { | ||
449 | // unregister environment | ||
450 | |||
451 | if (ChangedToFullScreen) | ||
452 | SHFullScreen(HWnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON); | ||
453 | |||
454 | irr::core::list<SEnvMapper>::Iterator it = EnvMap.begin(); | ||
455 | for (; it!= EnvMap.end(); ++it) | ||
456 | if ((*it).hWnd == HWnd) | ||
457 | { | ||
458 | EnvMap.erase(it); | ||
459 | break; | ||
460 | } | ||
461 | } | ||
462 | |||
463 | |||
464 | //! create the driver | ||
465 | void CIrrDeviceWinCE::createDriver() | ||
466 | { | ||
467 | switch(CreationParams.DriverType) | ||
468 | { | ||
469 | case video::EDT_DIRECT3D8: | ||
470 | #ifdef _IRR_COMPILE_WITH_DIRECT3D_8_ | ||
471 | VideoDriver = video::createDirectX8Driver(CreationParams, FileSystem, HWnd); | ||
472 | if (!VideoDriver) | ||
473 | { | ||
474 | os::Printer::log("Could not create DIRECT3D8 Driver.", ELL_ERROR); | ||
475 | } | ||
476 | #else | ||
477 | os::Printer::log("DIRECT3D8 Driver was not compiled into this dll. Try another one.", ELL_ERROR); | ||
478 | #endif // _IRR_COMPILE_WITH_DIRECT3D_8_ | ||
479 | |||
480 | break; | ||
481 | |||
482 | case video::EDT_DIRECT3D9: | ||
483 | #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_ | ||
484 | VideoDriver = video::createDirectX9Driver(CreationParams, FileSystem, HWnd); | ||
485 | if (!VideoDriver) | ||
486 | { | ||
487 | os::Printer::log("Could not create DIRECT3D9 Driver.", ELL_ERROR); | ||
488 | } | ||
489 | #else | ||
490 | os::Printer::log("DIRECT3D9 Driver was not compiled into this dll. Try another one.", ELL_ERROR); | ||
491 | #endif // _IRR_COMPILE_WITH_DIRECT3D_9_ | ||
492 | |||
493 | break; | ||
494 | |||
495 | case video::EDT_OPENGL: | ||
496 | |||
497 | #ifdef _IRR_COMPILE_WITH_OPENGL_ | ||
498 | if (CreationParams.Fullscreen) | ||
499 | switchToFullScreen(); | ||
500 | VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem); | ||
501 | if (!VideoDriver) | ||
502 | { | ||
503 | os::Printer::log("Could not create OpenGL driver.", ELL_ERROR); | ||
504 | } | ||
505 | #else | ||
506 | os::Printer::log("OpenGL driver was not compiled in.", ELL_ERROR); | ||
507 | #endif | ||
508 | break; | ||
509 | |||
510 | case video::EDT_SOFTWARE: | ||
511 | |||
512 | #ifdef _IRR_COMPILE_WITH_SOFTWARE_ | ||
513 | if (CreationParams.Fullscreen) | ||
514 | switchToFullScreen(); | ||
515 | VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this); | ||
516 | #else | ||
517 | os::Printer::log("Software driver was not compiled in.", ELL_ERROR); | ||
518 | #endif | ||
519 | |||
520 | break; | ||
521 | |||
522 | case video::EDT_BURNINGSVIDEO: | ||
523 | #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ | ||
524 | if (CreationParams.Fullscreen) | ||
525 | switchToFullScreen(); | ||
526 | VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this); | ||
527 | #else | ||
528 | os::Printer::log("Burning's Video driver was not compiled in.", ELL_ERROR); | ||
529 | #endif | ||
530 | break; | ||
531 | |||
532 | case video::EDT_NULL: | ||
533 | // create null driver | ||
534 | VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); | ||
535 | break; | ||
536 | |||
537 | default: | ||
538 | os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); | ||
539 | break; | ||
540 | } | ||
541 | } | ||
542 | |||
543 | |||
544 | //! runs the device. Returns false if device wants to be deleted | ||
545 | bool CIrrDeviceWinCE::run() | ||
546 | { | ||
547 | os::Timer::tick(); | ||
548 | |||
549 | MSG msg; | ||
550 | |||
551 | while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) | ||
552 | { | ||
553 | TranslateMessage(&msg); | ||
554 | |||
555 | if (ExternalWindow && msg.hwnd == HWnd) | ||
556 | WndProc(HWnd, msg.message, msg.wParam, msg.lParam); | ||
557 | else | ||
558 | DispatchMessage(&msg); | ||
559 | |||
560 | if (msg.message == WM_QUIT) | ||
561 | Close = true; | ||
562 | } | ||
563 | |||
564 | if (!Close) | ||
565 | resizeIfNecessary(); | ||
566 | |||
567 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
568 | return !Close; | ||
569 | } | ||
570 | |||
571 | |||
572 | //! Pause the current process for the minimum time allowed only to allow other processes to execute | ||
573 | void CIrrDeviceWinCE::yield() | ||
574 | { | ||
575 | Sleep(1); | ||
576 | } | ||
577 | |||
578 | |||
579 | //! Pause execution and let other processes to run for a specified amount of time. | ||
580 | void CIrrDeviceWinCE::sleep(u32 timeMs, bool pauseTimer) | ||
581 | { | ||
582 | const bool wasStopped = Timer ? Timer->isStopped() : true; | ||
583 | if (pauseTimer && !wasStopped) | ||
584 | Timer->stop(); | ||
585 | |||
586 | Sleep(timeMs); | ||
587 | |||
588 | if (pauseTimer && !wasStopped) | ||
589 | Timer->start(); | ||
590 | } | ||
591 | |||
592 | |||
593 | void CIrrDeviceWinCE::resizeIfNecessary() | ||
594 | { | ||
595 | if (!Resized) | ||
596 | return; | ||
597 | |||
598 | RECT r; | ||
599 | GetClientRect(HWnd, &r); | ||
600 | |||
601 | char tmp[255]; | ||
602 | |||
603 | if (r.right < 2 || r.bottom < 2) | ||
604 | { | ||
605 | sprintf(tmp, "Ignoring resize operation to (%ld %ld)", r.right, r.bottom); | ||
606 | os::Printer::log(tmp); | ||
607 | } | ||
608 | else | ||
609 | { | ||
610 | sprintf(tmp, "Resizing window (%ld %ld)", r.right, r.bottom); | ||
611 | os::Printer::log(tmp); | ||
612 | |||
613 | getVideoDriver()->OnResize(irr::core::dimension2d<irr::u32>(r.right, r.bottom)); | ||
614 | getWin32CursorControl()->OnResize(getVideoDriver()->getScreenSize()); | ||
615 | } | ||
616 | |||
617 | Resized = false; | ||
618 | } | ||
619 | |||
620 | |||
621 | //! sets the caption of the window | ||
622 | void CIrrDeviceWinCE::setWindowCaption(const wchar_t* text) | ||
623 | { | ||
624 | SetWindowTextW(HWnd, text); | ||
625 | } | ||
626 | |||
627 | |||
628 | #if !defined(BITMAPV4HEADER) | ||
629 | typedef struct { | ||
630 | DWORD bV4Size; | ||
631 | LONG bV4Width; | ||
632 | LONG bV4Height; | ||
633 | WORD bV4Planes; | ||
634 | WORD bV4BitCount; | ||
635 | DWORD bV4V4Compression; | ||
636 | DWORD bV4SizeImage; | ||
637 | LONG bV4XPelsPerMeter; | ||
638 | LONG bV4YPelsPerMeter; | ||
639 | DWORD bV4ClrUsed; | ||
640 | DWORD bV4ClrImportant; | ||
641 | DWORD bV4RedMask; | ||
642 | DWORD bV4GreenMask; | ||
643 | DWORD bV4BlueMask; | ||
644 | DWORD bV4AlphaMask; | ||
645 | DWORD bV4CSType; | ||
646 | DWORD un[9]; | ||
647 | } BITMAPV4HEADER, *PBITMAPV4HEADER; | ||
648 | #endif | ||
649 | |||
650 | |||
651 | //! presents a surface in the client area | ||
652 | bool CIrrDeviceWinCE::present(video::IImage* image, void* windowId, core::rect<s32>* src) | ||
653 | { | ||
654 | HWND hwnd = HWnd; | ||
655 | if ( windowId ) | ||
656 | hwnd = (HWND)windowId; | ||
657 | |||
658 | HDC dc = GetDC(hwnd); | ||
659 | |||
660 | if ( dc ) | ||
661 | { | ||
662 | RECT rect; | ||
663 | GetClientRect(hwnd, &rect); | ||
664 | const void* memory = (const void *)image->lock(); | ||
665 | |||
666 | BITMAPV4HEADER bi; | ||
667 | memset (&bi, 0, sizeof(bi)); | ||
668 | bi.bV4Size = sizeof(BITMAPINFOHEADER); | ||
669 | bi.bV4BitCount = image->getBitsPerPixel(); | ||
670 | bi.bV4Planes = 1; | ||
671 | bi.bV4Width = image->getDimension().Width; | ||
672 | bi.bV4Height = 0 - image->getDimension().Height; | ||
673 | bi.bV4V4Compression = BI_BITFIELDS; | ||
674 | bi.bV4AlphaMask = image->getAlphaMask (); | ||
675 | bi.bV4RedMask = image->getRedMask (); | ||
676 | bi.bV4GreenMask = image->getGreenMask(); | ||
677 | bi.bV4BlueMask = image->getBlueMask(); | ||
678 | |||
679 | int r = 0; | ||
680 | if ( src ) | ||
681 | { | ||
682 | r = StretchDIBits(dc, 0,0, rect.right, rect.bottom, | ||
683 | src->UpperLeftCorner.X, src->UpperLeftCorner.Y, | ||
684 | src->getWidth(), src->getHeight(), | ||
685 | memory, (const BITMAPINFO*)(&bi), DIB_RGB_COLORS, SRCCOPY); | ||
686 | } | ||
687 | else | ||
688 | { | ||
689 | r = StretchDIBits(dc, 0,0, rect.right, rect.bottom, | ||
690 | 0, 0, image->getDimension().Width, image->getDimension().Height, | ||
691 | memory, (const BITMAPINFO*)(&bi), DIB_RGB_COLORS, SRCCOPY); | ||
692 | } | ||
693 | |||
694 | image->unlock(); | ||
695 | |||
696 | ReleaseDC(hwnd, dc); | ||
697 | } | ||
698 | return true; | ||
699 | } | ||
700 | |||
701 | |||
702 | //! notifies the device that it should close itself | ||
703 | void CIrrDeviceWinCE::closeDevice() | ||
704 | { | ||
705 | MSG msg; | ||
706 | PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE); | ||
707 | PostQuitMessage(0); | ||
708 | PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE); | ||
709 | if (!ExternalWindow) | ||
710 | { | ||
711 | DestroyWindow(HWnd); | ||
712 | const fschar_t* ClassName = __TEXT("CIrrDeviceWin32"); | ||
713 | HINSTANCE hInstance = GetModuleHandle(0); | ||
714 | UnregisterClass(ClassName, hInstance); | ||
715 | } | ||
716 | Close=true; | ||
717 | } | ||
718 | |||
719 | |||
720 | //! returns if window is active. if not, nothing need to be drawn | ||
721 | bool CIrrDeviceWinCE::isWindowActive() const | ||
722 | { | ||
723 | bool ret = (GetActiveWindow() == HWnd); | ||
724 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
725 | return ret; | ||
726 | } | ||
727 | |||
728 | |||
729 | //! returns if window has focus | ||
730 | bool CIrrDeviceWinCE::isWindowFocused() const | ||
731 | { | ||
732 | bool ret = (GetFocus() == HWnd); | ||
733 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
734 | return ret; | ||
735 | } | ||
736 | |||
737 | |||
738 | //! returns if window is minimized | ||
739 | bool CIrrDeviceWinCE::isWindowMinimized() const | ||
740 | { | ||
741 | #if 0 | ||
742 | WINDOWPLACEMENT plc; | ||
743 | plc.length=sizeof(WINDOWPLACEMENT); | ||
744 | bool ret=false; | ||
745 | if (GetWindowPlacement(HWnd,&plc)) | ||
746 | ret=(plc.showCmd & SW_SHOWMINIMIZED); | ||
747 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
748 | return ret; | ||
749 | #endif | ||
750 | return false; | ||
751 | } | ||
752 | |||
753 | |||
754 | //! switches to fullscreen | ||
755 | bool CIrrDeviceWinCE::switchToFullScreen() | ||
756 | { | ||
757 | ChangedToFullScreen = SHFullScreen(HWnd, SHFS_HIDESIPBUTTON | SHFS_HIDETASKBAR) != 0; | ||
758 | return ChangedToFullScreen; | ||
759 | } | ||
760 | |||
761 | |||
762 | //! returns the win32 cursor control | ||
763 | CIrrDeviceWinCE::CCursorControl* CIrrDeviceWinCE::getWin32CursorControl() | ||
764 | { | ||
765 | return Win32CursorControl; | ||
766 | } | ||
767 | |||
768 | |||
769 | //! Return pointer to a list with all video modes supported by the gfx adapter. | ||
770 | /** \return Pointer to video modes list */ | ||
771 | video::IVideoModeList* CIrrDeviceWinCE::getVideoModeList() | ||
772 | { | ||
773 | if (!VideoModeList->getVideoModeCount()) | ||
774 | { | ||
775 | // enumerate video modes. | ||
776 | DWORD i=0; | ||
777 | DEVMODE mode; | ||
778 | memset(&mode, 0, sizeof(mode)); | ||
779 | mode.dmSize = sizeof(mode); | ||
780 | |||
781 | while (EnumDisplaySettings(NULL, i, &mode)) | ||
782 | { | ||
783 | VideoModeList->addMode(core::dimension2d<u32>(mode.dmPelsWidth, mode.dmPelsHeight), | ||
784 | mode.dmBitsPerPel); | ||
785 | |||
786 | ++i; | ||
787 | } | ||
788 | |||
789 | if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &mode)) | ||
790 | VideoModeList->setDesktop(mode.dmBitsPerPel, core::dimension2d<u32>(mode.dmPelsWidth, mode.dmPelsHeight)); | ||
791 | } | ||
792 | |||
793 | return VideoModeList; | ||
794 | } | ||
795 | |||
796 | |||
797 | void CIrrDeviceWinCE::getWindowsVersion(core::stringc& out) | ||
798 | { | ||
799 | out = "WinCE"; | ||
800 | } | ||
801 | |||
802 | |||
803 | //! Notifies the device, that it has been resized | ||
804 | void CIrrDeviceWinCE::OnResized() | ||
805 | { | ||
806 | Resized = true; | ||
807 | } | ||
808 | |||
809 | |||
810 | //! Sets if the window should be resizable in windowed mode. | ||
811 | void CIrrDeviceWinCE::setResizable(bool resize) | ||
812 | { | ||
813 | if (ExternalWindow || !getVideoDriver() || CreationParams.Fullscreen) | ||
814 | return; | ||
815 | |||
816 | LONG style = WS_POPUP; | ||
817 | |||
818 | if (!resize) | ||
819 | style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; | ||
820 | else | ||
821 | style = WS_THICKFRAME | WS_SYSMENU | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX; | ||
822 | |||
823 | if (!SetWindowLong(HWnd, GWL_STYLE, style)) | ||
824 | os::Printer::log("Could not change window style."); | ||
825 | |||
826 | RECT clientSize; | ||
827 | clientSize.top = 0; | ||
828 | clientSize.left = 0; | ||
829 | clientSize.right = getVideoDriver()->getScreenSize().Width; | ||
830 | clientSize.bottom = getVideoDriver()->getScreenSize().Height; | ||
831 | |||
832 | AdjustWindowRectEx(&clientSize, style, FALSE, 0); | ||
833 | |||
834 | const s32 realWidth = clientSize.right - clientSize.left; | ||
835 | const s32 realHeight = clientSize.bottom - clientSize.top; | ||
836 | |||
837 | const s32 windowLeft = (GetSystemMetrics(SM_CXSCREEN) - realWidth) / 2; | ||
838 | const s32 windowTop = (GetSystemMetrics(SM_CYSCREEN) - realHeight) / 2; | ||
839 | |||
840 | SetWindowPos(HWnd, HWND_TOP, windowLeft, windowTop, realWidth, realHeight, | ||
841 | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_SHOWWINDOW); | ||
842 | } | ||
843 | |||
844 | |||
845 | //! Minimizes the window. | ||
846 | void CIrrDeviceWinCE::minimizeWindow() | ||
847 | { | ||
848 | // do nothing | ||
849 | } | ||
850 | |||
851 | //! Maximize window | ||
852 | void CIrrDeviceWinCE::maximizeWindow() | ||
853 | { | ||
854 | // do nothing | ||
855 | } | ||
856 | |||
857 | |||
858 | //! Restore original window size | ||
859 | void CIrrDeviceWinCE::restoreWindow() | ||
860 | { | ||
861 | // do nothing | ||
862 | } | ||
863 | |||
864 | |||
865 | } // end namespace | ||
866 | |||
867 | #endif // _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ | ||
868 | |||