diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceSDL.h | 470 |
1 files changed, 235 insertions, 235 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceSDL.h b/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceSDL.h index c151f1d..f614a87 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceSDL.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceSDL.h | |||
@@ -1,235 +1,235 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | // This device code is based on the original SDL device implementation | 4 | // This device code is based on the original SDL device implementation |
5 | // contributed by Shane Parker (sirshane). | 5 | // contributed by Shane Parker (sirshane). |
6 | 6 | ||
7 | #ifndef __C_IRR_DEVICE_SDL_H_INCLUDED__ | 7 | #ifndef __C_IRR_DEVICE_SDL_H_INCLUDED__ |
8 | #define __C_IRR_DEVICE_SDL_H_INCLUDED__ | 8 | #define __C_IRR_DEVICE_SDL_H_INCLUDED__ |
9 | 9 | ||
10 | #include "IrrCompileConfig.h" | 10 | #include "IrrCompileConfig.h" |
11 | 11 | ||
12 | #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ | 12 | #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ |
13 | 13 | ||
14 | #include "IrrlichtDevice.h" | 14 | #include "IrrlichtDevice.h" |
15 | #include "CIrrDeviceStub.h" | 15 | #include "CIrrDeviceStub.h" |
16 | #include "IImagePresenter.h" | 16 | #include "IImagePresenter.h" |
17 | #include "ICursorControl.h" | 17 | #include "ICursorControl.h" |
18 | 18 | ||
19 | #include <SDL/SDL.h> | 19 | #include <SDL/SDL.h> |
20 | #include <SDL/SDL_syswm.h> | 20 | #include <SDL/SDL_syswm.h> |
21 | 21 | ||
22 | namespace irr | 22 | namespace irr |
23 | { | 23 | { |
24 | 24 | ||
25 | class CIrrDeviceSDL : public CIrrDeviceStub, video::IImagePresenter | 25 | class CIrrDeviceSDL : public CIrrDeviceStub, video::IImagePresenter |
26 | { | 26 | { |
27 | public: | 27 | public: |
28 | 28 | ||
29 | //! constructor | 29 | //! constructor |
30 | CIrrDeviceSDL(const SIrrlichtCreationParameters& param); | 30 | CIrrDeviceSDL(const SIrrlichtCreationParameters& param); |
31 | 31 | ||
32 | //! destructor | 32 | //! destructor |
33 | virtual ~CIrrDeviceSDL(); | 33 | virtual ~CIrrDeviceSDL(); |
34 | 34 | ||
35 | //! runs the device. Returns false if device wants to be deleted | 35 | //! runs the device. Returns false if device wants to be deleted |
36 | virtual bool run(); | 36 | virtual bool run(); |
37 | 37 | ||
38 | //! pause execution temporarily | 38 | //! pause execution temporarily |
39 | virtual void yield(); | 39 | virtual void yield(); |
40 | 40 | ||
41 | //! pause execution for a specified time | 41 | //! pause execution for a specified time |
42 | virtual void sleep(u32 timeMs, bool pauseTimer); | 42 | virtual void sleep(u32 timeMs, bool pauseTimer); |
43 | 43 | ||
44 | //! sets the caption of the window | 44 | //! sets the caption of the window |
45 | virtual void setWindowCaption(const wchar_t* text); | 45 | virtual void setWindowCaption(const wchar_t* text); |
46 | 46 | ||
47 | //! returns if window is active. if not, nothing need to be drawn | 47 | //! returns if window is active. if not, nothing need to be drawn |
48 | virtual bool isWindowActive() const; | 48 | virtual bool isWindowActive() const; |
49 | 49 | ||
50 | //! returns if window has focus. | 50 | //! returns if window has focus. |
51 | bool isWindowFocused() const; | 51 | bool isWindowFocused() const; |
52 | 52 | ||
53 | //! returns if window is minimized. | 53 | //! returns if window is minimized. |
54 | bool isWindowMinimized() const; | 54 | bool isWindowMinimized() const; |
55 | 55 | ||
56 | //! returns color format of the window. | 56 | //! returns color format of the window. |
57 | video::ECOLOR_FORMAT getColorFormat() const; | 57 | video::ECOLOR_FORMAT getColorFormat() const; |
58 | 58 | ||
59 | //! presents a surface in the client area | 59 | //! presents a surface in the client area |
60 | virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0); | 60 | virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0); |
61 | 61 | ||
62 | //! notifies the device that it should close itself | 62 | //! notifies the device that it should close itself |
63 | virtual void closeDevice(); | 63 | virtual void closeDevice(); |
64 | 64 | ||
65 | //! \return Returns a pointer to a list with all video modes supported | 65 | //! \return Returns a pointer to a list with all video modes supported |
66 | video::IVideoModeList* getVideoModeList(); | 66 | video::IVideoModeList* getVideoModeList(); |
67 | 67 | ||
68 | //! Sets if the window should be resizable in windowed mode. | 68 | //! Sets if the window should be resizable in windowed mode. |
69 | virtual void setResizable(bool resize=false); | 69 | virtual void setResizable(bool resize=false); |
70 | 70 | ||
71 | //! Minimizes the window. | 71 | //! Minimizes the window. |
72 | virtual void minimizeWindow(); | 72 | virtual void minimizeWindow(); |
73 | 73 | ||
74 | //! Maximizes the window. | 74 | //! Maximizes the window. |
75 | virtual void maximizeWindow(); | 75 | virtual void maximizeWindow(); |
76 | 76 | ||
77 | //! Restores the window size. | 77 | //! Restores the window size. |
78 | virtual void restoreWindow(); | 78 | virtual void restoreWindow(); |
79 | 79 | ||
80 | //! Activate any joysticks, and generate events for them. | 80 | //! Activate any joysticks, and generate events for them. |
81 | virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); | 81 | virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); |
82 | 82 | ||
83 | //! Set the current Gamma Value for the Display | 83 | //! Set the current Gamma Value for the Display |
84 | virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast ); | 84 | virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast ); |
85 | 85 | ||
86 | //! Get the current Gamma Value for the Display | 86 | //! Get the current Gamma Value for the Display |
87 | virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast ); | 87 | virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast ); |
88 | 88 | ||
89 | //! Get the device type | 89 | //! Get the device type |
90 | virtual E_DEVICE_TYPE getType() const | 90 | virtual E_DEVICE_TYPE getType() const |
91 | { | 91 | { |
92 | return EIDT_SDL; | 92 | return EIDT_SDL; |
93 | } | 93 | } |
94 | 94 | ||
95 | //! Implementation of the linux cursor control | 95 | //! Implementation of the linux cursor control |
96 | class CCursorControl : public gui::ICursorControl | 96 | class CCursorControl : public gui::ICursorControl |
97 | { | 97 | { |
98 | public: | 98 | public: |
99 | 99 | ||
100 | CCursorControl(CIrrDeviceSDL* dev) | 100 | CCursorControl(CIrrDeviceSDL* dev) |
101 | : Device(dev), IsVisible(true) | 101 | : Device(dev), IsVisible(true) |
102 | { | 102 | { |
103 | } | 103 | } |
104 | 104 | ||
105 | //! Changes the visible state of the mouse cursor. | 105 | //! Changes the visible state of the mouse cursor. |
106 | virtual void setVisible(bool visible) | 106 | virtual void setVisible(bool visible) |
107 | { | 107 | { |
108 | IsVisible = visible; | 108 | IsVisible = visible; |
109 | if ( visible ) | 109 | if ( visible ) |
110 | SDL_ShowCursor( SDL_ENABLE ); | 110 | SDL_ShowCursor( SDL_ENABLE ); |
111 | else | 111 | else |
112 | SDL_ShowCursor( SDL_DISABLE ); | 112 | SDL_ShowCursor( SDL_DISABLE ); |
113 | } | 113 | } |
114 | 114 | ||
115 | //! Returns if the cursor is currently visible. | 115 | //! Returns if the cursor is currently visible. |
116 | virtual bool isVisible() const | 116 | virtual bool isVisible() const |
117 | { | 117 | { |
118 | return IsVisible; | 118 | return IsVisible; |
119 | } | 119 | } |
120 | 120 | ||
121 | //! Sets the new position of the cursor. | 121 | //! Sets the new position of the cursor. |
122 | virtual void setPosition(const core::position2d<f32> &pos) | 122 | virtual void setPosition(const core::position2d<f32> &pos) |
123 | { | 123 | { |
124 | setPosition(pos.X, pos.Y); | 124 | setPosition(pos.X, pos.Y); |
125 | } | 125 | } |
126 | 126 | ||
127 | //! Sets the new position of the cursor. | 127 | //! Sets the new position of the cursor. |
128 | virtual void setPosition(f32 x, f32 y) | 128 | virtual void setPosition(f32 x, f32 y) |
129 | { | 129 | { |
130 | setPosition((s32)(x*Device->Width), (s32)(y*Device->Height)); | 130 | setPosition((s32)(x*Device->Width), (s32)(y*Device->Height)); |
131 | } | 131 | } |
132 | 132 | ||
133 | //! Sets the new position of the cursor. | 133 | //! Sets the new position of the cursor. |
134 | virtual void setPosition(const core::position2d<s32> &pos) | 134 | virtual void setPosition(const core::position2d<s32> &pos) |
135 | { | 135 | { |
136 | setPosition(pos.X, pos.Y); | 136 | setPosition(pos.X, pos.Y); |
137 | } | 137 | } |
138 | 138 | ||
139 | //! Sets the new position of the cursor. | 139 | //! Sets the new position of the cursor. |
140 | virtual void setPosition(s32 x, s32 y) | 140 | virtual void setPosition(s32 x, s32 y) |
141 | { | 141 | { |
142 | SDL_WarpMouse( x, y ); | 142 | SDL_WarpMouse( x, y ); |
143 | } | 143 | } |
144 | 144 | ||
145 | //! Returns the current position of the mouse cursor. | 145 | //! Returns the current position of the mouse cursor. |
146 | virtual const core::position2d<s32>& getPosition() | 146 | virtual const core::position2d<s32>& getPosition() |
147 | { | 147 | { |
148 | updateCursorPos(); | 148 | updateCursorPos(); |
149 | return CursorPos; | 149 | return CursorPos; |
150 | } | 150 | } |
151 | 151 | ||
152 | //! Returns the current position of the mouse cursor. | 152 | //! Returns the current position of the mouse cursor. |
153 | virtual core::position2d<f32> getRelativePosition() | 153 | virtual core::position2d<f32> getRelativePosition() |
154 | { | 154 | { |
155 | updateCursorPos(); | 155 | updateCursorPos(); |
156 | return core::position2d<f32>(CursorPos.X / (f32)Device->Width, | 156 | return core::position2d<f32>(CursorPos.X / (f32)Device->Width, |
157 | CursorPos.Y / (f32)Device->Height); | 157 | CursorPos.Y / (f32)Device->Height); |
158 | } | 158 | } |
159 | 159 | ||
160 | virtual void setReferenceRect(core::rect<s32>* rect=0) | 160 | virtual void setReferenceRect(core::rect<s32>* rect=0) |
161 | { | 161 | { |
162 | } | 162 | } |
163 | 163 | ||
164 | private: | 164 | private: |
165 | 165 | ||
166 | void updateCursorPos() | 166 | void updateCursorPos() |
167 | { | 167 | { |
168 | CursorPos.X = Device->MouseX; | 168 | CursorPos.X = Device->MouseX; |
169 | CursorPos.Y = Device->MouseY; | 169 | CursorPos.Y = Device->MouseY; |
170 | 170 | ||
171 | if (CursorPos.X < 0) | 171 | if (CursorPos.X < 0) |
172 | CursorPos.X = 0; | 172 | CursorPos.X = 0; |
173 | if (CursorPos.X > (s32)Device->Width) | 173 | if (CursorPos.X > (s32)Device->Width) |
174 | CursorPos.X = Device->Width; | 174 | CursorPos.X = Device->Width; |
175 | if (CursorPos.Y < 0) | 175 | if (CursorPos.Y < 0) |
176 | CursorPos.Y = 0; | 176 | CursorPos.Y = 0; |
177 | if (CursorPos.Y > (s32)Device->Height) | 177 | if (CursorPos.Y > (s32)Device->Height) |
178 | CursorPos.Y = Device->Height; | 178 | CursorPos.Y = Device->Height; |
179 | } | 179 | } |
180 | 180 | ||
181 | CIrrDeviceSDL* Device; | 181 | CIrrDeviceSDL* Device; |
182 | core::position2d<s32> CursorPos; | 182 | core::position2d<s32> CursorPos; |
183 | bool IsVisible; | 183 | bool IsVisible; |
184 | }; | 184 | }; |
185 | 185 | ||
186 | private: | 186 | private: |
187 | 187 | ||
188 | //! create the driver | 188 | //! create the driver |
189 | void createDriver(); | 189 | void createDriver(); |
190 | 190 | ||
191 | bool createWindow(); | 191 | bool createWindow(); |
192 | 192 | ||
193 | void createKeyMap(); | 193 | void createKeyMap(); |
194 | 194 | ||
195 | SDL_Surface* Screen; | 195 | SDL_Surface* Screen; |
196 | int SDL_Flags; | 196 | int SDL_Flags; |
197 | #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) | 197 | #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) |
198 | core::array<SDL_Joystick*> Joysticks; | 198 | core::array<SDL_Joystick*> Joysticks; |
199 | #endif | 199 | #endif |
200 | 200 | ||
201 | s32 MouseX, MouseY; | 201 | s32 MouseX, MouseY; |
202 | u32 MouseButtonStates; | 202 | u32 MouseButtonStates; |
203 | 203 | ||
204 | u32 Width, Height; | 204 | u32 Width, Height; |
205 | 205 | ||
206 | bool Resizable; | 206 | bool Resizable; |
207 | bool WindowHasFocus; | 207 | bool WindowHasFocus; |
208 | bool WindowMinimized; | 208 | bool WindowMinimized; |
209 | 209 | ||
210 | struct SKeyMap | 210 | struct SKeyMap |
211 | { | 211 | { |
212 | SKeyMap() {} | 212 | SKeyMap() {} |
213 | SKeyMap(s32 x11, s32 win32) | 213 | SKeyMap(s32 x11, s32 win32) |
214 | : SDLKey(x11), Win32Key(win32) | 214 | : SDLKey(x11), Win32Key(win32) |
215 | { | 215 | { |
216 | } | 216 | } |
217 | 217 | ||
218 | s32 SDLKey; | 218 | s32 SDLKey; |
219 | s32 Win32Key; | 219 | s32 Win32Key; |
220 | 220 | ||
221 | bool operator<(const SKeyMap& o) const | 221 | bool operator<(const SKeyMap& o) const |
222 | { | 222 | { |
223 | return SDLKey<o.SDLKey; | 223 | return SDLKey<o.SDLKey; |
224 | } | 224 | } |
225 | }; | 225 | }; |
226 | 226 | ||
227 | core::array<SKeyMap> KeyMap; | 227 | core::array<SKeyMap> KeyMap; |
228 | SDL_SysWMinfo Info; | 228 | SDL_SysWMinfo Info; |
229 | }; | 229 | }; |
230 | 230 | ||
231 | } // end namespace irr | 231 | } // end namespace irr |
232 | 232 | ||
233 | #endif // _IRR_COMPILE_WITH_SDL_DEVICE_ | 233 | #endif // _IRR_COMPILE_WITH_SDL_DEVICE_ |
234 | #endif // __C_IRR_DEVICE_SDL_H_INCLUDED__ | 234 | #endif // __C_IRR_DEVICE_SDL_H_INCLUDED__ |
235 | 235 | ||