]> git.lizzy.rs Git - irrlicht.git/blob - include/IrrlichtDevice.h
07d4f9f823839a2e1a9ea3374064b21c5d350159
[irrlicht.git] / include / IrrlichtDevice.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __I_IRRLICHT_DEVICE_H_INCLUDED__\r
6 #define __I_IRRLICHT_DEVICE_H_INCLUDED__\r
7 \r
8 #include "IReferenceCounted.h"\r
9 #include "dimension2d.h"\r
10 #include "IVideoDriver.h"\r
11 #include "EDriverTypes.h"\r
12 #include "EDeviceTypes.h"\r
13 #include "IEventReceiver.h"\r
14 #include "ICursorControl.h"\r
15 #include "ITimer.h"\r
16 #include "IOSOperator.h"\r
17 \r
18 namespace irr\r
19 {\r
20         class ILogger;\r
21         class IEventReceiver;\r
22 \r
23         namespace io {\r
24                 class IFileSystem;\r
25         } // end namespace io\r
26 \r
27         namespace gui {\r
28                 class IGUIEnvironment;\r
29         } // end namespace gui\r
30 \r
31         namespace scene {\r
32                 class ISceneManager;\r
33         } // end namespace scene\r
34 \r
35         namespace video {\r
36                 class IContextManager;\r
37         } // end namespace video\r
38 \r
39         //! The Irrlicht device. You can create it with createDevice() or createDeviceEx().\r
40         /** This is the most important class of the Irrlicht Engine. You can\r
41         access everything in the engine if you have a pointer to an instance of\r
42         this class.  There should be only one instance of this class at any\r
43         time.\r
44         */\r
45         class IrrlichtDevice : public virtual IReferenceCounted\r
46         {\r
47         public:\r
48 \r
49                 //! Runs the device.\r
50                 /** Also increments the virtual timer by calling\r
51                 ITimer::tick();. You can prevent this\r
52                 by calling ITimer::stop(); before and ITimer::start() after\r
53                 calling IrrlichtDevice::run(). Returns false if device wants\r
54                 to be deleted. Use it in this way:\r
55                 \code\r
56                 while(device->run())\r
57                 {\r
58                         // draw everything here\r
59                 }\r
60                 \endcode\r
61                 If you want the device to do nothing if the window is inactive\r
62                 (recommended), use the slightly enhanced code shown at isWindowActive().\r
63 \r
64                 Note if you are running Irrlicht inside an external, custom\r
65                 created window: Calling Device->run() will cause Irrlicht to\r
66                 dispatch windows messages internally.\r
67                 If you are running Irrlicht in your own custom window, you can\r
68                 also simply use your own message loop using GetMessage,\r
69                 DispatchMessage and whatever and simply don't use this method.\r
70                 But note that Irrlicht will not be able to fetch user input\r
71                 then. See irr::SIrrlichtCreationParameters::WindowId for more\r
72                 information and example code.\r
73                 */\r
74                 virtual bool run() = 0;\r
75 \r
76                 //! Cause the device to temporarily pause execution and let other processes run.\r
77                 /** This should bring down processor usage without major\r
78                 performance loss for Irrlicht */\r
79                 virtual void yield() = 0;\r
80 \r
81                 //! Pause execution and let other processes to run for a specified amount of time.\r
82                 /** It may not wait the full given time, as sleep may be interrupted\r
83                 \param timeMs: Time to sleep for in milliseconds.\r
84                 \param pauseTimer: If true, pauses the device timer while sleeping\r
85                 */\r
86                 virtual void sleep(u32 timeMs, bool pauseTimer=false) = 0;\r
87 \r
88                 //! Provides access to the video driver for drawing 3d and 2d geometry.\r
89                 /** \return Pointer the video driver. */\r
90                 virtual video::IVideoDriver* getVideoDriver() = 0;\r
91 \r
92                 //! Provides access to the virtual file system.\r
93                 /** \return Pointer to the file system. */\r
94                 virtual io::IFileSystem* getFileSystem() = 0;\r
95 \r
96                 //! Provides access to the 2d user interface environment.\r
97                 /** \return Pointer to the gui environment. */\r
98                 virtual gui::IGUIEnvironment* getGUIEnvironment() = 0;\r
99 \r
100                 //! Provides access to the scene manager.\r
101                 /** \return Pointer to the scene manager. */\r
102                 virtual scene::ISceneManager* getSceneManager() = 0;\r
103 \r
104                 //! Provides access to the cursor control.\r
105                 /** \return Pointer to the mouse cursor control interface. */\r
106                 virtual gui::ICursorControl* getCursorControl() = 0;\r
107 \r
108                 //! Provides access to the message logger.\r
109                 /** \return Pointer to the logger. */\r
110                 virtual ILogger* getLogger() = 0;\r
111 \r
112                 //! Get context manager\r
113                 virtual video::IContextManager* getContextManager() = 0;\r
114 \r
115                 //! Provides access to the operation system operator object.\r
116                 /** The OS operator provides methods for\r
117                 getting system specific information and doing system\r
118                 specific operations, such as exchanging data with the clipboard\r
119                 or reading the operation system version.\r
120                 \return Pointer to the OS operator. */\r
121                 virtual IOSOperator* getOSOperator() = 0;\r
122 \r
123                 //! Provides access to the engine's timer.\r
124                 /** The system time can be retrieved by it as\r
125                 well as the virtual time, which also can be manipulated.\r
126                 \return Pointer to the ITimer object. */\r
127                 virtual ITimer* getTimer() = 0;\r
128 \r
129                 //! Sets the caption of the window.\r
130                 /** \param text: New text of the window caption. */\r
131                 virtual void setWindowCaption(const wchar_t* text) = 0;\r
132 \r
133                 //! Returns if the window is active.\r
134                 /** If the window is inactive,\r
135                 nothing needs to be drawn. So if you don't want to draw anything\r
136                 when the window is inactive, create your drawing loop this way:\r
137                 \code\r
138                 while(device->run())\r
139                 {\r
140                         if (device->isWindowActive())\r
141                         {\r
142                                 // draw everything here\r
143                         }\r
144                         else\r
145                                 device->yield();\r
146                 }\r
147                 \endcode\r
148                 \return True if window is active. */\r
149                 virtual bool isWindowActive() const = 0;\r
150 \r
151                 //! Checks if the Irrlicht window has the input focus\r
152                 /** \return True if window has focus. */\r
153                 virtual bool isWindowFocused() const = 0;\r
154 \r
155                 //! Checks if the Irrlicht window is minimized\r
156                 /** \return True if window is minimized. */\r
157                 virtual bool isWindowMinimized() const = 0;\r
158 \r
159                 //! Checks if the Irrlicht window is maximized\r
160                 //! Only fully works on SDL. Returns false, or the last value set via\r
161                 //! maximizeWindow() and restoreWindow(), on other backends.\r
162                 /** \return True if window is maximized. */\r
163                 virtual bool isWindowMaximized() const = 0;\r
164 \r
165                 //! Checks if the Irrlicht window is running in fullscreen mode\r
166                 /** \return True if window is fullscreen. */\r
167                 virtual bool isFullscreen() const = 0;\r
168 \r
169                 //! Get the current color format of the window\r
170                 /** \return Color format of the window. */\r
171                 virtual video::ECOLOR_FORMAT getColorFormat() const = 0;\r
172 \r
173                 //! Notifies the device that it should close itself.\r
174                 /** IrrlichtDevice::run() will always return false after closeDevice() was called. */\r
175                 virtual void closeDevice() = 0;\r
176 \r
177                 //! Get the version of the engine.\r
178                 /** The returned string\r
179                 will look like this: "1.2.3" or this: "1.2".\r
180                 \return String which contains the version. */\r
181                 virtual const c8* getVersion() const = 0;\r
182 \r
183                 //! Sets a new user event receiver which will receive events from the engine.\r
184                 /** Return true in IEventReceiver::OnEvent to prevent the event from continuing along\r
185                 the chain of event receivers. The path that an event takes through the system depends\r
186                 on its type. See irr::EEVENT_TYPE for details.\r
187                 \param receiver New receiver to be used. */\r
188                 virtual void setEventReceiver(IEventReceiver* receiver) = 0;\r
189 \r
190                 //! Provides access to the current event receiver.\r
191                 /** \return Pointer to the current event receiver. Returns 0 if there is none. */\r
192                 virtual IEventReceiver* getEventReceiver() = 0;\r
193 \r
194                 //! Sends a user created event to the engine.\r
195                 /** Is is usually not necessary to use this. However, if you\r
196                 are using an own input library for example for doing joystick\r
197                 input, you can use this to post key or mouse input events to\r
198                 the engine. Internally, this method only delegates the events\r
199                 further to the scene manager and the GUI environment. */\r
200                 virtual bool postEventFromUser(const SEvent& event) = 0;\r
201 \r
202                 //! Sets the input receiving scene manager.\r
203                 /** If set to null, the main scene manager (returned by\r
204                 GetSceneManager()) will receive the input\r
205                 \param sceneManager New scene manager to be used. */\r
206                 virtual void setInputReceivingSceneManager(scene::ISceneManager* sceneManager) = 0;\r
207 \r
208                 //! Sets if the window should be resizable in windowed mode.\r
209                 /** The default is false. This method only works in windowed\r
210                 mode.\r
211                 \param resize Flag whether the window should be resizable. */\r
212                 virtual void setResizable(bool resize=false) = 0;\r
213 \r
214                 //! Resize the render window.\r
215                 /**     This will only work in windowed mode and is not yet supported on all systems.\r
216                 It does set the drawing/clientDC size of the window, the window decorations are added to that.\r
217                 You get the current window size with IVideoDriver::getScreenSize() (might be unified in future)\r
218                 */\r
219                 virtual void setWindowSize(const irr::core::dimension2d<u32>& size) = 0;\r
220 \r
221                 //! Minimizes the window if possible.\r
222                 virtual void minimizeWindow() =0;\r
223 \r
224                 //! Maximizes the window if possible.\r
225                 virtual void maximizeWindow() =0;\r
226 \r
227                 //! Restore the window to normal size if possible.\r
228                 virtual void restoreWindow() =0;\r
229 \r
230                 //! Get the position of the frame on-screen\r
231                 virtual core::position2di getWindowPosition() = 0;\r
232 \r
233                 //! Activate any joysticks, and generate events for them.\r
234                 /** Irrlicht contains support for joysticks, but does not generate joystick events by default,\r
235                 as this would consume joystick info that 3rd party libraries might rely on. Call this method to\r
236                 activate joystick support in Irrlicht and to receive irr::SJoystickEvent events.\r
237                 \param joystickInfo On return, this will contain an array of each joystick that was found and activated.\r
238                 \return true if joysticks are supported on this device, false if joysticks are not\r
239                              supported or support is compiled out.\r
240                 */\r
241                 virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo) =0;\r
242 \r
243         //! Activate accelerometer.\r
244         virtual bool activateAccelerometer(float updateInterval = 0.016666f) = 0;\r
245 \r
246         //! Deactivate accelerometer.\r
247         virtual bool deactivateAccelerometer() = 0;\r
248 \r
249         //! Is accelerometer active.\r
250         virtual bool isAccelerometerActive() = 0;\r
251 \r
252         //! Is accelerometer available.\r
253         virtual bool isAccelerometerAvailable() = 0;\r
254 \r
255         //! Activate gyroscope.\r
256         virtual bool activateGyroscope(float updateInterval = 0.016666f) = 0;\r
257 \r
258         //! Deactivate gyroscope.\r
259         virtual bool deactivateGyroscope() = 0;\r
260 \r
261         //! Is gyroscope active.\r
262         virtual bool isGyroscopeActive() = 0;\r
263 \r
264         //! Is gyroscope available.\r
265         virtual bool isGyroscopeAvailable() = 0;\r
266 \r
267         //! Activate device motion.\r
268         virtual bool activateDeviceMotion(float updateInterval = 0.016666f) = 0;\r
269 \r
270         //! Deactivate device motion.\r
271         virtual bool deactivateDeviceMotion() = 0;\r
272 \r
273         //! Is device motion active.\r
274         virtual bool isDeviceMotionActive() = 0;\r
275 \r
276         //! Is device motion available.\r
277         virtual bool isDeviceMotionAvailable() = 0;\r
278 \r
279                 //! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.\r
280                 /** When set to 0 no double- and tripleclicks will be generated.\r
281                 \param timeMs maximal time in milliseconds for two consecutive clicks to be recognized as double click\r
282                 */\r
283                 virtual void setDoubleClickTime(u32 timeMs) =0;\r
284 \r
285                 //! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse.\r
286                 /** When return value is 0 no double- and tripleclicks will be generated.\r
287                 \return maximal time in milliseconds for two consecutive clicks to be recognized as double click\r
288                 */\r
289                 virtual u32 getDoubleClickTime() const =0;\r
290 \r
291                 //! Remove messages pending in the system message loop\r
292                 /** This function is usually used after messages have been buffered for a longer time, for example\r
293                 when loading a large scene. Clearing the message loop prevents that mouse- or buttonclicks which users\r
294                 have pressed in the meantime will now trigger unexpected actions in the gui. <br>\r
295                 So far the following messages are cleared:<br>\r
296                 Win32: All keyboard and mouse messages<br>\r
297                 Linux: All keyboard and mouse messages<br>\r
298                 All other devices are not yet supported here.<br>\r
299                 The function is still somewhat experimental, as the kind of messages we clear is based on just a few use-cases.\r
300                 If you think further messages should be cleared, or some messages should not be cleared here, then please tell us. */\r
301                 virtual void clearSystemMessages() = 0;\r
302 \r
303                 //! Get the type of the device.\r
304                 /** This allows the user to check which windowing system is currently being\r
305                 used. */\r
306                 virtual E_DEVICE_TYPE getType() const = 0;\r
307 \r
308                 //! Check if a driver type is supported by the engine.\r
309                 /** Even if true is returned the driver may not be available\r
310                 for a configuration requested when creating the device. */\r
311                 static bool isDriverSupported(video::E_DRIVER_TYPE driver)\r
312                 {\r
313                         return true;\r
314                 }\r
315         };\r
316 \r
317 } // end namespace irr\r
318 \r
319 #endif\r
320 \r