/src/ois/src/SDL/SDLInputManager.cpp

https://bitbucket.org/cabalistic/ogredeps/ · C++ · 114 lines · 64 code · 17 blank · 33 comment · 5 complexity · f60714088ddf48070730d7cc066207b8 MD5 · raw file

  1. /*
  2. The zlib/libpng License
  3. Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
  4. This software is provided 'as-is', without any express or implied warranty. In no event will
  5. the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose, including commercial
  7. applications, and to alter it and redistribute it freely, subject to the following
  8. restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that
  10. you wrote the original software. If you use this software in a product,
  11. an acknowledgment in the product documentation would be appreciated but is
  12. not required.
  13. 2. Altered source versions must be plainly marked as such, and must not be
  14. misrepresented as being the original software.
  15. 3. This notice may not be removed or altered from any source distribution.
  16. */
  17. #include "SDL/SDLInputManager.h"
  18. #include "SDL/SDLKeyboard.h"
  19. #include "SDL/SDLMouse.h"
  20. #include "SDL/SDLJoyStick.h"
  21. #include "OISException.h"
  22. #include "OISObject.h"
  23. using namespace OIS;
  24. const std::string SDLInputManager::iName = "SDL Input Wrapper";
  25. //--------------------------------------------------------------------------------//
  26. SDLInputManager::SDLInputManager() : mGrabbed(false)
  27. {
  28. }
  29. //--------------------------------------------------------------------------------//
  30. SDLInputManager::~SDLInputManager()
  31. {
  32. }
  33. //--------------------------------------------------------------------------------//
  34. void SDLInputManager::_initialize( ParamList &paramList )
  35. {
  36. Uint32 flags = SDL_WasInit(0);
  37. if( flags == 0 )
  38. OIS_EXCEPT( E_General, "SDLInputManager::SDLInputManager >> SDL Not Initialized already!");
  39. //Ok, now we have DirectInput, parse whatever extra settings were sent to us
  40. _parseConfigSettings( paramList );
  41. _enumerateDevices();
  42. }
  43. //--------------------------------------------------------------------------------//
  44. void SDLInputManager::_parseConfigSettings( ParamList &paramList )
  45. {
  46. }
  47. //--------------------------------------------------------------------------------//
  48. void SDLInputManager::_enumerateDevices()
  49. {
  50. }
  51. //--------------------------------------------------------------------------------//
  52. int SDLInputManager::numJoySticks()
  53. {
  54. return 0;
  55. }
  56. //--------------------------------------------------------------------------------//
  57. int SDLInputManager::numMice()
  58. {
  59. return 1;
  60. }
  61. //--------------------------------------------------------------------------------//
  62. int SDLInputManager::numKeyboards()
  63. {
  64. return 1;
  65. }
  66. //----------------------------------------------------------------------------//
  67. Object* SDLInputManager::createInputObject( Type iType, bool bufferMode )
  68. {
  69. Object* obj = 0;
  70. switch( iType )
  71. {
  72. case OISKeyboard: obj = new SDLKeyboard( bufferMode ); break;
  73. case OISMouse: obj = new SDLMouse( bufferMode ); break;
  74. case OISJoyStick:
  75. default: OIS_EXCEPT( E_InputDeviceNotSupported, "Type not implemented");
  76. }
  77. try {
  78. obj->_initialize();
  79. }
  80. catch(...) {
  81. delete obj;
  82. throw; //rethrow
  83. }
  84. return obj;
  85. }
  86. //----------------------------------------------------------------------------//
  87. void SDLInputManager::destroyInputObject( Object* obj )
  88. {
  89. if( obj == 0 ) return;
  90. delete obj;
  91. }