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
5 #include "CIrrDeviceStub.h"
\r
6 #include "ISceneManager.h"
\r
7 #include "IEventReceiver.h"
\r
8 #include "IFileSystem.h"
\r
9 #include "IGUIElement.h"
\r
10 #include "IGUIEnvironment.h"
\r
13 #include "CLogger.h"
\r
14 #include "irrString.h"
\r
15 #include "IrrCompileConfig.h" // for IRRLICHT_SDK_VERSION
\r
20 CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters& params)
\r
21 : IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
\r
22 Timer(0), CursorControl(0), UserReceiver(params.EventReceiver),
\r
23 Logger(0), Operator(0), FileSystem(0),
\r
24 InputReceivingSceneManager(0), ContextManager(0),
\r
25 CreationParams(params), Close(false)
\r
27 Timer = new CTimer(params.UsePerformanceTimer);
\r
28 if (os::Printer::Logger)
\r
30 os::Printer::Logger->grab();
\r
31 Logger = (CLogger*)os::Printer::Logger;
\r
32 Logger->setReceiver(UserReceiver);
\r
36 Logger = new CLogger(UserReceiver);
\r
37 os::Printer::Logger = Logger;
\r
39 Logger->setLogLevel(CreationParams.LoggingLevel);
\r
41 os::Printer::Logger = Logger;
\r
43 FileSystem = io::createFileSystem();
\r
45 core::stringc s = "Irrlicht Engine version ";
\r
46 s.append(getVersion());
\r
47 os::Printer::log(s.c_str(), ELL_INFORMATION);
\r
49 checkVersion(params.SDK_version_do_not_use);
\r
53 CIrrDeviceStub::~CIrrDeviceStub()
\r
56 GUIEnvironment->drop();
\r
59 SceneManager->drop();
\r
62 VideoDriver->drop();
\r
65 ContextManager->drop();
\r
70 if (InputReceivingSceneManager)
\r
71 InputReceivingSceneManager->drop();
\r
74 CursorControl->drop();
\r
85 os::Printer::Logger = 0;
\r
89 void CIrrDeviceStub::createGUIAndScene()
\r
91 // create gui environment
\r
92 GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator);
\r
94 // create Scene manager
\r
95 SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl);
\r
97 setEventReceiver(UserReceiver);
\r
101 //! returns the video driver
\r
102 video::IVideoDriver* CIrrDeviceStub::getVideoDriver()
\r
104 return VideoDriver;
\r
108 //! return file system
\r
109 io::IFileSystem* CIrrDeviceStub::getFileSystem()
\r
116 //! returns the gui environment
\r
117 gui::IGUIEnvironment* CIrrDeviceStub::getGUIEnvironment()
\r
119 return GUIEnvironment;
\r
124 //! returns the scene manager
\r
125 scene::ISceneManager* CIrrDeviceStub::getSceneManager()
\r
127 return SceneManager;
\r
131 //! \return Returns a pointer to the ITimer object. With it the
\r
132 //! current Time can be received.
\r
133 ITimer* CIrrDeviceStub::getTimer()
\r
139 //! Returns the version of the engine.
\r
140 const char* CIrrDeviceStub::getVersion() const
\r
142 return IRRLICHT_SDK_VERSION;
\r
145 //! \return Returns a pointer to the mouse cursor control interface.
\r
146 gui::ICursorControl* CIrrDeviceStub::getCursorControl()
\r
148 return CursorControl;
\r
152 //! return the context manager
\r
153 video::IContextManager* CIrrDeviceStub::getContextManager()
\r
155 return ContextManager;
\r
158 //! checks version of sdk and prints warning if there might be a problem
\r
159 bool CIrrDeviceStub::checkVersion(const char* version)
\r
161 if (strcmp(getVersion(), version))
\r
164 w = "Warning: The library version of the Irrlicht Engine (";
\r
166 w += ") does not match the version the application was compiled with (";
\r
168 w += "). This may cause problems.";
\r
169 os::Printer::log(w.c_str(), ELL_WARNING);
\r
178 //! Compares to the last call of this function to return double and triple clicks.
\r
179 u32 CIrrDeviceStub::checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent )
\r
181 const s32 MAX_MOUSEMOVE = 3;
\r
183 irr::u32 clickTime = getTimer()->getRealTime();
\r
185 if ( (clickTime-MouseMultiClicks.LastClickTime) < MouseMultiClicks.DoubleClickTime
\r
186 && core::abs_(MouseMultiClicks.LastClick.X - mouseX ) <= MAX_MOUSEMOVE
\r
187 && core::abs_(MouseMultiClicks.LastClick.Y - mouseY ) <= MAX_MOUSEMOVE
\r
188 && MouseMultiClicks.CountSuccessiveClicks < 3
\r
189 && MouseMultiClicks.LastMouseInputEvent == inputEvent
\r
192 ++MouseMultiClicks.CountSuccessiveClicks;
\r
196 MouseMultiClicks.CountSuccessiveClicks = 1;
\r
199 MouseMultiClicks.LastMouseInputEvent = inputEvent;
\r
200 MouseMultiClicks.LastClickTime = clickTime;
\r
201 MouseMultiClicks.LastClick.X = mouseX;
\r
202 MouseMultiClicks.LastClick.Y = mouseY;
\r
204 return MouseMultiClicks.CountSuccessiveClicks;
\r
208 //! send the event to the right receiver
\r
209 bool CIrrDeviceStub::postEventFromUser(const SEvent& event)
\r
211 bool absorbed = false;
\r
214 absorbed = UserReceiver->OnEvent(event);
\r
216 if (!absorbed && GUIEnvironment)
\r
217 absorbed = GUIEnvironment->postEventFromUser(event);
\r
219 scene::ISceneManager* inputReceiver = InputReceivingSceneManager;
\r
220 if (!inputReceiver)
\r
221 inputReceiver = SceneManager;
\r
223 if (!absorbed && inputReceiver)
\r
224 absorbed = inputReceiver->postEventFromUser(event);
\r
230 //! Sets a new event receiver to receive events
\r
231 void CIrrDeviceStub::setEventReceiver(IEventReceiver* receiver)
\r
233 UserReceiver = receiver;
\r
234 Logger->setReceiver(receiver);
\r
235 if (GUIEnvironment)
\r
236 GUIEnvironment->setUserEventReceiver(receiver);
\r
240 //! Returns poinhter to the current event receiver. Returns 0 if there is none.
\r
241 IEventReceiver* CIrrDeviceStub::getEventReceiver()
\r
243 return UserReceiver;
\r
247 //! \return Returns a pointer to the logger.
\r
248 ILogger* CIrrDeviceStub::getLogger()
\r
254 //! Returns the operation system opertator object.
\r
255 IOSOperator* CIrrDeviceStub::getOSOperator()
\r
261 //! Sets the input receiving scene manager.
\r
262 void CIrrDeviceStub::setInputReceivingSceneManager(scene::ISceneManager* sceneManager)
\r
265 sceneManager->grab();
\r
266 if (InputReceivingSceneManager)
\r
267 InputReceivingSceneManager->drop();
\r
269 InputReceivingSceneManager = sceneManager;
\r
273 //! Checks if the window is maximized.
\r
274 bool CIrrDeviceStub::isWindowMaximized() const
\r
280 //! Checks if the window is running in fullscreen mode
\r
281 bool CIrrDeviceStub::isFullscreen() const
\r
283 return CreationParams.Fullscreen;
\r
287 //! returns color format
\r
288 video::ECOLOR_FORMAT CIrrDeviceStub::getColorFormat() const
\r
290 return video::ECF_R5G6B5;
\r
293 //! No-op in this implementation
\r
294 bool CIrrDeviceStub::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
\r
299 //! No-op in this implementation
\r
300 bool CIrrDeviceStub::activateAccelerometer(float updateInterval)
\r
305 //! No-op in this implementation
\r
306 bool CIrrDeviceStub::deactivateAccelerometer()
\r
311 //! No-op in this implementation
\r
312 bool CIrrDeviceStub::isAccelerometerActive()
\r
317 //! No-op in this implementation
\r
318 bool CIrrDeviceStub::isAccelerometerAvailable()
\r
323 //! No-op in this implementation
\r
324 bool CIrrDeviceStub::activateGyroscope(float updateInterval)
\r
329 //! No-op in this implementation
\r
330 bool CIrrDeviceStub::deactivateGyroscope()
\r
335 //! No-op in this implementation
\r
336 bool CIrrDeviceStub::isGyroscopeActive()
\r
341 //! No-op in this implementation
\r
342 bool CIrrDeviceStub::isGyroscopeAvailable()
\r
347 //! No-op in this implementation
\r
348 bool CIrrDeviceStub::activateDeviceMotion(float updateInterval)
\r
353 //! No-op in this implementation
\r
354 bool CIrrDeviceStub::deactivateDeviceMotion()
\r
359 //! No-op in this implementation
\r
360 bool CIrrDeviceStub::isDeviceMotionActive()
\r
365 //! No-op in this implementation
\r
366 bool CIrrDeviceStub::isDeviceMotionAvailable()
\r
371 //! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.
\r
372 void CIrrDeviceStub::setDoubleClickTime( u32 timeMs )
\r
374 MouseMultiClicks.DoubleClickTime = timeMs;
\r
377 //! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse.
\r
378 u32 CIrrDeviceStub::getDoubleClickTime() const
\r
380 return MouseMultiClicks.DoubleClickTime;
\r
383 //! Remove all messages pending in the system message loop
\r
384 void CIrrDeviceStub::clearSystemMessages()
\r
388 //! Checks whether the input device should take input from the IME
\r
389 bool CIrrDeviceStub::acceptsIME()
\r
391 if (!GUIEnvironment)
\r
393 gui::IGUIElement *elem = GUIEnvironment->getFocus();
\r
394 return elem && elem->acceptsIME();
\r
398 } // end namespace irr
\r