]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CIrrDeviceFB.h
Merging r5975 through r6036 from trunk to ogl-es branch.
[irrlicht.git] / source / Irrlicht / CIrrDeviceFB.h
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
5
6 #ifndef __C_IRR_DEVICE_FB_H_INCLUDED__
7 #define __C_IRR_DEVICE_FB_H_INCLUDED__
8
9 #include "IrrCompileConfig.h"
10
11 #ifdef _IRR_COMPILE_WITH_FB_DEVICE_
12
13 #include "CIrrDeviceStub.h"
14 #include "SIrrCreationParameters.h"
15 #include "IrrlichtDevice.h"
16 #include "IImagePresenter.h"
17 #include "ICursorControl.h"
18
19 #define KeySym s32
20 #include <linux/fb.h>
21 #include <linux/kd.h>
22
23 namespace irr
24 {
25         class CIrrDeviceFB : public CIrrDeviceStub, public video::IImagePresenter
26         {
27         public:
28
29                 //! constructor
30                 CIrrDeviceFB(const SIrrlichtCreationParameters& params);
31
32                 //! destructor
33                 virtual ~CIrrDeviceFB();
34
35                 //! runs the device. Returns false if device wants to be deleted
36                 virtual bool run() _IRR_OVERRIDE_;
37
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_;
41
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_;
44
45                 //! sets the caption of the window
46                 virtual void setWindowCaption(const wchar_t* text) _IRR_OVERRIDE_;
47
48                 //! returns if window is active. if not, nothing need to be drawn
49                 virtual bool isWindowActive() const _IRR_OVERRIDE_;
50
51                 //! returns if window has focus
52                 virtual bool isWindowFocused() const _IRR_OVERRIDE_;
53
54                 //! returns if window is minimized
55                 virtual bool isWindowMinimized() const _IRR_OVERRIDE_;
56
57                 //! Minimizes window
58                 virtual void minimizeWindow() _IRR_OVERRIDE_;
59
60                 //! Maximizes window
61                 virtual void maximizeWindow() _IRR_OVERRIDE_;
62
63                 //! Restores original window size
64                 virtual void restoreWindow() _IRR_OVERRIDE_;
65
66                 //! returns current window position (not supported for this device)
67                 virtual core::position2di getWindowPosition() _IRR_OVERRIDE_
68                 {
69                         return core::position2di(-1, -1);
70                 }
71
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_;
74
75                 //! notifies the device that it should close itself
76                 virtual void closeDevice() _IRR_OVERRIDE_;
77
78                 //! Sets if the window should be resizeable in windowed mode.
79                 virtual void setResizable(bool resize=false) _IRR_OVERRIDE_;
80
81                 //! Returns the type of this device
82                 virtual E_DEVICE_TYPE getType() const _IRR_OVERRIDE_;
83
84         private:
85
86                 //! create the driver
87                 void createDriver();
88
89                 bool createWindow(const core::dimension2d<u32>& windowSize, u32 bits);
90
91                 //! Implementation of the cursor control
92                 class CCursorControl : public gui::ICursorControl
93                 {
94                 public:
95
96                         CCursorControl(CIrrDeviceFB* dev, bool null)
97                                 : Device(dev), IsVisible(true), Null(null)
98                         {
99                                 Device->grab();
100                         }
101
102                         ~CCursorControl()
103                         {
104                                 Device->drop();
105                         }
106
107                         //! Changes the visible state of the mouse cursor.
108                         virtual void setVisible(bool visible) _IRR_OVERRIDE_
109                         {
110                                 IsVisible = visible;
111                         }
112
113                         //! Returns if the cursor is currently visible.
114                         virtual bool isVisible() const _IRR_OVERRIDE_
115                         {
116                                 return IsVisible;
117                         }
118
119                         //! Sets the new position of the cursor.
120                         virtual void setPosition(const core::position2d<f32> &pos) _IRR_OVERRIDE_
121                         {
122                                 setPosition(pos.X, pos.Y);
123                         }
124
125                         //! Sets the new position of the cursor.
126                         virtual void setPosition(f32 x, f32 y) _IRR_OVERRIDE_
127                         {
128                                 setPosition((s32)(x*Device->CreationParams.WindowSize.Width), (s32)(y*Device->CreationParams.WindowSize.Height));
129                         }
130
131                         //! Sets the new position of the cursor.
132                         virtual void setPosition(const core::position2d<s32> &pos) _IRR_OVERRIDE_
133                         {
134                                 setPosition(pos.X, pos.Y);
135                         }
136
137                         //! Sets the new position of the cursor.
138                         virtual void setPosition(s32 x, s32 y) _IRR_OVERRIDE_
139                         {
140                         }
141
142                         //! Returns the current position of the mouse cursor.
143                         virtual const core::position2d<s32>& getPosition(bool updateCursor) _IRR_OVERRIDE_
144                         {
145                                 if ( updateCursor )
146                                         updateCursorPos();
147                                 return CursorPos;
148                         }
149
150                         //! Returns the current position of the mouse cursor.
151                         virtual core::position2d<f32> getRelativePosition(bool updateCursor) _IRR_OVERRIDE_
152                         {
153                                 if ( updateCursor)
154                                         updateCursorPos();
155                                 return core::position2d<f32>(CursorPos.X / (f32)Device->CreationParams.WindowSize.Width,
156                                         CursorPos.Y / (f32)Device->CreationParams.WindowSize.Height);
157                         }
158
159                         virtual void setReferenceRect(core::rect<s32>* rect=0) _IRR_OVERRIDE_
160                         {
161                         }
162
163                 private:
164
165                         void updateCursorPos()
166                         {
167                         }
168
169                         core::position2d<s32> CursorPos;
170                         CIrrDeviceFB* Device;
171                         bool IsVisible;
172                         bool Null;
173                 };
174
175                 friend class CCursorControl;
176
177                 int Framebuffer;
178                 int EventDevice;
179                 int KeyboardDevice;
180                 struct fb_fix_screeninfo fbfixscreeninfo;
181                 struct fb_var_screeninfo fbscreeninfo;
182                 struct fb_var_screeninfo oldscreeninfo;
183                 long KeyboardMode;
184                 u8* SoftwareImage;
185
186                 u32 Pitch;
187                 video::ECOLOR_FORMAT FBColorFormat;
188                 bool Close;
189
190                 struct SKeyMap
191                 {
192                         SKeyMap() {}
193                         SKeyMap(s32 x11, s32 win32)
194                                 : X11Key(x11), Win32Key(win32)
195                         {
196                         }
197
198                         KeySym X11Key;
199                         s32 Win32Key;
200
201                         bool operator<(const SKeyMap& o) const
202                         {
203                                 return X11Key<o.X11Key;
204                         }
205                 };
206
207                 core::array<SKeyMap> KeyMap;
208         };
209
210
211 } // end namespace irr
212
213 #endif // _IRR_USE_FB_DEVICE_
214 #endif // __C_IRR_DEVICE_FB_H_INCLUDED__
215