E:/Download/ois-1.0RC1/src/linux/LinuxInputManager.cpp

Go to the documentation of this file.
00001 /*
00002 The zlib/libpng License
00003 
00004 Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com)
00005 
00006 This software is provided 'as-is', without any express or implied warranty. In no event will
00007 the authors be held liable for any damages arising from the use of this software.
00008 
00009 Permission is granted to anyone to use this software for any purpose, including commercial 
00010 applications, and to alter it and redistribute it freely, subject to the following
00011 restrictions:
00012 
00013     1. The origin of this software must not be misrepresented; you must not claim that 
00014                 you wrote the original software. If you use this software in a product, 
00015                 an acknowledgment in the product documentation would be appreciated but is 
00016                 not required.
00017 
00018     2. Altered source versions must be plainly marked as such, and must not be 
00019                 misrepresented as being the original software.
00020 
00021     3. This notice may not be removed or altered from any source distribution.
00022 */
00023 #include "linux/LinuxInputManager.h"
00024 #include "linux/LinuxKeyboard.h"
00025 #include "linux/LinuxJoyStickEvents.h"
00026 #include "linux/LinuxMouse.h"
00027 #include "OISException.h"
00028 
00029 using namespace OIS;
00030 
00031 const std::string LinuxInputManager::iName = "X11 Linux Input Manager";
00032 //--------------------------------------------------------------------------------//
00033 LinuxInputManager::LinuxInputManager()
00034 {
00035         window = 0;
00036 
00037         //Default settings
00038         grabMouse = true;
00039         grabKeyboard = true;
00040         hideMouse = true;
00041         mGrabs = true;
00042         useXRepeat = false;
00043 }
00044 
00045 //--------------------------------------------------------------------------------//
00046 LinuxInputManager::~LinuxInputManager()
00047 {
00048         LinuxJoyStick::_clearJoys(unusedJoyStickList);
00049 }
00050 
00051 //--------------------------------------------------------------------------------//
00052 void LinuxInputManager::_initialize( ParamList &paramList )
00053 {
00054         _parseConfigSettings( paramList );
00055 
00056         //Enumerate all devices attached
00057         _enumerateDevices();
00058 }
00059 
00060 //--------------------------------------------------------------------------------//
00061 void LinuxInputManager::_parseConfigSettings( ParamList &paramList )
00062 {
00063         ParamList::iterator i = paramList.find("WINDOW");
00064         if( i == paramList.end() ) 
00065                 OIS_EXCEPT( E_InvalidParam, "LinuxInputManager >> No WINDOW!" );
00066 
00067         //TODO 64 bit proof this little conversion xxx wip
00068         window  = strtoul(i->second.c_str(), 0, 10);
00069 
00070         //--------- Keyboard Settings ------------//
00071         i = paramList.find("XAutoRepeatOn");
00072         if( i != paramList.end() )
00073                 if( i->second == "true" )
00074                         useXRepeat = true;
00075 
00076         i = paramList.find("x11_keyboard_grab");
00077         if( i != paramList.end() )
00078                 if( i->second == "false" )
00079                         grabKeyboard = false;
00080 
00081         //--------- Mouse Settings ------------//
00082         i = paramList.find("x11_mouse_grab");
00083         if( i != paramList.end() )
00084                 if( i->second == "false" )
00085                         grabMouse = false;
00086 
00087         i = paramList.find("x11_mouse_hide");
00088         if( i != paramList.end() )
00089                 if( i->second == "false" )
00090                         hideMouse = false;
00091 }
00092 
00093 //--------------------------------------------------------------------------------//
00094 void LinuxInputManager::_enumerateDevices()
00095 {
00096         //Enumerate all attached devices
00097         unusedJoyStickList = LinuxJoyStick::_scanJoys();
00098         joySticks = unusedJoyStickList.size();
00099 }
00100 
00101 //--------------------------------------------------------------------------------//
00102 int LinuxInputManager::numJoysticks()
00103 {
00104         return joySticks;
00105 }
00106 
00107 //--------------------------------------------------------------------------------//
00108 int LinuxInputManager::numMice()
00109 {
00110         return 1;
00111 }
00112 
00113 //--------------------------------------------------------------------------------//
00114 int LinuxInputManager::numKeyBoards()
00115 {
00116         return 1;
00117 }
00118 
00119 //----------------------------------------------------------------------------//
00120 Object* LinuxInputManager::createInputObject( Type iType, bool bufferMode )
00121 {
00122         Object* obj = 0;
00123         
00124         switch( iType )
00125         {
00126                 case OISKeyboard: 
00127                         obj = new LinuxKeyboard(this, bufferMode, grabKeyboard, useXRepeat); 
00128                         break;
00129                 case OISMouse: 
00130                         obj = new LinuxMouse(this, bufferMode, grabMouse, hideMouse); 
00131                         break;
00132                 case OISJoyStick: 
00133                 {
00134                         //Find a JoyStick not in use
00135                         JoyStickInfoList::iterator i = unusedJoyStickList.begin();
00136                         if( i != unusedJoyStickList.end() )
00137                         {
00138                                 obj = new LinuxJoyStick(bufferMode, *i);
00139                                 unusedJoyStickList.erase(i);
00140                                 break;
00141                         }
00142                         OIS_EXCEPT(E_InputDeviceNonExistant, "No JoySticks Available!");
00143                 }
00144                 default: 
00145                         OIS_EXCEPT( E_InputDeviceNotSupported, "Device Not Supported!");
00146         }
00147 
00148         //Seperate initialization from construction.. as bad things happen when
00149         //throwing exceptions from constructors
00150         try
00151         {
00152                 obj->_initialize();
00153         }
00154         catch(...) 
00155         {
00156                 delete obj;
00157                 throw; //rethrow the exception
00158         }
00159 
00160         return obj;
00161 }
00162 
00163 //----------------------------------------------------------------------------//
00164 void LinuxInputManager::destroyInputObject( Object* obj )
00165 {
00166         if( obj )
00167         {
00168                 //We put joys back into unused list
00169                 if( obj->type() == OISJoyStick )
00170                         unusedJoyStickList.push_back(((LinuxJoyStick*)obj)->_getJoyInfo());
00171 
00172                 delete obj;
00173         }
00174 }

Generated on Sat Dec 1 20:13:51 2007 for OIS by  doxygen 1.5.4