ois-1.3.0.dfsg0.orig/0000775000175000017500000000000011563205244014132 5ustar alessioalessioois-1.3.0.dfsg0.orig/demos/0000775000175000017500000000000011562210433015234 5ustar alessioalessioois-1.3.0.dfsg0.orig/demos/OISConsole.cpp0000664000175000017500000003522311562210433017722 0ustar alessioalessio//////////////////////////////// OS Nuetral Headers //////////////// #include "OISInputManager.h" #include "OISException.h" #include "OISKeyboard.h" #include "OISMouse.h" #include "OISJoyStick.h" #include "OISEvents.h" //Advanced Usage #include "OISForceFeedback.h" #include #include #include ////////////////////////////////////Needed Windows Headers//////////// #if defined OIS_WIN32_PLATFORM # define WIN32_LEAN_AND_MEAN # include "windows.h" # ifdef min # undef min # endif # include "resource.h" LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); ////////////////////////////////////////////////////////////////////// ////////////////////////////////////Needed Linux Headers////////////// #elif defined OIS_LINUX_PLATFORM # include void checkX11Events(); ////////////////////////////////////////////////////////////////////// ////////////////////////////////////Needed Mac Headers////////////// #elif defined OIS_APPLE_PLATFORM # include void checkMacEvents(); #endif ////////////////////////////////////////////////////////////////////// using namespace OIS; //-- Some local prototypes --// void doStartup(); void handleNonBufferedKeys(); void handleNonBufferedMouse(); void handleNonBufferedJoy( JoyStick* js ); //-- Easy access globals --// bool appRunning = true; //Global Exit Flag const char *g_DeviceType[6] = {"OISUnknown", "OISKeyboard", "OISMouse", "OISJoyStick", "OISTablet", "OISOther"}; InputManager *g_InputManager = 0; //Our Input System Keyboard *g_kb = 0; //Keyboard Device Mouse *g_m = 0; //Mouse Device JoyStick* g_joys[4] = {0,0,0,0}; //This demo supports up to 4 controllers //-- OS Specific Globals --// #if defined OIS_WIN32_PLATFORM HWND hWnd = 0; #elif defined OIS_LINUX_PLATFORM Display *xDisp = 0; Window xWin = 0; #elif defined OIS_APPLE_PLATFORM WindowRef mWin = 0; #endif //////////// Common Event handler class //////// class EventHandler : public KeyListener, public MouseListener, public JoyStickListener { public: EventHandler() {} ~EventHandler() {} bool keyPressed( const KeyEvent &arg ) { std::cout << " KeyPressed {" << arg.key << ", " << ((Keyboard*)(arg.device))->getAsString(arg.key) << "} || Character (" << (char)arg.text << ")" << std::endl; return true; } bool keyReleased( const KeyEvent &arg ) { if( arg.key == KC_ESCAPE || arg.key == KC_Q ) appRunning = false; std::cout << "KeyReleased {" << ((Keyboard*)(arg.device))->getAsString(arg.key) << "}\n"; return true; } bool mouseMoved( const MouseEvent &arg ) { const OIS::MouseState& s = arg.state; std::cout << "\nMouseMoved: Abs(" << s.X.abs << ", " << s.Y.abs << ", " << s.Z.abs << ") Rel(" << s.X.rel << ", " << s.Y.rel << ", " << s.Z.rel << ")"; return true; } bool mousePressed( const MouseEvent &arg, MouseButtonID id ) { const OIS::MouseState& s = arg.state; std::cout << "\nMouse button #" << id << " pressed. Abs(" << s.X.abs << ", " << s.Y.abs << ", " << s.Z.abs << ") Rel(" << s.X.rel << ", " << s.Y.rel << ", " << s.Z.rel << ")"; return true; } bool mouseReleased( const MouseEvent &arg, MouseButtonID id ) { const OIS::MouseState& s = arg.state; std::cout << "\nMouse button #" << id << " released. Abs(" << s.X.abs << ", " << s.Y.abs << ", " << s.Z.abs << ") Rel(" << s.X.rel << ", " << s.Y.rel << ", " << s.Z.rel << ")"; return true; } bool buttonPressed( const JoyStickEvent &arg, int button ) { std::cout << std::endl << arg.device->vendor() << ". Button Pressed # " << button; return true; } bool buttonReleased( const JoyStickEvent &arg, int button ) { std::cout << std::endl << arg.device->vendor() << ". Button Released # " << button; return true; } bool axisMoved( const JoyStickEvent &arg, int axis ) { //Provide a little dead zone if( arg.state.mAxes[axis].abs > 2500 || arg.state.mAxes[axis].abs < -2500 ) std::cout << std::endl << arg.device->vendor() << ". Axis # " << axis << " Value: " << arg.state.mAxes[axis].abs; return true; } bool povMoved( const JoyStickEvent &arg, int pov ) { std::cout << std::endl << arg.device->vendor() << ". POV" << pov << " "; if( arg.state.mPOV[pov].direction & Pov::North ) //Going up std::cout << "North"; else if( arg.state.mPOV[pov].direction & Pov::South ) //Going down std::cout << "South"; if( arg.state.mPOV[pov].direction & Pov::East ) //Going right std::cout << "East"; else if( arg.state.mPOV[pov].direction & Pov::West ) //Going left std::cout << "West"; if( arg.state.mPOV[pov].direction == Pov::Centered ) //stopped/centered out std::cout << "Centered"; return true; } bool vector3Moved( const JoyStickEvent &arg, int index) { std::cout.precision(2); std::cout.flags(std::ios::fixed | std::ios::right); std::cout << std::endl << arg.device->vendor() << ". Orientation # " << index << " X Value: " << arg.state.mVectors[index].x << " Y Value: " << arg.state.mVectors[index].y << " Z Value: " << arg.state.mVectors[index].z; std::cout.precision(); std::cout.flags(); return true; } }; //Create a global instance EventHandler handler; int main() { std::cout << "\n\n*** OIS Console Demo App is starting up... *** \n"; try { doStartup(); std::cout << "\nStartup done... Hit 'q' or ESC to exit.\n\n"; while(appRunning) { //Throttle down CPU usage #if defined OIS_WIN32_PLATFORM Sleep(90); MSG msg; while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } #elif defined OIS_LINUX_PLATFORM checkX11Events(); usleep( 500 ); #elif defined OIS_APPLE_PLATFORM checkMacEvents(); usleep( 500 ); #endif if( g_kb ) { g_kb->capture(); if( !g_kb->buffered() ) handleNonBufferedKeys(); } if( g_m ) { g_m->capture(); if( !g_m->buffered() ) handleNonBufferedMouse(); } for( int i = 0; i < 4 ; ++i ) { if( g_joys[i] ) { g_joys[i]->capture(); if( !g_joys[i]->buffered() ) handleNonBufferedJoy( g_joys[i] ); } } } } catch( const Exception &ex ) { #if defined OIS_WIN32_PLATFORM MessageBox( NULL, ex.eText, "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else std::cout << "\nOIS Exception Caught!\n" << "\t" << ex.eText << "[Line " << ex.eLine << " in " << ex.eFile << "]\nExiting App"; #endif } catch(std::exception &ex) { std::cout << "Caught std::exception: what = " << ex.what() << std::endl; } //Destroying the manager will cleanup unfreed devices if( g_InputManager ) InputManager::destroyInputSystem(g_InputManager); #if defined OIS_LINUX_PLATFORM // Be nice to X and clean up the x window XDestroyWindow(xDisp, xWin); XCloseDisplay(xDisp); #endif std::cout << "\n\nGoodbye\n\n"; return 0; } void doStartup() { ParamList pl; #if defined OIS_WIN32_PLATFORM //Create a capture window for Input Grabbing hWnd = CreateDialog( 0, MAKEINTRESOURCE(IDD_DIALOG1), 0,(DLGPROC)DlgProc); if( hWnd == NULL ) OIS_EXCEPT(E_General, "Failed to create Win32 Window Dialog!"); ShowWindow(hWnd, SW_SHOW); std::ostringstream wnd; wnd << (size_t)hWnd; pl.insert(std::make_pair( std::string("WINDOW"), wnd.str() )); //Default mode is foreground exclusive..but, we want to show mouse - so nonexclusive // pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" ))); // pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); #elif defined OIS_LINUX_PLATFORM //Connects to default X window if( !(xDisp = XOpenDisplay(0)) ) OIS_EXCEPT(E_General, "Error opening X!"); //Create a window xWin = XCreateSimpleWindow(xDisp,DefaultRootWindow(xDisp), 0,0, 100,100, 0, 0, 0); //bind our connection to that window XMapWindow(xDisp, xWin); //Select what events we want to listen to locally XSelectInput(xDisp, xWin, StructureNotifyMask); XEvent evtent; do { XNextEvent(xDisp, &evtent); } while(evtent.type != MapNotify); std::ostringstream wnd; wnd << xWin; pl.insert(std::make_pair(std::string("WINDOW"), wnd.str())); //For this demo, show mouse and do not grab (confine to window) // pl.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false"))); // pl.insert(std::make_pair(std::string("x11_mouse_hide"), std::string("false"))); #elif defined OIS_APPLE_PLATFORM // create the window rect in global coords ::Rect windowRect; windowRect.left = 0; windowRect.top = 0; windowRect.right = 300; windowRect.bottom = 300; // set the default attributes for the window WindowAttributes windowAttrs = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute | kWindowHideOnFullScreenAttribute; // Create the window CreateNewWindow(kDocumentWindowClass, windowAttrs, &windowRect, &mWin); // Color the window background black SetThemeWindowBackground (mWin, kThemeBrushBlack, true); // Set the title of our window CFStringRef titleRef = CFStringCreateWithCString( kCFAllocatorDefault, "OIS Input", kCFStringEncodingASCII ); SetWindowTitleWithCFString( mWin, titleRef ); // Center our window on the screen RepositionWindow( mWin, NULL, kWindowCenterOnMainScreen ); // Install the event handler for the window InstallStandardEventHandler(GetWindowEventTarget(mWin)); // This will give our window focus, and not lock it to the terminal ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType( &psn, kProcessTransformToForegroundApplication ); SetFrontProcess(&psn); // Display and select our window ShowWindow(mWin); SelectWindow(mWin); std::ostringstream wnd; wnd << (unsigned int)mWin; //cast to int so it gets encoded correctly (else it gets stored as a hex string) std::cout << "WindowRef: " << mWin << " WindowRef as int: " << wnd.str() << "\n"; pl.insert(std::make_pair(std::string("WINDOW"), wnd.str())); #endif //This never returns null.. it will raise an exception on errors g_InputManager = InputManager::createInputSystem(pl); //Lets enable all addons that were compiled in: g_InputManager->enableAddOnFactory(InputManager::AddOn_All); //Print debugging information unsigned int v = g_InputManager->getVersionNumber(); std::cout << "OIS Version: " << (v>>16 ) << "." << ((v>>8) & 0x000000FF) << "." << (v & 0x000000FF) << "\nRelease Name: " << g_InputManager->getVersionName() << "\nManager: " << g_InputManager->inputSystemName() << "\nTotal Keyboards: " << g_InputManager->getNumberOfDevices(OISKeyboard) << "\nTotal Mice: " << g_InputManager->getNumberOfDevices(OISMouse) << "\nTotal JoySticks: " << g_InputManager->getNumberOfDevices(OISJoyStick); //List all devices DeviceList list = g_InputManager->listFreeDevices(); for( DeviceList::iterator i = list.begin(); i != list.end(); ++i ) std::cout << "\n\tDevice: " << g_DeviceType[i->first] << " Vendor: " << i->second; g_kb = (Keyboard*)g_InputManager->createInputObject( OISKeyboard, true ); g_kb->setEventCallback( &handler ); g_m = (Mouse*)g_InputManager->createInputObject( OISMouse, true ); g_m->setEventCallback( &handler ); const MouseState &ms = g_m->getMouseState(); ms.width = 100; ms.height = 100; try { //This demo uses at most 4 joysticks - use old way to create (i.e. disregard vendor) int numSticks = std::min(g_InputManager->getNumberOfDevices(OISJoyStick), 4); for( int i = 0; i < numSticks; ++i ) { g_joys[i] = (JoyStick*)g_InputManager->createInputObject( OISJoyStick, true ); g_joys[i]->setEventCallback( &handler ); std::cout << "\n\nCreating Joystick " << (i + 1) << "\n\tAxes: " << g_joys[i]->getNumberOfComponents(OIS_Axis) << "\n\tSliders: " << g_joys[i]->getNumberOfComponents(OIS_Slider) << "\n\tPOV/HATs: " << g_joys[i]->getNumberOfComponents(OIS_POV) << "\n\tButtons: " << g_joys[i]->getNumberOfComponents(OIS_Button) << "\n\tVector3: " << g_joys[i]->getNumberOfComponents(OIS_Vector3); } } catch(OIS::Exception &ex) { std::cout << "\nException raised on joystick creation: " << ex.eText << std::endl; } } void handleNonBufferedKeys() { if( g_kb->isKeyDown( KC_ESCAPE ) || g_kb->isKeyDown( KC_Q ) ) appRunning = false; if( g_kb->isModifierDown(Keyboard::Shift) ) std::cout << "Shift is down..\n"; if( g_kb->isModifierDown(Keyboard::Alt) ) std::cout << "Alt is down..\n"; if( g_kb->isModifierDown(Keyboard::Ctrl) ) std::cout << "Ctrl is down..\n"; } void handleNonBufferedMouse() { //Just dump the current mouse state const MouseState &ms = g_m->getMouseState(); std::cout << "\nMouse: Abs(" << ms.X.abs << " " << ms.Y.abs << " " << ms.Z.abs << ") B: " << ms.buttons << " Rel(" << ms.X.rel << " " << ms.Y.rel << " " << ms.Z.rel << ")"; } void handleNonBufferedJoy( JoyStick* js ) { //Just dump the current joy state const JoyStickState &joy = js->getJoyStickState(); for( unsigned int i = 0; i < joy.mAxes.size(); ++i ) std::cout << "\nAxis " << i << " X: " << joy.mAxes[i].abs; } #if defined OIS_WIN32_PLATFORM LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { return FALSE; } #endif #if defined OIS_LINUX_PLATFORM //This is just here to show that you still recieve x11 events, as the lib only needs mouse/key events void checkX11Events() { XEvent event; //Poll x11 for events (keyboard and mouse events are caught here) while( XPending(xDisp) > 0 ) { XNextEvent(xDisp, &event); //Handle Resize events if( event.type == ConfigureNotify ) { if( g_m ) { const MouseState &ms = g_m->getMouseState(); ms.width = event.xconfigure.width; ms.height = event.xconfigure.height; } } else if( event.type == DestroyNotify ) { std::cout << "Exiting...\n"; appRunning = false; } else std::cout << "\nUnknown X Event: " << event.type << std::endl; } } #endif #if defined OIS_APPLE_PLATFORM void checkMacEvents() { //TODO - Check for window resize events, and then adjust the members of mousestate EventRef event = NULL; EventTargetRef targetWindow = GetEventDispatcherTarget(); if( ReceiveNextEvent( 0, NULL, kEventDurationNoWait, true, &event ) == noErr ) { SendEventToEventTarget(event, targetWindow); std::cout << "Event : " << GetEventKind(event) << "\n"; ReleaseEvent(event); } } #endif ois-1.3.0.dfsg0.orig/demos/Makefile.am0000664000175000017500000000055211562210433017272 0ustar alessioalessioINCLUDES = $(STLPORT_CFLAGS) -I$(top_srcdir)/includes $(CFLAGS) -I/usr/X11R6/include noinst_PROGRAMS = ConsoleApp FFConsoleTest ConsoleApp_SOURCES = OISConsole.cpp ConsoleApp_LDFLAGS = -L$(top_builddir)/src ConsoleApp_LDADD = -lOIS FFConsoleTest_SOURCES = FFConsoleDemo.cpp FFConsoleTest_LDFLAGS = -L$(top_builddir)/src FFConsoleTest_LDADD = -lOIS ois-1.3.0.dfsg0.orig/demos/FFConsoleDemo.cpp0000664000175000017500000010061111562210433020362 0ustar alessioalessio#include "OIS.h" #include #include #include #include #include #include #include using namespace std; ////////////////////////////////////Needed Windows Headers//////////// #if defined OIS_WIN32_PLATFORM # define WIN32_LEAN_AND_MEAN # include "windows.h" # include "resource.h" ////////////////////////////////////Needed Linux Headers////////////// #elif defined OIS_LINUX_PLATFORM # include #else # error Sorry, not yet implemented on this platform. #endif using namespace OIS; #if defined OIS_WIN32_PLATFORM // The dialog proc we have to give to CreateDialog LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { return FALSE; } #endif //////////// Event handler class declaration //////////////////////////////////////////////// class Application; class JoystickManager; class EffectManager; class EventHandler : public KeyListener, public JoyStickListener { protected: Application* _pApplication; JoystickManager* _pJoystickMgr; EffectManager* _pEffectMgr; public: EventHandler(Application* pApp); void initialize(JoystickManager* pJoystickMgr, EffectManager* pEffectMgr); bool keyPressed( const KeyEvent &arg ); bool keyReleased( const KeyEvent &arg ); bool buttonPressed( const JoyStickEvent &arg, int button ); bool buttonReleased( const JoyStickEvent &arg, int button ); bool axisMoved( const JoyStickEvent &arg, int axis ); bool povMoved( const JoyStickEvent &arg, int pov ); }; //////////// Variable classes //////////////////////////////////////////////////////// class Variable { protected: double _dInitValue; double _dValue; public: Variable(double dInitValue) : _dInitValue(dInitValue) { reset(); } double getValue() const { return _dValue; } void reset() { _dValue = _dInitValue; } virtual void setValue(double dValue) { _dValue = dValue; } virtual string toString() const { ostringstream oss; oss << _dValue; return oss.str(); } virtual void update() {}; }; class Constant : public Variable { public: Constant(double dInitValue) : Variable(dInitValue) {} virtual void setValue(double dValue) { } }; class LimitedVariable : public Variable { protected: double _dMinValue; double _dMaxValue; public: LimitedVariable(double dInitValue, double dMinValue, double dMaxValue) : _dMinValue(dMinValue), _dMaxValue(dMaxValue), Variable(dInitValue) {} virtual void setValue(double dValue) { _dValue = dValue; if (_dValue > _dMaxValue) _dValue = _dMaxValue; else if (_dValue < _dMinValue) _dValue = _dMinValue; } /* virtual string toString() const { ostringstream oss; oss << setiosflags(ios_base::right) << setw(4) << (int)(200.0 * getValue()/(_dMaxValue - _dMinValue)); // [-100%, +100%] return oss.str(); }*/ }; class TriangleVariable : public LimitedVariable { protected: double _dDeltaValue; public: TriangleVariable(double dInitValue, double dDeltaValue, double dMinValue, double dMaxValue) : LimitedVariable(dInitValue, dMinValue, dMaxValue), _dDeltaValue(dDeltaValue) {}; virtual void update() { double dValue = getValue() + _dDeltaValue; if (dValue > _dMaxValue) { dValue = _dMaxValue; _dDeltaValue = -_dDeltaValue; //cout << "Decreasing variable towards " << _dMinValue << endl; } else if (dValue < _dMinValue) { dValue = _dMinValue; _dDeltaValue = -_dDeltaValue; //cout << "Increasing variable towards " << _dMaxValue << endl; } setValue(dValue); //cout << "TriangleVariable::update : delta=" << _dDeltaValue << ", value=" << dValue << endl; } }; //////////// Variable effect class ////////////////////////////////////////////////////////// typedef map MapVariables; typedef void (*EffectVariablesApplier)(MapVariables& mapVars, Effect* pEffect); class VariableEffect { protected: // Effect description const char* _pszDesc; // The associate OIS effect Effect* _pEffect; // The effect variables. MapVariables _mapVariables; // The effect variables applier function. EffectVariablesApplier _pfApplyVariables; // True if the effect is currently being played. bool _bActive; public: VariableEffect(const char* pszDesc, Effect* pEffect, const MapVariables& mapVars, const EffectVariablesApplier pfApplyVars) : _pszDesc(pszDesc), _pEffect(pEffect), _mapVariables(mapVars), _pfApplyVariables(pfApplyVars), _bActive(false) {} ~VariableEffect() { if (_pEffect) delete _pEffect; MapVariables::iterator iterVars; for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++) if (iterVars->second) delete iterVars->second; } void setActive(bool bActive = true) { reset(); _bActive = bActive; } bool isActive() { return _bActive; } Effect* getFFEffect() { return _pEffect; } const char* getDescription() const { return _pszDesc; } void update() { if (isActive()) { // Update the variables. MapVariables::iterator iterVars; for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++) iterVars->second->update(); // Apply the updated variable values to the effect. _pfApplyVariables(_mapVariables, _pEffect); } } void reset() { MapVariables::iterator iterVars; for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++) iterVars->second->reset(); _pfApplyVariables(_mapVariables, _pEffect); } string toString() const { string str; MapVariables::const_iterator iterVars; for (iterVars = _mapVariables.begin(); iterVars != _mapVariables.end(); iterVars++) str += iterVars->first + ":" + iterVars->second->toString() + " "; return str; } }; //////////// Joystick manager class //////////////////////////////////////////////////////// class JoystickManager { protected: // Input manager. InputManager* _pInputMgr; // Vectors to hold joysticks and associated force feedback devices vector _vecJoys; vector _vecFFDev; // Selected joystick int _nCurrJoyInd; // Force feedback detected ? bool _bFFFound; // Selected joystick master gain. float _dMasterGain; // Selected joystick auto-center mode. bool _bAutoCenter; public: JoystickManager(InputManager* pInputMgr, EventHandler* pEventHdlr) : _pInputMgr(pInputMgr), _nCurrJoyInd(-1), _dMasterGain(0.5), _bAutoCenter(true) { _bFFFound = false; for( int nJoyInd = 0; nJoyInd < pInputMgr->getNumberOfDevices(OISJoyStick); ++nJoyInd ) { //Create the stick JoyStick* pJoy = (JoyStick*)pInputMgr->createInputObject( OISJoyStick, true ); cout << endl << "Created buffered joystick #" << nJoyInd << " '" << pJoy->vendor() << "' (Id=" << pJoy->getID() << ")"; // Check for FF, and if so, keep the joy and dump FF info ForceFeedback* pFFDev = (ForceFeedback*)pJoy->queryInterface(Interface::ForceFeedback ); if( pFFDev ) { _bFFFound = true; // Keep the joy to play with it. pJoy->setEventCallback(pEventHdlr); _vecJoys.push_back(pJoy); // Keep also the associated FF device _vecFFDev.push_back(pFFDev); // Dump FF supported effects and other info. cout << endl << " * Number of force feedback axes : " << pFFDev->getFFAxesNumber() << endl; const ForceFeedback::SupportedEffectList &lstFFEffects = pFFDev->getSupportedEffects(); if (lstFFEffects.size() > 0) { cout << " * Supported effects :"; ForceFeedback::SupportedEffectList::const_iterator itFFEff; for(itFFEff = lstFFEffects.begin(); itFFEff != lstFFEffects.end(); ++itFFEff) cout << " " << Effect::getEffectTypeName(itFFEff->second); cout << endl << endl; } else cout << "Warning: no supported effect found !" << endl; } else { cout << " (no force feedback support detected) => ignored." << endl << endl; _pInputMgr->destroyInputObject(pJoy); } } } ~JoystickManager() { for(size_t nJoyInd = 0; nJoyInd < _vecJoys.size(); ++nJoyInd) _pInputMgr->destroyInputObject( _vecJoys[nJoyInd] ); } size_t getNumberOfJoysticks() const { return _vecJoys.size(); } bool wasFFDetected() const { return _bFFFound; } enum EWhichJoystick { ePrevious=-1, eNext=+1 }; void selectJoystick(EWhichJoystick eWhich) { // Note: Reset the master gain to half the maximum and autocenter mode to Off, // when really selecting a new joystick. if (_nCurrJoyInd < 0) { _nCurrJoyInd = 0; _dMasterGain = 0.5; // Half the maximum. changeMasterGain(0.0); } else { _nCurrJoyInd += eWhich; if (_nCurrJoyInd < -1 || _nCurrJoyInd >= (int)_vecJoys.size()) _nCurrJoyInd = -1; if (_vecJoys.size() > 1 && _nCurrJoyInd >= 0) { _dMasterGain = 0.5; // Half the maximum. changeMasterGain(0.0); } } } ForceFeedback* getCurrentFFDevice() { return (_nCurrJoyInd >= 0) ? _vecFFDev[_nCurrJoyInd] : 0; } void changeMasterGain(float dDeltaPercent) { if (_nCurrJoyInd >= 0) { _dMasterGain += dDeltaPercent / 100; if (_dMasterGain > 1.0) _dMasterGain = 1.0; else if (_dMasterGain < 0.0) _dMasterGain = 0.0; _vecFFDev[_nCurrJoyInd]->setMasterGain(_dMasterGain); } } enum EAutoCenterHow { eOff, eOn, eToggle }; void changeAutoCenter(EAutoCenterHow eHow = eToggle) { if (_nCurrJoyInd >= 0) { if (eHow == eToggle) _bAutoCenter = !_bAutoCenter; else _bAutoCenter = (eHow == eOn ? true : false); _vecFFDev[_nCurrJoyInd]->setAutoCenterMode(_bAutoCenter); } } void captureEvents() { // This fires off buffered events for each joystick we have for(size_t nJoyInd = 0; nJoyInd < _vecJoys.size(); ++nJoyInd) if( _vecJoys[nJoyInd] ) _vecJoys[nJoyInd]->capture(); } string toString() const { // Warning: Wrong result if more than 10 joysticks ... ostringstream oss; oss << "Joy:" << (_nCurrJoyInd >= 0 ? (char)('0' + _nCurrJoyInd) : '-'); oss << " Gain:" << setiosflags(ios_base::right) << setw(3) << (int)(_dMasterGain*100); oss << "% Center:" << (_bAutoCenter ? " On " : "Off"); return oss.str(); } }; //////////// Effect variables applier functions ///////////////////////////////////////////// // These functions apply the given Variables to the given OIS::Effect // Variable force "Force" + optional "AttackFactor" constant, on a OIS::ConstantEffect void forceVariableApplier(MapVariables& mapVars, Effect* pEffect) { double dForce = mapVars["Force"]->getValue(); double dAttackFactor = 1.0; if (mapVars.find("AttackFactor") != mapVars.end()) dAttackFactor = mapVars["AttackFactor"]->getValue(); ConstantEffect* pConstForce = dynamic_cast(pEffect->getForceEffect()); pConstForce->level = (int)dForce; pConstForce->envelope.attackLevel = (unsigned short)fabs(dForce*dAttackFactor); pConstForce->envelope.fadeLevel = (unsigned short)fabs(dForce); // Fade never reached, in fact. } // Variable "Period" on an OIS::PeriodicEffect void periodVariableApplier(MapVariables& mapVars, Effect* pEffect) { double dPeriod = mapVars["Period"]->getValue(); PeriodicEffect* pPeriodForce = dynamic_cast(pEffect->getForceEffect()); pPeriodForce->period = (unsigned int)dPeriod; } //////////// Effect manager class ////////////////////////////////////////////////////////// class EffectManager { protected: // The joystick manager JoystickManager* _pJoystickMgr; // Vector to hold variable effects vector _vecEffects; // Selected effect int _nCurrEffectInd; // Update frequency (Hz) unsigned int _nUpdateFreq; // Indexes (in _vecEffects) of the variable effects that are playable by the selected joystick. vector _vecPlayableEffectInd; public: EffectManager(JoystickManager* pJoystickMgr, unsigned int nUpdateFreq) : _pJoystickMgr(pJoystickMgr), _nUpdateFreq(nUpdateFreq), _nCurrEffectInd(-1) { Effect* pEffect; MapVariables mapVars; ConstantEffect* pConstForce; PeriodicEffect* pPeriodForce; // Please don't modify or remove effects (unless there is some bug ...) : // add new ones to enhance the test repository. // And feel free to add any tested device, even when the test failed ! // Tested devices capabilities : // - Logitech G25 Racing wheel : // * Only 1 axis => no directional 2D effect (only left and right) // * Full support for constant force under WinXPSP2DX9 and Linux 2.6.22.9 // * Full support for periodic forces under WinXPSP2DX9 // (but poor rendering under 20ms period), and no support under Linux 2.6.22.9 // * Full support reported (not tested) for all other forces under WinXPSP2DX9, // and no support under Linux 2.6.22.9 // - Logitech Rumble pad 2 : // * Only 1 axis => no directional 2D effect (only left and right) // * Forces amplitude is rendered through the inertia motors rotation frequency // (stronger force => quicker rotation) // * 2 inertia motors : 1 with small inertia, 1 with "heavy" one. // => poor force feedback rendering ... // * Support (poor) for all OIS forces under WinXPSP2DX9, // and only for Triangle, Square and Sine periodic forces under Linux 2.6.22.9 // (reported by enumeration, but does not seem to work actually) // Master gain setting tests: // - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux2.6.22.9=OK. // - Logitech Rumble pad 2 : WinXPSP2DX9=OK, Linux2.6.22.9=OK. // Auto-center mode setting tests: // - Logitech G25 Racing wheel : WinXPSP2DX9=Failed (DINPUT?), Linux2.6.22.9=Reported as not supported. // - Logitech Rumble pad 2 : WinXPSP2DX9=Failed (DINPUT?), Linux2.6.22.9=Reported as not supported. // 1) Constant force on 1 axis with 20s-period triangle oscillations in [-10K, +10K]. // Notes: Linux: replay_length: no way to get it to work if not 0 or Effect::OIS_INFINITE // Tested devices : // - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux2.6.22.9=OK. // - Logitech Rumble pad 2 : WinXPSP2DX9=OK (but only light motor involved), // Linux2.6.22.9=Not supported pEffect = new Effect(Effect::ConstantForce, Effect::Constant); pEffect->direction = Effect::North; pEffect->trigger_button = 0; pEffect->trigger_interval = 0; pEffect->replay_length = Effect::OIS_INFINITE; // Linux/Win32: Same behaviour as 0. pEffect->replay_delay = 0; pEffect->setNumAxes(1); pConstForce = dynamic_cast(pEffect->getForceEffect()); pConstForce->level = 5000; //-10K to +10k pConstForce->envelope.attackLength = 0; pConstForce->envelope.attackLevel = (unsigned short)pConstForce->level; pConstForce->envelope.fadeLength = 0; pConstForce->envelope.fadeLevel = (unsigned short)pConstForce->level; mapVars.clear(); mapVars["Force"] = new TriangleVariable(0.0, // F0 4*10000/_nUpdateFreq / 20.0, // dF for a 20s-period triangle -10000.0, // Fmin 10000.0); // Fmax mapVars["AttackFactor"] = new Constant(1.0); _vecEffects.push_back (new VariableEffect ("Constant force on 1 axis with 20s-period triangle oscillations " "of its signed amplitude in [-10K, +10K]", pEffect, mapVars, forceVariableApplier)); // 2) Constant force on 1 axis with noticeable attack // with 20s-period triangle oscillations in [-10K, +10K]. // Tested devices : // - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux=OK. // - Logitech Rumble pad 2 : WinXPSP2DX9=OK (including attack, but only light motor involved), // Linux2.6.22.9=Not supported. pEffect = new Effect(Effect::ConstantForce, Effect::Constant); pEffect->direction = Effect::North; pEffect->trigger_button = 0; pEffect->trigger_interval = 0; pEffect->replay_length = Effect::OIS_INFINITE; //(unsigned int)(1000000.0/_nUpdateFreq); // Linux: Does not work. pEffect->replay_delay = 0; pEffect->setNumAxes(1); pConstForce = dynamic_cast(pEffect->getForceEffect()); pConstForce->level = 5000; //-10K to +10k pConstForce->envelope.attackLength = (unsigned int)(1000000.0/_nUpdateFreq/2); pConstForce->envelope.attackLevel = (unsigned short)(pConstForce->level*0.1); pConstForce->envelope.fadeLength = 0; // Never reached, actually. pConstForce->envelope.fadeLevel = (unsigned short)pConstForce->level; // Idem mapVars.clear(); mapVars["Force"] = new TriangleVariable(0.0, // F0 4*10000/_nUpdateFreq / 20.0, // dF for a 20s-period triangle -10000.0, // Fmin 10000.0); // Fmax mapVars["AttackFactor"] = new Constant(0.1); _vecEffects.push_back (new VariableEffect ("Constant force on 1 axis with noticeable attack (app update period / 2)" "and 20s-period triangle oscillations of its signed amplitude in [-10K, +10K]", pEffect, mapVars, forceVariableApplier)); // 3) Triangle periodic force on 1 axis with 40s-period triangle oscillations // of its period in [10, 400] ms, and constant amplitude // Tested devices : // - Logitech G25 Racing wheel : WinXPSP2DX9=OK, Linux=OK. // - Logitech Rumble pad 2 : WinXPSP2DX9=OK but only light motor involved, // Linux2.6.22.9=Failed. pEffect = new Effect(Effect::PeriodicForce, Effect::Triangle); pEffect->direction = Effect::North; pEffect->trigger_button = 0; pEffect->trigger_interval = 0; pEffect->replay_length = Effect::OIS_INFINITE; pEffect->replay_delay = 0; pEffect->setNumAxes(1); pPeriodForce = dynamic_cast(pEffect->getForceEffect()); pPeriodForce->magnitude = 10000; // 0 to +10k pPeriodForce->offset = 0; pPeriodForce->phase = 0; // 0 to 35599 pPeriodForce->period = 10000; // Micro-seconds pPeriodForce->envelope.attackLength = 0; pPeriodForce->envelope.attackLevel = (unsigned short)pPeriodForce->magnitude; pPeriodForce->envelope.fadeLength = 0; pPeriodForce->envelope.fadeLevel = (unsigned short)pPeriodForce->magnitude; mapVars.clear(); mapVars["Period"] = new TriangleVariable(1*1000.0, // P0 4*(400-10)*1000.0/_nUpdateFreq / 40.0, // dP for a 40s-period triangle 10*1000.0, // Pmin 400*1000.0); // Pmax _vecEffects.push_back (new VariableEffect ("Periodic force on 1 axis with 40s-period triangle oscillations " "of its period in [10, 400] ms, and constant amplitude", pEffect, mapVars, periodVariableApplier)); } ~EffectManager() { vector::iterator iterEffs; for (iterEffs = _vecEffects.begin(); iterEffs != _vecEffects.end(); iterEffs++) delete *iterEffs; } void updateActiveEffects() { vector::iterator iterEffs; for (iterEffs = _vecEffects.begin(); iterEffs != _vecEffects.end(); iterEffs++) if ((*iterEffs)->isActive()) { (*iterEffs)->update(); _pJoystickMgr->getCurrentFFDevice()->modify((*iterEffs)->getFFEffect()); } } void checkPlayableEffects() { // Nothing to do if no joystick currently selected if (!_pJoystickMgr->getCurrentFFDevice()) return; // Get the list of indexes of effects that the selected device can play _vecPlayableEffectInd.clear(); for (size_t nEffInd = 0; nEffInd < _vecEffects.size(); nEffInd++) { const Effect::EForce eForce = _vecEffects[nEffInd]->getFFEffect()->force; const Effect::EType eType = _vecEffects[nEffInd]->getFFEffect()->type; if (_pJoystickMgr->getCurrentFFDevice()->supportsEffect(eForce, eType)) { _vecPlayableEffectInd.push_back(nEffInd); } } // Print details about playable effects if (_vecPlayableEffectInd.empty()) { cout << endl << endl << "The device can't play any effect of the test set" << endl; } else { cout << endl << endl << "Selected device can play the following effects :" << endl; for (size_t nEffIndInd = 0; nEffIndInd < _vecPlayableEffectInd.size(); nEffIndInd++) printEffect(_vecPlayableEffectInd[nEffIndInd]); cout << endl; } } enum EWhichEffect { ePrevious=-1, eNone=0, eNext=+1 }; void selectEffect(EWhichEffect eWhich) { // Nothing to do if no joystick currently selected if (!_pJoystickMgr->getCurrentFFDevice()) { cout << "\nNo Joystick selected.\n"; return; } // Nothing to do if joystick cannot play any effect if (_vecPlayableEffectInd.empty()) { cout << "\nNo playable effects.\n"; return; } // If no effect selected, and next or previous requested, select the first one. if (eWhich != eNone && _nCurrEffectInd < 0) _nCurrEffectInd = 0; // Otherwise, remove the current one from the device, // and then select the requested one if any. else if (_nCurrEffectInd >= 0) { _pJoystickMgr->getCurrentFFDevice() ->remove(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect()); _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(false); _nCurrEffectInd += eWhich; if (_nCurrEffectInd < -1 || _nCurrEffectInd >= (int)_vecPlayableEffectInd.size()) _nCurrEffectInd = -1; } // If no effect must be selected, reset the selection index if (eWhich == eNone) { _nCurrEffectInd = -1; } // Otherwise, upload the new selected effect to the device if any. else if (_nCurrEffectInd >= 0) { _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(true); _pJoystickMgr->getCurrentFFDevice() ->upload(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect()); } } void printEffect(size_t nEffInd) { cout << "* #" << nEffInd << " : " << _vecEffects[nEffInd]->getDescription() << endl; } void printEffects() { for (size_t nEffInd = 0; nEffInd < _vecEffects.size(); nEffInd++) printEffect(nEffInd); } string toString() const { ostringstream oss; oss << "DevMem: " << setiosflags(ios_base::right) << setw(3); //This causes constant exceptions with my device. Not needed for anything other than debugging //if (_pJoystickMgr->getCurrentFFDevice()) // oss << _pJoystickMgr->getCurrentFFDevice()->getFFMemoryLoad() << "%"; //else // oss << "----"; oss << " Effect:" << setw(2); if (_nCurrEffectInd >= 0) oss << _vecPlayableEffectInd[_nCurrEffectInd] << " " << _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->toString(); else oss << "--"; return oss.str(); } }; //////////// Application class //////////////////////////////////////////////////////// class Application { protected: InputManager* _pInputMgr; EventHandler* _pEventHdlr; Keyboard* _pKeyboard; JoystickManager* _pJoystickMgr; EffectManager* _pEffectMgr; #if defined OIS_WIN32_PLATFORM HWND _hWnd; #elif defined OIS_LINUX_PLATFORM Display* _pXDisp; Window _xWin; #endif bool _bMustStop; bool _bIsInitialized; int _nStatus; // App. hart beat frequency. static const unsigned int _nHartBeatFreq = 20; // Hz // Effects update frequency (Hz) : Needs to be quite lower than app. hart beat frequency, // if we want to be able to calmly study effect changes ... static const unsigned int _nEffectUpdateFreq = 1; // Hz public: Application(int argc, const char* argv[]) { _pInputMgr = 0; _pEventHdlr = 0; _pKeyboard = 0; _pJoystickMgr = 0; _pEffectMgr = 0; #if defined OIS_WIN32_PLATFORM _hWnd = 0; #elif defined OIS_LINUX_PLATFORM _pXDisp = 0; _xWin = 0; #endif _bMustStop = false; _bIsInitialized = false; _nStatus = 0; } int initialize() { ostringstream wnd; #if defined OIS_WIN32_PLATFORM //Create a capture window for Input Grabbing _hWnd = CreateDialog( 0, MAKEINTRESOURCE(IDD_DIALOG1), 0,(DLGPROC)DlgProc); if( _hWnd == NULL ) OIS_EXCEPT(E_General, "Failed to create Win32 Window Dialog!"); ShowWindow(_hWnd, SW_SHOW); wnd << (size_t)_hWnd; #elif defined OIS_LINUX_PLATFORM //Connects to default X window if( !(_pXDisp = XOpenDisplay(0)) ) OIS_EXCEPT(E_General, "Error opening X!"); //Create a window _xWin = XCreateSimpleWindow(_pXDisp,DefaultRootWindow(_pXDisp), 0,0, 100,100, 0, 0, 0); //bind our connection to that window XMapWindow(_pXDisp, _xWin); //Select what events we want to listen to locally XSelectInput(_pXDisp, _xWin, StructureNotifyMask); //Wait for Window to show up XEvent event; do { XNextEvent(_pXDisp, &event); } while(event.type != MapNotify); wnd << _xWin; #endif // Create OIS input manager ParamList pl; pl.insert(make_pair(string("WINDOW"), wnd.str())); _pInputMgr = InputManager::createInputSystem(pl); cout << _pInputMgr->inputSystemName() << " created." << endl; // Create the event handler. _pEventHdlr = new EventHandler(this); // Create a simple keyboard _pKeyboard = (Keyboard*)_pInputMgr->createInputObject( OISKeyboard, true ); _pKeyboard->setEventCallback( _pEventHdlr ); // Create the joystick manager. _pJoystickMgr = new JoystickManager(_pInputMgr, _pEventHdlr); if( !_pJoystickMgr->wasFFDetected() ) { cout << "No Force Feedback device detected." << endl; _nStatus = 1; return _nStatus; } // Create force feedback effect manager. _pEffectMgr = new EffectManager(_pJoystickMgr, _nEffectUpdateFreq); // Initialize the event handler. _pEventHdlr->initialize(_pJoystickMgr, _pEffectMgr); _bIsInitialized = true; return _nStatus; } #if defined OIS_LINUX_PLATFORM // This is just here to show that you still receive x11 events, // as the lib only needs mouse/key events void checkX11Events() { XEvent event; //Poll x11 for events while( XPending(_pXDisp) > 0 ) { XNextEvent(_pXDisp, &event); } } #endif int run() { const unsigned int nMaxEffectUpdateCnt = _nHartBeatFreq / _nEffectUpdateFreq; unsigned int nEffectUpdateCnt = 0; // Initailize app. if not already done, and exit if something went wrong. if (!_bIsInitialized) initialize(); if (!_bIsInitialized) return _nStatus; try { //Main polling loop while(!_bMustStop) { // This fires off buffered events for keyboards _pKeyboard->capture(); // This fires off buffered events for each joystick we have _pJoystickMgr->captureEvents(); // Update currently selected effects if time has come to. if (!nEffectUpdateCnt) { _pEffectMgr->updateActiveEffects(); nEffectUpdateCnt = nMaxEffectUpdateCnt; } else nEffectUpdateCnt--; // Update state line. cout << "\r" << _pJoystickMgr->toString() << " " << _pEffectMgr->toString() << " "; //Throttle down CPU usage & handle OS events #if defined OIS_WIN32_PLATFORM Sleep( (DWORD)(1000.0/_nHartBeatFreq) ); MSG msg; while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } #elif defined OIS_LINUX_PLATFORM checkX11Events(); usleep(1000000.0/_nHartBeatFreq); #endif } } catch( const Exception &ex ) { #if defined OIS_WIN32_PLATFORM MessageBox(0, ex.eText, "Exception Raised!", MB_OK); #else cout << endl << "OIS Exception Caught!" << endl << "\t" << ex.eText << "[Line " << ex.eLine << " in " << ex.eFile << "]" << endl; #endif } terminate(); return _nStatus; } void stop() { _bMustStop = true; } void terminate() { if (_pInputMgr) { _pInputMgr->destroyInputObject( _pKeyboard ); _pKeyboard = 0; if (_pJoystickMgr) { delete _pJoystickMgr; _pJoystickMgr = 0; } InputManager::destroyInputSystem(_pInputMgr); _pInputMgr = 0; } if (_pEffectMgr) { delete _pEffectMgr; _pEffectMgr = 0; } if (_pEventHdlr) { delete _pEventHdlr; _pEventHdlr = 0; } #if defined OIS_LINUX_PLATFORM // Be nice to X and clean up the x window XDestroyWindow(_pXDisp, _xWin); XCloseDisplay(_pXDisp); #endif } JoystickManager* getJoystickManager() { return _pJoystickMgr; } EffectManager* getEffectManager() { return _pEffectMgr; } void printHelp() { cout << endl << "Keyboard actions :" << endl << "* Escape : Exit App" << endl << "* H : This help menu" << endl << "* Right/Left : Select next/previous joystick among the FF capable detected ones" << endl << "* Up/Down : Select next/previous effect for the selected joystick" << endl << "* PgUp/PgDn : Increase/decrease from 5% the master gain " << "for all the joysticks" << endl << "* Space : Toggle auto-centering on all the joysticks" << endl; if (_bIsInitialized) { cout << endl << "Implemented effects :" << endl << endl; _pEffectMgr->printEffects(); cout << endl; } } }; //////////// Event handler class definition //////////////////////////////////////////////// EventHandler::EventHandler(Application* pApp) : _pApplication(pApp) {} void EventHandler::initialize(JoystickManager* pJoystickMgr, EffectManager* pEffectMgr) { _pJoystickMgr = pJoystickMgr; _pEffectMgr = pEffectMgr; } bool EventHandler::keyPressed( const KeyEvent &arg ) { switch (arg.key) { // Quit. case KC_ESCAPE: _pApplication->stop(); break; // Help. case KC_H: _pApplication->printHelp(); break; // Change current joystick. case KC_RIGHT: _pEffectMgr->selectEffect(EffectManager::eNone); _pJoystickMgr->selectJoystick(JoystickManager::eNext); _pEffectMgr->checkPlayableEffects(); break; case KC_LEFT: _pEffectMgr->selectEffect(EffectManager::eNone); _pJoystickMgr->selectJoystick(JoystickManager::ePrevious); _pEffectMgr->checkPlayableEffects(); break; // Change current effect. case KC_UP: _pEffectMgr->selectEffect(EffectManager::eNext); break; case KC_DOWN: _pEffectMgr->selectEffect(EffectManager::ePrevious); break; // Change current master gain. case KC_PGUP: _pJoystickMgr->changeMasterGain(5.0); // Percent break; case KC_PGDOWN: _pJoystickMgr->changeMasterGain(-5.0); // Percent break; // Toggle auto-center mode. case KC_SPACE: _pJoystickMgr->changeAutoCenter(); break; default: cout << "Non mapped key: " << arg.key << endl; } return true; } bool EventHandler::keyReleased( const KeyEvent &arg ) { return true; } bool EventHandler::buttonPressed( const JoyStickEvent &arg, int button ) { return true; } bool EventHandler::buttonReleased( const JoyStickEvent &arg, int button ) { return true; } bool EventHandler::axisMoved( const JoyStickEvent &arg, int axis ) { return true; } bool EventHandler::povMoved( const JoyStickEvent &arg, int pov ) { return true; } //========================================================================================== int main(int argc, const char* argv[]) { cout << endl << "This is a simple command line Force Feedback testing demo ..." << endl << "All connected joystick devices will be created and if FF Support is found," << endl << "you'll be able to play some predefined variable effects on them." << endl << endl << "Note: 1 effect can be played on 1 joystick at a time for the moment." << endl << endl; Application app(argc, argv); int status = app.initialize(); if (!status) { app.printHelp(); status = app.run(); } cout << endl << endl << "Exiting ..." << endl << endl; #if defined OIS_WIN32_PLATFORM && _DEBUG cout << "Click on this window and ..." << endl; system("pause"); #endif exit(status); } ois-1.3.0.dfsg0.orig/Makefile.am0000664000175000017500000000013211562210433016155 0ustar alessioalessioSUBDIRS = src includes demos pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = OIS.pc ois-1.3.0.dfsg0.orig/ReadMe.txt0000664000175000017500000000632211562210433016026 0ustar alessioalessio====================================================================================== ================ LICENSE ============================================================= ====================================================================================== The zlib/libpng License Copyright (c) 2005-2010 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. ====================================================================================== ================ LICENSE EXPLAINED =================================================== ====================================================================================== In case the license was not clear enough... Basically, you can link with this lib which puts no restrictions on what you have to license your code as. You can modify this lib, and not have release your changes. Though, as explained above, Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software This is to allow users the greatest flexibility in what you can use this lib for. ====================================================================================== ================ INFO ================================================================ ====================================================================================== Cross Platform Object Oriented Input Lib System. Meant to be very robust and compatiable with many systems and operating systems Win32/ Contains Visual Studio .Net Solution Files Contains CodeBlocks project files for OIS ---- Dependencies ------------------------------------------------------ DirectInput 8 Linux/ ---- Dependencies ------------------------------------------------------ X11 Newer Linux Kernel (2.6+ ?) for Event API Steps to build on Linux: ./bootstrap ./configure ./make && make install ---- Configure build options -------------------------------------------- ./configure --help --- List all configure options LinuxCB/ Contains CodeBlock files for building OIS and Demos with codeblocks This project file looks for Ogre and other dependencies in /usr/local/lib and /usr/local/include. If installed elsewhere, modify the project settings. It also installs libOIS to ~/libs Mac/ XCode-2.2/ Working, mostly complete OSX vackend.ois-1.3.0.dfsg0.orig/acinclude.m40000664000175000017500000000102711562210433016316 0ustar alessioalessio AC_DEFUN([OIS_USE_STLPORT], [AC_ARG_WITH(stlport, AC_HELP_STRING([--with-stlport=PATH], [the path to STLPort.]), ac_cv_use_stlport=$withval, ac_cv_use_stlport=no) AC_CACHE_CHECK([whether to use STLPort], ac_cv_use_stlport, ac_cv_use_stlport=no) if test x$ac_cv_use_stlport != xno; then STLPORT_CFLAGS="-I$ac_cv_use_stlport/stlport" STLPORT_LIBS="-L$ac_cv_use_stlport/lib -lstlport" fi AC_SUBST(STLPORT_CFLAGS) AC_SUBST(STLPORT_LIBS) ]) ois-1.3.0.dfsg0.orig/includes/0000775000175000017500000000000011563205244015740 5ustar alessioalessioois-1.3.0.dfsg0.orig/includes/OISFactoryCreator.h0000664000175000017500000000473411562210433021416 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_FactoryCreator_H #define OIS_FactoryCreator_H #include "OISPrereqs.h" namespace OIS { /** Interface for creating devices - all devices ultimately get enumerated/created via a factory. A factory can create multiple types of objects. */ class _OISExport FactoryCreator { public: /** @remarks Virtual Destructor */ virtual ~FactoryCreator() {}; /** @remarks Return a list of all unused devices the factory maintains */ virtual DeviceList freeDeviceList() = 0; /** @remarks Number of total devices of requested type @param iType Type of devices to check */ virtual int totalDevices(Type iType) = 0; /** @remarks Number of free devices of requested type @param iType Type of devices to check */ virtual int freeDevices(Type iType) = 0; /** @remarks Does a Type exist with the given vendor name @param iType Type to check @param vendor Vendor name to test */ virtual bool vendorExist(Type iType, const std::string & vendor) = 0; /** @remarks Creates the object @param iType Type to create @param bufferMode True to setup for buffered events @param vendor Create a device with the vendor name, "" means vendor name is unimportant */ virtual Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = "") = 0; /** @remarks Destroys object @param obj Object to destroy */ virtual void destroyObject(Object* obj) = 0; }; } #endif //OIS_FactoryCreator_H ois-1.3.0.dfsg0.orig/includes/OISConfig.h0000664000175000017500000000522711562210433017672 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_CONFIG_HEADER #define OIS_CONFIG_HEADER //----------------------------------------------------------------------------// //* This file contains defines for building certain parts of this Lib //* This file is not meant for External inclusion. However, you can edit this //* file before a build to effect what features are used internally //----------------------------------------------------------------------------// /** @remarks These lines have no bearing on internal build of OIS. This is here for external build settings. Meaning, changing this does not require a rebuild of OIS. This just affects VC dll import settings, as the DLL build already defines this during its build for setting dll exports. The undefine here is here just incase you decide to only use DLL, and want to set it permently and recompile OIS too.. Avoid redefinition from DLL build of OIS. So, if wanting to link against DLL version, just uncomment these lines. */ //#ifdef OIS_DYNAMIC_LIB //# undef OIS_DYNAMIC_LIB //#endif //#define OIS_DYNAMIC_LIB /** @remarks Build in support for LIRC / WinLIRC - remote control support. Requires Boost::asio @notes Experimental - Supports connecting and enumerating. Control does not yet return state or events */ //#define OIS_LIRC_SUPPORT /** @remarks Build in support for PC Nintendo WiiMote Win32 HID interface. Requires Boost::threads @notes Useable, but not quite finished - supports rumble, all buttons, & main orientation axis. Still needs Nunchuck, IR, and LED/Battery support. */ //#define OIS_WIN32_WIIMOTE_SUPPORT /** @remarks Build in support for Win32 XInput (Xbox 360 Controller) */ //#define OIS_WIN32_XINPUT_SUPPORT #endif ois-1.3.0.dfsg0.orig/includes/OISEvents.h0000664000175000017500000000244311562210433017726 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _OIS_EVENTHEADERS_ #define _OIS_EVENTHEADERS_ #include "OISPrereqs.h" namespace OIS { /** Base class of all events */ class _OISExport EventArg { public: EventArg( Object* obj ) : device(obj) {} virtual ~EventArg() {} //! Pointer to the Input Device const Object* device; }; } #endif //_OIS_EVENTHEADERS_ ois-1.3.0.dfsg0.orig/includes/OISException.h0000664000175000017500000000477411562210433020431 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _OIS_EXCEPTION_HEADER_ #define _OIS_EXCEPTION_HEADER_ #include "OISPrereqs.h" #include namespace OIS { //! Simple enum's for dealing with exceptions enum OIS_ERROR { E_InputDisconnected, E_InputDeviceNonExistant, E_InputDeviceNotSupported, E_DeviceFull, E_NotSupported, E_NotImplemented, E_Duplicate, E_InvalidParam, E_General }; /** @remarks Class for handling OIS exceptions. Much cleaner than checking every method for reurn value. Inherits from std::exception so you can simply log those messages if you want to be generic. Also note that this has a source file now since OSX was not finding the OIS::Exception symbol which would cause program abortion with now correponding exception type. */ class _OISExport Exception : public std::exception { //! Hidden default Exception() : eType(E_General), eLine(0), eFile(0) {} public: //! Creates exception object Exception( OIS_ERROR err, const char* str, int line, const char *file ) : eType(err), eLine(line), eFile(file), eText(str) {} ~Exception() throw() {} virtual const char* what() const throw(); //! The type of exception raised const OIS_ERROR eType; //! The line number it occurred on const int eLine; //! The source file const char* eFile; //! A message passed along when the exception was raised const char* eText; }; } //! Use this macro to handle exceptions easily #define OIS_EXCEPT( err, str ) throw( OIS::Exception(err, str, __LINE__, __FILE__) ) #endif //_OIS_EXCEPTION_HEADER_ ois-1.3.0.dfsg0.orig/includes/OIS.h0000664000175000017500000000252711562210433016544 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_OISALL_H #define OIS_OISALL_H #include "OISPrereqs.h" #include "OISObject.h" #include "OISMouse.h" #include "OISKeyboard.h" #include "OISJoyStick.h" #include "OISMultiTouch.h" #include "OISInputManager.h" #include "OISFactoryCreator.h" #include "OISException.h" #include "OISEvents.h" #include "OISEffect.h" #include "OISInterface.h" #include "OISForceFeedback.h" #endif ois-1.3.0.dfsg0.orig/includes/OISKeyboard.h0000664000175000017500000002357111562210433020227 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Keyboard_H #define OIS_Keyboard_H #include "OISObject.h" #include "OISEvents.h" namespace OIS { //! Keyboard scan codes enum KeyCode { KC_UNASSIGNED = 0x00, KC_ESCAPE = 0x01, KC_1 = 0x02, KC_2 = 0x03, KC_3 = 0x04, KC_4 = 0x05, KC_5 = 0x06, KC_6 = 0x07, KC_7 = 0x08, KC_8 = 0x09, KC_9 = 0x0A, KC_0 = 0x0B, KC_MINUS = 0x0C, // - on main keyboard KC_EQUALS = 0x0D, KC_BACK = 0x0E, // backspace KC_TAB = 0x0F, KC_Q = 0x10, KC_W = 0x11, KC_E = 0x12, KC_R = 0x13, KC_T = 0x14, KC_Y = 0x15, KC_U = 0x16, KC_I = 0x17, KC_O = 0x18, KC_P = 0x19, KC_LBRACKET = 0x1A, KC_RBRACKET = 0x1B, KC_RETURN = 0x1C, // Enter on main keyboard KC_LCONTROL = 0x1D, KC_A = 0x1E, KC_S = 0x1F, KC_D = 0x20, KC_F = 0x21, KC_G = 0x22, KC_H = 0x23, KC_J = 0x24, KC_K = 0x25, KC_L = 0x26, KC_SEMICOLON = 0x27, KC_APOSTROPHE = 0x28, KC_GRAVE = 0x29, // accent KC_LSHIFT = 0x2A, KC_BACKSLASH = 0x2B, KC_Z = 0x2C, KC_X = 0x2D, KC_C = 0x2E, KC_V = 0x2F, KC_B = 0x30, KC_N = 0x31, KC_M = 0x32, KC_COMMA = 0x33, KC_PERIOD = 0x34, // . on main keyboard KC_SLASH = 0x35, // / on main keyboard KC_RSHIFT = 0x36, KC_MULTIPLY = 0x37, // * on numeric keypad KC_LMENU = 0x38, // left Alt KC_SPACE = 0x39, KC_CAPITAL = 0x3A, KC_F1 = 0x3B, KC_F2 = 0x3C, KC_F3 = 0x3D, KC_F4 = 0x3E, KC_F5 = 0x3F, KC_F6 = 0x40, KC_F7 = 0x41, KC_F8 = 0x42, KC_F9 = 0x43, KC_F10 = 0x44, KC_NUMLOCK = 0x45, KC_SCROLL = 0x46, // Scroll Lock KC_NUMPAD7 = 0x47, KC_NUMPAD8 = 0x48, KC_NUMPAD9 = 0x49, KC_SUBTRACT = 0x4A, // - on numeric keypad KC_NUMPAD4 = 0x4B, KC_NUMPAD5 = 0x4C, KC_NUMPAD6 = 0x4D, KC_ADD = 0x4E, // + on numeric keypad KC_NUMPAD1 = 0x4F, KC_NUMPAD2 = 0x50, KC_NUMPAD3 = 0x51, KC_NUMPAD0 = 0x52, KC_DECIMAL = 0x53, // . on numeric keypad KC_OEM_102 = 0x56, // < > | on UK/Germany keyboards KC_F11 = 0x57, KC_F12 = 0x58, KC_F13 = 0x64, // (NEC PC98) KC_F14 = 0x65, // (NEC PC98) KC_F15 = 0x66, // (NEC PC98) KC_KANA = 0x70, // (Japanese keyboard) KC_ABNT_C1 = 0x73, // / ? on Portugese (Brazilian) keyboards KC_CONVERT = 0x79, // (Japanese keyboard) KC_NOCONVERT = 0x7B, // (Japanese keyboard) KC_YEN = 0x7D, // (Japanese keyboard) KC_ABNT_C2 = 0x7E, // Numpad . on Portugese (Brazilian) keyboards KC_NUMPADEQUALS= 0x8D, // = on numeric keypad (NEC PC98) KC_PREVTRACK = 0x90, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard) KC_AT = 0x91, // (NEC PC98) KC_COLON = 0x92, // (NEC PC98) KC_UNDERLINE = 0x93, // (NEC PC98) KC_KANJI = 0x94, // (Japanese keyboard) KC_STOP = 0x95, // (NEC PC98) KC_AX = 0x96, // (Japan AX) KC_UNLABELED = 0x97, // (J3100) KC_NEXTTRACK = 0x99, // Next Track KC_NUMPADENTER = 0x9C, // Enter on numeric keypad KC_RCONTROL = 0x9D, KC_MUTE = 0xA0, // Mute KC_CALCULATOR = 0xA1, // Calculator KC_PLAYPAUSE = 0xA2, // Play / Pause KC_MEDIASTOP = 0xA4, // Media Stop KC_VOLUMEDOWN = 0xAE, // Volume - KC_VOLUMEUP = 0xB0, // Volume + KC_WEBHOME = 0xB2, // Web home KC_NUMPADCOMMA = 0xB3, // , on numeric keypad (NEC PC98) KC_DIVIDE = 0xB5, // / on numeric keypad KC_SYSRQ = 0xB7, KC_RMENU = 0xB8, // right Alt KC_PAUSE = 0xC5, // Pause KC_HOME = 0xC7, // Home on arrow keypad KC_UP = 0xC8, // UpArrow on arrow keypad KC_PGUP = 0xC9, // PgUp on arrow keypad KC_LEFT = 0xCB, // LeftArrow on arrow keypad KC_RIGHT = 0xCD, // RightArrow on arrow keypad KC_END = 0xCF, // End on arrow keypad KC_DOWN = 0xD0, // DownArrow on arrow keypad KC_PGDOWN = 0xD1, // PgDn on arrow keypad KC_INSERT = 0xD2, // Insert on arrow keypad KC_DELETE = 0xD3, // Delete on arrow keypad KC_LWIN = 0xDB, // Left Windows key KC_RWIN = 0xDC, // Right Windows key KC_APPS = 0xDD, // AppMenu key KC_POWER = 0xDE, // System Power KC_SLEEP = 0xDF, // System Sleep KC_WAKE = 0xE3, // System Wake KC_WEBSEARCH = 0xE5, // Web Search KC_WEBFAVORITES= 0xE6, // Web Favorites KC_WEBREFRESH = 0xE7, // Web Refresh KC_WEBSTOP = 0xE8, // Web Stop KC_WEBFORWARD = 0xE9, // Web Forward KC_WEBBACK = 0xEA, // Web Back KC_MYCOMPUTER = 0xEB, // My Computer KC_MAIL = 0xEC, // Mail KC_MEDIASELECT = 0xED // Media Select }; /** Specialised for key events */ class _OISExport KeyEvent : public EventArg { public: KeyEvent(Object* obj, KeyCode kc, unsigned int txt) : EventArg(obj), key(kc), text(txt) {} virtual ~KeyEvent() {} //! KeyCode of event const KeyCode key; //! Text character, depends on current TextTranslationMode unsigned int text; }; /** To recieve buffered keyboard input, derive a class from this, and implement the methods here. Then set the call back to your Keyboard instance with Keyboard::setEventCallback */ class _OISExport KeyListener { public: virtual ~KeyListener() {} virtual bool keyPressed(const KeyEvent &arg) = 0; virtual bool keyReleased(const KeyEvent &arg) = 0; }; /** Keyboard base class. To be implemented by specific system (ie. DirectX Keyboard) This class is useful as you remain OS independent using this common interface. */ class _OISExport Keyboard : public Object { public: virtual ~Keyboard() {}; /** @remarks Returns true if key is donwn @param key A KeyCode to check */ virtual bool isKeyDown(KeyCode key) const = 0; /** @remarks Register/unregister a Keyboard Listener - Only one allowed for simplicity. If broadcasting is neccessary, just broadcast from the callback you registered. @param keyListener Send a pointer to a class derived from KeyListener or 0 to clear the callback */ virtual void setEventCallback(KeyListener *keyListener) { mListener = keyListener;} /** @remarks Returns currently set callback.. or 0 */ KeyListener* getEventCallback() const {return mListener;} //! TextTranslation Mode enum TextTranslationMode { Off, Unicode, Ascii }; /** @remarks Enable extra processing to translate KC_*** to an actual text character based off of locale. Different managers may implement none or all. Check the translation mode after setting to be sure @param mode Off, Unicode, Ascii */ virtual void setTextTranslation(TextTranslationMode mode); /** @remarks Returns current translation mode */ TextTranslationMode getTextTranslation() const {return mTextMode;} /** @remarks Translates KeyCode to string representation. For example, KC_ENTER will be "Enter" - Locale specific of course. @param kc KeyCode to convert @returns The string as determined from the current locale */ virtual const std::string& getAsString(KeyCode kc) = 0; //! Enum of bit position of modifer enum Modifier { Shift = 0x0000001, Ctrl = 0x0000010, Alt = 0x0000100 }; /** @remarks Check modifier status */ bool isModifierDown(Modifier mod) const; /** @remarks Copies the state of the keys into the sent buffer (in the form of 1 is down and 0 is up) */ virtual void copyKeyStates(char keys[256]) const = 0; protected: Keyboard(const std::string &vendor, bool buffered, int devID, InputManager* creator) : Object(vendor, OISKeyboard, buffered, devID, creator), mModifiers(0), mListener(0), mTextMode(Unicode) {} //! Bit field that holds status of Alt, Ctrl, Shift unsigned int mModifiers; //! Used for buffered/actionmapping callback KeyListener *mListener; //! The current translation mode TextTranslationMode mTextMode; }; } #endif ois-1.3.0.dfsg0.orig/includes/OISForceFeedback.h0000664000175000017500000000714011562210433021124 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_ForceFeedBack_H #define OIS_ForceFeedBack_H #include "OISPrereqs.h" #include "OISInterface.h" #include "OISEffect.h" namespace OIS { /** Interface class for dealing with Force Feedback devices */ class _OISExport ForceFeedback : public Interface { public: ForceFeedback(); virtual ~ForceFeedback() {} /** @remarks This is like setting the master volume of an audio device. Individual effects have gain levels; however, this affects all effects at once. Note: If the device does not support master gain setting, nothing is done @param level A value between 0.0 and 1.0 represent the percentage of gain. 1.0 being the highest possible force level (means no scaling). */ virtual void setMasterGain( float level ) = 0; /** @remarks If using Force Feedback effects, this should be turned off before uploading any effects. Auto centering is the motor moving the joystick back to center. DirectInput only has an on/off setting, whereas linux has levels.. Though, we go with DI's on/off mode only Note: If the device does not support auto-centering, nothing is done @param auto_on true to turn auto centering on, false to turn off. */ virtual void setAutoCenterMode( bool auto_on ) = 0; /** @remarks Creates and Plays the effect immediately. If the device is full of effects, it will fail to be uploaded. You will know this by an invalid Effect Handle */ virtual void upload( const Effect* effect ) = 0; /** @remarks Modifies an effect that is currently playing */ virtual void modify( const Effect* effect ) = 0; /** @remarks Remove the effect from the device */ virtual void remove( const Effect* effect ) = 0; /** @remarks Get the number of supported Axes for FF usage */ virtual short getFFAxesNumber() = 0; /** @remarks Get the current load (%, in [0, 100] of the FF device memory */ virtual unsigned short getFFMemoryLoad() = 0; typedef std::multimap SupportedEffectList; /** @remarks Get a list of all supported effects */ const SupportedEffectList& getSupportedEffects() const; /** @remarks Tell if a given force / effect type pair is supported */ bool supportsEffect(Effect::EForce force, Effect::EType type) const; void _addEffectTypes( Effect::EForce force, Effect::EType type ); void _setGainSupport( bool on ); void _setAutoCenterSupport( bool on ); protected: SupportedEffectList mSupportedEffects; bool mSetGainSupport; bool mSetAutoCenterSupport; }; } #endif //OIS_ForceFeedBack_H ois-1.3.0.dfsg0.orig/includes/OISInterface.h0000664000175000017500000000253611562210433020365 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Interface_H #define OIS_Interface_H #include "OISPrereqs.h" namespace OIS { /** An Object's interface is a way to gain write access to devices which support it. For example, force feedack. */ class _OISExport Interface { public: virtual ~Interface() {}; //! Type of Interface enum IType { ForceFeedback, Reserved }; }; } #endif //OIS_Interface_H ois-1.3.0.dfsg0.orig/includes/OISObject.h0000664000175000017500000000560411562210433017672 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Object_H #define OIS_Object_H #include "OISPrereqs.h" #include "OISInterface.h" namespace OIS { /** The base class of all input types. */ class _OISExport Object { public: virtual ~Object() {} /** @remarks Get the type of device */ Type type() const { return mType; } /** @remarks Get the vender string name */ const std::string& vendor() const { return mVendor; } /** @remarks Get buffered mode - true is buffered, false otherwise */ virtual bool buffered() const { return mBuffered; } /** @remarks Returns this input object's creator */ InputManager* getCreator() const { return mCreator; } /** @remarks Sets buffered mode */ virtual void setBuffered(bool buffered) = 0; /** @remarks Used for updating call once per frame before checking state or to update events */ virtual void capture() = 0; /** @remarks This may/may not) differentiate the different controllers based on (for instance) a port number (useful for console InputManagers) */ virtual int getID() const {return mDevID;} /** @remarks If available, get an interface to write to some devices. Examples include, turning on and off LEDs, ForceFeedback, etc @param type The type of interface you are looking for */ virtual Interface* queryInterface(Interface::IType type) = 0; /** @remarks Internal... Do not call this directly. */ virtual void _initialize() = 0; protected: Object(const std::string &vendor, Type iType, bool buffered, int devID, InputManager* creator) : mVendor(vendor), mType(iType), mBuffered(buffered), mDevID(devID), mCreator(creator) {} //! Vendor name if applicable/known std::string mVendor; //! Type of controller object Type mType; //! Buffered flag bool mBuffered; //! Not fully implemented yet int mDevID; //! The creator who created this object InputManager* mCreator; }; } #endif ois-1.3.0.dfsg0.orig/includes/OISPrereqs.h0000664000175000017500000001471611562210433020111 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Prereqs_H #define OIS_Prereqs_H //----------------------------------------------------------------------------// // This Header File contains: forward declared classes // * Forward Declarations of all public API classes // * Several typedef's used around the library // * Base class component types // * Preprocessor definitons //----------------------------------------------------------------------------// //-------------- Common STL Containers ---------------------------------------// #include #include #include #include "OISConfig.h" // Default is blank for most OS's #define _OISExport //-------------- Determine Compiler --------------------------------- #if defined( _MSC_VER ) # define OIS_MSVC_COMPILER #elif defined( __GNUC__ ) # if defined( __WIN32__ ) || defined( _WIN32 ) # define OIS_MINGW_COMPILER # else # define OIS_GCC_COMPILER # endif #elif defined( __BORLANDC__ ) # define OIS_BORLAND_COMPILER #else # error No Recognized Compiler! #endif // --------------- Determine Operating System Platform --------------- #if defined( __WIN32__ ) || defined( _WIN32 ) // Windows 2000, XP, ETC # if defined ( _XBOX ) # define OIS_XBOX_PLATFORM # else # define OIS_WIN32_PLATFORM # if defined( OIS_DYNAMIC_LIB ) # undef _OISExport //Ignorable Dll interface warning... # if !defined(OIS_MINGW_COMPILER) # pragma warning (disable : 4251) # endif # if defined( OIS_NONCLIENT_BUILD ) # define _OISExport __declspec( dllexport ) # else # if defined(OIS_MINGW_COMPILER) # define _OISExport # else # define _OISExport __declspec( dllimport ) # endif # endif # endif # endif #elif defined( __APPLE_CC__ ) // Apple OS X // Device Simulator # if __IPHONE_OS_VERSION_MIN_REQUIRED >= 20201 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 20000 //# if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000 # define OIS_IPHONE_PLATFORM # else # define OIS_APPLE_PLATFORM # endif # undef _OISExport # define _OISExport __attribute__((visibility("default"))) #else //Probably Linux # define OIS_LINUX_PLATFORM #endif //Is Processor 32 or 64 bits... #if defined(__x86_64__) # define OIS_ARCH_64 #else # define OIS_ARCH_32 #endif //-------------- Common Classes, Enums, and Typdef's -------------------------// #define OIS_VERSION_MAJOR 1 #define OIS_VERSION_MINOR 3 #define OIS_VERSION_PATCH 0 #define OIS_VERSION_NAME "1.3.0" #define OIS_VERSION ((OIS_VERSION_MAJOR << 16) | (OIS_VERSION_MINOR << 8) | OIS_VERSION_PATCH) namespace OIS { //Forward Declarations class InputManager; class FactoryCreator; class Object; class Keyboard; class Mouse; class JoyStick; class MultiTouch; class KeyListener; class MouseListener; class MultiTouchListener; class JoyStickListener; class Interface; class ForceFeedback; class Effect; class Exception; //! Way to send OS nuetral parameters.. ie OS Window handles, modes, flags typedef std::multimap ParamList; //! List of FactoryCreator's typedef std::vector FactoryList; //! Map of FactoryCreator created Objects typedef std::map FactoryCreatedObject; //! Each Input class has a General Type variable, a form of RTTI enum Type { OISUnknown = 0, OISKeyboard = 1, OISMouse = 2, OISJoyStick = 3, OISTablet = 4, OISMultiTouch = 5 }; //! Map of device objects connected and their respective vendors typedef std::multimap DeviceList; //-------- Shared common components ------------------------// //! Base type for all device components (button, axis, etc) enum ComponentType { OIS_Unknown = 0, OIS_Button = 1, //ie. Key, mouse button, joy button, etc OIS_Axis = 2, //ie. A joystick or mouse axis OIS_Slider = 3, // OIS_POV = 4, //ie. Arrow direction keys OIS_Vector3 = 5 //ie. WiiMote orientation }; //! Base of all device components (button, axis, etc) class _OISExport Component { public: Component() : cType(OIS_Unknown) {}; Component(ComponentType type) : cType(type) {}; //! Indicates what type of coponent this is ComponentType cType; }; //! Button can be a keyboard key, mouse button, etc class _OISExport Button : public Component { public: Button() : Component(OIS_Button), pushed(false) {} Button(bool bPushed) : Component(OIS_Button), pushed(bPushed) {} //! true if pushed, false otherwise bool pushed; }; //! Axis component class _OISExport Axis : public Component { public: Axis() : Component(OIS_Axis), abs(0), rel(0), absOnly(false) {}; //! Absoulte and Relative value components int abs, rel; //! Indicates if this Axis only supports Absoulte (ie JoyStick) bool absOnly; //! Used internally by OIS void clear() { abs = rel = 0; } }; //! A 3D Vector component (perhaps an orientation, as in the WiiMote) class _OISExport Vector3 : public Component { public: Vector3() {} Vector3(float _x, float _y, float _z) : Component(OIS_Vector3), x(_x), y(_y), z(_z) {}; //! X component of vector float x; //! Y component of vector float y; //! Z component of vector float z; void clear() { x = y = z = 0.0f; } }; } #endif //end if prereq header defined ois-1.3.0.dfsg0.orig/includes/Makefile.am0000664000175000017500000000105011562210433017763 0ustar alessioalessiopkginclude_HEADERS = OISConfig.h \ OISEffect.h \ OISEvents.h \ OISException.h \ OISForceFeedback.h \ OISInputManager.h \ OISInterface.h \ OISJoyStick.h \ OISKeyboard.h \ OISMouse.h \ OISObject.h \ OISPrereqs.h \ OISFactoryCreator.h \ OISMultiTouch.h \ OIS.h ois-1.3.0.dfsg0.orig/includes/linux/0000775000175000017500000000000011562210433017072 5ustar alessioalessioois-1.3.0.dfsg0.orig/includes/linux/LinuxInputManager.h0000664000175000017500000000640511562210433022662 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_LinuxInputManager_H #define OIS_LinuxInputManager_H #include "linux/LinuxPrereqs.h" #include "OISFactoryCreator.h" #include "OISInputManager.h" #include namespace OIS { /** Linux X11 InputManager specialization - Using lowlevel joys */ class LinuxInputManager : public InputManager, public FactoryCreator { public: LinuxInputManager(); virtual ~LinuxInputManager(); //InputManager Overrides /** @copydoc InputManager::_initialize */ void _initialize( ParamList ¶mList ); //FactoryCreator Overrides /** @copydoc FactoryCreator::deviceList */ DeviceList freeDeviceList(); /** @copydoc FactoryCreator::totalDevices */ int totalDevices(Type iType); /** @copydoc FactoryCreator::freeDevices */ int freeDevices(Type iType); /** @copydoc FactoryCreator::vendorExist */ bool vendorExist(Type iType, const std::string & vendor); /** @copydoc FactoryCreator::createObject */ Object* createObject(InputManager *creator, Type iType, bool bufferMode, const std::string & vendor = ""); /** @copydoc FactoryCreator::destroyObject */ void destroyObject(Object* obj); //Internal Items //! Method for retrieving the XWindow Handle Window _getWindow() {return window;} //! Internal method for checking if regrabbing is needed void _setGrabState(bool grab) {mGrabs = grab;} bool _getGrabState() {return mGrabs;} //! Internal method, used for flaggin keyboard as available/unavailable for creation void _setKeyboardUsed(bool used) {keyboardUsed = used; } //! Internal method, used for flaggin mouse as available/unavailable for creation void _setMouseUsed(bool used) { mouseUsed = used; } protected: //! internal class method for dealing with param list void _parseConfigSettings( ParamList ¶mList ); //! internal class method for finding attached devices void _enumerateDevices(); //! List of unused joysticks ready to be used JoyStickInfoList unusedJoyStickList; //! Number of joysticks found char joySticks; //! Used to know if we used up keyboard bool keyboardUsed; //! Used to know if we used up mouse bool mouseUsed; //! X11 Stuff Window window; /// Keyboard, Mouse Settings bool grabMouse, grabKeyboard; bool mGrabs; bool hideMouse; }; } #endif ois-1.3.0.dfsg0.orig/includes/linux/LinuxJoyStickEvents.h0000664000175000017500000000442411562210433023213 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_JOYSTICK_H_EADER_ #define _LINUX_JOYSTICK_H_EADER_ #include "linux/LinuxPrereqs.h" #include "OISJoyStick.h" namespace OIS { /** Linux specialization of JoyStick class.. This version is favored over the other.. and has the *possibility* of Force Feedback.. notice I say possibility, i make no gaurantees under linux, as FF support is sketchy at best AFAIK. */ class LinuxJoyStick : public JoyStick { public: LinuxJoyStick(InputManager* creator, bool buffered, const JoyStickInfo& js); virtual ~LinuxJoyStick(); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type); /** @copydoc Object::_initialize */ virtual void _initialize(); /** @remarks For internal use only... Returns a structure to the manager, to make the device availiable for use again */ JoyStickInfo _getJoyInfo(); static JoyStickInfoList _scanJoys(); static void _clearJoys(JoyStickInfoList &joys); protected: int mJoyStick; LinuxForceFeedback* ff_effect; std::map mButtonMap; std::map mAxisMap; std::map mRanges; }; } #endif //_LINUX_JOYSTICK_H_EADER_ ois-1.3.0.dfsg0.orig/includes/linux/LinuxKeyboard.h0000664000175000017500000000553011562210433022026 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_KEYBOARD_H_EADER_ #define _LINUX_KEYBOARD_H_EADER_ #include "linux/LinuxPrereqs.h" #include "OISKeyboard.h" #include namespace OIS { /** Linux implementation of Keyboard object - uses x11 */ class LinuxKeyboard : public Keyboard { public: LinuxKeyboard(InputManager* creator, bool buffered, bool grab); virtual ~LinuxKeyboard(); /** @copydoc Keyboard::isKeyDown */ virtual bool isKeyDown( KeyCode key ) const; /** @copydoc Keyboard::getAsString */ virtual const std::string& getAsString( KeyCode kc ); /** @copydoc Keyboard::copyKeyStates */ virtual void copyKeyStates( char keys[256] ) const; /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); protected: inline bool _isKeyRepeat(XEvent &event) { //When a key is repeated, there will be two events: released, followed by another immediate pressed. So check to see if another pressed is present if(!XPending(display)) return false; XEvent e; XPeekEvent(display, &e); if(e.type == KeyPress && e.xkey.keycode == event.xkey.keycode && (e.xkey.time - event.xkey.time) < 2) { XNextEvent(display, &e); return true; } return false; } bool _injectKeyDown( KeySym key, int text ); bool _injectKeyUp( KeySym key ); //! 1:1 Conversion Map between X Key Events and OIS KeyCodes typedef std::map XtoOIS_KeyMap; XtoOIS_KeyMap keyConversion; //! Depressed Key List char KeyBuffer[256]; //! X11 Stuff Window window; Display *display; bool grabKeyboard; bool keyFocusLost; std::string mGetString; }; } #endif //_LINUX_KEYBOARD_H_EADER_ ois-1.3.0.dfsg0.orig/includes/linux/LinuxMouse.h0000664000175000017500000000441411562210433021356 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_MOUSE_H_EADER_ #define _LINUX_MOUSE_H_EADER_ #include "linux/LinuxPrereqs.h" #include "OISMouse.h" #include namespace OIS { class LinuxMouse : public Mouse { public: LinuxMouse(InputManager* creator, bool buffered, bool grab, bool hide); virtual ~LinuxMouse(); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @remarks Note: Calling this will also update the keyboard (X11 updates in a single event queue). Updates State and/or raises event for buffered mode.. */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); void grab(bool grab); void hide(bool hide); protected: void _processXEvents(); bool mMoved, mWarped; //Since X11 provides us with absolute values, we need to keep track of relative values long oldXMouseX, oldXMouseY, oldXMouseZ; Window window; //The X Window Display *display; //The X display Cursor cursor; //A blank cursor bool grabMouse; //Are we grabbing the mouse to the window? bool hideMouse; //Are we hiding OS mouse? bool mouseFocusLost;//Has the mouse just lost focus? }; } #endif //_LINUX_MOUSE_H_EADER_ ois-1.3.0.dfsg0.orig/includes/linux/EventHelpers.h0000664000175000017500000000326611562210433021656 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_OISEVENT_HEADER_ #define _LINUX_OISEVENT_HEADER_ #include "linux/LinuxPrereqs.h" #define OIS_MAX_DEVICES 32 #define OIS_DEVICE_NAME 128 namespace OIS { class EventUtils { public: static bool isJoyStick( int deviceID, JoyStickInfo &js ); static bool isMouse( int ) {return false;} static bool isKeyboard( int ) {return false;} //Double pointer is so that we can set the value of the sent pointer static void enumerateForceFeedback( int deviceID, LinuxForceFeedback** ff ); static void removeForceFeedback( LinuxForceFeedback** ff ); static std::string getName( int deviceID ); static std::string getUniqueId( int deviceID ); static std::string getPhysicalLocation( int deviceID ); }; } #endif ois-1.3.0.dfsg0.orig/includes/linux/LinuxPrereqs.h0000664000175000017500000000441511562210433021710 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_INPUTSYSTEM_PREREQS_H #define _LINUX_INPUTSYSTEM_PREREQS_H //Bring in any auto generated config files #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "OISPrereqs.h" //! Max number of elements to collect from buffered input #define JOY_BUFFERSIZE 64 namespace OIS { class LinuxInputManager; class LinuxKeyboard; class LinuxJoyStick; class LinuxMouse; class LinuxForceFeedback; class Range { public: Range() {}; Range(int _min, int _max) : min(_min), max(_max) {}; int min, max; }; class JoyStickInfo { public: JoyStickInfo(): devId(-1),joyFileD(-1),version(0),axes(0),buttons(0),hats(0) {} //! Device number (/dev/input/j#) or /dev/input/event# int devId; //! File descriptor int joyFileD; //! Driver version int version; //! Joy vendor std::string vendor; //! Number of axes unsigned char axes; //! Number of buttons unsigned char buttons; //! Number of hats unsigned char hats; //! Maps Linux button values to OIS buttons values std::map button_map; //! Maps Linux axis values to OIS axis std::map axis_map; //! Maps OIS axis values to it's range std::map axis_range; }; typedef std::vector< JoyStickInfo > JoyStickInfoList; } #endif //_LINUX_INPUTSYSTEM_PREREQS_H ois-1.3.0.dfsg0.orig/includes/linux/LinuxForceFeedback.h0000664000175000017500000000542311562210433022732 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_LinuxForceFeedBack_H #define OIS_LinuxForceFeedBack_H #include "linux/LinuxPrereqs.h" #include "OISForceFeedback.h" #include namespace OIS { class LinuxForceFeedback : public ForceFeedback { public: LinuxForceFeedback(int deviceID); ~LinuxForceFeedback(); /** @copydoc ForceFeedback::setMasterGain */ void setMasterGain(float); /** @copydoc ForceFeedback::setAutoCenterMode */ void setAutoCenterMode(bool); /** @copydoc ForceFeedback::upload */ void upload( const Effect* effect ); /** @copydoc ForceFeedback::modify */ void modify( const Effect* effect ); /** @copydoc ForceFeedback::remove */ void remove( const Effect* effect ); /** FF is not yet implemented fully on Linux.. just return -1 for now. todo, xxx */ short int getFFAxesNumber() { return -1; } /** @copydoc ForceFeedback::getFFMemoryLoad */ unsigned short getFFMemoryLoad(); protected: //Sets the common properties to all effects void _setCommonProperties(struct ff_effect *event, struct ff_envelope *ffenvelope, const Effect* effect, const Envelope *envelope ); //Specific Effect Settings void _updateConstantEffect( const Effect* effect ); void _updateRampEffect( const Effect* effect ); void _updatePeriodicEffect( const Effect* effect ); void _updateConditionalEffect( const Effect* effect ); //void _updateCustomEffect( const Effect* effect ); void _upload( struct ff_effect* ffeffect, const Effect* effect); void _stop( int handle); void _start( int handle); void _unload( int handle); // Map of currently uploaded effects (handle => effect) typedef std::map EffectList; EffectList mEffectList; // Joystick device (file) descriptor. int mJoyStick; }; } #endif //OIS_LinuxForceFeedBack_H ois-1.3.0.dfsg0.orig/includes/OISMouse.h0000664000175000017500000001013111562210433017543 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Mouse_H #define OIS_Mouse_H #include "OISObject.h" #include "OISEvents.h" namespace OIS { //! Button ID for mouse devices enum MouseButtonID { MB_Left = 0, MB_Right, MB_Middle, MB_Button3, MB_Button4, MB_Button5, MB_Button6, MB_Button7 }; /** Represents the state of the mouse All members are valid for both buffered and non buffered mode */ class _OISExport MouseState { public: MouseState() : width(50), height(50), buttons(0) {}; /** Represents the height/width of your display area.. used if mouse clipping or mouse grabbed in case of X11 - defaults to 50.. Make sure to set this and change when your size changes.. */ mutable int width, height; //! X Axis component Axis X; //! Y Axis Component Axis Y; //! Z Axis Component Axis Z; //! represents all buttons - bit position indicates button down int buttons; //! Button down test inline bool buttonDown( MouseButtonID button ) const { return ((buttons & ( 1L << button )) == 0) ? false : true; } //! Clear all the values void clear() { X.clear(); Y.clear(); Z.clear(); buttons = 0; } }; /** Specialised for mouse events */ class _OISExport MouseEvent : public EventArg { public: MouseEvent( Object *obj, const MouseState &ms ) : EventArg(obj), state(ms) {} virtual ~MouseEvent() {} //! The state of the mouse - including buttons and axes const MouseState &state; }; /** To recieve buffered mouse input, derive a class from this, and implement the methods here. Then set the call back to your Mouse instance with Mouse::setEventCallback */ class _OISExport MouseListener { public: virtual ~MouseListener() {} virtual bool mouseMoved( const MouseEvent &arg ) = 0; virtual bool mousePressed( const MouseEvent &arg, MouseButtonID id ) = 0; virtual bool mouseReleased( const MouseEvent &arg, MouseButtonID id ) = 0; }; /** Mouse base class. To be implemented by specific system (ie. DirectX Mouse) This class is useful as you remain OS independent using this common interface. */ class _OISExport Mouse : public Object { public: virtual ~Mouse() {} /** @remarks Register/unregister a Mouse Listener - Only one allowed for simplicity. If broadcasting is neccessary, just broadcast from the callback you registered. @param mouseListener Send a pointer to a class derived from MouseListener or 0 to clear the callback */ virtual void setEventCallback( MouseListener *mouseListener ) {mListener = mouseListener;} /** @remarks Returns currently set callback.. or 0 */ MouseListener* getEventCallback() const {return mListener;} /** @remarks Returns the state of the mouse - is valid for both buffered and non buffered mode */ const MouseState& getMouseState() const { return mState; } protected: Mouse(const std::string &vendor, bool buffered, int devID, InputManager* creator) : Object(vendor, OISMouse, buffered, devID, creator), mListener(0) {} //! The state of the mouse MouseState mState; //! Used for buffered/actionmapping callback MouseListener *mListener; }; } #endif ois-1.3.0.dfsg0.orig/includes/OISMultiTouch.h0000664000175000017500000001334711562210433020564 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_MultiTouch_H #define OIS_MultiTouch_H #include "OISObject.h" #include "OISEvents.h" #include #include #define OIS_MAX_NUM_TOUCHES 4 // 4 finger touches are probably the highest we'll ever get namespace OIS { /** Represents the state of the multi-touch device All members are valid for both buffered and non buffered mode */ //! Touch Event type enum MultiTypeEventTypeID { MT_None = 0, MT_Pressed, MT_Released, MT_Moved, MT_Cancelled }; class _OISExport MultiTouchState { public: MultiTouchState() : width(50), height(50), touchType(MT_None) {}; /** Represents the height/width of your display area.. used if touch clipping or touch grabbed in case of X11 - defaults to 50.. Make sure to set this and change when your size changes.. */ mutable int width, height; //! X Axis component Axis X; //! Y Axis Component Axis Y; //! Z Axis Component Axis Z; int touchType; inline bool touchIsType( MultiTypeEventTypeID touch ) const { return ((touchType & ( 1L << touch )) == 0) ? false : true; } //! Clear all the values void clear() { X.clear(); Y.clear(); Z.clear(); touchType = MT_None; } }; /** Specialised for multi-touch events */ class _OISExport MultiTouchEvent : public EventArg { public: MultiTouchEvent( Object *obj, const MultiTouchState &ms ) : EventArg(obj), state(ms) {} virtual ~MultiTouchEvent() {} //! The state of the touch - including axes const MultiTouchState &state; }; /** To receive buffered touch input, derive a class from this, and implement the methods here. Then set the call back to your MultiTouch instance with MultiTouch::setEventCallback */ class _OISExport MultiTouchListener { public: virtual ~MultiTouchListener() {} virtual bool touchMoved( const MultiTouchEvent &arg ) = 0; virtual bool touchPressed( const MultiTouchEvent &arg ) = 0; virtual bool touchReleased( const MultiTouchEvent &arg ) = 0; virtual bool touchCancelled( const MultiTouchEvent &arg ) = 0; }; /** MultiTouch base class. To be implemented by specific system (ie. iPhone UITouch) This class is useful as you remain OS independent using this common interface. */ class _OISExport MultiTouch : public Object { public: virtual ~MultiTouch() {} /** @remarks Register/unregister a MultiTouch Listener - Only one allowed for simplicity. If broadcasting is necessary, just broadcast from the callback you registered. @param touchListener Send a pointer to a class derived from MultiTouchListener or 0 to clear the callback */ virtual void setEventCallback( MultiTouchListener *touchListener ) {mListener = touchListener;} /** @remarks Returns currently set callback.. or 0 */ MultiTouchListener* getEventCallback() {return mListener;} /** @remarks Clear out the set of input states. Should be called after input has been processed by the application */ void clearStates(void) { mStates.clear(); } /** @remarks Returns the state of the touch - is valid for both buffered and non buffered mode */ std::vector getMultiTouchStates() const { return mStates; } /** @remarks Returns the first n touch states. Useful if you know your app only needs to process n touches. The return value is a vector to allow random access */ const std::vector getFirstNTouchStates(int n) { std::vector states; for( unsigned int i = 0; i < mStates.size(); i++ ) { if(!(mStates[i].touchIsType(MT_None))) { states.push_back(mStates[i]); } } return states; } /** @remarks Returns the first n touch states. Useful if you know your app only needs to process n touches. The return value is a vector to allow random access */ const std::vector getMultiTouchStatesOfType(MultiTypeEventTypeID type) { std::vector states; for( unsigned int i = 0; i < mStates.size(); i++ ) { if(mStates[i].touchIsType(type)) { states.push_back(mStates[i]); } } return states; } protected: MultiTouch(const std::string &vendor, bool buffered, int devID, InputManager* creator) : Object(vendor, OISMultiTouch, buffered, devID, creator), mListener(0) {} //! The state of the touch device, implemented in a vector to store the state from each finger touch std::vector mStates; //! Used for buffered/actionmapping callback MultiTouchListener *mListener; }; } #endif ois-1.3.0.dfsg0.orig/includes/OISInputManager.h0000664000175000017500000001367711562210433021067 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_InputManager_H #define OIS_InputManager_H #include "OISPrereqs.h" namespace OIS { //Forward declare a couple of classes we might use later class LIRCFactoryCreator; class WiiMoteFactoryCreator; /** Base Manager class. No longer a Singleton; so feel free to create as many InputManager's as you have windows. */ class _OISExport InputManager { public: /** @remarks Returns version number (useful in DLL/SO libs) @returns Bits: 1-8 Patch number, 9-16 Minor version, 17-32 Major version */ static unsigned int getVersionNumber(); /** @remarks Returns version string (useful in DLL/SO libs) @returns Version name */ const std::string &getVersionName(); /** @remarks Creates appropriate input system dependent on platform. @param winHandle Contains OS specific window handle (such as HWND or X11 Window) @returns A pointer to the created manager, or raises Exception */ static InputManager* createInputSystem( std::size_t winHandle ); /** @remarks Creates appropriate input system dependent on platform. @param paramList ParamList contains OS specific info (such as HWND and HINSTANCE for window apps), and access mode. @returns A pointer to the created manager, or raises Exception */ static InputManager* createInputSystem( ParamList ¶mList ); /** @remarks Destroys the InputManager @param manager Manager to destroy */ static void destroyInputSystem(InputManager* manager); /** @remarks Gets the name of the current platform input system */ const std::string& inputSystemName(); /** @remarks Returns the number of the specified OIS::Type devices discovered by OIS @param iType Type that you are interested in */ int getNumberOfDevices( Type iType ); /** @remarks Lists all unused devices @returns DeviceList which contains Type and vendor of device */ DeviceList listFreeDevices(); /** @remarks Tries to create an object with the specified vendor. If you have no preference of vendor, leave vender as default (""). Raises exception on failure */ Object* createInputObject( Type iType, bool bufferMode, const std::string &vendor = ""); /** @remarks Destroys Input Object */ void destroyInputObject( Object* obj ); /** @remarks Add a custom object factory to allow for user controls. @param factory Factory instance to add @notes Make sure you do not delete the factory before devices created from the factory are destroyed (either by calling RemoveFactoryCreator, or shutting down the input system). Order should be something like the following: * Create Input System * Create Factory Instance * AddFactoryCreator(factory) * Create a device from the InputManager (device created by factory) * One of the follwoing: * removeFactoryCreator(factory) * inputManager->destroyInputObject(obj) * destroyInputSystem(inputManager) * destroy Factory Instance You can safely delete the factory instance once you have removed it or shut down the input manager. */ void addFactoryCreator( FactoryCreator* factory ); /** @remarks Remove a previously added object factory @param factory Factory object to remove. @notes Removing a factory will automatically destroy any Objects created from the factory */ void removeFactoryCreator( FactoryCreator* factory ); //! All generic devices OIS supports internally (if they are compiled in) enum AddOnFactories { AddOn_All = 0, //All Devices AddOn_LIRC = 1, //PC Linux Infrared Remote Control AddOn_WiiMote = 2 //PC WiiMote Support }; /** @remarks Enable an addon FactoryCreator extension. By default, none are activated. If the desired support was not compiled in, this has no effect. Calling multiple times has no effect. Once activated, there is no way to deactivate - simply destroy and recreate input manager. */ void enableAddOnFactory(AddOnFactories factory); protected: /** @remarks Called from createInputSystem, gives derived input class a chance to setup after it is created */ virtual void _initialize(ParamList ¶mList) = 0; /** @remarks Derived classes must provide input system name */ InputManager(const std::string& name); /** @remarks Virtual Destructor - this base class will clean up all devices still opened in mFactoryObjects list */ virtual ~InputManager(); //! OIS Version name const std::string m_VersionName; //! FactoryCreator list FactoryList mFactories; //! Factory created objects - useful so we can find creator to send destruction request to FactoryCreatedObject mFactoryObjects; //! Name of the input system const std::string mInputSystemName; //! Extra factory (not enabled by default) LIRCFactoryCreator *m_lircSupport; WiiMoteFactoryCreator *m_wiiMoteSupport; }; } #endif ois-1.3.0.dfsg0.orig/includes/OISJoyStick.h0000664000175000017500000001555611562210433020232 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Joystick_H #define OIS_Joystick_H #include "OISObject.h" #include "OISEvents.h" namespace OIS { /** @remarks default sensitivity for vector3 component of joystick */ #define OIS_JOYSTICK_VECTOR3_DEFAULT 2.28f //! POV / HAT Joystick component class _OISExport Pov : public Component { public: Pov() : Component(OIS_POV), direction(0) {} static const int Centered = 0x00000000; static const int North = 0x00000001; static const int South = 0x00000010; static const int East = 0x00000100; static const int West = 0x00001000; static const int NorthEast = 0x00000101; static const int SouthEast = 0x00000110; static const int NorthWest = 0x00001001; static const int SouthWest = 0x00001010; int direction; }; //! A sliding axis - only used in Win32 Right Now class _OISExport Slider : public Component { public: Slider() : Component(OIS_Slider), abX(0), abY(0) {}; //! true if pushed, false otherwise int abX, abY; }; /** Represents the state of the joystick All members are valid for both buffered and non buffered mode Sticks with zero values are not present on the device */ class _OISExport JoyStickState { public: //! Constructor JoyStickState() { clear(); } //! Represents all the buttons (uses a bitset) std::vector mButtons; //! Represents all the single axes on the device std::vector mAxes; //! Represents the value of a POV. Maximum of 4 Pov mPOV[4]; //! Represent the max sliders Slider mSliders[4]; //! Represents all Vector type controls the device exports std::vector mVectors; //! internal method to reset all variables to initial values void clear() { for( std::vector::iterator i = mButtons.begin(), e = mButtons.end(); i != e; ++i ) { (*i) = false; } for( std::vector::iterator i = mAxes.begin(), e = mAxes.end(); i != e; ++i ) { i->absOnly = true; //Currently, joysticks only report Absolute values i->clear(); } for( std::vector::iterator i = mVectors.begin(), e = mVectors.end(); i != e; ++i ) { i->clear(); } for( int i = 0; i < 4; ++i ) { mPOV[i].direction = Pov::Centered; mSliders[i].abX = mSliders[i].abY = 0; } } }; /** Specialised for joystick events */ class _OISExport JoyStickEvent : public EventArg { public: JoyStickEvent( Object* obj, const JoyStickState &st ) : EventArg(obj), state(st) {} virtual ~JoyStickEvent() {} const JoyStickState &state; }; /** To recieve buffered joystick input, derive a class from this, and implement the methods here. Then set the call back to your JoyStick instance with JoyStick::setEventCallback Each JoyStick instance can use the same callback class, as a devID number will be provided to differentiate between connected joysticks. Of course, each can have a seperate callback instead. */ class _OISExport JoyStickListener { public: virtual ~JoyStickListener() {} /** @remarks Joystick button down event */ virtual bool buttonPressed( const JoyStickEvent &arg, int button ) = 0; /** @remarks Joystick button up event */ virtual bool buttonReleased( const JoyStickEvent &arg, int button ) = 0; /** @remarks Joystick axis moved event */ virtual bool axisMoved( const JoyStickEvent &arg, int axis ) = 0; //-- Not so common control events, so are not required --// //! Joystick Event, and sliderID virtual bool sliderMoved( const JoyStickEvent &, int index) {return true;} //! Joystick Event, and povID virtual bool povMoved( const JoyStickEvent &arg, int index) {return true;} //! Joystick Event, and Vector3ID virtual bool vector3Moved( const JoyStickEvent &arg, int index) {return true;} }; /** Joystick base class. To be implemented by specific system (ie. DirectX joystick) This class is useful as you remain OS independent using this common interface. */ class _OISExport JoyStick : public Object { public: virtual ~JoyStick() {} /** @remarks Returns the number of requested components @param cType The ComponentType you are interested in knowing about */ int getNumberOfComponents(ComponentType cType) const; /** @remarks Sets a cutoff limit for changes in the Vector3 component for movement to be ignored. Helps reduce much event traffic for frequent small/sensitive changes @param degrees The degree under which Vector3 events should be discarded */ void setVector3Sensitivity(float degrees = OIS_JOYSTICK_VECTOR3_DEFAULT); /** @remarks Returns the sensitivity cutoff for Vector3 Component */ float getVector3Sensitivity() const; /** @remarks Register/unregister a JoyStick Listener - Only one allowed for simplicity. If broadcasting is neccessary, just broadcast from the callback you registered. @param joyListener Send a pointer to a class derived from JoyStickListener or 0 to clear the callback */ virtual void setEventCallback( JoyStickListener *joyListener ); /** @remarks Returns currently set callback.. or null */ JoyStickListener* getEventCallback() const; /** @remarks Returns the state of the joystick - is valid for both buffered and non buffered mode */ const JoyStickState& getJoyStickState() const { return mState; } //! The minimal axis value static const int MIN_AXIS = -32768; //! The maximum axis value static const int MAX_AXIS = 32767; protected: JoyStick(const std::string &vendor, bool buffered, int devID, InputManager* creator); //! Number of sliders int mSliders; //! Number of POVs int mPOVs; //! The JoyStickState structure (contains all component values) JoyStickState mState; //! The callback listener JoyStickListener *mListener; //! Adjustment factor for orientation vector accuracy float mVector3Sensitivity; }; } #endif ois-1.3.0.dfsg0.orig/includes/OISEffect.h0000664000175000017500000002042611562210433017657 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Effect_H #define OIS_Effect_H #include "OISPrereqs.h" namespace OIS { //Predeclare some Effect Property structs class ForceEffect; class ConstantEffect; class RampEffect; class PeriodicEffect; class ConditionalEffect; /** Force Feedback is a relatively complex set of properties to upload to a device. The best place for information on the different properties, effects, etc is in the DX Documentation and MSDN - there are even pretty graphs ther =) As this class is modeled on the the DX interface you can apply that same knowledge to creating effects via this class on any OS supported by OIS. In anycase, this is the main class you will be using. There is *absolutely* no need to instance any of the supporting ForceEffect classes yourself. */ class _OISExport Effect { /** hidden so this class cannot be instanced with default constructor */ Effect(); public: //! Type of force enum EForce { UnknownForce = 0, ConstantForce, RampForce, PeriodicForce, ConditionalForce, CustomForce, _ForcesNumber // Always keep in last position. }; static const char* getForceTypeName(EForce eValue); //! Type of effect enum EType { //Type ----- Pairs with force: Unknown = 0, //UnknownForce Constant, //ConstantForce Ramp, //RampForce Square, //PeriodicForce Triangle, //PeriodicForce Sine, //PeriodicForce SawToothUp, //PeriodicForce SawToothDown,//PeriodicForce Friction, //ConditionalForce Damper, //ConditionalForce Inertia, //ConditionalForce Spring, //ConditionalForce Custom, //CustomForce _TypesNumber // Always keep in last position. }; static const char* getEffectTypeName(EType eValue); //! Direction of the Force enum EDirection { NorthWest, North, NorthEast, East, SouthEast, South, SouthWest, West, _DirectionsNumber // Always keep in last position. }; static const char* getDirectionName(EDirection eValue); /** This constructor allows you to set the force type and effect. */ Effect(EForce ef, EType et); virtual ~Effect(); const EForce force; const EType type; //Infinite Time static const unsigned int OIS_INFINITE = 0xFFFFFFFF; //-------------------------------------------------------------------// //--- Set these variables before uploading or modifying an effect ---// //Direction to apply to the force - affects two axes+ effects EDirection direction; //Number of button triggering an effect (-1 means no trigger) short trigger_button; //Time to wait before an effect can be re-triggered (microseconds) unsigned int trigger_interval; //Duration of an effect (microseconds) unsigned int replay_length; //Time to wait before to start playing an effect (microseconds) unsigned int replay_delay; //Get the specific Force Effect. This should be cast depending on the EForce ForceEffect* getForceEffect() const; /** @remarks Set the number of Axes to use before the initial creation of the effect. Can only be done prior to creation! Use the FF interface to determine how many axes can be used (are availiable) */ void setNumAxes(short nAxes); /** @remarks Returns the number of axes used in this effect */ short getNumAxes() const; //------------- Library Internal -------------------------------------// /** set internally.. do not change or you will not be able to upload/stop this effect any more. It will become lost. It is mutable so even with const reference it can/will be changed by this lib */ mutable int _handle; protected: ForceEffect* effect; //Properties depend on EForce short axes; //Number of axes to use in effect }; //-----------------------------------------------------------------------------// /** Base class of all effect property classes */ class _OISExport ForceEffect { public: virtual ~ForceEffect() {} }; //-----------------------------------------------------------------------------// /** An optional envelope to be applied to the start/end of an effect. If any of these values are nonzero, then the envelope will be used in setting up the effect. */ class _OISExport Envelope : public ForceEffect { public: Envelope() : attackLength(0), attackLevel(0), fadeLength(0), fadeLevel(0) {} #if defined(OIS_MSVC_COMPILER) #pragma warning (push) #pragma warning (disable : 4800) #endif bool isUsed() const { return attackLength | attackLevel | fadeLength | fadeLevel; } #if defined(OIS_MSVC_COMPILER) #pragma warning (pop) #endif // Duration of the attack (microseconds) unsigned int attackLength; // Absolute level at the beginning of the attack (0 to 10K) // (automatically signed when necessary by FF core according to effect level sign) unsigned short attackLevel; // Duration of fade (microseconds) unsigned int fadeLength; // Absolute level at the end of fade (0 to 10K) // (automatically signed when necessary by FF core according to effect level sign) unsigned short fadeLevel; }; //-----------------------------------------------------------------------------// /** Use this class when dealing with Force type of Constant */ class _OISExport ConstantEffect : public ForceEffect { public: ConstantEffect() : level(5000) {} class Envelope envelope; //Optional envolope signed short level; //-10K to +10k }; //-----------------------------------------------------------------------------// /** Use this class when dealing with Force type of Ramp */ class _OISExport RampEffect : public ForceEffect { public: RampEffect() : startLevel(0), endLevel(0) {} class Envelope envelope; //Optional envelope signed short startLevel; //-10K to +10k signed short endLevel; //-10K to +10k }; //-----------------------------------------------------------------------------// /** Use this class when dealing with Force type of Periodic */ class _OISExport PeriodicEffect : public ForceEffect { public: PeriodicEffect() : magnitude(0), offset(0), phase(0), period(0) {} class Envelope envelope; //Optional Envelope unsigned short magnitude; //0 to 10,0000 signed short offset; unsigned short phase; //Position at which playback begins 0 to 35,999 unsigned int period; //Period of effect (microseconds) }; //-----------------------------------------------------------------------------// /** Use this class when dealing with Force type of Condional */ class _OISExport ConditionalEffect : public ForceEffect { public: ConditionalEffect() : rightCoeff(0), leftCoeff(0), rightSaturation(0), leftSaturation(0), deadband(0), center(0) {} signed short rightCoeff; //-10k to +10k (Positive Coeff) signed short leftCoeff; //-10k to +10k (Negative Coeff) unsigned short rightSaturation; //0 to 10k (Pos Saturation) unsigned short leftSaturation; //0 to 10k (Neg Saturation) //Region around center in which the condition is not active, in the range //from 0 through 10,000 unsigned short deadband; //(Offset in DX) -10k and 10k signed short center; }; } #endif //OIS_Effect_H ois-1.3.0.dfsg0.orig/includes/SDL/0000775000175000017500000000000011562210433016355 5ustar alessioalessioois-1.3.0.dfsg0.orig/includes/SDL/SDLInputManager.h0000664000175000017500000000447211562210433021472 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_SDLInputManager_H #define OIS_SDLInputManager_H #include "OISInputManager.h" #include "SDL/SDLPrereqs.h" namespace OIS { /** SDL Input Manager wrapper */ class SDLInputManager : public InputManager { public: SDLInputManager(); virtual ~SDLInputManager(); /** @copydoc InputManager::inputSystemName */ virtual const std::string& inputSystemName() { return iName; } /** @copydoc InputManager::numJoysticks */ virtual int numJoySticks(); /** @copydoc InputManager::numMice */ virtual int numMice(); /** @copydoc InputManager::numKeyBoards */ virtual int numKeyboards(); /** @copydoc InputManager::createInputObject */ Object* createInputObject( Type iType, bool bufferMode ); /** @copydoc InputManager::destroyInputObject */ void destroyInputObject( Object* obj ); /** @copydoc InputManager::_initialize */ void _initialize( ParamList ¶mList ); //Utility methods to coordinate between mouse and keyboard grabbing bool _getGrabMode() {return mGrabbed;}; void _setGrabMode(bool grabbed) {mGrabbed = grabbed;} protected: //! internal class method for dealing with param list void _parseConfigSettings( ParamList ¶mList ); //! internal class method for finding attached devices void _enumerateDevices(); static const std::string iName; bool mGrabbed; }; } #endif ois-1.3.0.dfsg0.orig/includes/SDL/SDLPrereqs.h0000664000175000017500000000232211562210433020511 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_SDLPrereqs_H #define OIS_SDLPrereqs_H #include "OISPrereqs.h" #ifdef OIS_APPLE_PLATFORM # include #else # include #endif #define OIS_SDL_KEY_BUFF 16 #define OIS_SDL_MOUSE_BUFF 50 #define OIS_SDL_JOY_BUFF 80 #endif ois-1.3.0.dfsg0.orig/includes/SDL/SDLKeyboard.h0000664000175000017500000000427111562210433020635 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _OIS_SDLKEYBOARD_H #define _OIS_SDLKEYBOARD_H #include "OISKeyboard.h" #include "SDL/SDLPrereqs.h" namespace OIS { class SDLKeyboard : public Keyboard { public: /** @remarks Constructor @param buffered True for buffered input mode */ SDLKeyboard( bool buffered ); virtual ~SDLKeyboard(); /** @copydoc Keyboard::isKeyDown */ virtual bool isKeyDown( KeyCode key ); /** @copydoc Keyboard::getAsString */ virtual const std::string& getAsString( KeyCode kc ); /** @copydoc Keyboard::copyKeyStates */ virtual void copyKeyStates( char keys[256] ); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); /** @copydoc Object::setTextTranslation */ virtual void setTextTranslation( TextTranslationMode mode ); protected: SDLKeyboard() {} typedef std::map KeyMap; KeyMap mKeyMap; unsigned char KeyBuffer[256]; Uint8* mSDLBuff; std::string mGetString; }; } #endif ois-1.3.0.dfsg0.orig/includes/SDL/SDLJoyStick.h0000664000175000017500000000000011562210433020616 0ustar alessioalessioois-1.3.0.dfsg0.orig/includes/SDL/SDLMouse.h0000664000175000017500000000321311562210433020160 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _OIS_SDLMOUSE_H #define _OIS_SDLMOUSE_H #include "OISMouse.h" #include "SDL/SDLPrereqs.h" namespace OIS { class SDLMouse : public Mouse { public: SDLMouse( bool buffered ); virtual ~SDLMouse(); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); void _setGrab(bool grabbed); void _setVisible(bool visible); protected: SDLMouse() {} bool mGrabbed; bool mRegainFocus; }; } #endif ois-1.3.0.dfsg0.orig/bootstrap0000664000175000017500000000052711562210433016071 0ustar alessioalessio#!/bin/sh # Deal with some gentoo-specific issues export WANT_AUTOMAKE='1.7' export WANT_AUTOCONF='2.5' # clean up files which cause confusion when switch versions of auto* rm -rf autom4te.cache # Fire up autotools libtoolize --force --copy aclocal $ACLOCAL_FLAGS autoheader automake --include-deps --add-missing --foreign --copy autoconf ois-1.3.0.dfsg0.orig/LinuxCB/0000775000175000017500000000000011562210433015431 5ustar alessioalessioois-1.3.0.dfsg0.orig/LinuxCB/OIS.cbp0000664000175000017500000001426311562210433016557 0ustar alessioalessio ois-1.3.0.dfsg0.orig/LinuxCB/ActionMapOgreDemo.cbp0000664000175000017500000000432211562210433021415 0ustar alessioalessio ois-1.3.0.dfsg0.orig/LinuxCB/ConsoleDemo.cbp0000664000175000017500000000154411562210433020332 0ustar alessioalessio ois-1.3.0.dfsg0.orig/LinuxCB/LinuxOIS.workspace0000664000175000017500000000061111562210433021021 0ustar alessioalessio ois-1.3.0.dfsg0.orig/configure.ac0000664000175000017500000000135211562210433016414 0ustar alessioalessio# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.50) AC_INIT( [OIS], 1.3.0 ) AC_CANONICAL_TARGET AM_INIT_AUTOMAKE( [OIS], 1.3.0 ) AM_CONFIG_HEADER([includes/config.h]) dnl Check for programs AC_PROG_CC AC_PROG_CXX AM_PROG_CC_C_O AC_PROG_INSTALL AM_PROG_LIBTOOL dnl Checking for STLPort OIS_USE_STLPORT CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LIBS="$LIBS" dnl Detect X11 AC_CHECK_HEADERS([X11/Xaw/Command.h],, [AC_MSG_ERROR("libxaw headers not found")]) dnl Added for BSD's AC_PROG_LIBTOOL AC_CONFIG_FILES([Makefile includes/Makefile src/Makefile demos/Makefile OIS.pc]) AC_OUTPUT ois-1.3.0.dfsg0.orig/src/0000775000175000017500000000000011563205244014721 5ustar alessioalessioois-1.3.0.dfsg0.orig/src/Makefile.am0000664000175000017500000000132711562210433016753 0ustar alessioalessioINCLUDES = $(STLPORT_CFLAGS) -I$(top_srcdir)/includes $(CFLAGS) -I/usr/X11R6/include lib_LTLIBRARIES=libOIS.la libOIS_la_SOURCES = OISInputManager.cpp \ OISObject.cpp \ OISEffect.cpp \ OISJoyStick.cpp \ OISKeyboard.cpp \ OISForceFeedback.cpp \ OISException.cpp \ ./linux/EventHelpers.cpp \ ./linux/LinuxInputManager.cpp \ ./linux/LinuxJoyStickEvents.cpp \ ./linux/LinuxForceFeedback.cpp \ ./linux/LinuxKeyboard.cpp \ ./linux/LinuxMouse.cpp libOIS_la_LDFLAGS = -release @PACKAGE_VERSION@ #libOIS_la_LDFLAGS = -version-info $(shell echo "@PACKAGE_VERSION@" | tr '.' ':') libOIS_la_LIBADD = $(STLPORT_LIBS) -L/usr/X11R6/lib -lX11 #eof "$Id: Makefile.am,v 1.15.2.1 2008/02/14 03:33:36 pjcast Exp $" ois-1.3.0.dfsg0.orig/src/linux/0000775000175000017500000000000011562210433016053 5ustar alessioalessioois-1.3.0.dfsg0.orig/src/linux/LinuxForceFeedback.cpp0000664000175000017500000004317011562210433022247 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "linux/LinuxForceFeedback.h" #include "OISException.h" #include #include #include using namespace OIS; // 0 = No trace; 1 = Important traces; 2 = Debug traces #define OIS_LINUX_JOYFF_DEBUG 1 #ifdef OIS_LINUX_JOYFF_DEBUG # include using namespace std; #endif //--------------------------------------------------------------// LinuxForceFeedback::LinuxForceFeedback(int deviceID) : ForceFeedback(), mJoyStick(deviceID) { } //--------------------------------------------------------------// LinuxForceFeedback::~LinuxForceFeedback() { // Unload all effects. for(EffectList::iterator i = mEffectList.begin(); i != mEffectList.end(); ++i ) { struct ff_effect *linEffect = i->second; if( linEffect ) _unload(linEffect->id); } mEffectList.clear(); } //--------------------------------------------------------------// unsigned short LinuxForceFeedback::getFFMemoryLoad() { int nEffects = -1; if (ioctl(mJoyStick, EVIOCGEFFECTS, &nEffects) == -1) OIS_EXCEPT(E_General, "Unknown error reading max number of uploaded effects."); #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << "LinuxForceFeedback("<< mJoyStick << ") : Read device max number of uploaded effects : " << nEffects << endl; #endif return (unsigned short int)(nEffects > 0 ? 100.0*mEffectList.size()/nEffects : 100); } //--------------------------------------------------------------// void LinuxForceFeedback::setMasterGain(float value) { if (!mSetGainSupport) { #if (OIS_LINUX_JOYFF_DEBUG > 0) cout << "LinuxForceFeedback("<< mJoyStick << ") : Setting master gain " << "is not supported by the device" << endl; #endif return; } struct input_event event; memset(&event, 0, sizeof(event)); event.type = EV_FF; event.code = FF_GAIN; if (value < 0.0) value = 0.0; else if (value > 1.0) value = 1.0; event.value = (__s32)(value * 0xFFFFUL); #if (OIS_LINUX_JOYFF_DEBUG > 0) cout << "LinuxForceFeedback("<< mJoyStick << ") : Setting master gain to " << value << " => " << event.value << endl; #endif if (write(mJoyStick, &event, sizeof(event)) != sizeof(event)) { OIS_EXCEPT(E_General, "Unknown error changing master gain."); } } //--------------------------------------------------------------// void LinuxForceFeedback::setAutoCenterMode(bool enabled) { if (!mSetAutoCenterSupport) { #if (OIS_LINUX_JOYFF_DEBUG > 0) cout << "LinuxForceFeedback("<< mJoyStick << ") : Setting auto-center mode " << "is not supported by the device" << endl; #endif return; } struct input_event event; memset(&event, 0, sizeof(event)); event.type = EV_FF; event.code = FF_AUTOCENTER; event.value = (__s32)(enabled*0xFFFFFFFFUL); #if (OIS_LINUX_JOYFF_DEBUG > 0) cout << "LinuxForceFeedback("<< mJoyStick << ") : Toggling auto-center to " << enabled << " => 0x" << hex << event.value << dec << endl; #endif if (write(mJoyStick, &event, sizeof(event)) != sizeof(event)) { OIS_EXCEPT(E_General, "Unknown error toggling auto-center."); } } //--------------------------------------------------------------// void LinuxForceFeedback::upload( const Effect* effect ) { switch( effect->force ) { case OIS::Effect::ConstantForce: _updateConstantEffect(effect); break; case OIS::Effect::ConditionalForce: _updateConditionalEffect(effect); break; case OIS::Effect::PeriodicForce: _updatePeriodicEffect(effect); break; case OIS::Effect::RampForce: _updateRampEffect(effect); break; case OIS::Effect::CustomForce: //_updateCustomEffect(effect); //break; default: OIS_EXCEPT(E_NotImplemented, "Requested force not implemented yet, sorry!"); break; } } //--------------------------------------------------------------// void LinuxForceFeedback::modify( const Effect* effect ) { upload(effect); } //--------------------------------------------------------------// void LinuxForceFeedback::remove( const Effect* effect ) { //Get the effect - if it exists EffectList::iterator i = mEffectList.find(effect->_handle); if( i != mEffectList.end() ) { struct ff_effect *linEffect = i->second; if( linEffect ) { _stop(effect->_handle); _unload(effect->_handle); free(linEffect); mEffectList.erase(i); } else mEffectList.erase(i); } } //--------------------------------------------------------------// // To Signed16/Unsigned15 safe conversions #define MaxUnsigned15Value 0x7FFF #define toUnsigned15(value) \ (__u16)((value) < 0 ? 0 : ((value) > MaxUnsigned15Value ? MaxUnsigned15Value : (value))) #define MaxSigned16Value 0x7FFF #define MinSigned16Value -0x7FFF #define toSigned16(value) \ (__s16)((value) < MinSigned16Value ? MinSigned16Value : ((value) > MaxSigned16Value ? MaxSigned16Value : (value))) // OIS to Linux duration #define LinuxInfiniteDuration 0xFFFF #define OISDurationUnitMS 1000 // OIS duration unit (microseconds), expressed in milliseconds (theLinux duration unit) // linux/input.h : All duration values are expressed in ms. Values above 32767 ms (0x7fff) // should not be used and have unspecified results. #define LinuxDuration(oisDuration) ((oisDuration) == Effect::OIS_INFINITE ? LinuxInfiniteDuration \ : toUnsigned15((oisDuration)/OISDurationUnitMS)) // OIS to Linux levels #define OISMaxLevel 10000 #define LinuxMaxLevel 0x7FFF // linux/input.h : Valid range for the attack and fade levels is 0x0000 - 0x7fff #define LinuxPositiveLevel(oisLevel) toUnsigned15(LinuxMaxLevel*(long)(oisLevel)/OISMaxLevel) #define LinuxSignedLevel(oisLevel) toSigned16(LinuxMaxLevel*(long)(oisLevel)/OISMaxLevel) //--------------------------------------------------------------// void LinuxForceFeedback::_setCommonProperties(struct ff_effect *event, struct ff_envelope *ffenvelope, const Effect* effect, const Envelope *envelope ) { memset(event, 0, sizeof(struct ff_effect)); if (envelope && ffenvelope && envelope->isUsed()) { ffenvelope->attack_length = LinuxDuration(envelope->attackLength); ffenvelope->attack_level = LinuxPositiveLevel(envelope->attackLevel); ffenvelope->fade_length = LinuxDuration(envelope->fadeLength); ffenvelope->fade_level = LinuxPositiveLevel(envelope->fadeLevel); } #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << endl; if (envelope && ffenvelope) { cout << " Enveloppe :" << endl << " AttackLen : " << envelope->attackLength << " => " << ffenvelope->attack_length << endl << " AttackLvl : " << envelope->attackLevel << " => " << ffenvelope->attack_level << endl << " FadeLen : " << envelope->fadeLength << " => " << ffenvelope->fade_length << endl << " FadeLvl : " << envelope->fadeLevel << " => " << ffenvelope->fade_level << endl; } #endif event->direction = (__u16)(1 + (effect->direction*45.0+135.0)*0xFFFFUL/360.0); #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << " Direction : " << Effect::getDirectionName(effect->direction) << " => 0x" << hex << event->direction << dec << endl; #endif // TODO trigger_button 0 vs. -1 event->trigger.button = effect->trigger_button; // < 0 ? 0 : effect->trigger_button; event->trigger.interval = LinuxDuration(effect->trigger_interval); #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << " Trigger :" << endl << " Button : " << effect->trigger_button << " => " << event->trigger.button << endl << " Interval : " << effect->trigger_interval << " => " << event->trigger.interval << endl; #endif event->replay.length = LinuxDuration(effect->replay_length); event->replay.delay = LinuxDuration(effect->replay_delay); #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << " Replay :" << endl << " Length : " << effect->replay_length << " => " << event->replay.length << endl << " Delay : " << effect->replay_delay << " => " << event->replay.delay << endl; #endif } //--------------------------------------------------------------// void LinuxForceFeedback::_updateConstantEffect( const Effect* eff ) { struct ff_effect event; ConstantEffect *effect = static_cast(eff->getForceEffect()); _setCommonProperties(&event, &event.u.constant.envelope, eff, &effect->envelope); event.type = FF_CONSTANT; event.id = -1; event.u.constant.level = LinuxSignedLevel(effect->level); #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << " Level : " << effect->level << " => " << event.u.constant.level << endl; #endif _upload(&event, eff); } //--------------------------------------------------------------// void LinuxForceFeedback::_updateRampEffect( const Effect* eff ) { struct ff_effect event; RampEffect *effect = static_cast(eff->getForceEffect()); _setCommonProperties(&event, &event.u.constant.envelope, eff, &effect->envelope); event.type = FF_RAMP; event.id = -1; event.u.ramp.start_level = LinuxSignedLevel(effect->startLevel); event.u.ramp.end_level = LinuxSignedLevel(effect->endLevel); #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << " StartLevel : " << effect->startLevel << " => " << event.u.ramp.start_level << endl << " EndLevel : " << effect->endLevel << " => " << event.u.ramp.end_level << endl; #endif _upload(&event, eff); } //--------------------------------------------------------------// void LinuxForceFeedback::_updatePeriodicEffect( const Effect* eff ) { struct ff_effect event; PeriodicEffect *effect = static_cast(eff->getForceEffect()); _setCommonProperties(&event, &event.u.periodic.envelope, eff, &effect->envelope); event.type = FF_PERIODIC; event.id = -1; switch( eff->type ) { case OIS::Effect::Square: event.u.periodic.waveform = FF_SQUARE; break; case OIS::Effect::Triangle: event.u.periodic.waveform = FF_TRIANGLE; break; case OIS::Effect::Sine: event.u.periodic.waveform = FF_SINE; break; case OIS::Effect::SawToothUp: event.u.periodic.waveform = FF_SAW_UP; break; case OIS::Effect::SawToothDown: event.u.periodic.waveform = FF_SAW_DOWN; break; // Note: No support for Custom periodic force effect for the moment //case OIS::Effect::Custom: //event.u.periodic.waveform = FF_CUSTOM; //break; default: OIS_EXCEPT(E_General, "No such available effect for Periodic force!"); break; } event.u.periodic.period = LinuxDuration(effect->period); event.u.periodic.magnitude = LinuxPositiveLevel(effect->magnitude); event.u.periodic.offset = LinuxPositiveLevel(effect->offset); event.u.periodic.phase = (__u16)(effect->phase*event.u.periodic.period/36000.0); // ????? // Note: No support for Custom periodic force effect for the moment event.u.periodic.custom_len = 0; event.u.periodic.custom_data = 0; #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << " Magnitude : " << effect->magnitude << " => " << event.u.periodic.magnitude << endl << " Period : " << effect->period << " => " << event.u.periodic.period << endl << " Offset : " << effect->offset << " => " << event.u.periodic.offset << endl << " Phase : " << effect->phase << " => " << event.u.periodic.phase << endl; #endif _upload(&event, eff); } //--------------------------------------------------------------// void LinuxForceFeedback::_updateConditionalEffect( const Effect* eff ) { struct ff_effect event; ConditionalEffect *effect = static_cast(eff->getForceEffect()); _setCommonProperties(&event, NULL, eff, NULL); switch( eff->type ) { case OIS::Effect::Friction: event.type = FF_FRICTION; break; case OIS::Effect::Damper: event.type = FF_DAMPER; break; case OIS::Effect::Inertia: event.type = FF_INERTIA; break; case OIS::Effect::Spring: event.type = FF_SPRING; break; default: OIS_EXCEPT(E_General, "No such available effect for Conditional force!"); break; } event.id = -1; event.u.condition[0].right_saturation = LinuxSignedLevel(effect->rightSaturation); event.u.condition[0].left_saturation = LinuxSignedLevel(effect->leftSaturation); event.u.condition[0].right_coeff = LinuxSignedLevel(effect->rightCoeff); event.u.condition[0].left_coeff = LinuxSignedLevel(effect->leftCoeff); event.u.condition[0].deadband = LinuxPositiveLevel(effect->deadband);// Unit ?? event.u.condition[0].center = LinuxSignedLevel(effect->center); // Unit ?? TODO ? // TODO support for second condition event.u.condition[1] = event.u.condition[0]; #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << " Condition[0] : " << endl << " RightSaturation : " << effect->rightSaturation << " => " << event.u.condition[0].right_saturation << endl << " LeftSaturation : " << effect->leftSaturation << " => " << event.u.condition[0]. left_saturation << endl << " RightCoefficient : " << effect->rightCoeff << " => " << event.u.condition[0].right_coeff << endl << " LeftCoefficient : " << effect->leftCoeff << " => " << event.u.condition[0].left_coeff << endl << " DeadBand : " << effect->deadband << " => " << event.u.condition[0].deadband << endl << " Center : " << effect->center << " => " << event.u.condition[0].center << endl; cout << " Condition[1] : Not implemented" << endl; #endif _upload(&event, eff); } //--------------------------------------------------------------// void LinuxForceFeedback::_upload( struct ff_effect* ffeffect, const Effect* effect) { struct ff_effect *linEffect = 0; //Get the effect - if it exists EffectList::iterator i = mEffectList.find(effect->_handle); //It has been created already if( i != mEffectList.end() ) linEffect = i->second; if( linEffect == 0 ) { #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << endl << "LinuxForceFeedback("<< mJoyStick << ") : Adding new effect : " << Effect::getEffectTypeName(effect->type) << endl; #endif //This effect has not yet been created, so create it in the device if (ioctl(mJoyStick, EVIOCSFF, ffeffect) == -1) { // TODO device full check // OIS_EXCEPT(E_DeviceFull, "Remove an effect before adding more!"); OIS_EXCEPT(E_General, "Unknown error creating effect (may be the device is full)->.."); } // Save returned effect handle effect->_handle = ffeffect->id; // Save a copy of the uploaded effect for later simple modifications linEffect = (struct ff_effect *)calloc(1, sizeof(struct ff_effect)); memcpy(linEffect, ffeffect, sizeof(struct ff_effect)); mEffectList[effect->_handle] = linEffect; // Start playing the effect. _start(effect->_handle); } else { #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << endl << "LinuxForceFeedback("<< mJoyStick << ") : Replacing effect : " << Effect::getEffectTypeName(effect->type) << endl; #endif // Keep same id/handle, as this is just an update in the device. ffeffect->id = effect->_handle; // Update effect in the device. if (ioctl(mJoyStick, EVIOCSFF, ffeffect) == -1) { OIS_EXCEPT(E_General, "Unknown error updating an effect->.."); } // Update local linEffect for next time. memcpy(linEffect, ffeffect, sizeof(struct ff_effect)); } #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << "LinuxForceFeedback("<< mJoyStick << ") : Effect handle : " << effect->_handle << endl; #endif } //--------------------------------------------------------------// void LinuxForceFeedback::_stop( int handle) { struct input_event stop; stop.type = EV_FF; stop.code = handle; stop.value = 0; #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << endl << "LinuxForceFeedback("<< mJoyStick << ") : Stopping effect with handle " << handle << endl; #endif if (write(mJoyStick, &stop, sizeof(stop)) != sizeof(stop)) { OIS_EXCEPT(E_General, "Unknown error stopping effect->.."); } } //--------------------------------------------------------------// void LinuxForceFeedback::_start( int handle) { struct input_event play; play.type = EV_FF; play.code = handle; play.value = 1; // Play once. #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << endl << "LinuxForceFeedback("<< mJoyStick << ") : Starting effect with handle " << handle << endl; #endif if (write(mJoyStick, &play, sizeof(play)) != sizeof(play)) { OIS_EXCEPT(E_General, "Unknown error playing effect->.."); } } //--------------------------------------------------------------// void LinuxForceFeedback::_unload( int handle) { #if (OIS_LINUX_JOYFF_DEBUG > 1) cout << endl << "LinuxForceFeedback("<< mJoyStick << ") : Removing effect with handle " << handle << endl; #endif if (ioctl(mJoyStick, EVIOCRMFF, handle) == -1) { OIS_EXCEPT(E_General, "Unknown error removing effect->.."); } } ois-1.3.0.dfsg0.orig/src/linux/LinuxInputManager.cpp0000664000175000017500000001362011562210433022173 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "linux/LinuxInputManager.h" #include "linux/LinuxKeyboard.h" #include "linux/LinuxJoyStickEvents.h" #include "linux/LinuxMouse.h" #include "OISException.h" #include using namespace OIS; //--------------------------------------------------------------------------------// LinuxInputManager::LinuxInputManager() : InputManager("X11InputManager") { window = 0; //Default settings grabMouse = true; grabKeyboard = true; hideMouse = true; mGrabs = true; keyboardUsed = mouseUsed = false; //Setup our internal factories mFactories.push_back(this); } //--------------------------------------------------------------------------------// LinuxInputManager::~LinuxInputManager() { //Close all joysticks LinuxJoyStick::_clearJoys(unusedJoyStickList); } //--------------------------------------------------------------------------------// void LinuxInputManager::_initialize( ParamList ¶mList ) { _parseConfigSettings( paramList ); //Enumerate all devices attached _enumerateDevices(); } //--------------------------------------------------------------------------------// void LinuxInputManager::_parseConfigSettings( ParamList ¶mList ) { ParamList::iterator i = paramList.find("WINDOW"); if( i == paramList.end() ) OIS_EXCEPT( E_InvalidParam, "LinuxInputManager >> No WINDOW!" ); //TODO 64 bit proof this little conversion xxx wip window = strtoul(i->second.c_str(), 0, 10); //--------- Keyboard Settings ------------// i = paramList.find("x11_keyboard_grab"); if( i != paramList.end() ) if( i->second == "false" ) grabKeyboard = false; //--------- Mouse Settings ------------// i = paramList.find("x11_mouse_grab"); if( i != paramList.end() ) if( i->second == "false" ) grabMouse = false; i = paramList.find("x11_mouse_hide"); if( i != paramList.end() ) if( i->second == "false" ) hideMouse = false; } //--------------------------------------------------------------------------------// void LinuxInputManager::_enumerateDevices() { //Enumerate all attached devices unusedJoyStickList = LinuxJoyStick::_scanJoys(); joySticks = unusedJoyStickList.size(); } //----------------------------------------------------------------------------// DeviceList LinuxInputManager::freeDeviceList() { DeviceList ret; if( keyboardUsed == false ) ret.insert(std::make_pair(OISKeyboard, mInputSystemName)); if( mouseUsed == false ) ret.insert(std::make_pair(OISMouse, mInputSystemName)); for(JoyStickInfoList::iterator i = unusedJoyStickList.begin(); i != unusedJoyStickList.end(); ++i) ret.insert(std::make_pair(OISJoyStick, i->vendor)); return ret; } //----------------------------------------------------------------------------// int LinuxInputManager::totalDevices(Type iType) { switch(iType) { case OISKeyboard: return 1; case OISMouse: return 1; case OISJoyStick: return joySticks; default: return 0; } } //----------------------------------------------------------------------------// int LinuxInputManager::freeDevices(Type iType) { switch(iType) { case OISKeyboard: return keyboardUsed ? 0 : 1; case OISMouse: return mouseUsed ? 0 : 1; case OISJoyStick: return (int)unusedJoyStickList.size(); default: return 0; } } //----------------------------------------------------------------------------// bool LinuxInputManager::vendorExist(Type iType, const std::string & vendor) { if( (iType == OISKeyboard || iType == OISMouse) && vendor == mInputSystemName ) { return true; } else if( iType == OISJoyStick ) { for(JoyStickInfoList::iterator i = unusedJoyStickList.begin(); i != unusedJoyStickList.end(); ++i) if(i->vendor == vendor) return true; } return false; } //----------------------------------------------------------------------------// Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool bufferMode, const std::string & vendor) { Object *obj = 0; switch(iType) { case OISKeyboard: { if( keyboardUsed == false ) obj = new LinuxKeyboard(this, bufferMode, grabKeyboard); break; } case OISMouse: { if( mouseUsed == false ) obj = new LinuxMouse(this, bufferMode, grabMouse, hideMouse); break; } case OISJoyStick: { for(JoyStickInfoList::iterator i = unusedJoyStickList.begin(); i != unusedJoyStickList.end(); ++i) { if(vendor == "" || i->vendor == vendor) { obj = new LinuxJoyStick(this, bufferMode, *i); unusedJoyStickList.erase(i); break; } } break; } default: break; } if( obj == 0 ) OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type."); return obj; } //----------------------------------------------------------------------------// void LinuxInputManager::destroyObject( Object* obj ) { if( obj ) { if( obj->type() == OISJoyStick ) { unusedJoyStickList.push_back( ((LinuxJoyStick*)obj)->_getJoyInfo() ); } delete obj; } } ois-1.3.0.dfsg0.orig/src/linux/EventHelpers.cpp0000664000175000017500000002733211562210433021172 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "linux/EventHelpers.h" #include "linux/LinuxPrereqs.h" #include "linux/LinuxForceFeedback.h" #include "OISException.h" #include "OISJoyStick.h" #include #include //#define OIS_LINUX_JOY_DEBUG #ifdef OIS_LINUX_JOY_DEBUG # include #endif using namespace std; using namespace OIS; class DeviceComponentInfo { public: vector buttons, relAxes, absAxes, hats; }; bool inline isBitSet(unsigned char bits[], unsigned int bit) { return (bits[(bit)/(sizeof(unsigned char)*8)] >> ((bit)%(sizeof(unsigned char)*8))) & 1; } //-----------------------------------------------------------------------------// DeviceComponentInfo getComponentInfo( int deviceID ) { unsigned char ev_bits[1 + EV_MAX/8/sizeof(unsigned char)]; memset( ev_bits, 0, sizeof(ev_bits) ); //Read "all" (hence 0) components of the device #ifdef OIS_LINUX_JOY_DEBUG cout << "EventUtils::getComponentInfo(" << deviceID << ") : Reading device events features" << endl; #endif if (ioctl(deviceID, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) OIS_EXCEPT( E_General, "Could not read device events features"); DeviceComponentInfo components; for (int i = 0; i < EV_MAX; i++) { if( isBitSet(ev_bits, i) ) { // Absolute axis. if(i == EV_ABS) { unsigned char abs_bits[1 + ABS_MAX/8/sizeof(unsigned char)]; memset( abs_bits, 0, sizeof(abs_bits) ); #ifdef OIS_LINUX_JOY_DEBUG cout << "EventUtils::getComponentInfo(" << deviceID << ") : Reading device absolute axis features" << endl; #endif if (ioctl(deviceID, EVIOCGBIT(i, sizeof(abs_bits)), abs_bits) == -1) OIS_EXCEPT( E_General, "Could not read device absolute axis features"); for (int j = 0; j < ABS_MAX; j++) { if( isBitSet(abs_bits, j) ) { //input_absinfo abInfo; //ioctl( fd, EVIOCGABS(j), abInfo ); if( j >= ABS_HAT0X && j <= ABS_HAT3Y ) { components.hats.push_back(j); } else { components.absAxes.push_back(j); //input_absinfo absinfo; //ioctl(deviceID, EVIOCGABS(j), &absinfo); //We cannot actually change these values :| //absinfo.minimum = JoyStick::MIN_AXIS; //absinfo.maximum = JoyStick::MAX_AXIS; //ioctl(deviceID, EVIOCSABS(j), &absinfo); } } } } else if(i == EV_REL) { unsigned char rel_bits[1 + REL_MAX/8/sizeof(unsigned char)]; memset( rel_bits, 0, sizeof(rel_bits) ); #ifdef OIS_LINUX_JOY_DEBUG cout << "EventUtils::getComponentInfo(" << deviceID << ") : Reading device relative axis features" << endl; #endif if (ioctl(deviceID, EVIOCGBIT(i, sizeof(rel_bits)), rel_bits) == -1) OIS_EXCEPT( E_General, "Could not read device relative axis features"); for (int j = 0; j < REL_MAX; j++) { if( isBitSet(rel_bits, j) ) { components.relAxes.push_back(j); } } } else if(i == EV_KEY) { unsigned char key_bits[1 + KEY_MAX/8/sizeof(unsigned char)]; memset( key_bits, 0, sizeof(key_bits) ); #ifdef OIS_LINUX_JOY_DEBUG cout << "EventUtils::getComponentInfo(" << deviceID << ") : Reading device buttons features" << endl; #endif if (ioctl(deviceID, EVIOCGBIT(i, sizeof(key_bits)), key_bits) == -1) OIS_EXCEPT( E_General, "Could not read device buttons features"); for (int j = 0; j < KEY_MAX; j++) { if( isBitSet(key_bits, j) ) { components.buttons.push_back(j); } } } } } return components; } //-----------------------------------------------------------------------------// bool EventUtils::isJoyStick( int deviceID, JoyStickInfo &js ) { if( deviceID == -1 ) OIS_EXCEPT( E_General, "Error with File Descriptor" ); DeviceComponentInfo info = getComponentInfo( deviceID ); int buttons = 0; bool joyButtonFound = false; js.button_map.clear(); #ifdef OIS_LINUX_JOY_DEBUG cout << endl << "Displaying ButtonMapping Status:" << endl; #endif for(vector::iterator i = info.buttons.begin(), e = info.buttons.end(); i != e; ++i ) { //Check to ensure we find at least one joy only button if( (*i >= BTN_JOYSTICK && *i < BTN_GAMEPAD) || (*i >= BTN_GAMEPAD && *i < BTN_DIGI) || (*i >= BTN_WHEEL && *i < KEY_OK) ) joyButtonFound = true; js.button_map[*i] = buttons++; #ifdef OIS_LINUX_JOY_DEBUG cout << "Button Mapping ID (hex): " << hex << *i << " OIS Button Num: " << dec << buttons-1 << endl; #endif } #ifdef OIS_LINUX_JOY_DEBUG cout << endl; #endif //Joy Buttons found, so it must be a joystick or pad if( joyButtonFound ) { js.joyFileD = deviceID; js.vendor = getName(deviceID); js.buttons = buttons; js.axes = info.relAxes.size() + info.absAxes.size(); js.hats = info.hats.size(); #ifdef OIS_LINUX_JOY_DEBUG cout << endl << "Device name:" << js.vendor << endl; cout << "Device unique Id:" << getUniqueId(deviceID) << endl; cout << "Device physical location:" << getPhysicalLocation(deviceID) << endl; #endif //Map the Axes #ifdef OIS_LINUX_JOY_DEBUG cout << endl << "Displaying AxisMapping Status:" << endl; #endif int axes = 0; for(vector::iterator i = info.absAxes.begin(), e = info.absAxes.end(); i != e; ++i ) { js.axis_map[*i] = axes; #ifdef OIS_LINUX_JOY_DEBUG cout << "EventUtils::isJoyStick(" << deviceID << ") : Reading device absolute axis #" << *i << " features" << endl; #endif input_absinfo absinfo; if (ioctl(deviceID, EVIOCGABS(*i), &absinfo) == -1) OIS_EXCEPT( E_General, "Could not read device absolute axis features"); js.axis_range[axes] = Range(absinfo.minimum, absinfo.maximum); #ifdef OIS_LINUX_JOY_DEBUG cout << "Axis Mapping ID (hex): " << hex << *i << " OIS Axis Num: " << dec << axes << endl; #endif ++axes; } } return joyButtonFound; } //-----------------------------------------------------------------------------// string EventUtils::getName( int deviceID ) { #ifdef OIS_LINUX_JOY_DEBUG cout << "EventUtils::getName(" << deviceID << ") : Reading device name" << endl; #endif char name[OIS_DEVICE_NAME]; if (ioctl(deviceID, EVIOCGNAME(OIS_DEVICE_NAME), name) == -1) OIS_EXCEPT( E_General, "Could not read device name"); return string(name); } //-----------------------------------------------------------------------------// string EventUtils::getUniqueId( int deviceID ) { #ifdef OIS_LINUX_JOY_DEBUG cout << "EventUtils::getUniqueId(" << deviceID << ") : Reading device unique Id" << endl; #endif #define OIS_DEVICE_UNIQUE_ID 128 char uId[OIS_DEVICE_UNIQUE_ID]; if (ioctl(deviceID, EVIOCGUNIQ(OIS_DEVICE_UNIQUE_ID), uId) == -1) OIS_EXCEPT( E_General, "Could not read device unique Id"); return string(uId); } //-----------------------------------------------------------------------------// string EventUtils::getPhysicalLocation( int deviceID ) { #ifdef OIS_LINUX_JOY_DEBUG cout << "EventUtils::getPhysicalLocation(" << deviceID << ") : Reading device physical location" << endl; #endif #define OIS_DEVICE_PHYSICAL_LOCATION 128 char physLoc[OIS_DEVICE_PHYSICAL_LOCATION]; if (ioctl(deviceID, EVIOCGPHYS(OIS_DEVICE_PHYSICAL_LOCATION), physLoc) == -1) OIS_EXCEPT( E_General, "Could not read device physical location"); return string(physLoc); } //-----------------------------------------------------------------------------// void EventUtils::enumerateForceFeedback( int deviceID, LinuxForceFeedback** ff ) { //Linux Event to OIS Event Mappings map typeMap; typeMap[FF_CONSTANT] = Effect::Constant; typeMap[FF_RAMP] = Effect::Ramp; typeMap[FF_SPRING] = Effect::Spring; typeMap[FF_FRICTION] = Effect::Friction; typeMap[FF_SQUARE] = Effect::Square; typeMap[FF_TRIANGLE] = Effect::Triangle; typeMap[FF_SINE] = Effect::Sine; typeMap[FF_SAW_UP] = Effect::SawToothUp; typeMap[FF_SAW_DOWN] = Effect::SawToothDown; typeMap[FF_DAMPER] = Effect::Damper; typeMap[FF_INERTIA] = Effect::Inertia; typeMap[FF_CUSTOM] = Effect::Custom; map forceMap; forceMap[FF_CONSTANT] = Effect::ConstantForce; forceMap[FF_RAMP] = Effect::RampForce; forceMap[FF_SPRING] = Effect::ConditionalForce; forceMap[FF_FRICTION] = Effect::ConditionalForce; forceMap[FF_SQUARE] = Effect::PeriodicForce; forceMap[FF_TRIANGLE] = Effect::PeriodicForce; forceMap[FF_SINE] = Effect::PeriodicForce; forceMap[FF_SAW_UP] = Effect::PeriodicForce; forceMap[FF_SAW_DOWN] = Effect::PeriodicForce; forceMap[FF_DAMPER] = Effect::ConditionalForce; forceMap[FF_INERTIA] = Effect::ConditionalForce; forceMap[FF_CUSTOM] = Effect::CustomForce; //Remove any previously existing memory and create fresh removeForceFeedback( ff ); *ff = new LinuxForceFeedback(deviceID); //Read overall force feedback features unsigned char ff_bits[1 + FF_MAX/8/sizeof(unsigned char)]; memset(ff_bits, 0, sizeof(ff_bits)); #ifdef OIS_LINUX_JOY_DEBUG cout << "EventUtils::enumerateForceFeedback(" << deviceID << ") : Reading device force feedback features" << endl; #endif if (ioctl(deviceID, EVIOCGBIT(EV_FF, sizeof(ff_bits)), ff_bits) == -1) OIS_EXCEPT( E_General, "Could not read device force feedback features"); #ifdef OIS_LINUX_JOY_DEBUG cout << "FF bits: " << hex; for (int i = 0; i < sizeof(ff_bits); i++) cout << (int)ff_bits[i]; cout << endl << dec; #endif //FF Axes //if( isBitSet(ff_bits, ABS_X) ) //X Axis //if( isBitSet(ff_bits, ABS_Y) ) //Y Axis //if( isBitSet(ff_bits, ABS_WHEEL) ) //Wheel //FF Effects for( int effect = FF_EFFECT_MIN; effect <= FF_WAVEFORM_MAX; effect++ ) { // The RUMBLE force type is ignored, as periodic force one is more powerfull. // The PERIODIC force type is processed later, for each associated periodic effect type. if (effect == FF_RUMBLE || effect == FF_PERIODIC) continue; if(isBitSet(ff_bits, effect)) { #ifdef OIS_LINUX_JOY_DEBUG cout << " Effect Type: " << Effect::getEffectTypeName(typeMap[effect]) << endl; #endif (*ff)->_addEffectTypes( forceMap[effect], typeMap[effect] ); } } //FF device properties if (isBitSet(ff_bits, FF_GAIN)) (*ff)->_setGainSupport(true); if (isBitSet(ff_bits, FF_AUTOCENTER)) (*ff)->_setAutoCenterSupport(true); //Check to see if any effects were added, else destroy the pointer const ForceFeedback::SupportedEffectList &list = (*ff)->getSupportedEffects(); if( list.size() == 0 ) removeForceFeedback( ff ); } //-----------------------------------------------------------------------------// void EventUtils::removeForceFeedback( LinuxForceFeedback** ff ) { delete *ff; *ff = 0; } ois-1.3.0.dfsg0.orig/src/linux/LinuxMouse.cpp0000664000175000017500000001704211562210433020673 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered friosom any source distribution. */ #include "linux/LinuxMouse.h" #include "linux/LinuxInputManager.h" #include "OISException.h" #include "OISEvents.h" using namespace OIS; //-------------------------------------------------------------------// LinuxMouse::LinuxMouse(InputManager* creator, bool buffered, bool grab, bool hide) : Mouse(creator->inputSystemName(), buffered, 0, creator) { display = 0; window = 0; cursor = 0; grabMouse = grab; hideMouse = hide; static_cast(mCreator)->_setMouseUsed(true); } //-------------------------------------------------------------------// void LinuxMouse::_initialize() { //Clear old state mState.clear(); mMoved = false; mWarped = false; //6 is just some random value... hardly ever would anyone have a window smaller than 6 oldXMouseX = oldXMouseY = 6; oldXMouseZ = 0; if( display ) XCloseDisplay(display); display = 0; window = static_cast(mCreator)->_getWindow(); //Create our local X mListener connection if( !(display = XOpenDisplay(0)) ) OIS_EXCEPT(E_General, "LinuxMouse::_initialize >> Error opening X!"); //Set it to recieve Mouse Input events if( XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask) == BadWindow ) OIS_EXCEPT(E_General, "LinuxMouse::_initialize >> X error!"); //Warp mouse inside window XWarpPointer(display,None,window,0,0,0,0, 6,6); //Create a blank cursor: Pixmap bm_no; XColor black, dummy; Colormap colormap; static char no_data[] = { 0,0,0,0,0,0,0,0 }; colormap = DefaultColormap( display, DefaultScreen(display) ); XAllocNamedColor( display, colormap, "black", &black, &dummy ); bm_no = XCreateBitmapFromData( display, window, no_data, 8, 8 ); cursor = XCreatePixmapCursor( display, bm_no, bm_no, &black, &black, 0, 0 ); grab( grabMouse ); hide( hideMouse ); mouseFocusLost = false; } //-------------------------------------------------------------------// LinuxMouse::~LinuxMouse() { if( display ) { grab(false); hide(false); XFreeCursor(display, cursor); XCloseDisplay(display); } static_cast(mCreator)->_setMouseUsed(false); } //-------------------------------------------------------------------// void LinuxMouse::setBuffered(bool buffered) { mBuffered = buffered; } //-------------------------------------------------------------------// void LinuxMouse::capture() { //Clear out last frames values mState.X.rel = 0; mState.Y.rel = 0; mState.Z.rel = 0; _processXEvents(); mWarped = false; if( mMoved == true ) { if( mBuffered && mListener ) mListener->mouseMoved( MouseEvent( this, mState ) ); mMoved = false; } //Check for losing/gaining mouse grab focus (alt-tab, etc) if( grabMouse ) { if( static_cast(mCreator)->_getGrabState() ) { if( mouseFocusLost ) //We just regained mouse grab focus { grab( true ); hide( hideMouse ); mouseFocusLost = false; } } else { if( mouseFocusLost == false ) //We just lost mouse grab focus { grab( false ); hide( false ); mouseFocusLost = true; } } } } //-------------------------------------------------------------------// void LinuxMouse::_processXEvents() { //X11 Button Events: 1=left 2=middle 3=right; Our Bit Postion: 1=Left 2=Right 3=Middle char mask[4] = {0,1,4,2}; XEvent event; //Poll x11 for events mouse events while( XPending(display) > 0 ) { XNextEvent(display, &event); if( event.type == MotionNotify ) { //Mouse moved //Ignore out of bounds mouse if we just warped if( mWarped ) { if(event.xmotion.x < 5 || event.xmotion.x > mState.width - 5 || event.xmotion.y < 5 || event.xmotion.y > mState.height - 5) continue; } //Compute this frames Relative X & Y motion int dx = event.xmotion.x - oldXMouseX; int dy = event.xmotion.y - oldXMouseY; //Store old values for next time to compute relative motion oldXMouseX = event.xmotion.x; oldXMouseY = event.xmotion.y; mState.X.abs += dx; mState.Y.abs += dy; mState.X.rel += dx; mState.Y.rel += dy; //Check to see if we are grabbing the mouse to the window (requires clipping and warping) if( grabMouse ) { if( mState.X.abs < 0 ) mState.X.abs = 0; else if( mState.X.abs > mState.width ) mState.X.abs = mState.width; if( mState.Y.abs < 0 ) mState.Y.abs = 0; else if( mState.Y.abs > mState.height ) mState.Y.abs = mState.height; if( mouseFocusLost == false ) { //Keep mouse in window (fudge factor) if(event.xmotion.x < 5 || event.xmotion.x > mState.width - 5 || event.xmotion.y < 5 || event.xmotion.y > mState.height - 5 ) { oldXMouseX = mState.width >> 1; //center x oldXMouseY = mState.height >> 1; //center y XWarpPointer(display, None, window, 0, 0, 0, 0, oldXMouseX, oldXMouseY); mWarped = true; } } } mMoved = true; } else if( event.type == ButtonPress ) { //Button down static_cast(mCreator)->_setGrabState(true); if( event.xbutton.button < 4 ) { mState.buttons |= mask[event.xbutton.button]; if( mBuffered && mListener ) if( mListener->mousePressed( MouseEvent( this, mState ), (MouseButtonID)(mask[event.xbutton.button] >> 1)) == false ) return; } } else if( event.type == ButtonRelease ) { //Button up if( event.xbutton.button < 4 ) { mState.buttons &= ~mask[event.xbutton.button]; if( mBuffered && mListener ) if( mListener->mouseReleased( MouseEvent( this, mState ), (MouseButtonID)(mask[event.xbutton.button] >> 1)) == false ) return; } //The Z axis gets pushed/released pair message (this is up) else if( event.xbutton.button == 4 ) { mState.Z.rel += 120; mState.Z.abs += 120; mMoved = true; } //The Z axis gets pushed/released pair message (this is down) else if( event.xbutton.button == 5 ) { mState.Z.rel -= 120; mState.Z.abs -= 120; mMoved = true; } } } } //-------------------------------------------------------------------// void LinuxMouse::grab(bool grab) { if( grab ) XGrabPointer(display, window, True, 0, GrabModeAsync, GrabModeAsync, window, None, CurrentTime); else XUngrabPointer(display, CurrentTime); } //-------------------------------------------------------------------// void LinuxMouse::hide(bool hide) { if( hide ) XDefineCursor(display, window, cursor); else XUndefineCursor(display, window); } ois-1.3.0.dfsg0.orig/src/linux/LinuxJoyStickEvents.cpp0000664000175000017500000002151311562210433022525 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISConfig.h" #include "linux/LinuxJoyStickEvents.h" #include "linux/LinuxInputManager.h" #include "linux/LinuxForceFeedback.h" #include "linux/EventHelpers.h" #include "OISEvents.h" #include "OISException.h" #include //Needed to Open a file descriptor #include #include #include # include using namespace std; using namespace OIS; //#define OIS_LINUX_JOY_DEBUG //-------------------------------------------------------------------// LinuxJoyStick::LinuxJoyStick(InputManager* creator, bool buffered, const JoyStickInfo& js) : JoyStick(js.vendor, buffered, js.devId, creator) { mJoyStick = js.joyFileD; mState.mAxes.clear(); mState.mAxes.resize(js.axes); mState.mButtons.clear(); mState.mButtons.resize(js.buttons); mPOVs = js.hats; mButtonMap = js.button_map; mAxisMap = js.axis_map; mRanges = js.axis_range; ff_effect = 0; } //-------------------------------------------------------------------// LinuxJoyStick::~LinuxJoyStick() { EventUtils::removeForceFeedback( &ff_effect ); } //-------------------------------------------------------------------// void LinuxJoyStick::_initialize() { //Clear old joy state mState.mAxes.resize(mAxisMap.size()); mState.clear(); //This will create and new us a force feedback structure if it exists EventUtils::enumerateForceFeedback( mJoyStick, &ff_effect ); if( mJoyStick == -1 ) OIS_EXCEPT(E_InputDeviceNonExistant, "LinuxJoyStick::_initialize() >> JoyStick Not Found!"); } //-------------------------------------------------------------------// void LinuxJoyStick::capture() { static const short POV_MASK[8] = {0,0,1,1,2,2,3,3}; //Used to determine if an axis has been changed and needs an event bool axisMoved[32] = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}; //We are in non blocking mode - we just read once, and try to fill up buffer input_event js[JOY_BUFFERSIZE]; while(true) { int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE); if( ret < 0 ) break; //Determine how many whole events re read up ret /= sizeof(struct input_event); for(int i = 0; i < ret; ++i) { switch(js[i].type) { case EV_KEY: //Button { int button = mButtonMap[js[i].code]; #ifdef OIS_LINUX_JOY_DEBUG cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << endl; #endif //Check to see whether push or released event... if(js[i].value) { mState.mButtons[button] = true; if( mBuffered && mListener ) if(!mListener->buttonPressed(JoyStickEvent(this,mState), button)) return; } else { mState.mButtons[button] = false; if( mBuffered && mListener ) if(!mListener->buttonReleased(JoyStickEvent(this,mState), button)) return; } break; } case EV_ABS: //Absolute Axis { //A Stick (BrakeDefine is the highest possible Axis) if( js[i].code <= ABS_BRAKE ) { int axis = mAxisMap[js[i].code]; assert( axis < 32 && "Too many axes (Max supported is 32). Report this to OIS forums!" ); axisMoved[axis] = true; //check for rescaling: if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS ) { //Scale is perfect mState.mAxes[axis].abs = js[i].value; } else { //Rescale float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max); mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion)); } } else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed { //Normalise the POV to between 0-7 //Even is X Axis, Odd is Y Axis unsigned char LinuxPovNumber = js[i].code - 16; short OIS_POVIndex = POV_MASK[LinuxPovNumber]; //Handle X Axis first (Even) (left right) if((LinuxPovNumber & 0x0001) == 0) { //Why do this? Because, we use a bit field, and when this axis is east, //it can't possibly be west too. So clear out the two X axes, then refil //it in with the new direction bit. //Clear the East/West Bit Flags first mState.mPOV[OIS_POVIndex].direction &= 0x11110011; if( js[i].value == -1 ) //Left mState.mPOV[OIS_POVIndex].direction |= Pov::West; else if( js[i].value == 1 ) //Right mState.mPOV[OIS_POVIndex].direction |= Pov::East; } //Handle Y Axis (Odd) (up down) else { //Clear the North/South Bit Flags first mState.mPOV[OIS_POVIndex].direction &= 0x11111100; if( js[i].value == -1 ) //Up mState.mPOV[OIS_POVIndex].direction |= Pov::North; else if( js[i].value == 1 ) //Down mState.mPOV[OIS_POVIndex].direction |= Pov::South; } if( mBuffered && mListener ) if( mListener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false ) return; } break; } case EV_REL: //Relative Axes (Do any joystick actually have a relative axis?) #ifdef OIS_LINUX_JOY_DEBUG cout << "\nWarning: Relatives axes not supported yet" << endl; #endif break; default: break; } } } //All axes and POVs are combined into one movement per pair per captured frame if( mBuffered && mListener ) { for( int i = 0; i < 32; ++i ) if( axisMoved[i] ) if( mListener->axisMoved( JoyStickEvent(this,mState), i) == false ) return; } } //-------------------------------------------------------------------// void LinuxJoyStick::setBuffered(bool buffered) { if( buffered != mBuffered ) { mBuffered = buffered; _initialize(); } } //-------------------------------------------------------------------// JoyStickInfo LinuxJoyStick::_getJoyInfo() { JoyStickInfo js; js.devId = mDevID; js.joyFileD = mJoyStick; js.vendor = mVendor; js.axes = (int)mState.mAxes.size(); js.buttons = (int)mState.mButtons.size(); js.hats = mPOVs; js.button_map = mButtonMap; js.axis_map = mAxisMap; js.axis_range = mRanges; return js; } //-------------------------------------------------------------------// JoyStickInfoList LinuxJoyStick::_scanJoys() { JoyStickInfoList joys; //Search through all of the event devices.. and identify which ones are joysticks //xxx move this to InputManager, as it can also scan all other events for(int i = 0; i < 64; ++i ) { stringstream s; s << "/dev/input/event" << i; int fd = open( s.str().c_str(), O_RDWR |O_NONBLOCK ); if(fd == -1) continue; #ifdef OIS_LINUX_JOY_DEBUG cout << "Opening " << s.str() << "..." << endl; #endif try { JoyStickInfo js; if( EventUtils::isJoyStick(fd, js) ) { joys.push_back(js); #ifdef OIS_LINUX_JOY_DEBUG cout << "=> Joystick added to list." << endl; #endif } else { #ifdef OIS_LINUX_JOY_DEBUG cout << "=> Not a joystick." << endl; #endif close(fd); } } catch(...) { #ifdef OIS_LINUX_JOY_DEBUG cout << "Exception caught!!" << endl; #endif close(fd); } } return joys; } //-------------------------------------------------------------------// void LinuxJoyStick::_clearJoys(JoyStickInfoList &joys) { for(JoyStickInfoList::iterator i = joys.begin(); i != joys.end(); ++i) close(i->joyFileD); joys.clear(); } //-------------------------------------------------------------------// Interface* LinuxJoyStick::queryInterface(Interface::IType type) { if( ff_effect && type == Interface::ForceFeedback ) return ff_effect; return 0; } ois-1.3.0.dfsg0.orig/src/linux/LinuxKeyboard.cpp0000664000175000017500000003733211562210433021347 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "linux/LinuxInputManager.h" #include "linux/LinuxKeyboard.h" #include "OISException.h" #include "OISEvents.h" #include #include #include using namespace OIS; #include //-------------------------------------------------------------------// LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab) : Keyboard(creator->inputSystemName(), buffered, 0, creator) { setlocale(LC_CTYPE, ""); //Set the locale to (hopefully) the users LANG UTF-8 Env var display = 0; window = 0; grabKeyboard = grab; keyFocusLost = false; //X Key Map to KeyCode keyConversion.insert(XtoOIS_KeyMap::value_type(XK_1, KC_1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_2, KC_2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_3, KC_3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_4, KC_4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_5, KC_5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_6, KC_6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_7, KC_7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_8, KC_8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_9, KC_9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_0, KC_0)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_BackSpace, KC_BACK)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_minus, KC_MINUS)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_equal, KC_EQUALS)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_space, KC_SPACE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_comma, KC_COMMA)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_period, KC_PERIOD)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_backslash, KC_BACKSLASH)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_slash, KC_SLASH)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_bracketleft, KC_LBRACKET)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_bracketright, KC_RBRACKET)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Escape,KC_ESCAPE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Caps_Lock, KC_CAPITAL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Tab, KC_TAB)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Return, KC_RETURN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Control_L, KC_LCONTROL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Control_R, KC_RCONTROL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_colon, KC_COLON)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_semicolon, KC_SEMICOLON)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_apostrophe, KC_APOSTROPHE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_grave, KC_GRAVE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_b, KC_B)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_a, KC_A)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_c, KC_C)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_d, KC_D)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_e, KC_E)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_f, KC_F)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_g, KC_G)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_h, KC_H)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_i, KC_I)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_j, KC_J)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_k, KC_K)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_l, KC_L)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_m, KC_M)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_n, KC_N)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_o, KC_O)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_p, KC_P)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_q, KC_Q)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_r, KC_R)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_s, KC_S)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_t, KC_T)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_u, KC_U)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_v, KC_V)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_w, KC_W)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_x, KC_X)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_y, KC_Y)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_z, KC_Z)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F1, KC_F1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F2, KC_F2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F3, KC_F3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F4, KC_F4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F5, KC_F5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F6, KC_F6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F7, KC_F7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F8, KC_F8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F9, KC_F9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F10, KC_F10)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F11, KC_F11)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F12, KC_F12)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F13, KC_F13)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F14, KC_F14)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F15, KC_F15)); //Keypad keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_0, KC_NUMPAD0)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_1, KC_NUMPAD1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_2, KC_NUMPAD2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_3, KC_NUMPAD3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_4, KC_NUMPAD4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_5, KC_NUMPAD5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_6, KC_NUMPAD6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_7, KC_NUMPAD7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_8, KC_NUMPAD8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_9, KC_NUMPAD9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Add, KC_ADD)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Subtract, KC_SUBTRACT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Decimal, KC_DECIMAL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Equal, KC_NUMPADEQUALS)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Divide, KC_DIVIDE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Multiply, KC_MULTIPLY)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Enter, KC_NUMPADENTER)); //Keypad with numlock off keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Home, KC_NUMPAD7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Up, KC_NUMPAD8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Up, KC_NUMPAD9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Left, KC_NUMPAD4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Begin, KC_NUMPAD5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Right, KC_NUMPAD6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_End, KC_NUMPAD1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Down, KC_NUMPAD2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Down, KC_NUMPAD3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Insert, KC_NUMPAD0)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Delete, KC_DECIMAL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Up, KC_UP)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Down, KC_DOWN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Left, KC_LEFT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Right, KC_RIGHT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Up, KC_PGUP)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Down, KC_PGDOWN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Home, KC_HOME)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_End, KC_END)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Num_Lock, KC_NUMLOCK)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Print, KC_SYSRQ)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Scroll_Lock, KC_SCROLL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Pause, KC_PAUSE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_R, KC_RSHIFT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_L, KC_LSHIFT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_R, KC_RMENU)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_L, KC_LMENU)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Insert, KC_INSERT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Delete, KC_DELETE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_L, KC_LWIN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_R, KC_RWIN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Menu, KC_APPS)); static_cast(mCreator)->_setKeyboardUsed(true); } //-------------------------------------------------------------------// void LinuxKeyboard::_initialize() { //Clear our keyboard state buffer memset( &KeyBuffer, 0, 256 ); mModifiers = 0; if( display ) XCloseDisplay(display); display = 0; window = static_cast(mCreator)->_getWindow(); //Create our local X mListener connection if( !(display = XOpenDisplay(0)) ) OIS_EXCEPT(E_General, "LinuxKeyboard::_initialize >> Error opening X!"); //Set it to recieve Input events if( XSelectInput(display, window, KeyPressMask | KeyReleaseMask) == BadWindow ) OIS_EXCEPT(E_General, "LinuxKeyboard::_initialize: X error!"); if( grabKeyboard ) XGrabKeyboard(display,window,True,GrabModeAsync,GrabModeAsync,CurrentTime); keyFocusLost = false; } //-------------------------------------------------------------------// LinuxKeyboard::~LinuxKeyboard() { if( display ) { if( grabKeyboard ) XUngrabKeyboard(display, CurrentTime); XCloseDisplay(display); } static_cast(mCreator)->_setKeyboardUsed(true); } //-------------------------------------------------------------------// unsigned int UTF8ToUTF32(unsigned char* buf) { unsigned char &FirstChar = buf[0]; if(FirstChar < 128) return FirstChar; unsigned int val = 0; unsigned int len = 0; if((FirstChar & 0xE0) == 0xC0) //2 Chars { len = 2; val = FirstChar & 0x1F; } else if((FirstChar & 0xF0) == 0xE0) //3 Chars { len = 3; val = FirstChar & 0x0F; } else if((FirstChar & 0xF8) == 0xF0) //4 Chars { len = 4; val = FirstChar & 0x07; } else if((FirstChar & 0xFC) == 0xF8) //5 Chars { len = 5; val = FirstChar & 0x03; } else // if((FirstChar & 0xFE) == 0xFC) //6 Chars { len = 6; val = FirstChar & 0x01; } for(int i = 1; i < len; i++) val = (val << 6) | (buf[i] & 0x3F); return val; } //-------------------------------------------------------------------// bool LinuxKeyboard::isKeyDown( KeyCode key ) const { return (KeyBuffer[key]); } //-------------------------------------------------------------------// void LinuxKeyboard::capture() { KeySym key; XEvent event; LinuxInputManager* linMan = static_cast(mCreator); while( XPending(display) > 0 ) { XNextEvent(display, &event); if(KeyPress == event.type) { unsigned int character = 0; if(mTextMode != Off) { unsigned char buffer[6] = {0,0,0,0,0,0}; XLookupString(&event.xkey, (char*)buffer, 6, &key, 0); if( mTextMode == Unicode ) character = UTF8ToUTF32(buffer); else if( mTextMode == Ascii) character = buffer[0]; } //Mask out the modifier states X11 sets and read again event.xkey.state &= ~ShiftMask; event.xkey.state &= ~LockMask; XLookupString(&event.xkey, 0, 0,&key, 0); _injectKeyDown(key, character); //Just printing out some debugging info.. to verify all chars are mapped //std::cout << "KEY PRESSED X=" << event.xkey.keycode; //std::cout << "\n KeySym=" << key << std::endl; //Check for Alt-Tab if( event.xkey.state & Mod1Mask && key == XK_Tab ) linMan->_setGrabState(false); } else if(KeyRelease == event.type) { if(!_isKeyRepeat(event)) { //Mask out the modifier states X sets.. or we will get improper values event.xkey.state &= ~ShiftMask; event.xkey.state &= ~LockMask; XLookupString(&event.xkey,NULL,0,&key,NULL); _injectKeyUp(key); } } } //If grabbing mode is on.. Handle focus lost/gained via Alt-Tab and mouse clicks if( grabKeyboard ) { if( linMan->_getGrabState() == false ) { // are no longer grabbing if( keyFocusLost == false ) { //UnGrab KeyBoard XUngrabKeyboard(display, CurrentTime); keyFocusLost = true; } } else { //We are grabbing - and regained focus if( keyFocusLost == true ) { //ReGrab KeyBoard XGrabKeyboard(display, window, True, GrabModeAsync, GrabModeAsync, CurrentTime); keyFocusLost = false; } } } } //-------------------------------------------------------------------// void LinuxKeyboard::setBuffered(bool buffered) { mBuffered = buffered; } //-------------------------------------------------------------------// bool LinuxKeyboard::_injectKeyDown( KeySym key, int text ) { KeyCode kc = keyConversion[key]; KeyBuffer[kc] = 1; //Turn on modifier flags if( kc == KC_LCONTROL || kc == KC_RCONTROL) mModifiers |= Ctrl; else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) mModifiers |= Shift; else if( kc == KC_LMENU || kc == KC_RMENU ) mModifiers |= Alt; if( mBuffered && mListener ) return mListener->keyPressed(KeyEvent(this,kc,text)); return true; } //-------------------------------------------------------------------// bool LinuxKeyboard::_injectKeyUp( KeySym key ) { KeyCode kc = keyConversion[key]; KeyBuffer[kc] = 0; //Turn off modifier flags if( kc == KC_LCONTROL || kc == KC_RCONTROL) mModifiers &= ~Ctrl; else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) mModifiers &= ~Shift; else if( kc == KC_LMENU || kc == KC_RMENU ) mModifiers &= ~Alt; if( mBuffered && mListener ) return mListener->keyReleased(KeyEvent(this, kc, 0)); return true; } //-------------------------------------------------------------------// const std::string& LinuxKeyboard::getAsString( KeyCode kc ) { mGetString = "Unknown"; char *temp = 0; XtoOIS_KeyMap::iterator i = keyConversion.begin(), e = keyConversion.end(); for( ; i != e; ++i ) { if( i->second == kc ) { temp = XKeysymToString(i->first); if( temp ) mGetString = temp; break; } } return mGetString; } //-------------------------------------------------------------------// void LinuxKeyboard::copyKeyStates( char keys[256] ) const { memcpy( keys, KeyBuffer, 256 ); } ois-1.3.0.dfsg0.orig/src/OISInputManager.cpp0000664000175000017500000001741011562210433020370 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISInputManager.h" #include "OISException.h" #include "OISFactoryCreator.h" #include "OISObject.h" #include #include //Bring in correct Header / InputManager for current build platform #if defined OIS_SDL_PLATFORM # include "SDL/SDLInputManager.h" #elif defined OIS_WIN32_PLATFORM # include "win32/Win32InputManager.h" #elif defined OIS_LINUX_PLATFORM # include "linux/LinuxInputManager.h" #elif defined OIS_APPLE_PLATFORM # include "mac/MacInputManager.h" #elif defined OIS_IPHONE_PLATFORM # include "iphone/iPhoneInputManager.h" #elif defined OIS_XBOX_PLATFORM # include "xbox/XBoxInputManager.h" #endif //Bring in extra controls #if defined OIS_LIRC_SUPPORT # include "extras/LIRC/OISLIRCFactoryCreator.h" #endif #if defined OIS_WIN32_WIIMOTE_SUPPORT # include "win32/extras/WiiMote/OISWiiMoteFactoryCreator.h" #endif using namespace OIS; //----------------------------------------------------------------------------// InputManager::InputManager(const std::string& name) : m_VersionName(OIS_VERSION_NAME), mInputSystemName(name), m_lircSupport(0), m_wiiMoteSupport(0) { mFactories.clear(); mFactoryObjects.clear(); } //----------------------------------------------------------------------------// InputManager::~InputManager() { #if defined OIS_LIRC_SUPPORT delete m_lircSupport; #endif #if defined OIS_WIN32_WIIMOTE_SUPPORT delete m_wiiMoteSupport; #endif } //----------------------------------------------------------------------------// unsigned int InputManager::getVersionNumber() { return OIS_VERSION; } //----------------------------------------------------------------------------// const std::string &InputManager::getVersionName() { return m_VersionName; } //----------------------------------------------------------------------------// InputManager* InputManager::createInputSystem( std::size_t windowhandle ) { ParamList pl; std::ostringstream wnd; wnd << windowhandle; pl.insert(std::make_pair( std::string("WINDOW"), wnd.str() )); return createInputSystem( pl ); } //----------------------------------------------------------------------------// InputManager* InputManager::createInputSystem( ParamList ¶mList ) { InputManager* im = 0; #if defined OIS_SDL_PLATFORM im = new SDLInputManager(); #elif defined OIS_WIN32_PLATFORM im = new Win32InputManager(); #elif defined OIS_XBOX_PLATFORM im = new XBoxInputManager(); #elif defined OIS_LINUX_PLATFORM im = new LinuxInputManager(); #elif defined OIS_APPLE_PLATFORM im = new MacInputManager(); #elif defined OIS_IPHONE_PLATFORM im = new iPhoneInputManager(); #else OIS_EXCEPT(E_General, "No platform library.. check build platform defines!"); #endif try { im->_initialize(paramList); } catch(...) { delete im; throw; //rethrow } return im; } //----------------------------------------------------------------------------// void InputManager::destroyInputSystem(InputManager* manager) { if( manager == 0 ) return; //Cleanup before deleting... for( FactoryCreatedObject::iterator i = manager->mFactoryObjects.begin(); i != manager->mFactoryObjects.end(); ++i ) { i->second->destroyObject( i->first ); } manager->mFactoryObjects.clear(); delete manager; } //--------------------------------------------------------------------------------// const std::string& InputManager::inputSystemName() { return mInputSystemName; } //--------------------------------------------------------------------------------// int InputManager::getNumberOfDevices( Type iType ) { //Count up all the factories devices int factoyObjects = 0; FactoryList::iterator i = mFactories.begin(), e = mFactories.end(); for( ; i != e; ++i ) factoyObjects += (*i)->totalDevices(iType); return factoyObjects; } //----------------------------------------------------------------------------// DeviceList InputManager::listFreeDevices() { DeviceList list; FactoryList::iterator i = mFactories.begin(), e = mFactories.end(); for( ; i != e; ++i ) { DeviceList temp = (*i)->freeDeviceList(); list.insert(temp.begin(), temp.end()); } return list; } //----------------------------------------------------------------------------// Object* InputManager::createInputObject( Type iType, bool bufferMode, const std::string &vendor ) { Object* obj = 0; FactoryList::iterator i = mFactories.begin(), e = mFactories.end(); for( ; i != e; ++i) { if( (*i)->freeDevices(iType) > 0 ) { if( vendor == "" || (*i)->vendorExist(iType, vendor) ) { obj = (*i)->createObject(this, iType, bufferMode, vendor); mFactoryObjects[obj] = (*i); break; } } } if(!obj) OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type."); try { //Intialize device obj->_initialize(); } catch(...) { //Somekind of error, cleanup and rethrow destroyInputObject(obj); throw; } return obj; } //----------------------------------------------------------------------------// void InputManager::destroyInputObject( Object* obj ) { if( obj == 0 ) return; FactoryCreatedObject::iterator i = mFactoryObjects.find(obj); if( i != mFactoryObjects.end() ) { i->second->destroyObject(obj); mFactoryObjects.erase(i); } else { OIS_EXCEPT(E_General, "Object creator not known."); } } //----------------------------------------------------------------------------// void InputManager::addFactoryCreator( FactoryCreator* factory ) { if(factory != 0) mFactories.push_back(factory); } //----------------------------------------------------------------------------// void InputManager::removeFactoryCreator( FactoryCreator* factory ) { if(factory != 0) { //First, destroy all devices created with the factory for( FactoryCreatedObject::iterator i = mFactoryObjects.begin(); i != mFactoryObjects.end(); ++i ) { if( i->second == factory ) { i->second->destroyObject(i->first); mFactoryObjects.erase(i++); } } //Now, remove the factory itself FactoryList::iterator fact = std::find(mFactories.begin(), mFactories.end(), factory); if( fact != mFactories.end() ) mFactories.erase(fact); } } //----------------------------------------------------------------------------// void InputManager::enableAddOnFactory(AddOnFactories factory) { #if defined OIS_LIRC_SUPPORT if( factory == AddOn_LIRC || factory == AddOn_All ) { if( m_lircSupport == 0 ) { m_lircSupport = new LIRCFactoryCreator(); addFactoryCreator(m_lircSupport); } } #endif #if defined OIS_WIN32_WIIMOTE_SUPPORT if( factory == AddOn_WiiMote || factory == AddOn_All ) { if( m_wiiMoteSupport == 0 ) { m_wiiMoteSupport = new WiiMoteFactoryCreator(); addFactoryCreator(m_wiiMoteSupport); } } #endif } ois-1.3.0.dfsg0.orig/src/OISKeyboard.cpp0000664000175000017500000000277611562210433017547 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISKeyboard.h" #include "OISException.h" using namespace OIS; //----------------------------------------------------------------------// void Keyboard::setTextTranslation( TextTranslationMode mode ) { mTextMode = mode; } //----------------------------------------------------------------------// bool Keyboard::isModifierDown( Modifier mod ) const { #if defined(OIS_MSVC_COMPILER) #pragma warning (push) #pragma warning (disable : 4800) #endif return (mModifiers & mod); #if defined(OIS_MSVC_COMPILER) #pragma warning (pop) #endif } ois-1.3.0.dfsg0.orig/src/OISObject.cpp0000664000175000017500000000172711562210433017210 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //#include "OISObject.h" ois-1.3.0.dfsg0.orig/src/OISJoyStick.cpp0000664000175000017500000000465211562210433017541 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISJoyStick.h" using namespace OIS; //----------------------------------------------------------------------------// JoyStick::JoyStick(const std::string &vendor, bool buffered, int devID, InputManager* creator) : Object(vendor, OISJoyStick, buffered, devID, creator), mSliders(0), mPOVs(0), mListener(0), mVector3Sensitivity(OIS_JOYSTICK_VECTOR3_DEFAULT) { } //----------------------------------------------------------------------------// int JoyStick::getNumberOfComponents(ComponentType cType) const { switch( cType ) { case OIS_Button: return (int)mState.mButtons.size(); case OIS_Axis: return (int)mState.mAxes.size(); case OIS_Slider: return mSliders; case OIS_POV: return mPOVs; case OIS_Vector3: return (int)mState.mVectors.size(); default: return 0; } } //----------------------------------------------------------------------------// void JoyStick::setVector3Sensitivity(float degrees) { mVector3Sensitivity = degrees; } //----------------------------------------------------------------------------// float JoyStick::getVector3Sensitivity() const { return mVector3Sensitivity; } //----------------------------------------------------------------------------// void JoyStick::setEventCallback( JoyStickListener *joyListener ) { mListener = joyListener; } //----------------------------------------------------------------------------// JoyStickListener* JoyStick::getEventCallback() const { return mListener; } ois-1.3.0.dfsg0.orig/src/OISEffect.cpp0000664000175000017500000000760111562210433017173 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISEffect.h" #include "OISException.h" using namespace OIS; //VC7.1 had a problem with these not getting included.. //Perhaps a case of a crazy extreme optimizer :/ (moved to header) //const unsigned int Effect::OIS_INFINITE = 0xFFFFFFFF; //------------------------------------------------------------------------------// static const char* pszEForceString[] = { "UnknownForce", "ConstantForce", "RampForce", "PeriodicForce", "ConditionalForce", "CustomForce" }; const char* Effect::getForceTypeName(Effect::EForce eValue) { return (eValue >= 0 && eValue < _ForcesNumber) ? pszEForceString[eValue] : ""; } static const char* pszETypeString[] = { "Unknown", "Constant", "Ramp", "Square", "Triangle", "Sine", "SawToothUp", "SawToothDown", "Friction", "Damper", "Inertia", "Spring", "Custom" }; const char* Effect::getEffectTypeName(Effect::EType eValue) { return (eValue >= 0 && eValue < _TypesNumber) ? pszETypeString[eValue] : ""; } static const char* pszEDirectionString[] = { "NorthWest", "North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West"}; const char* Effect::getDirectionName(Effect::EDirection eValue) { return (eValue >= 0 && eValue < _DirectionsNumber) ? pszEDirectionString[eValue] : ""; } //------------------------------------------------------------------------------// Effect::Effect() : force(UnknownForce), type(Unknown), effect(0), axes(1) { } //------------------------------------------------------------------------------// Effect::Effect(EForce ef, EType et) : force(ef), type(et), direction(North), trigger_button(-1), trigger_interval(0), replay_length(Effect::OIS_INFINITE), replay_delay(0), _handle(-1), axes(1) { effect = 0; switch( ef ) { case ConstantForce: effect = new ConstantEffect(); break; case RampForce: effect = new RampEffect(); break; case PeriodicForce: effect = new PeriodicEffect(); break; case ConditionalForce: effect = new ConditionalEffect(); break; default: break; } } //------------------------------------------------------------------------------// Effect::~Effect() { delete effect; } //------------------------------------------------------------------------------// ForceEffect* Effect::getForceEffect() const { //If no effect was created in constructor, then we raise an error here if( effect == 0 ) OIS_EXCEPT( E_NotSupported, "Requested ForceEffect is null!" ); return effect; } //------------------------------------------------------------------------------// void Effect::setNumAxes(short nAxes) { //Can only be set before a handle was assigned (effect created) if( _handle != -1 ) axes = nAxes; } //------------------------------------------------------------------------------// short Effect::getNumAxes() const { return axes; } ois-1.3.0.dfsg0.orig/src/OISException.cpp0000664000175000017500000000221111562210433017725 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISException.h" using namespace OIS; //----------------------------------------------------------------------------// const char* Exception::what() const throw() { return eText; } ois-1.3.0.dfsg0.orig/src/OISForceFeedback.cpp0000664000175000017500000000514311562210433020441 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISForceFeedback.h" #include "OISException.h" using namespace OIS; //-------------------------------------------------------------// ForceFeedback::ForceFeedback() : mSetGainSupport(false), mSetAutoCenterSupport(false) { } //-------------------------------------------------------------// void ForceFeedback::_addEffectTypes( Effect::EForce force, Effect::EType type ) { if( force <= Effect::UnknownForce || force >= Effect::_ForcesNumber || type <= Effect::Unknown || type >= Effect::_TypesNumber ) OIS_EXCEPT( E_General, "Can't add unknown effect Force/Type to the supported list" ); mSupportedEffects.insert(std::pair(force, type)); } //-------------------------------------------------------------// void ForceFeedback::_setGainSupport( bool on ) { mSetGainSupport = on; } //-------------------------------------------------------------// void ForceFeedback::_setAutoCenterSupport( bool on ) { mSetAutoCenterSupport = on; } //-------------------------------------------------------------// const ForceFeedback::SupportedEffectList& ForceFeedback::getSupportedEffects() const { return mSupportedEffects; } //-------------------------------------------------------------// bool ForceFeedback::supportsEffect(Effect::EForce force, Effect::EType type) const { const std::pair iterRange = mSupportedEffects.equal_range(force); SupportedEffectList::const_iterator iter; for (iter = iterRange.first; iter != iterRange.second; iter++) { if ((*iter).second == type) return true; } return false; } ois-1.3.0.dfsg0.orig/src/SDL/0000775000175000017500000000000011562210433015336 5ustar alessioalessioois-1.3.0.dfsg0.orig/src/SDL/SDLJoyStick.cpp0000664000175000017500000000000011562210433020132 0ustar alessioalessioois-1.3.0.dfsg0.orig/src/SDL/SDLMouse.cpp0000664000175000017500000001164111562210433017500 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL/SDLMouse.h" #include "SDL/SDLInputManager.h" #include "OISException.h" #include "OISEvents.h" using namespace OIS; //-------------------------------------------------------------------// SDLMouse::SDLMouse( bool buffered ) : mGrabbed(false), mRegainFocus(false) { mBuffered = buffered; mType = OISMouse; listener = 0; } //-------------------------------------------------------------------// void SDLMouse::_initialize() { //Clear old state mState.clear(); mRegainFocus = false; _setGrab(true); _setVisible(false); static_cast(InputManager::getSingletonPtr())->_setGrabMode(true); } //-------------------------------------------------------------------// SDLMouse::~SDLMouse() { _setGrab(true); _setVisible(true); static_cast(InputManager::getSingletonPtr())->_setGrabMode(false); } //-------------------------------------------------------------------// void SDLMouse::capture() { //Used for going from SDL Button to OIS button static const MouseButtonID ButtonMask[4] = {MB_Left, MB_Left, MB_Middle, MB_Right}; //Clear old relative values mState.relX = mState.relY = mState.relZ = 0; SDL_Event events[OIS_SDL_MOUSE_BUFF]; int count = SDL_PeepEvents(events, OIS_SDL_MOUSE_BUFF, SDL_GETEVENT, SDL_MOUSEEVENTMASK); bool mouseXYMoved = false; bool mouseZMoved = false; for( int i = 0; i < count; ++i ) { switch( events[i].type ) { case SDL_MOUSEMOTION: mouseXYMoved = true; break; case SDL_MOUSEBUTTONDOWN: { mRegainFocus = true; int sdlButton = events[i].button.button; if( sdlButton <= SDL_BUTTON_RIGHT ) { //Left, Right, or Middle mState.buttons |= (1 << ButtonMask[sdlButton]); if( mBuffered && listener ) if( listener->mousePressed(MouseEvent(this,0,mState), ButtonMask[sdlButton]) == false ) return; } else { //mouse Wheel mouseZMoved = true; if( sdlButton == SDL_BUTTON_WHEELUP ) mState.relZ += 120; else if( sdlButton == SDL_BUTTON_WHEELDOWN ) mState.relZ -= 120; } break; } case SDL_MOUSEBUTTONUP: { int sdlButton = events[i].button.button; if( sdlButton <= SDL_BUTTON_RIGHT ) { //Left, Right, or Middle mState.buttons &= ~(1 << ButtonMask[sdlButton]); if( mBuffered && listener ) if( listener->mouseReleased(MouseEvent(this,0,mState), ButtonMask[sdlButton]) == false ) return; } break; } } } //Handle X/Y axis move if( mouseXYMoved ) { SDL_GetMouseState( &mState.abX, &mState.abY ); SDL_GetRelativeMouseState( &mState.relX, &mState.relY ); if( mBuffered && listener ) listener->mouseMoved(MouseEvent(this, 0, mState)); } //Handle Z Motion if( mouseZMoved ) { mState.abZ += mState.relZ; if( mBuffered && listener ) listener->mouseMoved(MouseEvent(this, 0, mState)); } //Handle Alt-Tabbing SDLInputManager* man = static_cast(InputManager::getSingletonPtr()); if( man->_getGrabMode() == false ) { if( mRegainFocus == false && mGrabbed == true ) { //We had focus, but must release it now _setGrab(false); _setVisible(true); } else if( mRegainFocus == true && mGrabbed == false ) { //We are gaining focus back (mouse clicked in window) _setGrab(true); _setVisible(false); man->_setGrabMode(true); //Notify manager } } } //-------------------------------------------------------------------// void SDLMouse::setBuffered(bool buffered) { mBuffered = buffered; } //-------------------------------------------------------------------// void SDLMouse::_setGrab(bool grabbed) { if( grabbed ) SDL_WM_GrabInput(SDL_GRAB_ON); else SDL_WM_GrabInput(SDL_GRAB_OFF); mGrabbed = grabbed; } //-------------------------------------------------------------------// void SDLMouse::_setVisible(bool visible) { if( visible ) SDL_ShowCursor(SDL_ENABLE); else SDL_ShowCursor(SDL_DISABLE); } ois-1.3.0.dfsg0.orig/src/SDL/SDLKeyboard.cpp0000664000175000017500000004454211562210433020156 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL/SDLKeyboard.h" #include "SDL/SDLInputManager.h" #include "OISException.h" #include "OISEvents.h" #include using namespace OIS; //-------------------------------------------------------------------// SDLKeyboard::SDLKeyboard( bool buffered ) { mBuffered = buffered; mType = OISKeyboard; listener = 0; //Clear our keyboard state buffer memset( &KeyBuffer, 0, 256 ); } //-------------------------------------------------------------------// void SDLKeyboard::_initialize() { mModifiers = 0; mSDLBuff = 0; mKeyMap.insert( KeyMap::value_type(SDLK_ESCAPE,KC_ESCAPE) ); mKeyMap.insert( KeyMap::value_type(SDLK_1, KC_1) ); mKeyMap.insert( KeyMap::value_type(SDLK_2, KC_2) ); mKeyMap.insert( KeyMap::value_type(SDLK_3, KC_3) ); mKeyMap.insert( KeyMap::value_type(SDLK_4, KC_4) ); mKeyMap.insert( KeyMap::value_type(SDLK_5, KC_5) ); mKeyMap.insert( KeyMap::value_type(SDLK_6, KC_6) ); mKeyMap.insert( KeyMap::value_type(SDLK_7, KC_7) ); mKeyMap.insert( KeyMap::value_type(SDLK_8, KC_8) ); mKeyMap.insert( KeyMap::value_type(SDLK_9, KC_9) ); mKeyMap.insert( KeyMap::value_type(SDLK_0, KC_0) ); mKeyMap.insert( KeyMap::value_type(SDLK_MINUS, KC_MINUS) ); mKeyMap.insert( KeyMap::value_type(SDLK_EQUALS, KC_EQUALS) ); mKeyMap.insert( KeyMap::value_type(SDLK_BACKSPACE, KC_BACK) ); mKeyMap.insert( KeyMap::value_type(SDLK_TAB, KC_TAB) ); mKeyMap.insert( KeyMap::value_type(SDLK_q, KC_Q) ); mKeyMap.insert( KeyMap::value_type(SDLK_w, KC_W) ); mKeyMap.insert( KeyMap::value_type(SDLK_e, KC_E) ); mKeyMap.insert( KeyMap::value_type(SDLK_r, KC_R) ); mKeyMap.insert( KeyMap::value_type(SDLK_t, KC_T) ); mKeyMap.insert( KeyMap::value_type(SDLK_y, KC_Y) ); mKeyMap.insert( KeyMap::value_type(SDLK_u, KC_U) ); mKeyMap.insert( KeyMap::value_type(SDLK_i, KC_I) ); mKeyMap.insert( KeyMap::value_type(SDLK_o, KC_O) ); mKeyMap.insert( KeyMap::value_type(SDLK_p, KC_P) ); mKeyMap.insert( KeyMap::value_type(SDLK_RETURN, KC_RETURN) ); mKeyMap.insert( KeyMap::value_type(SDLK_LCTRL, KC_LCONTROL)); mKeyMap.insert( KeyMap::value_type(SDLK_a, KC_A) ); mKeyMap.insert( KeyMap::value_type(SDLK_s, KC_S) ); mKeyMap.insert( KeyMap::value_type(SDLK_d, KC_D) ); mKeyMap.insert( KeyMap::value_type(SDLK_f, KC_F) ); mKeyMap.insert( KeyMap::value_type(SDLK_g, KC_G) ); mKeyMap.insert( KeyMap::value_type(SDLK_h, KC_H) ); mKeyMap.insert( KeyMap::value_type(SDLK_j, KC_J) ); mKeyMap.insert( KeyMap::value_type(SDLK_k, KC_K) ); mKeyMap.insert( KeyMap::value_type(SDLK_l, KC_L) ); mKeyMap.insert( KeyMap::value_type(SDLK_SEMICOLON, KC_SEMICOLON) ); mKeyMap.insert( KeyMap::value_type(SDLK_COLON, KC_COLON) ); mKeyMap.insert( KeyMap::value_type(SDLK_QUOTE, KC_APOSTROPHE) ); mKeyMap.insert( KeyMap::value_type(SDLK_BACKQUOTE, KC_GRAVE) ); mKeyMap.insert( KeyMap::value_type(SDLK_LSHIFT, KC_LSHIFT) ); mKeyMap.insert( KeyMap::value_type(SDLK_BACKSLASH, KC_BACKSLASH) ); mKeyMap.insert( KeyMap::value_type(SDLK_SLASH, KC_SLASH) ); mKeyMap.insert( KeyMap::value_type(SDLK_z, KC_Z) ); mKeyMap.insert( KeyMap::value_type(SDLK_x, KC_X) ); mKeyMap.insert( KeyMap::value_type(SDLK_c, KC_C) ); mKeyMap.insert( KeyMap::value_type(SDLK_v, KC_V) ); mKeyMap.insert( KeyMap::value_type(SDLK_b, KC_B) ); mKeyMap.insert( KeyMap::value_type(SDLK_n, KC_N) ); mKeyMap.insert( KeyMap::value_type(SDLK_m, KC_M) ); mKeyMap.insert( KeyMap::value_type(SDLK_COMMA, KC_COMMA) ); mKeyMap.insert( KeyMap::value_type(SDLK_PERIOD, KC_PERIOD)); mKeyMap.insert( KeyMap::value_type(SDLK_RSHIFT, KC_RSHIFT)); mKeyMap.insert( KeyMap::value_type(SDLK_KP_MULTIPLY, KC_MULTIPLY) ); mKeyMap.insert( KeyMap::value_type(SDLK_LALT, KC_LMENU) ); mKeyMap.insert( KeyMap::value_type(SDLK_SPACE, KC_SPACE)); mKeyMap.insert( KeyMap::value_type(SDLK_CAPSLOCK, KC_CAPITAL) ); mKeyMap.insert( KeyMap::value_type(SDLK_F1, KC_F1) ); mKeyMap.insert( KeyMap::value_type(SDLK_F2, KC_F2) ); mKeyMap.insert( KeyMap::value_type(SDLK_F3, KC_F3) ); mKeyMap.insert( KeyMap::value_type(SDLK_F4, KC_F4) ); mKeyMap.insert( KeyMap::value_type(SDLK_F5, KC_F5) ); mKeyMap.insert( KeyMap::value_type(SDLK_F6, KC_F6) ); mKeyMap.insert( KeyMap::value_type(SDLK_F7, KC_F7) ); mKeyMap.insert( KeyMap::value_type(SDLK_F8, KC_F8) ); mKeyMap.insert( KeyMap::value_type(SDLK_F9, KC_F9) ); mKeyMap.insert( KeyMap::value_type(SDLK_F10, KC_F10) ); mKeyMap.insert( KeyMap::value_type(SDLK_NUMLOCK, KC_NUMLOCK) ); mKeyMap.insert( KeyMap::value_type(SDLK_SCROLLOCK, KC_SCROLL)); mKeyMap.insert( KeyMap::value_type(SDLK_KP7, KC_NUMPAD7) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP8, KC_NUMPAD8) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP9, KC_NUMPAD9) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_MINUS, KC_SUBTRACT) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP4, KC_NUMPAD4) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP5, KC_NUMPAD5) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP6, KC_NUMPAD6) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_PLUS, KC_ADD) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP1, KC_NUMPAD1) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP2, KC_NUMPAD2) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP3, KC_NUMPAD3) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP0, KC_NUMPAD0) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_PERIOD, KC_DECIMAL) ); mKeyMap.insert( KeyMap::value_type(SDLK_F11, KC_F11) ); mKeyMap.insert( KeyMap::value_type(SDLK_F12, KC_F12) ); mKeyMap.insert( KeyMap::value_type(SDLK_F13, KC_F13) ); mKeyMap.insert( KeyMap::value_type(SDLK_F14, KC_F14) ); mKeyMap.insert( KeyMap::value_type(SDLK_F15, KC_F15) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_EQUALS, KC_NUMPADEQUALS) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_DIVIDE, KC_DIVIDE) ); mKeyMap.insert( KeyMap::value_type(SDLK_SYSREQ, KC_SYSRQ) ); mKeyMap.insert( KeyMap::value_type(SDLK_RALT, KC_RMENU) ); mKeyMap.insert( KeyMap::value_type(SDLK_HOME, KC_HOME) ); mKeyMap.insert( KeyMap::value_type(SDLK_UP, KC_UP) ); mKeyMap.insert( KeyMap::value_type(SDLK_PAGEUP, KC_PGUP) ); mKeyMap.insert( KeyMap::value_type(SDLK_LEFT, KC_LEFT) ); mKeyMap.insert( KeyMap::value_type(SDLK_RIGHT, KC_RIGHT) ); mKeyMap.insert( KeyMap::value_type(SDLK_END, KC_END) ); mKeyMap.insert( KeyMap::value_type(SDLK_DOWN, KC_DOWN) ); mKeyMap.insert( KeyMap::value_type(SDLK_PAGEDOWN, KC_PGDOWN) ); mKeyMap.insert( KeyMap::value_type(SDLK_INSERT, KC_INSERT) ); mKeyMap.insert( KeyMap::value_type(SDLK_DELETE, KC_DELETE) ); mKeyMap.insert( KeyMap::value_type(SDLK_LSUPER, KC_LWIN) ); mKeyMap.insert( KeyMap::value_type(SDLK_RSUPER, KC_RWIN) ); SDL_EnableUNICODE(1); } //-------------------------------------------------------------------// SDLKeyboard::~SDLKeyboard() { } //-------------------------------------------------------------------// void SDLKeyboard::capture() { SDL_Event events[OIS_SDL_KEY_BUFF]; int count = SDL_PeepEvents(events, OIS_SDL_KEY_BUFF, SDL_GETEVENT, SDL_EVENTMASK(SDL_KEYDOWN) | SDL_EVENTMASK(SDL_KEYUP)); for( int i = 0; i < count; ++i ) { KeyCode kc = mKeyMap[events[i].key.keysym.sym]; KeyBuffer[kc] = events[i].key.state; if( mBuffered && listener ) { if( events[i].key.state == SDL_PRESSED ) { if( listener->keyPressed(KeyEvent(this, 0, kc, events[i].key.keysym.unicode)) == false ) break; } else { if( listener->keyReleased(KeyEvent(this, 0, kc, events[i].key.keysym.unicode)) == false ) break; } } } //Release Grab mode on Alt-Tab combinations (for non-window systems) if( KeyBuffer[KC_RMENU] || KeyBuffer[KC_LMENU]) { if( KeyBuffer[KC_TAB] ) static_cast(InputManager::getSingletonPtr())->_setGrabMode(false); } } //-------------------------------------------------------------------// bool SDLKeyboard::isKeyDown( KeyCode key ) { return KeyBuffer[key] == 1 ? true : false; } //-------------------------------------------------------------------// const std::string& SDLKeyboard::getAsString( KeyCode kc ) { switch(kc) { case KC_ESCAPE: mGetString = SDL_GetKeyName(SDLK_ESCAPE); break; case KC_1: mGetString = SDL_GetKeyName(SDLK_1); break; case KC_2: mGetString = SDL_GetKeyName(SDLK_2); break; case KC_3: mGetString = SDL_GetKeyName(SDLK_3); break; case KC_4: mGetString = SDL_GetKeyName(SDLK_4); break; case KC_5: mGetString = SDL_GetKeyName(SDLK_5); break; case KC_6: mGetString = SDL_GetKeyName(SDLK_6); break; case KC_7: mGetString = SDL_GetKeyName(SDLK_7); break; case KC_8: mGetString = SDL_GetKeyName(SDLK_8); break; case KC_9: mGetString = SDL_GetKeyName(SDLK_9); break; case KC_0: mGetString = SDL_GetKeyName(SDLK_0); break; case KC_MINUS: mGetString = SDL_GetKeyName(SDLK_MINUS); break; case KC_EQUALS: mGetString = SDL_GetKeyName(SDLK_EQUALS); break; case KC_BACK: mGetString = SDL_GetKeyName(SDLK_BACKSPACE); break; case KC_TAB: mGetString = SDL_GetKeyName(SDLK_TAB); break; case KC_Q: mGetString = SDL_GetKeyName(SDLK_q); break; case KC_W: mGetString = SDL_GetKeyName(SDLK_w); break; case KC_E: mGetString = SDL_GetKeyName(SDLK_e); break; case KC_R: mGetString = SDL_GetKeyName(SDLK_r); break; case KC_T: mGetString = SDL_GetKeyName(SDLK_t); break; case KC_Y: mGetString = SDL_GetKeyName(SDLK_y); break; case KC_U: mGetString = SDL_GetKeyName(SDLK_u); break; case KC_I: mGetString = SDL_GetKeyName(SDLK_i); break; case KC_O: mGetString = SDL_GetKeyName(SDLK_o); break; case KC_P: mGetString = SDL_GetKeyName(SDLK_p); break; case KC_LBRACKET: mGetString = "["; break; case KC_RBRACKET: mGetString = "]"; break; case KC_RETURN: mGetString = SDL_GetKeyName(SDLK_RETURN); break; case KC_LCONTROL: mGetString = SDL_GetKeyName(SDLK_LCTRL); break; case KC_A: mGetString = SDL_GetKeyName(SDLK_a); break; case KC_S: mGetString = SDL_GetKeyName(SDLK_s); break; case KC_D: mGetString = SDL_GetKeyName(SDLK_d); break; case KC_F: mGetString = SDL_GetKeyName(SDLK_f); break; case KC_G: mGetString = SDL_GetKeyName(SDLK_g); break; case KC_H: mGetString = SDL_GetKeyName(SDLK_h); break; case KC_J: mGetString = SDL_GetKeyName(SDLK_j); break; case KC_K: mGetString = SDL_GetKeyName(SDLK_k); break; case KC_L: mGetString = SDL_GetKeyName(SDLK_l); break; case KC_SEMICOLON: mGetString = SDL_GetKeyName(SDLK_SEMICOLON); break; case KC_APOSTROPHE: mGetString = SDL_GetKeyName(SDLK_QUOTE); break; case KC_GRAVE: mGetString = SDL_GetKeyName(SDLK_BACKQUOTE); break; case KC_LSHIFT: mGetString = SDL_GetKeyName(SDLK_LSHIFT); break; case KC_BACKSLASH: mGetString = SDL_GetKeyName(SDLK_BACKSLASH); break; case KC_Z: mGetString = SDL_GetKeyName(SDLK_z); break; case KC_X: mGetString = SDL_GetKeyName(SDLK_x); break; case KC_C: mGetString = SDL_GetKeyName(SDLK_c); break; case KC_V: mGetString = SDL_GetKeyName(SDLK_v); break; case KC_B: mGetString = SDL_GetKeyName(SDLK_b); break; case KC_N: mGetString = SDL_GetKeyName(SDLK_n); break; case KC_M: mGetString = SDL_GetKeyName(SDLK_m); break; case KC_COMMA: mGetString = SDL_GetKeyName(SDLK_COMMA); break; case KC_PERIOD: mGetString = SDL_GetKeyName(SDLK_PERIOD); break; case KC_SLASH: mGetString = SDL_GetKeyName(SDLK_SLASH); break; case KC_RSHIFT: mGetString = SDL_GetKeyName(SDLK_RSHIFT); break; case KC_MULTIPLY: mGetString = SDL_GetKeyName(SDLK_KP_MULTIPLY); break; case KC_LMENU: mGetString = SDL_GetKeyName(SDLK_LALT); break; case KC_SPACE: mGetString = SDL_GetKeyName(SDLK_SPACE); break; case KC_CAPITAL: mGetString = SDL_GetKeyName(SDLK_CAPSLOCK); break; case KC_F1: mGetString = SDL_GetKeyName(SDLK_F1); break; case KC_F2: mGetString = SDL_GetKeyName(SDLK_F2); break; case KC_F3: mGetString = SDL_GetKeyName(SDLK_F3); break; case KC_F4: mGetString = SDL_GetKeyName(SDLK_F4); break; case KC_F5: mGetString = SDL_GetKeyName(SDLK_F5); break; case KC_F6: mGetString = SDL_GetKeyName(SDLK_F6); break; case KC_F7: mGetString = SDL_GetKeyName(SDLK_F7); break; case KC_F8: mGetString = SDL_GetKeyName(SDLK_F8); break; case KC_F9: mGetString = SDL_GetKeyName(SDLK_F9); break; case KC_F10: mGetString = SDL_GetKeyName(SDLK_F10); break; case KC_NUMLOCK: mGetString = SDL_GetKeyName(SDLK_NUMLOCK); break; case KC_SCROLL: mGetString = SDL_GetKeyName(SDLK_SCROLLOCK); break; case KC_NUMPAD7: mGetString = SDL_GetKeyName(SDLK_KP7); break; case KC_NUMPAD8: mGetString = SDL_GetKeyName(SDLK_KP8); break; case KC_NUMPAD9: mGetString = SDL_GetKeyName(SDLK_KP9); break; case KC_SUBTRACT: mGetString = SDL_GetKeyName(SDLK_KP_MINUS); break; case KC_NUMPAD4: mGetString = SDL_GetKeyName(SDLK_KP4); break; case KC_NUMPAD5: mGetString = SDL_GetKeyName(SDLK_KP5); break; case KC_NUMPAD6: mGetString = SDL_GetKeyName(SDLK_KP6); break; case KC_ADD: mGetString = SDL_GetKeyName(SDLK_KP_PLUS); break; case KC_NUMPAD1: mGetString = SDL_GetKeyName(SDLK_KP1); break; case KC_NUMPAD2: mGetString = SDL_GetKeyName(SDLK_KP2); break; case KC_NUMPAD3: mGetString = SDL_GetKeyName(SDLK_KP3); break; case KC_NUMPAD0: mGetString = SDL_GetKeyName(SDLK_KP0); break; case KC_DECIMAL: mGetString = SDL_GetKeyName(SDLK_KP_PERIOD); break; case KC_OEM_102: mGetString = "OEM_102"; break; case KC_F11: mGetString = SDL_GetKeyName(SDLK_F11); break; case KC_F12: mGetString = SDL_GetKeyName(SDLK_F12); break; case KC_F13: mGetString = SDL_GetKeyName(SDLK_F13); break; case KC_F14: mGetString = SDL_GetKeyName(SDLK_F14); break; case KC_F15: mGetString = SDL_GetKeyName(SDLK_F15); break; case KC_KANA: mGetString = "Kana"; break; case KC_ABNT_C1: mGetString = "ABNT_C1"; break; case KC_CONVERT: mGetString = "CONVERT"; break; case KC_NOCONVERT: mGetString = "NOCONVERT"; break; case KC_YEN: mGetString = "YEN"; break; case KC_ABNT_C2: mGetString = "ABNT_C2"; break; case KC_NUMPADEQUALS: mGetString = SDL_GetKeyName(SDLK_KP_EQUALS); break; case KC_PREVTRACK: mGetString = "KC_PREVTRACK"; break; case KC_AT: mGetString = "KC_AT"; break; case KC_COLON: mGetString = SDL_GetKeyName(SDLK_COLON); break; case KC_UNDERLINE: mGetString = "KC_UNDERLINE"; break; case KC_KANJI: mGetString = "KC_KANJI"; break; case KC_STOP: mGetString = "KC_STOP"; break; case KC_AX: mGetString = "KC_AX"; break; case KC_UNLABELED: mGetString = "KC_UNLABELED"; break; case KC_NEXTTRACK: mGetString = "KC_NEXTTRACK"; break; case KC_NUMPADENTER: mGetString = "KC_NUMPADENTER"; break; case KC_RCONTROL: mGetString = "KC_RCONTROL"; break; case KC_MUTE: mGetString = "KC_MUTE"; break; case KC_CALCULATOR: mGetString = "KC_CALCULATOR"; break; case KC_PLAYPAUSE: mGetString = "KC_PLAYPAUSE"; break; case KC_MEDIASTOP: mGetString = "KC_MEDIASTOP"; break; case KC_VOLUMEDOWN: mGetString = "KC_VOLUMEDOWN"; break; case KC_VOLUMEUP: mGetString = "KC_VOLUMEUP"; break; case KC_WEBHOME: mGetString = "KC_WEBHOME"; break; case KC_NUMPADCOMMA: mGetString = "KC_NUMPADCOMMA"; break; case KC_DIVIDE: mGetString = SDL_GetKeyName(SDLK_KP_DIVIDE); break; case KC_SYSRQ: mGetString = SDL_GetKeyName(SDLK_SYSREQ); break; case KC_RMENU: mGetString = SDL_GetKeyName(SDLK_RALT); break; case KC_PAUSE: mGetString = "Pause"; break; case KC_HOME: mGetString = SDL_GetKeyName(SDLK_HOME); break; case KC_UP: mGetString = SDL_GetKeyName(SDLK_UP); break; case KC_PGUP: mGetString = SDL_GetKeyName(SDLK_PAGEUP); break; case KC_LEFT: mGetString = SDL_GetKeyName(SDLK_LEFT); break; case KC_RIGHT: mGetString = SDL_GetKeyName(SDLK_RIGHT); break; case KC_END: mGetString = SDL_GetKeyName(SDLK_END); break; case KC_DOWN: mGetString = SDL_GetKeyName(SDLK_DOWN); break; case KC_PGDOWN: mGetString = SDL_GetKeyName(SDLK_PAGEDOWN); break; case KC_INSERT: mGetString = SDL_GetKeyName(SDLK_INSERT); break; case KC_DELETE: mGetString = SDL_GetKeyName(SDLK_DELETE); break; case KC_LWIN: mGetString = SDL_GetKeyName(SDLK_LSUPER); break; case KC_RWIN: mGetString = SDL_GetKeyName(SDLK_RSUPER); break; case KC_APPS: mGetString = "KC_APPS"; break; case KC_POWER: mGetString = "KC_POWER"; break; case KC_SLEEP: mGetString = "KC_SLEEP"; break; case KC_WAKE: mGetString = "KC_WAKE"; break; case KC_WEBSEARCH: mGetString = "KC_WEBSEARCH"; break; case KC_WEBFAVORITES: mGetString = "KC_WEBFAVORITES"; break; case KC_WEBREFRESH: mGetString = "KC_WEBREFRESH"; break; case KC_WEBSTOP: mGetString = "KC_WEBSTOP"; break; case KC_WEBFORWARD: mGetString = "KC_WEBFORWARD"; break; case KC_WEBBACK: mGetString = "KC_WEBBACK"; break; case KC_MYCOMPUTER: mGetString = "KC_MYCOMPUTER"; break; case KC_MAIL: mGetString = "KC_MAIL"; break; case KC_MEDIASELECT: mGetString = "KC_MEDIASELECT"; break; default: mGetString = "Unknown"; break; }; return mGetString; } //-------------------------------------------------------------------// void SDLKeyboard::copyKeyStates( char keys[256] ) { for(int i = 0; i < 256; ++i) keys[i] = KeyBuffer[i]; } //-------------------------------------------------------------------// void SDLKeyboard::setBuffered(bool buffered) { mBuffered = buffered; } //-------------------------------------------------------------------// void SDLKeyboard::setTextTranslation( TextTranslationMode mode ) { mTextMode = mode; if( mode == Off || mode == Ascii ) SDL_EnableUNICODE(0); else if( mode == Unicode ) SDL_EnableUNICODE(1); } ois-1.3.0.dfsg0.orig/src/SDL/SDLInputManager.cpp0000664000175000017500000000650611562210433021006 0ustar alessioalessio/* The zlib/libpng License Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL/SDLInputManager.h" #include "SDL/SDLKeyboard.h" #include "SDL/SDLMouse.h" #include "SDL/SDLJoyStick.h" #include "OISException.h" #include "OISObject.h" using namespace OIS; const std::string SDLInputManager::iName = "SDL Input Wrapper"; //--------------------------------------------------------------------------------// SDLInputManager::SDLInputManager() : mGrabbed(false) { } //--------------------------------------------------------------------------------// SDLInputManager::~SDLInputManager() { } //--------------------------------------------------------------------------------// void SDLInputManager::_initialize( ParamList ¶mList ) { Uint32 flags = SDL_WasInit(0); if( flags == 0 ) OIS_EXCEPT( E_General, "SDLInputManager::SDLInputManager >> SDL Not Initialized already!"); //Ok, now we have DirectInput, parse whatever extra settings were sent to us _parseConfigSettings( paramList ); _enumerateDevices(); } //--------------------------------------------------------------------------------// void SDLInputManager::_parseConfigSettings( ParamList ¶mList ) { } //--------------------------------------------------------------------------------// void SDLInputManager::_enumerateDevices() { } //--------------------------------------------------------------------------------// int SDLInputManager::numJoySticks() { return 0; } //--------------------------------------------------------------------------------// int SDLInputManager::numMice() { return 1; } //--------------------------------------------------------------------------------// int SDLInputManager::numKeyboards() { return 1; } //----------------------------------------------------------------------------// Object* SDLInputManager::createInputObject( Type iType, bool bufferMode ) { Object* obj = 0; switch( iType ) { case OISKeyboard: obj = new SDLKeyboard( bufferMode ); break; case OISMouse: obj = new SDLMouse( bufferMode ); break; case OISJoyStick: default: OIS_EXCEPT( E_InputDeviceNotSupported, "Type not implemented"); } try { obj->_initialize(); } catch(...) { delete obj; throw; //rethrow } return obj; } //----------------------------------------------------------------------------// void SDLInputManager::destroyInputObject( Object* obj ) { if( obj == 0 ) return; delete obj; } ois-1.3.0.dfsg0.orig/OIS.pc.in0000664000175000017500000000035311562210433015511 0ustar alessioalessioprefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: OIS Description: Cross platform C++ Input Framework Version: @VERSION@ Libs: -L${libdir} -lOIS Cflags: -I${includedir}/@PACKAGE@ -I${includedir}