aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWin32.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWin32.h420
1 files changed, 420 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWin32.h b/libraries/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWin32.h
new file mode 100644
index 0000000..c11a3fd
--- /dev/null
+++ b/libraries/irrlicht-1.8.1/source/Irrlicht/CIrrDeviceWin32.h
@@ -0,0 +1,420 @@
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#ifndef __C_IRR_DEVICE_WIN32_H_INCLUDED__
6#define __C_IRR_DEVICE_WIN32_H_INCLUDED__
7
8#include "IrrCompileConfig.h"
9#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
10
11#include "CIrrDeviceStub.h"
12#include "IrrlichtDevice.h"
13#include "IImagePresenter.h"
14
15#define WIN32_LEAN_AND_MEAN
16#if !defined(_IRR_XBOX_PLATFORM_)
17 #include <windows.h>
18 #include <mmsystem.h> // For JOYCAPS
19 #include <windowsx.h>
20#endif
21#if !defined(GET_X_LPARAM)
22#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
23#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
24#endif
25
26namespace irr
27{
28 struct SJoystickWin32Control;
29
30 class CIrrDeviceWin32 : public CIrrDeviceStub, video::IImagePresenter
31 {
32 friend struct SJoystickWin32Control;
33 public:
34
35 //! constructor
36 CIrrDeviceWin32(const SIrrlichtCreationParameters& params);
37
38 //! destructor
39 virtual ~CIrrDeviceWin32();
40
41 //! runs the device. Returns false if device wants to be deleted
42 virtual bool run();
43
44 //! Cause the device to temporarily pause execution and let other processes to run
45 // This should bring down processor usage without major performance loss for Irrlicht
46 virtual void yield();
47
48 //! Pause execution and let other processes to run for a specified amount of time.
49 virtual void sleep(u32 timeMs, bool pauseTimer);
50
51 //! sets the caption of the window
52 virtual void setWindowCaption(const wchar_t* text);
53
54 //! returns if window is active. if not, nothing need to be drawn
55 virtual bool isWindowActive() const;
56
57 //! returns if window has focus
58 virtual bool isWindowFocused() const;
59
60 //! returns if window is minimized
61 virtual bool isWindowMinimized() const;
62
63 //! presents a surface in the client area
64 virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0);
65
66 //! notifies the device that it should close itself
67 virtual void closeDevice();
68
69 //! \return Returns a pointer to a list with all video modes
70 //! supported by the gfx adapter.
71 video::IVideoModeList* getVideoModeList();
72
73 //! Notifies the device, that it has been resized
74 void OnResized();
75
76 //! Sets if the window should be resizable in windowed mode.
77 virtual void setResizable(bool resize=false);
78
79 //! Minimizes the window.
80 virtual void minimizeWindow();
81
82 //! Maximizes the window.
83 virtual void maximizeWindow();
84
85 //! Restores the window size.
86 virtual void restoreWindow();
87
88 //! Activate any joysticks, and generate events for them.
89 virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);
90
91 //! Set the current Gamma Value for the Display
92 virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast );
93
94 //! Get the current Gamma Value for the Display
95 virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast );
96
97 //! Remove all messages pending in the system message loop
98 virtual void clearSystemMessages();
99
100 //! Get the device type
101 virtual E_DEVICE_TYPE getType() const
102 {
103 return EIDT_WIN32;
104 }
105
106 //! Compares to the last call of this function to return double and triple clicks.
107 //! \return Returns only 1,2 or 3. A 4th click will start with 1 again.
108 virtual u32 checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent )
109 {
110 // we just have to make it public
111 return CIrrDeviceStub::checkSuccessiveClicks(mouseX, mouseY, inputEvent );
112 }
113
114 //! switchs to fullscreen
115 bool switchToFullScreen(bool reset=false);
116
117 //! Check for and show last Windows API error to help internal debugging.
118 //! Does call GetLastError and on errors formats the errortext and displays it in a messagebox.
119 static void ReportLastWinApiError();
120
121 // convert an Irrlicht texture to a windows cursor
122 HCURSOR TextureToCursor(HWND hwnd, irr::video::ITexture * tex, const core::rect<s32>& sourceRect, const core::position2d<s32> &hotspot);
123
124 //! Implementation of the win32 cursor control
125 class CCursorControl : public gui::ICursorControl
126 {
127 public:
128
129 CCursorControl(CIrrDeviceWin32* device, const core::dimension2d<u32>& wsize, HWND hwnd, bool fullscreen);
130 ~CCursorControl();
131
132 //! Changes the visible state of the mouse cursor.
133 virtual void setVisible(bool visible)
134 {
135 CURSORINFO info;
136 info.cbSize = sizeof(CURSORINFO);
137 BOOL gotCursorInfo = GetCursorInfo(&info);
138 while ( gotCursorInfo )
139 {
140#ifdef CURSOR_SUPPRESSED
141 // new flag for Windows 8, where cursor
142 // might be suppressed for touch interface
143 if (info.flags == CURSOR_SUPPRESSED)
144 {
145 visible=false;
146 break;
147 }
148#endif
149 if ( (visible && info.flags == CURSOR_SHOWING) || // visible
150 (!visible && info.flags == 0 ) ) // hidden
151 {
152 break;
153 }
154 // this only increases an internal
155 // display counter in windows, so it
156 // might have to be called some more
157 const int showResult = ShowCursor(visible);
158 // if result has correct sign we can
159 // stop here as well
160 if (( !visible && showResult < 0 ) ||
161 (visible && showResult >= 0))
162 break;
163 // yes, it really must be set each time
164 info.cbSize = sizeof(CURSORINFO);
165 gotCursorInfo = GetCursorInfo(&info);
166 }
167 IsVisible = visible;
168 }
169
170 //! Returns if the cursor is currently visible.
171 virtual bool isVisible() const
172 {
173 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
174 return IsVisible;
175 }
176
177 //! Sets the new position of the cursor.
178 virtual void setPosition(const core::position2d<f32> &pos)
179 {
180 setPosition(pos.X, pos.Y);
181 }
182
183 //! Sets the new position of the cursor.
184 virtual void setPosition(f32 x, f32 y)
185 {
186 if (!UseReferenceRect)
187 setPosition(core::round32(x*WindowSize.Width), core::round32(y*WindowSize.Height));
188 else
189 setPosition(core::round32(x*ReferenceRect.getWidth()), core::round32(y*ReferenceRect.getHeight()));
190 }
191
192 //! Sets the new position of the cursor.
193 virtual void setPosition(const core::position2d<s32> &pos)
194 {
195 setPosition(pos.X, pos.Y);
196 }
197
198 //! Sets the new position of the cursor.
199 virtual void setPosition(s32 x, s32 y)
200 {
201 if (UseReferenceRect)
202 {
203 SetCursorPos(ReferenceRect.UpperLeftCorner.X + x,
204 ReferenceRect.UpperLeftCorner.Y + y);
205 }
206 else
207 {
208 RECT rect;
209 if (GetWindowRect(HWnd, &rect))
210 SetCursorPos(x + rect.left + BorderX, y + rect.top + BorderY);
211 }
212
213 CursorPos.X = x;
214 CursorPos.Y = y;
215 }
216
217 //! Returns the current position of the mouse cursor.
218 virtual const core::position2d<s32>& getPosition()
219 {
220 updateInternalCursorPosition();
221 return CursorPos;
222 }
223
224 //! Returns the current position of the mouse cursor.
225 virtual core::position2d<f32> getRelativePosition()
226 {
227 updateInternalCursorPosition();
228
229 if (!UseReferenceRect)
230 {
231 return core::position2d<f32>(CursorPos.X * InvWindowSize.Width,
232 CursorPos.Y * InvWindowSize.Height);
233 }
234
235 return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(),
236 CursorPos.Y / (f32)ReferenceRect.getHeight());
237 }
238
239 //! Sets an absolute reference rect for calculating the cursor position.
240 virtual void setReferenceRect(core::rect<s32>* rect=0)
241 {
242 if (rect)
243 {
244 ReferenceRect = *rect;
245 UseReferenceRect = true;
246
247 // prevent division through zero and uneven sizes
248
249 if (!ReferenceRect.getHeight() || ReferenceRect.getHeight()%2)
250 ReferenceRect.LowerRightCorner.Y += 1;
251
252 if (!ReferenceRect.getWidth() || ReferenceRect.getWidth()%2)
253 ReferenceRect.LowerRightCorner.X += 1;
254 }
255 else
256 UseReferenceRect = false;
257 }
258
259 /** Used to notify the cursor that the window was resized. */
260 virtual void OnResize(const core::dimension2d<u32>& size)
261 {
262 WindowSize = size;
263 if (size.Width!=0)
264 InvWindowSize.Width = 1.0f / size.Width;
265 else
266 InvWindowSize.Width = 0.f;
267
268 if (size.Height!=0)
269 InvWindowSize.Height = 1.0f / size.Height;
270 else
271 InvWindowSize.Height = 0.f;
272 }
273
274 /** Used to notify the cursor that the window resizable settings changed. */
275 void updateBorderSize(bool fullscreen, bool resizable)
276 {
277 if (!fullscreen)
278 {
279 if (resizable)
280 {
281 BorderX = GetSystemMetrics(SM_CXSIZEFRAME);
282 BorderY = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYSIZEFRAME);
283 }
284 else
285 {
286 BorderX = GetSystemMetrics(SM_CXDLGFRAME);
287 BorderY = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYDLGFRAME);
288 }
289 }
290 else
291 {
292 BorderX = BorderY = 0;
293 }
294 }
295
296
297 //! Sets the active cursor icon
298 virtual void setActiveIcon(gui::ECURSOR_ICON iconId);
299
300 //! Gets the currently active icon
301 virtual gui::ECURSOR_ICON getActiveIcon() const
302 {
303 return ActiveIcon;
304 }
305
306 //! Add a custom sprite as cursor icon.
307 virtual gui::ECURSOR_ICON addIcon(const gui::SCursorSprite& icon);
308
309 //! replace the given cursor icon.
310 virtual void changeIcon(gui::ECURSOR_ICON iconId, const gui::SCursorSprite& icon);
311
312 //! Return a system-specific size which is supported for cursors. Larger icons will fail, smaller icons might work.
313 virtual core::dimension2di getSupportedIconSize() const;
314
315 void update();
316
317 private:
318
319 //! Updates the internal cursor position
320 void updateInternalCursorPosition()
321 {
322 POINT p;
323 if (!GetCursorPos(&p))
324 {
325 DWORD xy = GetMessagePos();
326 p.x = GET_X_LPARAM(xy);
327 p.y = GET_Y_LPARAM(xy);
328 }
329
330 if (UseReferenceRect)
331 {
332 CursorPos.X = p.x - ReferenceRect.UpperLeftCorner.X;
333 CursorPos.Y = p.y - ReferenceRect.UpperLeftCorner.Y;
334 }
335 else
336 {
337 RECT rect;
338 if (GetWindowRect(HWnd, &rect))
339 {
340 CursorPos.X = p.x-rect.left-BorderX;
341 CursorPos.Y = p.y-rect.top-BorderY;
342 }
343 else
344 {
345 // window seems not to be existent, so set cursor to
346 // a negative value
347 CursorPos.X = -1;
348 CursorPos.Y = -1;
349 }
350 }
351 }
352
353 CIrrDeviceWin32* Device;
354 core::position2d<s32> CursorPos;
355 core::dimension2d<u32> WindowSize;
356 core::dimension2d<f32> InvWindowSize;
357 HWND HWnd;
358
359 s32 BorderX, BorderY;
360 core::rect<s32> ReferenceRect;
361 bool UseReferenceRect;
362 bool IsVisible;
363
364
365 struct CursorFrameW32
366 {
367 CursorFrameW32() : IconHW(0) {}
368 CursorFrameW32(HCURSOR icon) : IconHW(icon) {}
369
370 HCURSOR IconHW; // hardware cursor
371 };
372
373 struct CursorW32
374 {
375 CursorW32() {}
376 explicit CursorW32(HCURSOR iconHw, u32 frameTime=0) : FrameTime(frameTime)
377 {
378 Frames.push_back( CursorFrameW32(iconHw) );
379 }
380 core::array<CursorFrameW32> Frames;
381 u32 FrameTime;
382 };
383
384 core::array<CursorW32> Cursors;
385 gui::ECURSOR_ICON ActiveIcon;
386 u32 ActiveIconStartTime;
387
388 void initCursors();
389 };
390
391 //! returns the win32 cursor control
392 CCursorControl* getWin32CursorControl();
393
394 private:
395
396 //! create the driver
397 void createDriver();
398
399 //! Process system events
400 void handleSystemMessages();
401
402 void getWindowsVersion(core::stringc& version);
403
404 void resizeIfNecessary();
405
406 HWND HWnd;
407
408 bool ChangedToFullScreen;
409 bool Resized;
410 bool ExternalWindow;
411 CCursorControl* Win32CursorControl;
412 DEVMODE DesktopMode;
413
414 SJoystickWin32Control* JoyControl;
415 };
416
417} // end namespace irr
418
419#endif // _IRR_COMPILE_WITH_WINDOWS_DEVICE_
420#endif // __C_IRR_DEVICE_WIN32_H_INCLUDED__