1 // Copyright (C) 2002-2007 Nikolaus Gebhardt
2 // Copyright (C) 2007-2012 Christian Stehno
3 // This file is part of the "Irrlicht Engine".
4 // For conditions of distribution and use, see copyright notice in irrlicht.h
6 #ifndef __C_IRR_DEVICE_FB_H_INCLUDED__
7 #define __C_IRR_DEVICE_FB_H_INCLUDED__
9 #include "IrrCompileConfig.h"
11 #ifdef _IRR_COMPILE_WITH_FB_DEVICE_
13 #include "CIrrDeviceStub.h"
14 #include "SIrrCreationParameters.h"
15 #include "IrrlichtDevice.h"
16 #include "IImagePresenter.h"
17 #include "ICursorControl.h"
25 class CIrrDeviceFB : public CIrrDeviceStub, public video::IImagePresenter
30 CIrrDeviceFB(const SIrrlichtCreationParameters& params);
33 virtual ~CIrrDeviceFB();
35 //! runs the device. Returns false if device wants to be deleted
36 virtual bool run() _IRR_OVERRIDE_;
38 //! Cause the device to temporarily pause execution and let other processes to run
39 // This should bring down processor usage without major performance loss for Irrlicht
40 virtual void yield() _IRR_OVERRIDE_;
42 //! Pause execution and let other processes to run for a specified amount of time.
43 virtual void sleep(u32 timeMs, bool pauseTimer) _IRR_OVERRIDE_;
45 //! sets the caption of the window
46 virtual void setWindowCaption(const wchar_t* text) _IRR_OVERRIDE_;
48 //! returns if window is active. if not, nothing need to be drawn
49 virtual bool isWindowActive() const _IRR_OVERRIDE_;
51 //! returns if window has focus
52 virtual bool isWindowFocused() const _IRR_OVERRIDE_;
54 //! returns if window is minimized
55 virtual bool isWindowMinimized() const _IRR_OVERRIDE_;
58 virtual void minimizeWindow() _IRR_OVERRIDE_;
61 virtual void maximizeWindow() _IRR_OVERRIDE_;
63 //! Restores original window size
64 virtual void restoreWindow() _IRR_OVERRIDE_;
66 //! returns current window position (not supported for this device)
67 virtual core::position2di getWindowPosition() _IRR_OVERRIDE_
69 return core::position2di(-1, -1);
72 //! presents a surface in the client area
73 virtual bool present(video::IImage* surface, void* windowId = 0, core::rect<s32>* src=0 ) _IRR_OVERRIDE_;
75 //! notifies the device that it should close itself
76 virtual void closeDevice() _IRR_OVERRIDE_;
78 //! Sets if the window should be resizeable in windowed mode.
79 virtual void setResizable(bool resize=false) _IRR_OVERRIDE_;
81 //! Returns the type of this device
82 virtual E_DEVICE_TYPE getType() const _IRR_OVERRIDE_;
89 bool createWindow(const core::dimension2d<u32>& windowSize, u32 bits);
91 //! Implementation of the cursor control
92 class CCursorControl : public gui::ICursorControl
96 CCursorControl(CIrrDeviceFB* dev, bool null)
97 : Device(dev), IsVisible(true), Null(null)
107 //! Changes the visible state of the mouse cursor.
108 virtual void setVisible(bool visible) _IRR_OVERRIDE_
113 //! Returns if the cursor is currently visible.
114 virtual bool isVisible() const _IRR_OVERRIDE_
119 //! Sets the new position of the cursor.
120 virtual void setPosition(const core::position2d<f32> &pos) _IRR_OVERRIDE_
122 setPosition(pos.X, pos.Y);
125 //! Sets the new position of the cursor.
126 virtual void setPosition(f32 x, f32 y) _IRR_OVERRIDE_
128 setPosition((s32)(x*Device->CreationParams.WindowSize.Width), (s32)(y*Device->CreationParams.WindowSize.Height));
131 //! Sets the new position of the cursor.
132 virtual void setPosition(const core::position2d<s32> &pos) _IRR_OVERRIDE_
134 setPosition(pos.X, pos.Y);
137 //! Sets the new position of the cursor.
138 virtual void setPosition(s32 x, s32 y) _IRR_OVERRIDE_
142 //! Returns the current position of the mouse cursor.
143 virtual const core::position2d<s32>& getPosition(bool updateCursor) _IRR_OVERRIDE_
150 //! Returns the current position of the mouse cursor.
151 virtual core::position2d<f32> getRelativePosition(bool updateCursor) _IRR_OVERRIDE_
155 return core::position2d<f32>(CursorPos.X / (f32)Device->CreationParams.WindowSize.Width,
156 CursorPos.Y / (f32)Device->CreationParams.WindowSize.Height);
159 virtual void setReferenceRect(core::rect<s32>* rect=0) _IRR_OVERRIDE_
165 void updateCursorPos()
169 core::position2d<s32> CursorPos;
170 CIrrDeviceFB* Device;
175 friend class CCursorControl;
180 struct fb_fix_screeninfo fbfixscreeninfo;
181 struct fb_var_screeninfo fbscreeninfo;
182 struct fb_var_screeninfo oldscreeninfo;
187 video::ECOLOR_FORMAT FBColorFormat;
193 SKeyMap(s32 x11, s32 win32)
194 : X11Key(x11), Win32Key(win32)
201 bool operator<(const SKeyMap& o) const
203 return X11Key<o.X11Key;
207 core::array<SKeyMap> KeyMap;
211 } // end namespace irr
213 #endif // _IRR_USE_FB_DEVICE_
214 #endif // __C_IRR_DEVICE_FB_H_INCLUDED__