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
12 #include "IrrCompileConfig.h"
\r
14 #include "CLogger.h"
\r
15 #include "irrString.h"
\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 #ifdef _IRR_COMPILE_WITH_GUI_
\r
92 // create gui environment
\r
93 GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator);
\r
96 // create Scene manager
\r
97 SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl, GUIEnvironment);
\r
99 setEventReceiver(UserReceiver);
\r
103 //! returns the video driver
\r
104 video::IVideoDriver* CIrrDeviceStub::getVideoDriver()
\r
106 return VideoDriver;
\r
110 //! return file system
\r
111 io::IFileSystem* CIrrDeviceStub::getFileSystem()
\r
118 //! returns the gui environment
\r
119 gui::IGUIEnvironment* CIrrDeviceStub::getGUIEnvironment()
\r
121 return GUIEnvironment;
\r
126 //! returns the scene manager
\r
127 scene::ISceneManager* CIrrDeviceStub::getSceneManager()
\r
129 return SceneManager;
\r
133 //! \return Returns a pointer to the ITimer object. With it the
\r
134 //! current Time can be received.
\r
135 ITimer* CIrrDeviceStub::getTimer()
\r
141 //! Returns the version of the engine.
\r
142 const char* CIrrDeviceStub::getVersion() const
\r
144 return IRRLICHT_SDK_VERSION;
\r
147 //! \return Returns a pointer to the mouse cursor control interface.
\r
148 gui::ICursorControl* CIrrDeviceStub::getCursorControl()
\r
150 return CursorControl;
\r
154 //! return the context manager
\r
155 video::IContextManager* CIrrDeviceStub::getContextManager()
\r
157 return ContextManager;
\r
160 //! checks version of sdk and prints warning if there might be a problem
\r
161 bool CIrrDeviceStub::checkVersion(const char* version)
\r
163 if (strcmp(getVersion(), version))
\r
166 w = "Warning: The library version of the Irrlicht Engine (";
\r
168 w += ") does not match the version the application was compiled with (";
\r
170 w += "). This may cause problems.";
\r
171 os::Printer::log(w.c_str(), ELL_WARNING);
\r
180 //! Compares to the last call of this function to return double and triple clicks.
\r
181 u32 CIrrDeviceStub::checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent )
\r
183 const s32 MAX_MOUSEMOVE = 3;
\r
185 irr::u32 clickTime = getTimer()->getRealTime();
\r
187 if ( (clickTime-MouseMultiClicks.LastClickTime) < MouseMultiClicks.DoubleClickTime
\r
188 && core::abs_(MouseMultiClicks.LastClick.X - mouseX ) <= MAX_MOUSEMOVE
\r
189 && core::abs_(MouseMultiClicks.LastClick.Y - mouseY ) <= MAX_MOUSEMOVE
\r
190 && MouseMultiClicks.CountSuccessiveClicks < 3
\r
191 && MouseMultiClicks.LastMouseInputEvent == inputEvent
\r
194 ++MouseMultiClicks.CountSuccessiveClicks;
\r
198 MouseMultiClicks.CountSuccessiveClicks = 1;
\r
201 MouseMultiClicks.LastMouseInputEvent = inputEvent;
\r
202 MouseMultiClicks.LastClickTime = clickTime;
\r
203 MouseMultiClicks.LastClick.X = mouseX;
\r
204 MouseMultiClicks.LastClick.Y = mouseY;
\r
206 return MouseMultiClicks.CountSuccessiveClicks;
\r
210 //! send the event to the right receiver
\r
211 bool CIrrDeviceStub::postEventFromUser(const SEvent& event)
\r
213 bool absorbed = false;
\r
216 absorbed = UserReceiver->OnEvent(event);
\r
218 if (!absorbed && GUIEnvironment)
\r
219 absorbed = GUIEnvironment->postEventFromUser(event);
\r
221 scene::ISceneManager* inputReceiver = InputReceivingSceneManager;
\r
222 if (!inputReceiver)
\r
223 inputReceiver = SceneManager;
\r
225 if (!absorbed && inputReceiver)
\r
226 absorbed = inputReceiver->postEventFromUser(event);
\r
232 //! Sets a new event receiver to receive events
\r
233 void CIrrDeviceStub::setEventReceiver(IEventReceiver* receiver)
\r
235 UserReceiver = receiver;
\r
236 Logger->setReceiver(receiver);
\r
237 if (GUIEnvironment)
\r
238 GUIEnvironment->setUserEventReceiver(receiver);
\r
242 //! Returns poinhter to the current event receiver. Returns 0 if there is none.
\r
243 IEventReceiver* CIrrDeviceStub::getEventReceiver()
\r
245 return UserReceiver;
\r
249 //! \return Returns a pointer to the logger.
\r
250 ILogger* CIrrDeviceStub::getLogger()
\r
256 //! Returns the operation system opertator object.
\r
257 IOSOperator* CIrrDeviceStub::getOSOperator()
\r
263 //! Sets the input receiving scene manager.
\r
264 void CIrrDeviceStub::setInputReceivingSceneManager(scene::ISceneManager* sceneManager)
\r
267 sceneManager->grab();
\r
268 if (InputReceivingSceneManager)
\r
269 InputReceivingSceneManager->drop();
\r
271 InputReceivingSceneManager = sceneManager;
\r
275 //! Checks if the window is running in fullscreen mode
\r
276 bool CIrrDeviceStub::isFullscreen() const
\r
278 return CreationParams.Fullscreen;
\r
282 //! returns color format
\r
283 video::ECOLOR_FORMAT CIrrDeviceStub::getColorFormat() const
\r
285 return video::ECF_R5G6B5;
\r
288 //! No-op in this implementation
\r
289 bool CIrrDeviceStub::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
\r
294 //! No-op in this implementation
\r
295 bool CIrrDeviceStub::activateAccelerometer(float updateInterval)
\r
300 //! No-op in this implementation
\r
301 bool CIrrDeviceStub::deactivateAccelerometer()
\r
306 //! No-op in this implementation
\r
307 bool CIrrDeviceStub::isAccelerometerActive()
\r
312 //! No-op in this implementation
\r
313 bool CIrrDeviceStub::isAccelerometerAvailable()
\r
318 //! No-op in this implementation
\r
319 bool CIrrDeviceStub::activateGyroscope(float updateInterval)
\r
324 //! No-op in this implementation
\r
325 bool CIrrDeviceStub::deactivateGyroscope()
\r
330 //! No-op in this implementation
\r
331 bool CIrrDeviceStub::isGyroscopeActive()
\r
336 //! No-op in this implementation
\r
337 bool CIrrDeviceStub::isGyroscopeAvailable()
\r
342 //! No-op in this implementation
\r
343 bool CIrrDeviceStub::activateDeviceMotion(float updateInterval)
\r
348 //! No-op in this implementation
\r
349 bool CIrrDeviceStub::deactivateDeviceMotion()
\r
354 //! No-op in this implementation
\r
355 bool CIrrDeviceStub::isDeviceMotionActive()
\r
360 //! No-op in this implementation
\r
361 bool CIrrDeviceStub::isDeviceMotionAvailable()
\r
368 void CIrrDeviceStub::calculateGammaRamp ( u16 *ramp, f32 gamma, f32 relativebrightness, f32 relativecontrast )
\r
372 s32 rbright = (s32) ( relativebrightness * (65535.f / 4 ) );
\r
373 f32 rcontrast = 1.f / (255.f - ( relativecontrast * 127.5f ) );
\r
375 gamma = gamma > 0.f ? 1.0f / gamma : 0.f;
\r
377 for ( i = 0; i < 256; ++i )
\r
379 value = (s32)(pow( rcontrast * i, gamma)*65535.f + 0.5f );
\r
380 ramp[i] = (u16) core::s32_clamp ( value + rbright, 0, 65535 );
\r
385 void CIrrDeviceStub::calculateGammaFromRamp ( f32 &gamma, const u16 *ramp )
\r
387 /* The following is adapted from a post by Garrett Bass on OpenGL
\r
388 Gamedev list, March 4, 2000.
\r
394 for ( i = 1; i < 256; ++i ) {
\r
395 if ( (ramp[i] != 0) && (ramp[i] != 65535) ) {
\r
396 f32 B = (f32)i / 256.f;
\r
397 f32 A = ramp[i] / 65535.f;
\r
398 sum += (f32) ( logf(A) / logf(B) );
\r
402 if ( count && sum ) {
\r
403 gamma = 1.0f / (sum / count);
\r
408 //! Set the current Gamma Value for the Display
\r
409 bool CIrrDeviceStub::setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast )
\r
414 //! Get the current Gamma Value for the Display
\r
415 bool CIrrDeviceStub::getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast )
\r
420 //! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.
\r
421 void CIrrDeviceStub::setDoubleClickTime( u32 timeMs )
\r
423 MouseMultiClicks.DoubleClickTime = timeMs;
\r
426 //! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse.
\r
427 u32 CIrrDeviceStub::getDoubleClickTime() const
\r
429 return MouseMultiClicks.DoubleClickTime;
\r
432 //! Remove all messages pending in the system message loop
\r
433 void CIrrDeviceStub::clearSystemMessages()
\r
437 //! Checks whether the input device should take input from the IME
\r
438 bool CIrrDeviceStub::acceptsIME()
\r
440 if (!GUIEnvironment)
\r
442 gui::IGUIElement *elem = GUIEnvironment->getFocus();
\r
443 return elem && elem->acceptsIME();
\r
447 } // end namespace irr
\r