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