Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_INPUTOUTPUT_CONTROL_H__
00009 #define __SP_INPUTOUTPUT_CONTROL_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spInputKeyCodes.hpp"
00014 #include "Base/spDimensionPoint2D.hpp"
00015 #include "Base/spDimensionVector3D.hpp"
00016 #include "Base/spInputOutputLog.hpp"
00017 #include "Base/spXBox360GamePad.hpp"
00018
00019 #include <math.h>
00020 #include <boost/shared_ptr.hpp>
00021
00022 #if defined(SP_PLATFORM_LINUX)
00023 # include <X11/X.h>
00024 # include <X11/Xlib.h>
00025 # include <X11/Xutil.h>
00026 #elif defined(SP_PLATFORM_ANDROID)
00027 # include <android/input.h>
00028 # include "Platform/Android/android_native_app_glue.h"
00029 #endif
00030
00031
00032 namespace sp
00033 {
00034
00035 class SoftPixelDevice;
00036
00037 #if defined(SP_PLATFORM_WINDOWS)
00038 class SoftPixelDeviceWin32;
00039 #elif defined(SP_PLATFORM_LINUX)
00040 class SoftPixelDeviceLinux;
00041 #elif defined(SP_PLATFORM_ANDROID)
00042 class SoftPixelDeviceAndroid;
00043 #elif defined(SP_PLATFORM_IOS)
00044 class SoftPixelDeviceIOS;
00045 #endif
00046
00047 #ifdef SP_COMPILE_WITH_OPENGL
00048 namespace video
00049 {
00050 class RenderContext;
00051 }
00052 #endif
00053
00054 namespace io
00055 {
00056
00057
00058 #if defined(SP_PLATFORM_WINDOWS) || defined(SP_PLATFORM_LINUX)
00059
00061 class SP_EXPORT InputControl
00062 {
00063
00064 public:
00065
00066 InputControl();
00067 ~InputControl();
00068
00069
00070
00072 void setCursorPosition(const dim::point2di &Position, bool UpdateCursorSpeed = true);
00073 dim::point2di getCursorPosition() const;
00074
00076 dim::point2di getCursorSpeed();
00077
00082 bool& keyDown(const EKeyCodes KeyCode);
00084 bool& keyHit(const EKeyCodes KeyCode);
00086 bool& keyReleased(const EKeyCodes KeyCode);
00087
00089 void keyDownSimulation(const EKeyCodes KeyCode) const;
00090 void keyReleasedSimulation(const EKeyCodes KeyCode) const;
00091
00096 bool& mouseDown(const EMouseKeyCodes KeyCode);
00098 bool& mouseHit(const EMouseKeyCodes KeyCode);
00100 bool& mouseReleased(const EMouseKeyCodes KeyCode);
00102 bool& mouseDoubleClicked(const EMouseKeyCodes KeyCode);
00103
00104 void mouseDownSimulation(const EMouseKeyCodes KeyCode) const;
00105 void mouseReleasedSimulation(const EMouseKeyCodes KeyCode) const;
00106
00108 s16 getMouseWheel() const;
00109
00111 void setMouseWheel(s16 Value);
00112
00117 void setCursorVisible(bool Visible);
00118
00120 bool joystickDown(const EJoystickKeyCodes KeyCode) const;
00121
00123 dim::vector3df getJoystickPosition() const;
00124
00125
00126
00128 static void clearInput();
00130 static void resetInput();
00131
00133 static void keyEventDown(u32 KeyCode);
00135 static void keyEventUp(u32 KeyCode);
00136
00137
00138
00145 inline void setWordInput(bool Enable)
00146 {
00147 WordInput_ = Enable;
00148 }
00150 inline bool getWordInput() const
00151 {
00152 return WordInput_;
00153 }
00154
00159 inline io::stringc getEnteredWord() const
00160 {
00161 return WordString_;
00162 }
00168 inline io::stringc& getEnteredWord()
00169 {
00170 return WordString_;
00171 }
00176 inline void releaseEnteredWord(io::stringc &Str)
00177 {
00178 Str = WordString_;
00179 WordString_.clear();
00180 }
00181
00182 #ifdef SP_COMPILE_WITH_XBOX360GAMEPAD
00183
00185 inline XBox360GamePadPtr getXBox360GamePad(s32 Number) const
00186 {
00187 return XBox360GamePads_[math::MinMax(Number, 0, 3)];
00188 }
00189
00190 #endif
00191
00192 private:
00193
00194 friend class sp::SoftPixelDevice;
00195 friend class video::RenderContext;
00196
00197 #if defined(SP_PLATFORM_WINDOWS)
00198 friend class sp::SoftPixelDeviceWin32;
00199 #elif defined(SP_PLATFORM_LINUX)
00200 friend class sp::SoftPixelDeviceLinux;
00201 #endif
00202
00203
00204
00209 void updatePrevCursorPosition(const dim::point2di &PositionShift);
00210 void setupInitialCursorPosition();
00211
00212 void updateBaseEvents();
00213
00214 static void recordKey(u32 KeyCode);
00215
00216
00217
00218 bool isCursorSpeedBlocked_;
00219 dim::point2di LastCursorPos_, CursorSpeed_;
00220
00221 bool WordInput_;
00222 io::stringc WordString_;
00223
00224 #ifdef SP_COMPILE_WITH_XBOX360GAMEPAD
00225 XBox360GamePadPtr XBox360GamePads_[MAX_XBOX_CONTROLLERS];
00226 #endif
00227
00228 };
00229
00230 #elif defined(SP_PLATFORM_ANDROID)
00231
00233 class SP_EXPORT InputControl
00234 {
00235
00236 public:
00237
00238 InputControl();
00239 ~InputControl();
00240
00241
00242
00243 s32 processEvent(android_app* App, AInputEvent* Event);
00244
00246 dim::point2df getPointerPosition(u32 Index = 0) const;
00247
00249 f32 getPointerSize(u32 Index = 0) const;
00250
00251 dim::point2df getMotionSpeed(u32 Index = 0);
00252
00254 bool isPointerActive(u32 Index = 0) const;
00255
00257 f32 getPinchSpeed();
00258
00264 bool& keyDown(const EKeyCodes KeyCode);
00265 bool& keyHit(const EKeyCodes KeyCode);
00266 bool& keyReleased(const EKeyCodes KeyCode);
00267
00268
00269
00270 inline u32 getPointerCount() const
00271 {
00272 return PointerCount_;
00273 }
00274
00275 inline bool isMotionEvent() const
00276 {
00277 return isMotionEvent_;
00278 }
00279
00280 inline dim::vector3df getGyroscopeSensor() const
00281 {
00282 return GyroscopeSensor_;
00283 }
00284 inline dim::vector3df getAccelerometerSensor() const
00285 {
00286 return AccelerometerSensor_;
00287 }
00288 inline f32 getLightSensor() const
00289 {
00290 return LightSensor_;
00291 }
00292
00297 inline void setDefaultKeyEventHandling(bool Enable)
00298 {
00299 isDefaultKeyEventHandling_ = Enable;
00300 }
00301 inline bool getDefaultKeyEventHandling() const
00302 {
00303 return isDefaultKeyEventHandling_;
00304 }
00305
00307 inline void setKeyEnable(const EKeyCodes KeyCode, bool Enable)
00308 {
00309 isKeyEnabled_[KeyCode] = Enable;
00310 }
00311 inline bool getKeyEnable(const EKeyCodes KeyCode) const
00312 {
00313 return isKeyEnabled_[KeyCode];
00314 }
00315
00316 private:
00317
00318 friend class sp::SoftPixelDevice;
00319 friend class sp::SoftPixelDeviceAndroid;
00320
00321
00322
00323 static const s32 POINTER_COUNT = 5;
00324
00325
00326
00327 struct STouchPointer
00328 {
00329 dim::point2df Position;
00330 f32 Size;
00331 };
00332
00333
00334
00335 void setPointer(u32 Index, const dim::point2df &Position, f32 Size);
00336 void resetInputEvents();
00337
00338
00339
00340 bool isCursorSpeedBlocked_;
00341 bool isMotionEvent_;
00342
00343 bool isDefaultKeyEventHandling_;
00344 bool isKeyEnabled_[KEY_BUTTON_MODE + 1];
00345
00346 u32 PointerCount_;
00347 STouchPointer Pointer_[POINTER_COUNT];
00348 dim::point2df MotionSpeed_[POINTER_COUNT], MotionPointerPos_[POINTER_COUNT], LastPointerPos_[POINTER_COUNT];
00349 f32 DragDistance_, LastDragDistance_;
00350
00351 dim::vector3df GyroscopeSensor_, AccelerometerSensor_;
00352 f32 LightSensor_;
00353
00354 };
00355
00356 #elif defined(SP_PLATFORM_IOS)
00357
00359 class SP_EXPORT InputControl
00360 {
00361
00362 public:
00363
00364 InputControl();
00365 ~InputControl();
00366
00367
00368
00370 dim::point2di getPointerPosition(u32 Index = 0) const;
00371
00373 dim::point2di getMotionSpeed(u32 Index = 0) const;
00374
00376 bool isPointerActive(u32 Index = 0) const;
00377
00379 f32 getPinchSpeed();
00380
00382 u32 getPointerCount() const;
00383
00384 private:
00385
00386 friend class sp::SoftPixelDevice;
00387 friend class sp::SoftPixelDeviceIOS;
00388
00389
00390
00391 static const s32 POINTER_COUNT = 5;
00392
00393
00394
00395 void resetInputEvents();
00396
00397
00398
00399 bool isCursorSpeedBlocked_;
00400
00401 f32 DragDistance_, LastDragDistance_;
00402
00403 };
00404
00405 #endif
00406
00407
00408 }
00409
00410 }
00411
00412
00413 #endif
00414
00415
00416
00417