Commit 7087bd0f authored by Kyle Rassweiler's avatar Kyle Rassweiler
Browse files

Merge branch 'master' of https://github.com/wgois/OIS

Conflicts:
	demos/OISConsole.cpp

Had pushed this fix to the wrong repo previously - KR
parents abd16784 692546bf
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2006 Chris Snyder Copyright (c) 2006 Chris Snyder
This software is provided 'as-is', without any express or implied warranty. In no event will 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_MacInputManager_H #ifndef OIS_MacInputManager_H
#define OIS_MacInputManager_H #define OIS_MacInputManager_H
#include "OISInputManager.h" #include "OISInputManager.h"
#include "OISFactoryCreator.h" #include "OISFactoryCreator.h"
#include "mac/MacPrereqs.h" #include "mac/MacPrereqs.h"
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
namespace OIS namespace OIS
{ {
class MacInputManager : public InputManager, public FactoryCreator class MacInputManager : public InputManager, public FactoryCreator
{ {
public: public:
MacInputManager(); MacInputManager();
virtual ~MacInputManager(); virtual ~MacInputManager();
//InputManager Overrides //InputManager Overrides
/** @copydoc InputManager::_initialize */ /** @copydoc InputManager::_initialize */
void _initialize( ParamList &paramList ); void _initialize( ParamList &paramList );
//FactoryCreator Overrides //FactoryCreator Overrides
/** @copydoc FactoryCreator::deviceList */ /** @copydoc FactoryCreator::deviceList */
DeviceList freeDeviceList(); DeviceList freeDeviceList();
/** @copydoc FactoryCreator::totalDevices */ /** @copydoc FactoryCreator::totalDevices */
int totalDevices(Type iType); int totalDevices(Type iType);
/** @copydoc FactoryCreator::freeDevices */ /** @copydoc FactoryCreator::freeDevices */
int freeDevices(Type iType); int freeDevices(Type iType);
/** @copydoc FactoryCreator::vendorExist */ /** @copydoc FactoryCreator::vendorExist */
bool vendorExist(Type iType, const std::string & vendor); bool vendorExist(Type iType, const std::string & vendor);
/** @copydoc FactoryCreator::createObject */ /** @copydoc FactoryCreator::createObject */
Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = ""); Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = "");
/** @copydoc FactoryCreator::destroyObject */ /** @copydoc FactoryCreator::destroyObject */
void destroyObject(Object* obj); void destroyObject(Object* obj);
//Internal Items //Internal Items
//! Internal method, used for flaggin keyboard as available/unavailable for creation //! Internal method, used for flaggin keyboard as available/unavailable for creation
void _setKeyboardUsed(bool used) {keyboardUsed = used; } void _setKeyboardUsed(bool used) {keyboardUsed = used; }
//! Internal method, used for flaggin mouse as available/unavailable for creation //! Internal method, used for flaggin mouse as available/unavailable for creation
void _setMouseUsed(bool used) { mouseUsed = used; } void _setMouseUsed(bool used) { mouseUsed = used; }
//! methodfor getting the event target //! methodfor getting the event target
EventTargetRef _getEventTarget() {return mEventTargetRef;} EventTargetRef _getEventTarget() {return mEventTargetRef;}
//! method for getting window //! method for getting window
WindowRef _getWindow() {return mWindow;} WindowRef _getWindow() {return mWindow;}
protected: protected:
void _parseConfigSettings( ParamList& paramList ); void _parseConfigSettings( ParamList& paramList );
void _enumerateDevices(); void _enumerateDevices();
static const std::string iName; static const std::string iName;
// Mac stuff // Mac stuff
EventTargetRef mEventTargetRef; EventTargetRef mEventTargetRef;
WindowRef mWindow; WindowRef mWindow;
// settings // settings
bool mHideMouse; bool mHideMouse;
bool mUseRepeat; bool mUseRepeat;
//! Used to know if we used up keyboard //! Used to know if we used up keyboard
bool keyboardUsed; bool keyboardUsed;
//! Used to know if we used up mouse //! Used to know if we used up mouse
bool mouseUsed; bool mouseUsed;
//! HID Manager class handling devices other than keyboard/mouse //! HID Manager class handling devices other than keyboard/mouse
MacHIDManager *mHIDManager; MacHIDManager *mHIDManager;
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef MAC_Joystick_H #ifndef MAC_Joystick_H
#define MAC_Joystick_H #define MAC_Joystick_H
#include "OISJoyStick.h" #include "OISJoyStick.h"
#include "mac/MacPrereqs.h" #include "mac/MacPrereqs.h"
#include "mac/MacHIDManager.h" #include "mac/MacHIDManager.h"
namespace OIS namespace OIS
{ {
struct AxisInfo struct AxisInfo
{ {
int min; int min;
int max; int max;
AxisInfo(int min, int max) AxisInfo(int min, int max)
: min(min), max(max) {} : min(min), max(max) {}
}; };
typedef struct cookie_struct typedef struct cookie_struct
{ {
std::map<IOHIDElementCookie, AxisInfo> axisCookies; std::map<IOHIDElementCookie, AxisInfo> axisCookies;
std::vector<IOHIDElementCookie> buttonCookies; std::vector<IOHIDElementCookie> buttonCookies;
} cookie_struct_t; } cookie_struct_t;
//class HidDeviceInfo //class HidDeviceInfo
class MacJoyStick : public JoyStick class MacJoyStick : public JoyStick
{ {
public: public:
MacJoyStick(const std::string& vendor, bool buffered, HidInfo* info, InputManager* creator, int devID); MacJoyStick(const std::string& vendor, bool buffered, HidInfo* info, InputManager* creator, int devID);
virtual ~MacJoyStick(); virtual ~MacJoyStick();
/** @copydoc Object::setBuffered */ /** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered); virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */ /** @copydoc Object::capture */
virtual void capture(); virtual void capture();
/** @copydoc Object::queryInterface */ /** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type); virtual Interface* queryInterface(Interface::IType type);
/** @copydoc Object::_initialize */ /** @copydoc Object::_initialize */
virtual void _initialize(); virtual void _initialize();
void _enumerateCookies(); void _enumerateCookies();
IOHIDQueueInterface** _createQueue(unsigned int depth = 8); IOHIDQueueInterface** _createQueue(unsigned int depth = 8);
protected: protected:
HidInfo* mInfo; HidInfo* mInfo;
cookie_struct_t mCookies; cookie_struct_t mCookies;
IOHIDQueueInterface** mQueue; IOHIDQueueInterface** mQueue;
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2006 Chris Snyder Copyright (c) 2006 Chris Snyder
This software is provided 'as-is', without any express or implied warranty. In no event will 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_MacKeyboard_H #ifndef OIS_MacKeyboard_H
#define OIS_MacKeyboard_H #define OIS_MacKeyboard_H
#include "OISKeyboard.h" #include "OISKeyboard.h"
#include "mac/MacHelpers.h" #include "mac/MacHelpers.h"
#include "mac/MacPrereqs.h" #include "mac/MacPrereqs.h"
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
namespace OIS namespace OIS
{ {
class MacKeyboard : public Keyboard class MacKeyboard : public Keyboard
{ {
public: public:
MacKeyboard( InputManager* creator, bool buffered, bool repeat ); MacKeyboard( InputManager* creator, bool buffered, bool repeat );
virtual ~MacKeyboard(); virtual ~MacKeyboard();
// Sets buffered mode // Sets buffered mode
virtual void setBuffered( bool buffered ); virtual void setBuffered( bool buffered );
// unbuffered keydown check // unbuffered keydown check
virtual bool isKeyDown( KeyCode key ) const; virtual bool isKeyDown( KeyCode key ) const;
// This will send listener events if buffered is on. // This will send listener events if buffered is on.
// Note that in the mac implementation, unbuffered input is // Note that in the mac implementation, unbuffered input is
// automatically updated without calling this. // automatically updated without calling this.
virtual void capture(); virtual void capture();
// Copies the current key buffer // Copies the current key buffer
virtual void copyKeyStates( char keys[256] ) const; virtual void copyKeyStates( char keys[256] ) const;
// Returns a description of the given key // Returns a description of the given key
virtual std::string& getAsString( KeyCode key ); virtual std::string& getAsString( KeyCode key );
virtual KeyCode getAsKeyCode( std::string str ) {/*TODO: Implement OS version*/;}
virtual Interface* queryInterface( Interface::IType type ) { return 0; }
virtual Interface* queryInterface( Interface::IType type ) { return 0; }
// Public but reserved for internal use:
virtual void _initialize(); // Public but reserved for internal use:
void _keyDownCallback( EventRef theEvent ); virtual void _initialize();
void _keyUpCallback( EventRef theEvent ); void _keyDownCallback( EventRef theEvent );
void _modChangeCallback( EventRef theEvent ); void _keyUpCallback( EventRef theEvent );
void _modChangeCallback( EventRef theEvent );
protected:
// just to get this out of the way protected:
void populateKeyConversion(); // just to get this out of the way
void populateKeyConversion();
// updates the keybuffer and optionally the eventStack
void injectEvent(KeyCode kc, unsigned int time, MacEventType type, unsigned int txt = 0 ); // updates the keybuffer and optionally the eventStack
void injectEvent(KeyCode kc, unsigned int time, MacEventType type, unsigned int txt = 0 );
typedef std::map<UInt32, KeyCode> VirtualtoOIS_KeyMap;
VirtualtoOIS_KeyMap keyConversion; typedef std::map<UInt32, KeyCode> VirtualtoOIS_KeyMap;
VirtualtoOIS_KeyMap keyConversion;
std::string getString;
std::string getString;
char KeyBuffer[256];
UInt32 prevModMask; char KeyBuffer[256];
UInt32 prevModMask;
// "universal procedure pointers" - required reference for callbacks
EventHandlerUPP keyDownUPP; // "universal procedure pointers" - required reference for callbacks
EventHandlerUPP keyUpUPP; EventHandlerUPP keyDownUPP;
EventHandlerUPP keyModUPP; EventHandlerUPP keyUpUPP;
EventHandlerUPP keyModUPP;
// so we can delete the handlers on destruction
EventHandlerRef keyDownEventRef; // so we can delete the handlers on destruction
EventHandlerRef keyUpEventRef; EventHandlerRef keyDownEventRef;
EventHandlerRef keyModEventRef; EventHandlerRef keyUpEventRef;
EventHandlerRef keyModEventRef;
// buffered events, fifo stack
typedef std::list<MacKeyStackEvent> eventStack; // buffered events, fifo stack
eventStack pendingEvents; typedef std::list<MacKeyStackEvent> eventStack;
eventStack pendingEvents;
bool useRepeat;
bool useRepeat;
};
} };
#endif }
#endif
#ifndef OIS_MacMouse_H #ifndef OIS_MacMouse_H
#define OIS_MacMouse_H #define OIS_MacMouse_H
#include "OISMouse.h" #include "OISMouse.h"
#include "mac/MacHelpers.h" #include "mac/MacHelpers.h"
#include "mac/MacPrereqs.h" #include "mac/MacPrereqs.h"
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
namespace OIS namespace OIS
{ {
class MacMouse : public Mouse class MacMouse : public Mouse
{ {
public: public:
MacMouse( InputManager* creator, bool buffered ); MacMouse( InputManager* creator, bool buffered );
virtual ~MacMouse(); virtual ~MacMouse();
/** @copydoc Object::setBuffered */ /** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered); virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */ /** @copydoc Object::capture */
virtual void capture(); virtual void capture();
/** @copydoc Object::queryInterface */ /** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type) {return 0;} virtual Interface* queryInterface(Interface::IType type) {return 0;}
/** @copydoc Object::_initialize */ /** @copydoc Object::_initialize */
virtual void _initialize(); virtual void _initialize();
public: public:
void _mouseCallback( EventRef theEvent ); void _mouseCallback( EventRef theEvent );
protected: protected:
static OSStatus WindowFocusChanged(EventHandlerCallRef nextHandler, EventRef event, void* macMouse); static OSStatus WindowFocusChanged(EventHandlerCallRef nextHandler, EventRef event, void* macMouse);
// "universal procedure pointers" - required reference for callbacks // "universal procedure pointers" - required reference for callbacks
EventHandlerUPP mouseUPP; EventHandlerUPP mouseUPP;
EventHandlerRef mouseEventRef; EventHandlerRef mouseEventRef;
EventHandlerUPP mWindowFocusListener; EventHandlerUPP mWindowFocusListener;
EventHandlerRef mWindowFocusHandler; EventHandlerRef mWindowFocusHandler;
bool mNeedsToRegainFocus; bool mNeedsToRegainFocus;
bool mMouseWarped; bool mMouseWarped;
MouseState mTempState; MouseState mTempState;
}; };
} }
#endif // OIS_MacMouse_H #endif // OIS_MacMouse_H
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2006 Chris Snyder Copyright (c) 2006 Chris Snyder
This software is provided 'as-is', without any express or implied warranty. In no event will 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_MacPrereqs_H #ifndef OIS_MacPrereqs_H
#define OIS_MacPrereqs_H #define OIS_MacPrereqs_H
#include <string> #include <string>
#include <list> #include <list>
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
namespace OIS namespace OIS
{ {
class MacInputManager; class MacInputManager;
class MacHIDManager; class MacHIDManager;
class MacMouse; class MacMouse;
class MacKeyboard; class MacKeyboard;
/** /**
Simple wrapper class for CFString which will create a valid CFString and retain ownership until class instance is outof scope Simple wrapper class for CFString which will create a valid CFString and retain ownership until class instance is outof scope
To Access the CFStringRef instance, simply cast to void*, pass into a function expecting a void* CFStringRef object, or access via cf_str() method To Access the CFStringRef instance, simply cast to void*, pass into a function expecting a void* CFStringRef object, or access via cf_str() method
*/ */
class OIS_CFString class OIS_CFString
{ {
public: public:
OIS_CFString() { m_StringRef = CFStringCreateWithCString(NULL, "", kCFStringEncodingUTF8); } OIS_CFString() { m_StringRef = CFStringCreateWithCString(NULL, "", kCFStringEncodingUTF8); }
OIS_CFString(const char* c_str) { m_StringRef = CFStringCreateWithCString(NULL, c_str, kCFStringEncodingUTF8); } OIS_CFString(const char* c_str) { m_StringRef = CFStringCreateWithCString(NULL, c_str, kCFStringEncodingUTF8); }
OIS_CFString(const std::string &s_str) { m_StringRef = CFStringCreateWithCString(NULL, s_str.c_str(), kCFStringEncodingUTF8); } OIS_CFString(const std::string &s_str) { m_StringRef = CFStringCreateWithCString(NULL, s_str.c_str(), kCFStringEncodingUTF8); }
~OIS_CFString() { CFRelease(m_StringRef); } ~OIS_CFString() { CFRelease(m_StringRef); }
//Allow this class to be autoconverted to base class of StringRef (void*) //Allow this class to be autoconverted to base class of StringRef (void*)
operator void*() { return (void*)m_StringRef; } operator void*() { return (void*)m_StringRef; }
CFStringRef cf_str() { return m_StringRef; } CFStringRef cf_str() { return m_StringRef; }
private: private:
CFStringRef m_StringRef; CFStringRef m_StringRef;
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_Win32ForceFeedBack_H #ifndef OIS_Win32ForceFeedBack_H
#define OIS_Win32ForceFeedBack_H #define OIS_Win32ForceFeedBack_H
#include "OISPrereqs.h" #include "OISPrereqs.h"
#include "OISForceFeedback.h" #include "OISForceFeedback.h"
#include "win32/Win32Prereqs.h" #include "win32/Win32Prereqs.h"
namespace OIS namespace OIS
{ {
class Win32ForceFeedback : public ForceFeedback class Win32ForceFeedback : public ForceFeedback
{ {
Win32ForceFeedback() {} Win32ForceFeedback() {}
public: public:
Win32ForceFeedback(IDirectInputDevice8* pDIJoy, const DIDEVCAPS* pDIJoyCaps); Win32ForceFeedback(IDirectInputDevice8* pDIJoy, const DIDEVCAPS* pDIJoyCaps);
~Win32ForceFeedback(); ~Win32ForceFeedback();
/** @copydoc ForceFeedback::upload */ /** @copydoc ForceFeedback::upload */
void upload( const Effect* effect ); void upload( const Effect* effect );
/** @copydoc ForceFeedback::modify */ /** @copydoc ForceFeedback::modify */
void modify( const Effect* effect ); void modify( const Effect* effect );
/** @copydoc ForceFeedback::remove */ /** @copydoc ForceFeedback::remove */
void remove( const Effect* effect ); void remove( const Effect* effect );
/** @copydoc ForceFeedback::setMasterGain */ /** @copydoc ForceFeedback::setMasterGain */
void setMasterGain( float level ); void setMasterGain( float level );
/** @copydoc ForceFeedback::setAutoCenterMode */ /** @copydoc ForceFeedback::setAutoCenterMode */
void setAutoCenterMode( bool auto_on ); void setAutoCenterMode( bool auto_on );
/** @copydoc ForceFeedback::getFFAxesNumber */ /** @copydoc ForceFeedback::getFFAxesNumber */
short getFFAxesNumber(); short getFFAxesNumber();
/** @copydoc ForceFeedback::getFFMemoryLoad */ /** @copydoc ForceFeedback::getFFMemoryLoad */
unsigned short getFFMemoryLoad(); unsigned short getFFMemoryLoad();
/** /**
@remarks @remarks
Internal use.. Used during enumeration to build a list of a devices Internal use.. Used during enumeration to build a list of a devices
support effects. support effects.
*/ */
void _addEffectSupport( LPCDIEFFECTINFO pdei ); void _addEffectSupport( LPCDIEFFECTINFO pdei );
/** /**
@remarks @remarks
Internal use.. Used during axis enumeration to get number of FF axes Internal use.. Used during axis enumeration to get number of FF axes
support effects. support effects.
*/ */
void _addFFAxis(); void _addFFAxis();
protected: protected:
//Specific Effect Settings //Specific Effect Settings
void _updateConstantEffect( const Effect* effect ); void _updateConstantEffect( const Effect* effect );
void _updateRampEffect( const Effect* effect ); void _updateRampEffect( const Effect* effect );
void _updatePeriodicEffect( const Effect* effect ); void _updatePeriodicEffect( const Effect* effect );
void _updateConditionalEffect( const Effect* effect ); void _updateConditionalEffect( const Effect* effect );
void _updateCustomEffect( const Effect* effect ); void _updateCustomEffect( const Effect* effect );
//Sets the common properties to all effects //Sets the common properties to all effects
void _setCommonProperties( DIEFFECT* diEffect, DWORD* rgdwAxes, void _setCommonProperties( DIEFFECT* diEffect, DWORD* rgdwAxes,
LONG* rglDirection, DIENVELOPE* diEnvelope, DWORD struct_size, LONG* rglDirection, DIENVELOPE* diEnvelope, DWORD struct_size,
LPVOID struct_type, const Effect* effect, const Envelope* envelope ); LPVOID struct_type, const Effect* effect, const Envelope* envelope );
//Actually do the upload //Actually do the upload
void _upload( GUID, DIEFFECT*, const Effect* ); void _upload( GUID, DIEFFECT*, const Effect* );
// Map of currently uploaded effects (handle => effect) // Map of currently uploaded effects (handle => effect)
typedef std::map<int,LPDIRECTINPUTEFFECT> EffectList; typedef std::map<int,LPDIRECTINPUTEFFECT> EffectList;
EffectList mEffectList; EffectList mEffectList;
//Simple unique handle creation - allows for upto 2+ billion effects //Simple unique handle creation - allows for upto 2+ billion effects
//during the lifetime of application. Hopefully, that is enough. //during the lifetime of application. Hopefully, that is enough.
int mHandles; int mHandles;
// Joystick device descriptor. // Joystick device descriptor.
IDirectInputDevice8* mJoyStick; IDirectInputDevice8* mJoyStick;
// Joystick capabilities. // Joystick capabilities.
const DIDEVCAPS* mpDIJoyCaps; const DIDEVCAPS* mpDIJoyCaps;
// Number of axis supporting FF. // Number of axis supporting FF.
short mFFAxes; short mFFAxes;
}; };
} }
#endif //OIS_Win32ForceFeedBack_H #endif //OIS_Win32ForceFeedBack_H
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef OIS_Win32InputManager_H #ifndef OIS_Win32InputManager_H
#define OIS_Win32InputManager_H #define OIS_Win32InputManager_H
#include "OISInputManager.h" #include "OISInputManager.h"
#include "OISFactoryCreator.h" #include "OISFactoryCreator.h"
#include "win32/Win32Prereqs.h" #include "win32/Win32Prereqs.h"
namespace OIS namespace OIS
{ {
/** Win32InputManager specialization - Using DirectInput8 */ /** Win32InputManager specialization - Using DirectInput8 */
class Win32InputManager : public InputManager, public FactoryCreator class Win32InputManager : public InputManager, public FactoryCreator
{ {
public: public:
Win32InputManager(); Win32InputManager();
virtual ~Win32InputManager(); virtual ~Win32InputManager();
//InputManager Overrides //InputManager Overrides
/** @copydoc InputManager::_initialize */ /** @copydoc InputManager::_initialize */
void _initialize( ParamList &paramList ); void _initialize( ParamList &paramList );
//FactoryCreator Overrides //FactoryCreator Overrides
/** @copydoc FactoryCreator::deviceList */ /** @copydoc FactoryCreator::deviceList */
DeviceList freeDeviceList(); DeviceList freeDeviceList();
/** @copydoc FactoryCreator::totalDevices */ /** @copydoc FactoryCreator::totalDevices */
int totalDevices(Type iType); int totalDevices(Type iType);
/** @copydoc FactoryCreator::freeDevices */ /** @copydoc FactoryCreator::freeDevices */
int freeDevices(Type iType); int freeDevices(Type iType);
/** @copydoc FactoryCreator::vendorExist */ /** @copydoc FactoryCreator::vendorExist */
bool vendorExist(Type iType, const std::string & vendor); bool vendorExist(Type iType, const std::string & vendor);
/** @copydoc FactoryCreator::createObject */ /** @copydoc FactoryCreator::createObject */
Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = ""); Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = "");
/** @copydoc FactoryCreator::destroyObject */ /** @copydoc FactoryCreator::destroyObject */
void destroyObject(Object* obj); void destroyObject(Object* obj);
//Internal Items //Internal Items
//! Internal method, used for flaggin keyboard as available/unavailable for creation //! Internal method, used for flaggin keyboard as available/unavailable for creation
void _setKeyboardUsed(bool used) {keyboardUsed = used; } void _setKeyboardUsed(bool used) {keyboardUsed = used; }
//! Internal method, used for flaggin mouse as available/unavailable for creation //! Internal method, used for flaggin mouse as available/unavailable for creation
void _setMouseUsed(bool used) { mouseUsed = used; } void _setMouseUsed(bool used) { mouseUsed = used; }
//! Internal method, return unused joystick to queue //! Internal method, return unused joystick to queue
void _returnJoyStick(const JoyStickInfo& joystick); void _returnJoyStick(const JoyStickInfo& joystick);
//! Returns HWND needed by DirectInput Device Object //! Returns HWND needed by DirectInput Device Object
HWND getWindowHandle() { return hWnd; } HWND getWindowHandle() { return hWnd; }
protected: protected:
//! internal class method for dealing with param list //! internal class method for dealing with param list
void _parseConfigSettings( ParamList &paramList ); void _parseConfigSettings( ParamList &paramList );
//! internal class method for finding attached devices //! internal class method for finding attached devices
void _enumerateDevices(); void _enumerateDevices();
//! Used during device enumeration //! Used during device enumeration
static BOOL CALLBACK _DIEnumDevCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef); static BOOL CALLBACK _DIEnumDevCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
//! Keep a list of all joysticks enumerated, but not in use //! Keep a list of all joysticks enumerated, but not in use
JoyStickInfoList unusedJoyStickList; JoyStickInfoList unusedJoyStickList;
//! The window handle we are using //! The window handle we are using
HWND hWnd; HWND hWnd;
//! Direct Input Interface //! Direct Input Interface
IDirectInput8* mDirectInput; IDirectInput8* mDirectInput;
//! Used for keyboard device settings //! Used for keyboard device settings
DWORD kbSettings; DWORD kbSettings;
//! Used for mouse device settings //! Used for mouse device settings
DWORD mouseSettings; DWORD mouseSettings;
//! Used for joystick device settings //! Used for joystick device settings
DWORD joySettings; DWORD joySettings;
//! Number of total joysticks (inuse or not) //! Number of total joysticks (inuse or not)
char joySticks; char joySticks;
//! Used to know if we used up keyboard //! Used to know if we used up keyboard
bool keyboardUsed; bool keyboardUsed;
//! Used to know if we used up mouse //! Used to know if we used up mouse
bool mouseUsed; bool mouseUsed;
}; };
} }
#endif #endif
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef _WIN32_JOYSTICK_H_EADER_ #ifndef _WIN32_JOYSTICK_H_EADER_
#define _WIN32_JOYSTICK_H_EADER_ #define _WIN32_JOYSTICK_H_EADER_
#include "OISJoyStick.h" #include "OISJoyStick.h"
#include "win32/Win32Prereqs.h" #include "win32/Win32Prereqs.h"
namespace OIS namespace OIS
{ {
class Win32JoyStick : public JoyStick class Win32JoyStick : public JoyStick
{ {
public: public:
Win32JoyStick( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings, const JoyStickInfo &info ); Win32JoyStick( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings, const JoyStickInfo &info );
virtual ~Win32JoyStick(); virtual ~Win32JoyStick();
/** @copydoc Object::setBuffered */ /** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered); virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */ /** @copydoc Object::capture */
virtual void capture(); virtual void capture();
//! hanlde xinput //! hanlde xinput
void captureXInput(); void captureXInput();
/** @copydoc Object::queryInterface */ /** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type); virtual Interface* queryInterface(Interface::IType type);
/** @copydoc Object::_initialize */ /** @copydoc Object::_initialize */
virtual void _initialize(); virtual void _initialize();
#ifdef OIS_WIN32_XINPUT_SUPPORT #ifdef OIS_WIN32_XINPUT_SUPPORT
/** /**
@remarks @remarks
Enum each PNP device using WMI and check each device ID to see if it contains Enum each PNP device using WMI and check each device ID to see if it contains
"IG_" (ex. "VID_045E&PID_028E&IG_00"). If it does, then it's an XInput device "IG_" (ex. "VID_045E&PID_028E&IG_00"). If it does, then it's an XInput device
Unfortunately this information can not be found by just using DirectInput Unfortunately this information can not be found by just using DirectInput
*/ */
static void CheckXInputDevices(JoyStickInfoList &joys); static void CheckXInputDevices(JoyStickInfoList &joys);
#endif #endif
protected: protected:
//! Enumerates all things //! Enumerates all things
void _enumerate(); void _enumerate();
//! Enumerate axis callback //! Enumerate axis callback
static BOOL CALLBACK DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef); static BOOL CALLBACK DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef);
//! Enumerate Force Feedback callback //! Enumerate Force Feedback callback
static BOOL CALLBACK DIEnumEffectsCallback(LPCDIEFFECTINFO pdei, LPVOID pvRef); static BOOL CALLBACK DIEnumEffectsCallback(LPCDIEFFECTINFO pdei, LPVOID pvRef);
bool _doButtonClick( int button, DIDEVICEOBJECTDATA& di ); bool _doButtonClick( int button, DIDEVICEOBJECTDATA& di );
bool _changePOV( int pov, DIDEVICEOBJECTDATA& di ); bool _changePOV( int pov, DIDEVICEOBJECTDATA& di );
IDirectInput8* mDirectInput; IDirectInput8* mDirectInput;
IDirectInputDevice8* mJoyStick; IDirectInputDevice8* mJoyStick;
DIDEVCAPS mDIJoyCaps; DIDEVCAPS mDIJoyCaps;
DWORD coopSetting; DWORD coopSetting;
JoyStickInfo mJoyInfo; JoyStickInfo mJoyInfo;
//! A force feedback device //! A force feedback device
Win32ForceFeedback* mFfDevice; Win32ForceFeedback* mFfDevice;
//! Mapping //! Mapping
int _AxisNumber; int _AxisNumber;
}; };
} }
#endif //_WIN32_JOYSTICK_H_EADER_ #endif //_WIN32_JOYSTICK_H_EADER_
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef _WIN32_KEYBOARD_H_EADER_ #ifndef _WIN32_KEYBOARD_H_EADER_
#define _WIN32_KEYBOARD_H_EADER_ #define _WIN32_KEYBOARD_H_EADER_
#include "OISKeyboard.h" #include "OISKeyboard.h"
#include "win32/Win32Prereqs.h" #include "win32/Win32Prereqs.h"
namespace OIS namespace OIS
{ {
class Win32Keyboard : public Keyboard class Win32Keyboard : public Keyboard
{ {
public: public:
/** /**
@remarks @remarks
Constructor Constructor
@param pDI @param pDI
Valid DirectInput8 Interface Valid DirectInput8 Interface
@param buffered @param buffered
True for buffered input mode True for buffered input mode
@param coopSettings @param coopSettings
A combination of DI Flags (see DX Help for info on input device settings) A combination of DI Flags (see DX Help for info on input device settings)
*/ */
Win32Keyboard(InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings); Win32Keyboard(InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings);
virtual ~Win32Keyboard(); virtual ~Win32Keyboard();
/** @copydoc Keyboard::isKeyDown */ /** @copydoc Keyboard::isKeyDown */
virtual bool isKeyDown(KeyCode key) const; virtual bool isKeyDown(KeyCode key) const;
/** @copydoc Keyboard::getAsString */ /** @copydoc Keyboard::getAsString */
virtual const std::string& getAsString(KeyCode kc); virtual const std::string& getAsString(KeyCode kc);
/** @copydoc Keyboard::copyKeyStates */ /** @copydoc Keyboard::getAsKeyCode */
virtual void copyKeyStates(char keys[256]) const; virtual KeyCode getAsKeyCode( std::string str ) {/*TODO: Implement OS version*/;}
/** @copydoc Object::setBuffered */ /** @copydoc Keyboard::copyKeyStates */
virtual void setBuffered(bool buffered); virtual void copyKeyStates(char keys[256]) const;
/** @copydoc Object::capture */ /** @copydoc Object::setBuffered */
virtual void capture(); virtual void setBuffered(bool buffered);
/** @copydoc Object::queryInterface */ /** @copydoc Object::capture */
virtual Interface* queryInterface(Interface::IType type) {return 0;} virtual void capture();
/** @copydoc Object::_initialize */ /** @copydoc Object::queryInterface */
virtual void _initialize(); virtual Interface* queryInterface(Interface::IType type) { OIS_UNUSED(type); return 0; }
protected:
void _readBuffered(); /** @copydoc Object::_initialize */
void _read(); virtual void _initialize();
protected:
IDirectInput8* mDirectInput; void _readBuffered();
IDirectInputDevice8* mKeyboard; void _read();
DWORD coopSetting;
IDirectInput8* mDirectInput;
unsigned char KeyBuffer[256]; IDirectInputDevice8* mKeyboard;
DWORD coopSetting;
//! Internal method for translating KeyCodes to Text
int _translateText( KeyCode kc ); unsigned char KeyBuffer[256];
//! Stored dead key from last translation //! Internal method for translating KeyCodes to Text
WCHAR deadKey; int _translateText( KeyCode kc );
//! used for getAsString //! Stored dead key from last translation
std::string mGetString; WCHAR deadKey;
};
} //! used for getAsString
#endif //_WIN32_KEYBOARD_H_EADER_ std::string mGetString;
};
}
#endif //_WIN32_KEYBOARD_H_EADER_
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef _WIN32_MOUSE_H_EADER_ #ifndef _WIN32_MOUSE_H_EADER_
#define _WIN32_MOUSE_H_EADER_ #define _WIN32_MOUSE_H_EADER_
#include "OISMouse.h" #include "OISMouse.h"
#include "win32/Win32Prereqs.h" #include "win32/Win32Prereqs.h"
namespace OIS namespace OIS
{ {
class Win32Mouse : public Mouse class Win32Mouse : public Mouse
{ {
public: public:
Win32Mouse( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings ); Win32Mouse( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings );
virtual ~Win32Mouse(); virtual ~Win32Mouse();
/** @copydoc Object::setBuffered */ /** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered); virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */ /** @copydoc Object::capture */
virtual void capture(); virtual void capture();
/** @copydoc Object::queryInterface */ /** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type) {return 0;} virtual Interface* queryInterface(Interface::IType type) { OIS_UNUSED(type); return 0;}
/** @copydoc Object::_initialize */ /** @copydoc Object::_initialize */
virtual void _initialize(); virtual void _initialize();
protected: protected:
bool _doMouseClick( int mouseButton, DIDEVICEOBJECTDATA& di ); bool _doMouseClick( int mouseButton, DIDEVICEOBJECTDATA& di );
IDirectInput8* mDirectInput; IDirectInput8* mDirectInput;
IDirectInputDevice8* mMouse; IDirectInputDevice8* mMouse;
DWORD coopSetting; DWORD coopSetting;
HWND mHwnd; HWND mHwnd;
}; };
} }
#endif //_WIN32_MOUSE_H_EADER_ #endif //_WIN32_MOUSE_H_EADER_
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef _WIN32_INPUTSYSTEM_PREREQS_H #ifndef _WIN32_INPUTSYSTEM_PREREQS_H
#define _WIN32_INPUTSYSTEM_PREREQS_H #define _WIN32_INPUTSYSTEM_PREREQS_H
#include <cstddef> #include <cstddef>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define DIRECTINPUT_VERSION 0x0800 #define DIRECTINPUT_VERSION 0x0800
#include <windows.h> #include <windows.h>
#include <dinput.h> #include <dinput.h>
#ifdef OIS_WIN32_XINPUT_SUPPORT #ifdef OIS_WIN32_XINPUT_SUPPORT
# include <XInput.h> # include <XInput.h>
#endif #endif
//Max number of elements to collect from buffered DirectInput //Max number of elements to collect from buffered DirectInput
#define KEYBOARD_DX_BUFFERSIZE 17 #define KEYBOARD_DX_BUFFERSIZE 17
#define MOUSE_DX_BUFFERSIZE 128 #define MOUSE_DX_BUFFERSIZE 128
#define JOYSTICK_DX_BUFFERSIZE 129 #define JOYSTICK_DX_BUFFERSIZE 129
//MinGW defines //MinGW defines
#if defined(OIS_MINGW_COMPILER) #if defined(OIS_MINGW_COMPILER)
# undef FIELD_OFFSET # undef FIELD_OFFSET
# define FIELD_OFFSET offsetof # define FIELD_OFFSET offsetof
#endif #endif
namespace OIS namespace OIS
{ {
//Local Forward declarations //Local Forward declarations
class Win32InputManager; class Win32InputManager;
class Win32Keyboard; class Win32Keyboard;
class Win32JoyStick; class Win32JoyStick;
class Win32Mouse; class Win32Mouse;
class Win32ForceFeedback; class Win32ForceFeedback;
//Information needed to create DirectInput joysticks //Information needed to create DirectInput joysticks
class JoyStickInfo class JoyStickInfo
{ {
public: public:
int devId; int devId;
GUID deviceID; GUID deviceID;
GUID productGuid; GUID productGuid;
std::string vendor; std::string vendor;
bool isXInput; bool isXInput;
int xInputDev; int xInputDev;
}; };
typedef std::vector<JoyStickInfo> JoyStickInfoList; typedef std::vector<JoyStickInfo> JoyStickInfoList;
} }
#endif //_WIN32_INPUTSYSTEM_PREREQS_H #endif //_WIN32_INPUTSYSTEM_PREREQS_H
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "OISEffect.h" #include "OISEffect.h"
#include "OISException.h" #include "OISException.h"
using namespace OIS; using namespace OIS;
//VC7.1 had a problem with these not getting included.. //VC7.1 had a problem with these not getting included..
//Perhaps a case of a crazy extreme optimizer :/ (moved to header) //Perhaps a case of a crazy extreme optimizer :/ (moved to header)
//const unsigned int Effect::OIS_INFINITE = 0xFFFFFFFF; //const unsigned int Effect::OIS_INFINITE = 0xFFFFFFFF;
//------------------------------------------------------------------------------// //------------------------------------------------------------------------------//
static const char* pszEForceString[] = static const char* pszEForceString[] =
{ "UnknownForce", { "UnknownForce",
"ConstantForce", "ConstantForce",
"RampForce", "RampForce",
"PeriodicForce", "PeriodicForce",
"ConditionalForce", "ConditionalForce",
"CustomForce" }; "CustomForce" };
const char* Effect::getForceTypeName(Effect::EForce eValue) const char* Effect::getForceTypeName(Effect::EForce eValue)
{ {
return (eValue >= 0 && eValue < _ForcesNumber) ? pszEForceString[eValue] : "<Bad force type>"; return (eValue >= 0 && eValue < _ForcesNumber) ? pszEForceString[eValue] : "<Bad force type>";
} }
static const char* pszETypeString[] = static const char* pszETypeString[] =
{ "Unknown", { "Unknown",
"Constant", "Constant",
"Ramp", "Ramp",
"Square", "Triangle", "Sine", "SawToothUp", "SawToothDown", "Square", "Triangle", "Sine", "SawToothUp", "SawToothDown",
"Friction", "Damper", "Inertia", "Spring", "Friction", "Damper", "Inertia", "Spring",
"Custom" }; "Custom" };
const char* Effect::getEffectTypeName(Effect::EType eValue) const char* Effect::getEffectTypeName(Effect::EType eValue)
{ {
return (eValue >= 0 && eValue < _TypesNumber) ? pszETypeString[eValue] : "<Bad effect type>"; return (eValue >= 0 && eValue < _TypesNumber) ? pszETypeString[eValue] : "<Bad effect type>";
} }
static const char* pszEDirectionString[] = static const char* pszEDirectionString[] =
{ "NorthWest", "North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West"}; { "NorthWest", "North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West"};
const char* Effect::getDirectionName(Effect::EDirection eValue) const char* Effect::getDirectionName(Effect::EDirection eValue)
{ {
return (eValue >= 0 && eValue < _DirectionsNumber) ? pszEDirectionString[eValue] : "<Bad direction>"; return (eValue >= 0 && eValue < _DirectionsNumber) ? pszEDirectionString[eValue] : "<Bad direction>";
} }
//------------------------------------------------------------------------------// //------------------------------------------------------------------------------//
Effect::Effect() : Effect::Effect(EForce ef, EType et) :
force(UnknownForce), force(ef),
type(Unknown), type(et),
effect(0), direction(North),
axes(1) trigger_button(-1),
{ trigger_interval(0),
} replay_length(Effect::OIS_INFINITE),
replay_delay(0),
//------------------------------------------------------------------------------// _handle(-1),
Effect::Effect(EForce ef, EType et) : axes(1)
force(ef), {
type(et), effect = 0;
direction(North),
trigger_button(-1), switch( ef )
trigger_interval(0), {
replay_length(Effect::OIS_INFINITE), case ConstantForce: effect = new ConstantEffect(); break;
replay_delay(0), case RampForce: effect = new RampEffect(); break;
_handle(-1), case PeriodicForce: effect = new PeriodicEffect(); break;
axes(1) case ConditionalForce: effect = new ConditionalEffect(); break;
{ default: break;
effect = 0; }
}
switch( ef )
{ //------------------------------------------------------------------------------//
case ConstantForce: effect = new ConstantEffect(); break; Effect::~Effect()
case RampForce: effect = new RampEffect(); break; {
case PeriodicForce: effect = new PeriodicEffect(); break; delete effect;
case ConditionalForce: effect = new ConditionalEffect(); break; }
default: break;
} //------------------------------------------------------------------------------//
} ForceEffect* Effect::getForceEffect() const
{
//------------------------------------------------------------------------------// //If no effect was created in constructor, then we raise an error here
Effect::~Effect() if( effect == 0 )
{ OIS_EXCEPT( E_NotSupported, "Requested ForceEffect is null!" );
delete effect;
} return effect;
}
//------------------------------------------------------------------------------//
ForceEffect* Effect::getForceEffect() const //------------------------------------------------------------------------------//
{ void Effect::setNumAxes(short nAxes)
//If no effect was created in constructor, then we raise an error here {
if( effect == 0 ) //Can only be set before a handle was assigned (effect created)
OIS_EXCEPT( E_NotSupported, "Requested ForceEffect is null!" ); if( _handle != -1 )
axes = nAxes;
return effect; }
}
//------------------------------------------------------------------------------//
//------------------------------------------------------------------------------// short Effect::getNumAxes() const
void Effect::setNumAxes(short nAxes) {
{ return axes;
//Can only be set before a handle was assigned (effect created) }
if( _handle != -1 )
axes = nAxes;
}
//------------------------------------------------------------------------------//
short Effect::getNumAxes() const
{
return axes;
}
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "OISException.h" #include "OISException.h"
using namespace OIS; using namespace OIS;
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
const char* Exception::what() const throw() const char* Exception::what() const throw()
{ {
return eText; return eText;
} }
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "OISForceFeedback.h" #include "OISForceFeedback.h"
#include "OISException.h" #include "OISException.h"
using namespace OIS; using namespace OIS;
//-------------------------------------------------------------// //-------------------------------------------------------------//
ForceFeedback::ForceFeedback() : mSetGainSupport(false), mSetAutoCenterSupport(false) ForceFeedback::ForceFeedback() : mSetGainSupport(false), mSetAutoCenterSupport(false)
{ {
} }
//-------------------------------------------------------------// //-------------------------------------------------------------//
void ForceFeedback::_addEffectTypes( Effect::EForce force, Effect::EType type ) void ForceFeedback::_addEffectTypes( Effect::EForce force, Effect::EType type )
{ {
if( force <= Effect::UnknownForce || force >= Effect::_ForcesNumber if( force <= Effect::UnknownForce || force >= Effect::_ForcesNumber
|| type <= Effect::Unknown || type >= Effect::_TypesNumber ) || type <= Effect::Unknown || type >= Effect::_TypesNumber )
OIS_EXCEPT( E_General, "Can't add unknown effect Force/Type to the supported list" ); OIS_EXCEPT( E_General, "Can't add unknown effect Force/Type to the supported list" );
mSupportedEffects.insert(std::pair<Effect::EForce, Effect::EType>(force, type)); mSupportedEffects.insert(std::pair<Effect::EForce, Effect::EType>(force, type));
} }
//-------------------------------------------------------------// //-------------------------------------------------------------//
void ForceFeedback::_setGainSupport( bool on ) void ForceFeedback::_setGainSupport( bool on )
{ {
mSetGainSupport = on; mSetGainSupport = on;
} }
//-------------------------------------------------------------// //-------------------------------------------------------------//
void ForceFeedback::_setAutoCenterSupport( bool on ) void ForceFeedback::_setAutoCenterSupport( bool on )
{ {
mSetAutoCenterSupport = on; mSetAutoCenterSupport = on;
} }
//-------------------------------------------------------------// //-------------------------------------------------------------//
const ForceFeedback::SupportedEffectList& ForceFeedback::getSupportedEffects() const const ForceFeedback::SupportedEffectList& ForceFeedback::getSupportedEffects() const
{ {
return mSupportedEffects; return mSupportedEffects;
} }
//-------------------------------------------------------------// //-------------------------------------------------------------//
bool ForceFeedback::supportsEffect(Effect::EForce force, Effect::EType type) const bool ForceFeedback::supportsEffect(Effect::EForce force, Effect::EType type) const
{ {
const std::pair<SupportedEffectList::const_iterator, SupportedEffectList::const_iterator> const std::pair<SupportedEffectList::const_iterator, SupportedEffectList::const_iterator>
iterRange = mSupportedEffects.equal_range(force); iterRange = mSupportedEffects.equal_range(force);
SupportedEffectList::const_iterator iter; SupportedEffectList::const_iterator iter;
for (iter = iterRange.first; iter != iterRange.second; iter++) for (iter = iterRange.first; iter != iterRange.second; iter++)
{ {
if ((*iter).second == type) if ((*iter).second == type)
return true; return true;
} }
return false; return false;
} }
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "OISInputManager.h" #include "OISInputManager.h"
#include "OISException.h" #include "OISException.h"
#include "OISFactoryCreator.h" #include "OISFactoryCreator.h"
#include "OISObject.h" #include "OISObject.h"
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
//Bring in correct Header / InputManager for current build platform //Bring in correct Header / InputManager for current build platform
#if defined OIS_SDL_PLATFORM #if defined OIS_SDL_PLATFORM
# include "SDL/SDLInputManager.h" # include "SDL/SDLInputManager.h"
#elif defined OIS_WIN32_PLATFORM #elif defined OIS_WIN32_PLATFORM
# include "win32/Win32InputManager.h" # include "win32/Win32InputManager.h"
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
# include "linux/LinuxInputManager.h" # include "linux/LinuxInputManager.h"
#elif defined OIS_APPLE_PLATFORM #elif defined OIS_APPLE_PLATFORM
# include "mac/MacInputManager.h" # include "mac/MacInputManager.h"
#elif defined OIS_IPHONE_PLATFORM #elif defined OIS_IPHONE_PLATFORM
# include "iphone/iPhoneInputManager.h" # include "iphone/iPhoneInputManager.h"
#elif defined OIS_XBOX_PLATFORM #elif defined OIS_XBOX_PLATFORM
# include "xbox/XBoxInputManager.h" # include "xbox/XBoxInputManager.h"
#endif #endif
//Bring in extra controls //Bring in extra controls
#if defined OIS_LIRC_SUPPORT #if defined OIS_LIRC_SUPPORT
# include "extras/LIRC/OISLIRCFactoryCreator.h" # include "extras/LIRC/OISLIRCFactoryCreator.h"
#endif #endif
#if defined OIS_WIN32_WIIMOTE_SUPPORT #if defined OIS_WIN32_WIIMOTE_SUPPORT
# include "win32/extras/WiiMote/OISWiiMoteFactoryCreator.h" # include "win32/extras/WiiMote/OISWiiMoteFactoryCreator.h"
#endif #endif
using namespace OIS; using namespace OIS;
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
InputManager::InputManager(const std::string& name) : InputManager::InputManager(const std::string& name) :
m_VersionName(OIS_VERSION_NAME), m_VersionName(OIS_VERSION_NAME),
mInputSystemName(name), mInputSystemName(name),
m_lircSupport(0), m_lircSupport(0),
m_wiiMoteSupport(0) m_wiiMoteSupport(0)
{ {
mFactories.clear(); mFactories.clear();
mFactoryObjects.clear(); mFactoryObjects.clear();
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
InputManager::~InputManager() InputManager::~InputManager()
{ {
#if defined OIS_LIRC_SUPPORT #if defined OIS_LIRC_SUPPORT
delete m_lircSupport; delete m_lircSupport;
#endif #endif
#if defined OIS_WIN32_WIIMOTE_SUPPORT #if defined OIS_WIN32_WIIMOTE_SUPPORT
delete m_wiiMoteSupport; delete m_wiiMoteSupport;
#endif #endif
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
unsigned int InputManager::getVersionNumber() unsigned int InputManager::getVersionNumber()
{ {
return OIS_VERSION; return OIS_VERSION;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
const std::string &InputManager::getVersionName() const std::string &InputManager::getVersionName()
{ {
return m_VersionName; return m_VersionName;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
InputManager* InputManager::createInputSystem( std::size_t windowhandle ) InputManager* InputManager::createInputSystem( std::size_t windowhandle )
{ {
ParamList pl; ParamList pl;
std::ostringstream wnd; std::ostringstream wnd;
wnd << windowhandle; wnd << windowhandle;
pl.insert(std::make_pair( std::string("WINDOW"), wnd.str() )); pl.insert(std::make_pair( std::string("WINDOW"), wnd.str() ));
return createInputSystem( pl ); return createInputSystem( pl );
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
InputManager* InputManager::createInputSystem( ParamList &paramList ) InputManager* InputManager::createInputSystem( ParamList &paramList )
{ {
InputManager* im = 0; InputManager* im = 0;
#if defined OIS_SDL_PLATFORM #if defined OIS_SDL_PLATFORM
im = new SDLInputManager(); im = new SDLInputManager();
#elif defined OIS_WIN32_PLATFORM #elif defined OIS_WIN32_PLATFORM
im = new Win32InputManager(); im = new Win32InputManager();
#elif defined OIS_XBOX_PLATFORM #elif defined OIS_XBOX_PLATFORM
im = new XBoxInputManager(); im = new XBoxInputManager();
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
im = new LinuxInputManager(); im = new LinuxInputManager();
#elif defined OIS_APPLE_PLATFORM #elif defined OIS_APPLE_PLATFORM
im = new MacInputManager(); im = new MacInputManager();
#elif defined OIS_IPHONE_PLATFORM #elif defined OIS_IPHONE_PLATFORM
im = new iPhoneInputManager(); im = new iPhoneInputManager();
#else #else
OIS_EXCEPT(E_General, "No platform library.. check build platform defines!"); OIS_EXCEPT(E_General, "No platform library.. check build platform defines!");
#endif #endif
try try
{ {
im->_initialize(paramList); im->_initialize(paramList);
} }
catch(...) catch(...)
{ {
delete im; delete im;
throw; //rethrow throw; //rethrow
} }
return im; return im;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void InputManager::destroyInputSystem(InputManager* manager) void InputManager::destroyInputSystem(InputManager* manager)
{ {
if( manager == 0 ) if( manager == 0 )
return; return;
//Cleanup before deleting... //Cleanup before deleting...
for( FactoryCreatedObject::iterator i = manager->mFactoryObjects.begin(); for( FactoryCreatedObject::iterator i = manager->mFactoryObjects.begin();
i != manager->mFactoryObjects.end(); ++i ) i != manager->mFactoryObjects.end(); ++i )
{ {
i->second->destroyObject( i->first ); i->second->destroyObject( i->first );
} }
manager->mFactoryObjects.clear(); manager->mFactoryObjects.clear();
delete manager; delete manager;
} }
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
const std::string& InputManager::inputSystemName() const std::string& InputManager::inputSystemName()
{ {
return mInputSystemName; return mInputSystemName;
} }
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
int InputManager::getNumberOfDevices( Type iType ) int InputManager::getNumberOfDevices( Type iType )
{ {
//Count up all the factories devices //Count up all the factories devices
int factoyObjects = 0; int factoyObjects = 0;
FactoryList::iterator i = mFactories.begin(), e = mFactories.end(); FactoryList::iterator i = mFactories.begin(), e = mFactories.end();
for( ; i != e; ++i ) for( ; i != e; ++i )
factoyObjects += (*i)->totalDevices(iType); factoyObjects += (*i)->totalDevices(iType);
return factoyObjects; return factoyObjects;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
DeviceList InputManager::listFreeDevices() DeviceList InputManager::listFreeDevices()
{ {
DeviceList list; DeviceList list;
FactoryList::iterator i = mFactories.begin(), e = mFactories.end(); FactoryList::iterator i = mFactories.begin(), e = mFactories.end();
for( ; i != e; ++i ) for( ; i != e; ++i )
{ {
DeviceList temp = (*i)->freeDeviceList(); DeviceList temp = (*i)->freeDeviceList();
list.insert(temp.begin(), temp.end()); list.insert(temp.begin(), temp.end());
} }
return list; return list;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
Object* InputManager::createInputObject( Type iType, bool bufferMode, const std::string &vendor ) Object* InputManager::createInputObject( Type iType, bool bufferMode, const std::string &vendor )
{ {
Object* obj = 0; Object* obj = 0;
FactoryList::iterator i = mFactories.begin(), e = mFactories.end(); FactoryList::iterator i = mFactories.begin(), e = mFactories.end();
for( ; i != e; ++i) for( ; i != e; ++i)
{ {
if( (*i)->freeDevices(iType) > 0 ) if( (*i)->freeDevices(iType) > 0 )
{ {
if( vendor == "" || (*i)->vendorExist(iType, vendor) ) if( vendor == "" || (*i)->vendorExist(iType, vendor) )
{ {
obj = (*i)->createObject(this, iType, bufferMode, vendor); obj = (*i)->createObject(this, iType, bufferMode, vendor);
mFactoryObjects[obj] = (*i); mFactoryObjects[obj] = (*i);
break; break;
} }
} }
} }
if(!obj) if(!obj)
OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type."); OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type.");
try try
{ //Intialize device { //Intialize device
obj->_initialize(); obj->_initialize();
} }
catch(...) catch(...)
{ //Somekind of error, cleanup and rethrow { //Somekind of error, cleanup and rethrow
destroyInputObject(obj); destroyInputObject(obj);
throw; throw;
} }
return obj; return obj;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void InputManager::destroyInputObject( Object* obj ) void InputManager::destroyInputObject( Object* obj )
{ {
if( obj == 0 ) if( obj == 0 )
return; return;
FactoryCreatedObject::iterator i = mFactoryObjects.find(obj); FactoryCreatedObject::iterator i = mFactoryObjects.find(obj);
if( i != mFactoryObjects.end() ) if( i != mFactoryObjects.end() )
{ {
i->second->destroyObject(obj); i->second->destroyObject(obj);
mFactoryObjects.erase(i); mFactoryObjects.erase(i);
} }
else else
{ {
OIS_EXCEPT(E_General, "Object creator not known."); OIS_EXCEPT(E_General, "Object creator not known.");
} }
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void InputManager::addFactoryCreator( FactoryCreator* factory ) void InputManager::addFactoryCreator( FactoryCreator* factory )
{ {
if(factory != 0) if(factory != 0)
mFactories.push_back(factory); mFactories.push_back(factory);
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void InputManager::removeFactoryCreator( FactoryCreator* factory ) void InputManager::removeFactoryCreator( FactoryCreator* factory )
{ {
if(factory != 0) if(factory != 0)
{ {
//First, destroy all devices created with the factory //First, destroy all devices created with the factory
for( FactoryCreatedObject::iterator i = mFactoryObjects.begin(); i != mFactoryObjects.end(); ++i ) for( FactoryCreatedObject::iterator i = mFactoryObjects.begin(); i != mFactoryObjects.end(); ++i )
{ {
if( i->second == factory ) if( i->second == factory )
{ {
i->second->destroyObject(i->first); i->second->destroyObject(i->first);
mFactoryObjects.erase(i++); mFactoryObjects.erase(i++);
} }
} }
//Now, remove the factory itself //Now, remove the factory itself
FactoryList::iterator fact = std::find(mFactories.begin(), mFactories.end(), factory); FactoryList::iterator fact = std::find(mFactories.begin(), mFactories.end(), factory);
if( fact != mFactories.end() ) if( fact != mFactories.end() )
mFactories.erase(fact); mFactories.erase(fact);
} }
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void InputManager::enableAddOnFactory(AddOnFactories factory) void InputManager::enableAddOnFactory(AddOnFactories factory)
{ {
#if defined OIS_LIRC_SUPPORT OIS_UNUSED(factory);
if( factory == AddOn_LIRC || factory == AddOn_All )
{ #if defined OIS_LIRC_SUPPORT
if( m_lircSupport == 0 ) if( factory == AddOn_LIRC || factory == AddOn_All )
{ {
m_lircSupport = new LIRCFactoryCreator(); if( m_lircSupport == 0 )
addFactoryCreator(m_lircSupport); {
} m_lircSupport = new LIRCFactoryCreator();
} addFactoryCreator(m_lircSupport);
#endif }
}
#if defined OIS_WIN32_WIIMOTE_SUPPORT #endif
if( factory == AddOn_WiiMote || factory == AddOn_All )
{ #if defined OIS_WIN32_WIIMOTE_SUPPORT
if( m_wiiMoteSupport == 0 ) if( factory == AddOn_WiiMote || factory == AddOn_All )
{ {
m_wiiMoteSupport = new WiiMoteFactoryCreator(); if( m_wiiMoteSupport == 0 )
addFactoryCreator(m_wiiMoteSupport); {
} m_wiiMoteSupport = new WiiMoteFactoryCreator();
} addFactoryCreator(m_wiiMoteSupport);
#endif }
} }
#endif
}
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "OISJoyStick.h" #include "OISJoyStick.h"
using namespace OIS; using namespace OIS;
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
JoyStick::JoyStick(const std::string &vendor, bool buffered, int devID, InputManager* creator) : JoyStick::JoyStick(const std::string &vendor, bool buffered, int devID, InputManager* creator) :
Object(vendor, OISJoyStick, buffered, devID, creator), Object(vendor, OISJoyStick, buffered, devID, creator),
mSliders(0), mSliders(0),
mPOVs(0), mPOVs(0),
mListener(0), mListener(0),
mVector3Sensitivity(OIS_JOYSTICK_VECTOR3_DEFAULT) mVector3Sensitivity(OIS_JOYSTICK_VECTOR3_DEFAULT)
{ {
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
int JoyStick::getNumberOfComponents(ComponentType cType) const int JoyStick::getNumberOfComponents(ComponentType cType) const
{ {
switch( cType ) switch( cType )
{ {
case OIS_Button: return (int)mState.mButtons.size(); case OIS_Button: return (int)mState.mButtons.size();
case OIS_Axis: return (int)mState.mAxes.size(); case OIS_Axis: return (int)mState.mAxes.size();
case OIS_Slider: return mSliders; case OIS_Slider: return mSliders;
case OIS_POV: return mPOVs; case OIS_POV: return mPOVs;
case OIS_Vector3: return (int)mState.mVectors.size(); case OIS_Vector3: return (int)mState.mVectors.size();
default: return 0; default: return 0;
} }
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void JoyStick::setVector3Sensitivity(float degrees) void JoyStick::setVector3Sensitivity(float degrees)
{ {
mVector3Sensitivity = degrees; mVector3Sensitivity = degrees;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
float JoyStick::getVector3Sensitivity() const float JoyStick::getVector3Sensitivity() const
{ {
return mVector3Sensitivity; return mVector3Sensitivity;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void JoyStick::setEventCallback( JoyStickListener *joyListener ) void JoyStick::setEventCallback( JoyStickListener *joyListener )
{ {
mListener = joyListener; mListener = joyListener;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
JoyStickListener* JoyStick::getEventCallback() const JoyStickListener* JoyStick::getEventCallback() const
{ {
return mListener; return mListener;
} }
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "OISKeyboard.h" #include "OISKeyboard.h"
#include "OISException.h" #include "OISException.h"
using namespace OIS; using namespace OIS;
//----------------------------------------------------------------------// //----------------------------------------------------------------------//
void Keyboard::setTextTranslation( TextTranslationMode mode ) void Keyboard::setTextTranslation( TextTranslationMode mode )
{ {
mTextMode = mode; mTextMode = mode;
} }
//----------------------------------------------------------------------// //----------------------------------------------------------------------//
bool Keyboard::isModifierDown( Modifier mod ) const bool Keyboard::isModifierDown( Modifier mod ) const
{ {
#if defined(OIS_MSVC_COMPILER) #if defined(OIS_MSVC_COMPILER)
#pragma warning (push) #pragma warning (push)
#pragma warning (disable : 4800) #pragma warning (disable : 4800)
#endif #endif
return (mModifiers & mod); return (mModifiers & mod);
#if defined(OIS_MSVC_COMPILER) #if defined(OIS_MSVC_COMPILER)
#pragma warning (pop) #pragma warning (pop)
#endif #endif
} }
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
//#include "OISObject.h" //#include "OISObject.h"
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL/SDLInputManager.h" #include "SDL/SDLInputManager.h"
#include "SDL/SDLKeyboard.h" #include "SDL/SDLKeyboard.h"
#include "SDL/SDLMouse.h" #include "SDL/SDLMouse.h"
#include "SDL/SDLJoyStick.h" #include "SDL/SDLJoyStick.h"
#include "OISException.h" #include "OISException.h"
#include "OISObject.h" #include "OISObject.h"
using namespace OIS; using namespace OIS;
const std::string SDLInputManager::iName = "SDL Input Wrapper"; const std::string SDLInputManager::iName = "SDL Input Wrapper";
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
SDLInputManager::SDLInputManager() : mGrabbed(false) SDLInputManager::SDLInputManager() : mGrabbed(false)
{ {
} }
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
SDLInputManager::~SDLInputManager() SDLInputManager::~SDLInputManager()
{ {
} }
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
void SDLInputManager::_initialize( ParamList &paramList ) void SDLInputManager::_initialize( ParamList &paramList )
{ {
Uint32 flags = SDL_WasInit(0); Uint32 flags = SDL_WasInit(0);
if( flags == 0 ) if( flags == 0 )
OIS_EXCEPT( E_General, "SDLInputManager::SDLInputManager >> SDL Not Initialized already!"); OIS_EXCEPT( E_General, "SDLInputManager::SDLInputManager >> SDL Not Initialized already!");
//Ok, now we have DirectInput, parse whatever extra settings were sent to us //Ok, now we have DirectInput, parse whatever extra settings were sent to us
_parseConfigSettings( paramList ); _parseConfigSettings( paramList );
_enumerateDevices(); _enumerateDevices();
} }
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
void SDLInputManager::_parseConfigSettings( ParamList &paramList ) void SDLInputManager::_parseConfigSettings( ParamList &paramList )
{ {
} }
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
void SDLInputManager::_enumerateDevices() void SDLInputManager::_enumerateDevices()
{ {
} }
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
int SDLInputManager::numJoySticks() int SDLInputManager::numJoySticks()
{ {
return 0; return 0;
} }
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
int SDLInputManager::numMice() int SDLInputManager::numMice()
{ {
return 1; return 1;
} }
//--------------------------------------------------------------------------------// //--------------------------------------------------------------------------------//
int SDLInputManager::numKeyboards() int SDLInputManager::numKeyboards()
{ {
return 1; return 1;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
Object* SDLInputManager::createInputObject( Type iType, bool bufferMode ) Object* SDLInputManager::createInputObject( Type iType, bool bufferMode )
{ {
Object* obj = 0; Object* obj = 0;
switch( iType ) switch( iType )
{ {
case OISKeyboard: obj = new SDLKeyboard( bufferMode ); break; case OISKeyboard: obj = new SDLKeyboard( bufferMode ); break;
case OISMouse: obj = new SDLMouse( bufferMode ); break; case OISMouse: obj = new SDLMouse( bufferMode ); break;
case OISJoyStick: case OISJoyStick:
default: OIS_EXCEPT( E_InputDeviceNotSupported, "Type not implemented"); default: OIS_EXCEPT( E_InputDeviceNotSupported, "Type not implemented");
} }
try { try {
obj->_initialize(); obj->_initialize();
} }
catch(...) { catch(...) {
delete obj; delete obj;
throw; //rethrow throw; //rethrow
} }
return obj; return obj;
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void SDLInputManager::destroyInputObject( Object* obj ) void SDLInputManager::destroyInputObject( Object* obj )
{ {
if( obj == 0 ) return; if( obj == 0 ) return;
delete obj; delete obj;
} }
/* /*
The zlib/libpng License The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 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 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. 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 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 applications, and to alter it and redistribute it freely, subject to the following
restrictions: restrictions:
1. The origin of this software must not be misrepresented; you must not claim that 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, you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is an acknowledgment in the product documentation would be appreciated but is
not required. not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL/SDLKeyboard.h" #include "SDL/SDLKeyboard.h"
#include "SDL/SDLInputManager.h" #include "SDL/SDLInputManager.h"
#include "OISException.h" #include "OISException.h"
#include "OISEvents.h" #include "OISEvents.h"
#include <sstream> #include <sstream>
using namespace OIS; using namespace OIS;
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
SDLKeyboard::SDLKeyboard( bool buffered ) SDLKeyboard::SDLKeyboard( bool buffered )
{ {
mBuffered = buffered; mBuffered = buffered;
mType = OISKeyboard; mType = OISKeyboard;
listener = 0; listener = 0;
//Clear our keyboard state buffer //Clear our keyboard state buffer
memset( &KeyBuffer, 0, 256 ); memset( &KeyBuffer, 0, 256 );
} }
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
void SDLKeyboard::_initialize() void SDLKeyboard::_initialize()
{ {
mModifiers = 0; mModifiers = 0;
mSDLBuff = 0; mSDLBuff = 0;
mKeyMap.insert( KeyMap::value_type(SDLK_ESCAPE,KC_ESCAPE) ); mKeyMap.insert( KeyMap::value_type(SDLK_ESCAPE,KC_ESCAPE) );
mKeyMap.insert( KeyMap::value_type(SDLK_1, KC_1) ); mKeyMap.insert( KeyMap::value_type(SDLK_1, KC_1) );
mKeyMap.insert( KeyMap::value_type(SDLK_2, KC_2) ); mKeyMap.insert( KeyMap::value_type(SDLK_2, KC_2) );
mKeyMap.insert( KeyMap::value_type(SDLK_3, KC_3) ); mKeyMap.insert( KeyMap::value_type(SDLK_3, KC_3) );
mKeyMap.insert( KeyMap::value_type(SDLK_4, KC_4) ); mKeyMap.insert( KeyMap::value_type(SDLK_4, KC_4) );
mKeyMap.insert( KeyMap::value_type(SDLK_5, KC_5) ); mKeyMap.insert( KeyMap::value_type(SDLK_5, KC_5) );
mKeyMap.insert( KeyMap::value_type(SDLK_6, KC_6) ); mKeyMap.insert( KeyMap::value_type(SDLK_6, KC_6) );
mKeyMap.insert( KeyMap::value_type(SDLK_7, KC_7) ); mKeyMap.insert( KeyMap::value_type(SDLK_7, KC_7) );
mKeyMap.insert( KeyMap::value_type(SDLK_8, KC_8) ); mKeyMap.insert( KeyMap::value_type(SDLK_8, KC_8) );
mKeyMap.insert( KeyMap::value_type(SDLK_9, KC_9) ); mKeyMap.insert( KeyMap::value_type(SDLK_9, KC_9) );
mKeyMap.insert( KeyMap::value_type(SDLK_0, KC_0) ); mKeyMap.insert( KeyMap::value_type(SDLK_0, KC_0) );
mKeyMap.insert( KeyMap::value_type(SDLK_MINUS, KC_MINUS) ); mKeyMap.insert( KeyMap::value_type(SDLK_MINUS, KC_MINUS) );
mKeyMap.insert( KeyMap::value_type(SDLK_EQUALS, KC_EQUALS) ); mKeyMap.insert( KeyMap::value_type(SDLK_EQUALS, KC_EQUALS) );
mKeyMap.insert( KeyMap::value_type(SDLK_BACKSPACE, KC_BACK) ); mKeyMap.insert( KeyMap::value_type(SDLK_BACKSPACE, KC_BACK) );
mKeyMap.insert( KeyMap::value_type(SDLK_TAB, KC_TAB) ); mKeyMap.insert( KeyMap::value_type(SDLK_TAB, KC_TAB) );
mKeyMap.insert( KeyMap::value_type(SDLK_q, KC_Q) ); mKeyMap.insert( KeyMap::value_type(SDLK_q, KC_Q) );
mKeyMap.insert( KeyMap::value_type(SDLK_w, KC_W) ); mKeyMap.insert( KeyMap::value_type(SDLK_w, KC_W) );
mKeyMap.insert( KeyMap::value_type(SDLK_e, KC_E) ); mKeyMap.insert( KeyMap::value_type(SDLK_e, KC_E) );
mKeyMap.insert( KeyMap::value_type(SDLK_r, KC_R) ); mKeyMap.insert( KeyMap::value_type(SDLK_r, KC_R) );
mKeyMap.insert( KeyMap::value_type(SDLK_t, KC_T) ); mKeyMap.insert( KeyMap::value_type(SDLK_t, KC_T) );
mKeyMap.insert( KeyMap::value_type(SDLK_y, KC_Y) ); mKeyMap.insert( KeyMap::value_type(SDLK_y, KC_Y) );
mKeyMap.insert( KeyMap::value_type(SDLK_u, KC_U) ); mKeyMap.insert( KeyMap::value_type(SDLK_u, KC_U) );
mKeyMap.insert( KeyMap::value_type(SDLK_i, KC_I) ); mKeyMap.insert( KeyMap::value_type(SDLK_i, KC_I) );
mKeyMap.insert( KeyMap::value_type(SDLK_o, KC_O) ); mKeyMap.insert( KeyMap::value_type(SDLK_o, KC_O) );
mKeyMap.insert( KeyMap::value_type(SDLK_p, KC_P) ); mKeyMap.insert( KeyMap::value_type(SDLK_p, KC_P) );
mKeyMap.insert( KeyMap::value_type(SDLK_RETURN, KC_RETURN) ); mKeyMap.insert( KeyMap::value_type(SDLK_RETURN, KC_RETURN) );
mKeyMap.insert( KeyMap::value_type(SDLK_LCTRL, KC_LCONTROL)); mKeyMap.insert( KeyMap::value_type(SDLK_LCTRL, KC_LCONTROL));
mKeyMap.insert( KeyMap::value_type(SDLK_a, KC_A) ); mKeyMap.insert( KeyMap::value_type(SDLK_a, KC_A) );
mKeyMap.insert( KeyMap::value_type(SDLK_s, KC_S) ); mKeyMap.insert( KeyMap::value_type(SDLK_s, KC_S) );
mKeyMap.insert( KeyMap::value_type(SDLK_d, KC_D) ); mKeyMap.insert( KeyMap::value_type(SDLK_d, KC_D) );
mKeyMap.insert( KeyMap::value_type(SDLK_f, KC_F) ); mKeyMap.insert( KeyMap::value_type(SDLK_f, KC_F) );
mKeyMap.insert( KeyMap::value_type(SDLK_g, KC_G) ); mKeyMap.insert( KeyMap::value_type(SDLK_g, KC_G) );
mKeyMap.insert( KeyMap::value_type(SDLK_h, KC_H) ); mKeyMap.insert( KeyMap::value_type(SDLK_h, KC_H) );
mKeyMap.insert( KeyMap::value_type(SDLK_j, KC_J) ); mKeyMap.insert( KeyMap::value_type(SDLK_j, KC_J) );
mKeyMap.insert( KeyMap::value_type(SDLK_k, KC_K) ); mKeyMap.insert( KeyMap::value_type(SDLK_k, KC_K) );
mKeyMap.insert( KeyMap::value_type(SDLK_l, KC_L) ); mKeyMap.insert( KeyMap::value_type(SDLK_l, KC_L) );
mKeyMap.insert( KeyMap::value_type(SDLK_SEMICOLON, KC_SEMICOLON) ); mKeyMap.insert( KeyMap::value_type(SDLK_SEMICOLON, KC_SEMICOLON) );
mKeyMap.insert( KeyMap::value_type(SDLK_COLON, KC_COLON) ); mKeyMap.insert( KeyMap::value_type(SDLK_COLON, KC_COLON) );
mKeyMap.insert( KeyMap::value_type(SDLK_QUOTE, KC_APOSTROPHE) ); mKeyMap.insert( KeyMap::value_type(SDLK_QUOTE, KC_APOSTROPHE) );
mKeyMap.insert( KeyMap::value_type(SDLK_BACKQUOTE, KC_GRAVE) ); mKeyMap.insert( KeyMap::value_type(SDLK_BACKQUOTE, KC_GRAVE) );
mKeyMap.insert( KeyMap::value_type(SDLK_LSHIFT, KC_LSHIFT) ); mKeyMap.insert( KeyMap::value_type(SDLK_LSHIFT, KC_LSHIFT) );
mKeyMap.insert( KeyMap::value_type(SDLK_BACKSLASH, KC_BACKSLASH) ); mKeyMap.insert( KeyMap::value_type(SDLK_BACKSLASH, KC_BACKSLASH) );
mKeyMap.insert( KeyMap::value_type(SDLK_SLASH, KC_SLASH) ); mKeyMap.insert( KeyMap::value_type(SDLK_SLASH, KC_SLASH) );
mKeyMap.insert( KeyMap::value_type(SDLK_z, KC_Z) ); mKeyMap.insert( KeyMap::value_type(SDLK_z, KC_Z) );
mKeyMap.insert( KeyMap::value_type(SDLK_x, KC_X) ); mKeyMap.insert( KeyMap::value_type(SDLK_x, KC_X) );
mKeyMap.insert( KeyMap::value_type(SDLK_c, KC_C) ); mKeyMap.insert( KeyMap::value_type(SDLK_c, KC_C) );
mKeyMap.insert( KeyMap::value_type(SDLK_v, KC_V) ); mKeyMap.insert( KeyMap::value_type(SDLK_v, KC_V) );
mKeyMap.insert( KeyMap::value_type(SDLK_b, KC_B) ); mKeyMap.insert( KeyMap::value_type(SDLK_b, KC_B) );
mKeyMap.insert( KeyMap::value_type(SDLK_n, KC_N) ); mKeyMap.insert( KeyMap::value_type(SDLK_n, KC_N) );
mKeyMap.insert( KeyMap::value_type(SDLK_m, KC_M) ); mKeyMap.insert( KeyMap::value_type(SDLK_m, KC_M) );
mKeyMap.insert( KeyMap::value_type(SDLK_COMMA, KC_COMMA) ); mKeyMap.insert( KeyMap::value_type(SDLK_COMMA, KC_COMMA) );
mKeyMap.insert( KeyMap::value_type(SDLK_PERIOD, KC_PERIOD)); mKeyMap.insert( KeyMap::value_type(SDLK_PERIOD, KC_PERIOD));
mKeyMap.insert( KeyMap::value_type(SDLK_RSHIFT, KC_RSHIFT)); 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_KP_MULTIPLY, KC_MULTIPLY) );
mKeyMap.insert( KeyMap::value_type(SDLK_LALT, KC_LMENU) ); mKeyMap.insert( KeyMap::value_type(SDLK_LALT, KC_LMENU) );
mKeyMap.insert( KeyMap::value_type(SDLK_SPACE, KC_SPACE)); mKeyMap.insert( KeyMap::value_type(SDLK_SPACE, KC_SPACE));
mKeyMap.insert( KeyMap::value_type(SDLK_CAPSLOCK, KC_CAPITAL) ); mKeyMap.insert( KeyMap::value_type(SDLK_CAPSLOCK, KC_CAPITAL) );
mKeyMap.insert( KeyMap::value_type(SDLK_F1, KC_F1) ); mKeyMap.insert( KeyMap::value_type(SDLK_F1, KC_F1) );
mKeyMap.insert( KeyMap::value_type(SDLK_F2, KC_F2) ); mKeyMap.insert( KeyMap::value_type(SDLK_F2, KC_F2) );
mKeyMap.insert( KeyMap::value_type(SDLK_F3, KC_F3) ); mKeyMap.insert( KeyMap::value_type(SDLK_F3, KC_F3) );
mKeyMap.insert( KeyMap::value_type(SDLK_F4, KC_F4) ); mKeyMap.insert( KeyMap::value_type(SDLK_F4, KC_F4) );
mKeyMap.insert( KeyMap::value_type(SDLK_F5, KC_F5) ); mKeyMap.insert( KeyMap::value_type(SDLK_F5, KC_F5) );
mKeyMap.insert( KeyMap::value_type(SDLK_F6, KC_F6) ); mKeyMap.insert( KeyMap::value_type(SDLK_F6, KC_F6) );
mKeyMap.insert( KeyMap::value_type(SDLK_F7, KC_F7) ); mKeyMap.insert( KeyMap::value_type(SDLK_F7, KC_F7) );
mKeyMap.insert( KeyMap::value_type(SDLK_F8, KC_F8) ); mKeyMap.insert( KeyMap::value_type(SDLK_F8, KC_F8) );
mKeyMap.insert( KeyMap::value_type(SDLK_F9, KC_F9) ); mKeyMap.insert( KeyMap::value_type(SDLK_F9, KC_F9) );
mKeyMap.insert( KeyMap::value_type(SDLK_F10, KC_F10) ); mKeyMap.insert( KeyMap::value_type(SDLK_F10, KC_F10) );
mKeyMap.insert( KeyMap::value_type(SDLK_NUMLOCK, KC_NUMLOCK) ); mKeyMap.insert( KeyMap::value_type(SDLK_NUMLOCK, KC_NUMLOCK) );
mKeyMap.insert( KeyMap::value_type(SDLK_SCROLLOCK, KC_SCROLL)); mKeyMap.insert( KeyMap::value_type(SDLK_SCROLLOCK, KC_SCROLL));
mKeyMap.insert( KeyMap::value_type(SDLK_KP7, KC_NUMPAD7) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP7, KC_NUMPAD7) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP8, KC_NUMPAD8) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP8, KC_NUMPAD8) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP9, KC_NUMPAD9) ); 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_KP_MINUS, KC_SUBTRACT) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP4, KC_NUMPAD4) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP4, KC_NUMPAD4) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP5, KC_NUMPAD5) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP5, KC_NUMPAD5) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP6, KC_NUMPAD6) ); 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_KP_PLUS, KC_ADD) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP1, KC_NUMPAD1) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP1, KC_NUMPAD1) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP2, KC_NUMPAD2) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP2, KC_NUMPAD2) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP3, KC_NUMPAD3) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP3, KC_NUMPAD3) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP0, KC_NUMPAD0) ); 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_KP_PERIOD, KC_DECIMAL) );
mKeyMap.insert( KeyMap::value_type(SDLK_F11, KC_F11) ); mKeyMap.insert( KeyMap::value_type(SDLK_F11, KC_F11) );
mKeyMap.insert( KeyMap::value_type(SDLK_F12, KC_F12) ); mKeyMap.insert( KeyMap::value_type(SDLK_F12, KC_F12) );
mKeyMap.insert( KeyMap::value_type(SDLK_F13, KC_F13) ); mKeyMap.insert( KeyMap::value_type(SDLK_F13, KC_F13) );
mKeyMap.insert( KeyMap::value_type(SDLK_F14, KC_F14) ); mKeyMap.insert( KeyMap::value_type(SDLK_F14, KC_F14) );
mKeyMap.insert( KeyMap::value_type(SDLK_F15, KC_F15) ); 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_EQUALS, KC_NUMPADEQUALS) );
mKeyMap.insert( KeyMap::value_type(SDLK_KP_DIVIDE, KC_DIVIDE) ); 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_SYSREQ, KC_SYSRQ) );
mKeyMap.insert( KeyMap::value_type(SDLK_RALT, KC_RMENU) ); mKeyMap.insert( KeyMap::value_type(SDLK_RALT, KC_RMENU) );
mKeyMap.insert( KeyMap::value_type(SDLK_HOME, KC_HOME) ); mKeyMap.insert( KeyMap::value_type(SDLK_HOME, KC_HOME) );
mKeyMap.insert( KeyMap::value_type(SDLK_UP, KC_UP) ); mKeyMap.insert( KeyMap::value_type(SDLK_UP, KC_UP) );
mKeyMap.insert( KeyMap::value_type(SDLK_PAGEUP, KC_PGUP) ); mKeyMap.insert( KeyMap::value_type(SDLK_PAGEUP, KC_PGUP) );
mKeyMap.insert( KeyMap::value_type(SDLK_LEFT, KC_LEFT) ); mKeyMap.insert( KeyMap::value_type(SDLK_LEFT, KC_LEFT) );
mKeyMap.insert( KeyMap::value_type(SDLK_RIGHT, KC_RIGHT) ); mKeyMap.insert( KeyMap::value_type(SDLK_RIGHT, KC_RIGHT) );
mKeyMap.insert( KeyMap::value_type(SDLK_END, KC_END) ); mKeyMap.insert( KeyMap::value_type(SDLK_END, KC_END) );
mKeyMap.insert( KeyMap::value_type(SDLK_DOWN, KC_DOWN) ); mKeyMap.insert( KeyMap::value_type(SDLK_DOWN, KC_DOWN) );
mKeyMap.insert( KeyMap::value_type(SDLK_PAGEDOWN, KC_PGDOWN) ); mKeyMap.insert( KeyMap::value_type(SDLK_PAGEDOWN, KC_PGDOWN) );
mKeyMap.insert( KeyMap::value_type(SDLK_INSERT, KC_INSERT) ); mKeyMap.insert( KeyMap::value_type(SDLK_INSERT, KC_INSERT) );
mKeyMap.insert( KeyMap::value_type(SDLK_DELETE, KC_DELETE) ); mKeyMap.insert( KeyMap::value_type(SDLK_DELETE, KC_DELETE) );
mKeyMap.insert( KeyMap::value_type(SDLK_LSUPER, KC_LWIN) ); mKeyMap.insert( KeyMap::value_type(SDLK_LSUPER, KC_LWIN) );
mKeyMap.insert( KeyMap::value_type(SDLK_RSUPER, KC_RWIN) ); mKeyMap.insert( KeyMap::value_type(SDLK_RSUPER, KC_RWIN) );
SDL_EnableUNICODE(1); SDL_EnableUNICODE(1);
} }
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
SDLKeyboard::~SDLKeyboard() SDLKeyboard::~SDLKeyboard()
{ {
} }
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
void SDLKeyboard::capture() void SDLKeyboard::capture()
{ {
SDL_Event events[OIS_SDL_KEY_BUFF]; SDL_Event events[OIS_SDL_KEY_BUFF];
int count = SDL_PeepEvents(events, OIS_SDL_KEY_BUFF, SDL_GETEVENT, int count = SDL_PeepEvents(events, OIS_SDL_KEY_BUFF, SDL_GETEVENT,
SDL_EVENTMASK(SDL_KEYDOWN) | SDL_EVENTMASK(SDL_KEYUP)); SDL_EVENTMASK(SDL_KEYDOWN) | SDL_EVENTMASK(SDL_KEYUP));
for( int i = 0; i < count; ++i ) for( int i = 0; i < count; ++i )
{ {
KeyCode kc = mKeyMap[events[i].key.keysym.sym]; KeyCode kc = mKeyMap[events[i].key.keysym.sym];
KeyBuffer[kc] = events[i].key.state; KeyBuffer[kc] = events[i].key.state;
if( mBuffered && listener ) if( mBuffered && listener )
{ {
if( events[i].key.state == SDL_PRESSED ) if( events[i].key.state == SDL_PRESSED )
{ {
if( listener->keyPressed(KeyEvent(this, 0, kc, events[i].key.keysym.unicode)) == false ) if( listener->keyPressed(KeyEvent(this, 0, kc, events[i].key.keysym.unicode)) == false )
break; break;
} }
else else
{ {
if( listener->keyReleased(KeyEvent(this, 0, kc, events[i].key.keysym.unicode)) == false ) if( listener->keyReleased(KeyEvent(this, 0, kc, events[i].key.keysym.unicode)) == false )
break; break;
} }
} }
} }
//Release Grab mode on Alt-Tab combinations (for non-window systems) //Release Grab mode on Alt-Tab combinations (for non-window systems)
if( KeyBuffer[KC_RMENU] || KeyBuffer[KC_LMENU]) if( KeyBuffer[KC_RMENU] || KeyBuffer[KC_LMENU])
{ {
if( KeyBuffer[KC_TAB] ) if( KeyBuffer[KC_TAB] )
static_cast<SDLInputManager*>(InputManager::getSingletonPtr())->_setGrabMode(false); static_cast<SDLInputManager*>(InputManager::getSingletonPtr())->_setGrabMode(false);
} }
} }
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
bool SDLKeyboard::isKeyDown( KeyCode key ) bool SDLKeyboard::isKeyDown( KeyCode key )
{ {
return KeyBuffer[key] == 1 ? true : false; return KeyBuffer[key] == 1 ? true : false;
} }
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
const std::string& SDLKeyboard::getAsString( KeyCode kc ) const std::string& SDLKeyboard::getAsString( KeyCode kc )
{ {
switch(kc) switch(kc)
{ {
case KC_ESCAPE: mGetString = SDL_GetKeyName(SDLK_ESCAPE); break; case KC_ESCAPE: mGetString = SDL_GetKeyName(SDLK_ESCAPE); break;
case KC_1: mGetString = SDL_GetKeyName(SDLK_1); break; case KC_1: mGetString = SDL_GetKeyName(SDLK_1); break;
case KC_2: mGetString = SDL_GetKeyName(SDLK_2); break; case KC_2: mGetString = SDL_GetKeyName(SDLK_2); break;
case KC_3: mGetString = SDL_GetKeyName(SDLK_3); break; case KC_3: mGetString = SDL_GetKeyName(SDLK_3); break;
case KC_4: mGetString = SDL_GetKeyName(SDLK_4); break; case KC_4: mGetString = SDL_GetKeyName(SDLK_4); break;
case KC_5: mGetString = SDL_GetKeyName(SDLK_5); break; case KC_5: mGetString = SDL_GetKeyName(SDLK_5); break;
case KC_6: mGetString = SDL_GetKeyName(SDLK_6); break; case KC_6: mGetString = SDL_GetKeyName(SDLK_6); break;
case KC_7: mGetString = SDL_GetKeyName(SDLK_7); break; case KC_7: mGetString = SDL_GetKeyName(SDLK_7); break;
case KC_8: mGetString = SDL_GetKeyName(SDLK_8); break; case KC_8: mGetString = SDL_GetKeyName(SDLK_8); break;
case KC_9: mGetString = SDL_GetKeyName(SDLK_9); break; case KC_9: mGetString = SDL_GetKeyName(SDLK_9); break;
case KC_0: mGetString = SDL_GetKeyName(SDLK_0); break; case KC_0: mGetString = SDL_GetKeyName(SDLK_0); break;
case KC_MINUS: mGetString = SDL_GetKeyName(SDLK_MINUS); break; case KC_MINUS: mGetString = SDL_GetKeyName(SDLK_MINUS); break;
case KC_EQUALS: mGetString = SDL_GetKeyName(SDLK_EQUALS); break; case KC_EQUALS: mGetString = SDL_GetKeyName(SDLK_EQUALS); break;
case KC_BACK: mGetString = SDL_GetKeyName(SDLK_BACKSPACE); break; case KC_BACK: mGetString = SDL_GetKeyName(SDLK_BACKSPACE); break;
case KC_TAB: mGetString = SDL_GetKeyName(SDLK_TAB); break; case KC_TAB: mGetString = SDL_GetKeyName(SDLK_TAB); break;
case KC_Q: mGetString = SDL_GetKeyName(SDLK_q); break; case KC_Q: mGetString = SDL_GetKeyName(SDLK_q); break;
case KC_W: mGetString = SDL_GetKeyName(SDLK_w); break; case KC_W: mGetString = SDL_GetKeyName(SDLK_w); break;
case KC_E: mGetString = SDL_GetKeyName(SDLK_e); break; case KC_E: mGetString = SDL_GetKeyName(SDLK_e); break;
case KC_R: mGetString = SDL_GetKeyName(SDLK_r); break; case KC_R: mGetString = SDL_GetKeyName(SDLK_r); break;
case KC_T: mGetString = SDL_GetKeyName(SDLK_t); break; case KC_T: mGetString = SDL_GetKeyName(SDLK_t); break;
case KC_Y: mGetString = SDL_GetKeyName(SDLK_y); break; case KC_Y: mGetString = SDL_GetKeyName(SDLK_y); break;
case KC_U: mGetString = SDL_GetKeyName(SDLK_u); break; case KC_U: mGetString = SDL_GetKeyName(SDLK_u); break;
case KC_I: mGetString = SDL_GetKeyName(SDLK_i); break; case KC_I: mGetString = SDL_GetKeyName(SDLK_i); break;
case KC_O: mGetString = SDL_GetKeyName(SDLK_o); break; case KC_O: mGetString = SDL_GetKeyName(SDLK_o); break;
case KC_P: mGetString = SDL_GetKeyName(SDLK_p); break; case KC_P: mGetString = SDL_GetKeyName(SDLK_p); break;
case KC_LBRACKET: mGetString = "["; break; case KC_LBRACKET: mGetString = "["; break;
case KC_RBRACKET: mGetString = "]"; break; case KC_RBRACKET: mGetString = "]"; break;
case KC_RETURN: mGetString = SDL_GetKeyName(SDLK_RETURN); break; case KC_RETURN: mGetString = SDL_GetKeyName(SDLK_RETURN); break;
case KC_LCONTROL: mGetString = SDL_GetKeyName(SDLK_LCTRL); break; case KC_LCONTROL: mGetString = SDL_GetKeyName(SDLK_LCTRL); break;
case KC_A: mGetString = SDL_GetKeyName(SDLK_a); break; case KC_A: mGetString = SDL_GetKeyName(SDLK_a); break;
case KC_S: mGetString = SDL_GetKeyName(SDLK_s); break; case KC_S: mGetString = SDL_GetKeyName(SDLK_s); break;
case KC_D: mGetString = SDL_GetKeyName(SDLK_d); break; case KC_D: mGetString = SDL_GetKeyName(SDLK_d); break;
case KC_F: mGetString = SDL_GetKeyName(SDLK_f); break; case KC_F: mGetString = SDL_GetKeyName(SDLK_f); break;
case KC_G: mGetString = SDL_GetKeyName(SDLK_g); break; case KC_G: mGetString = SDL_GetKeyName(SDLK_g); break;
case KC_H: mGetString = SDL_GetKeyName(SDLK_h); break; case KC_H: mGetString = SDL_GetKeyName(SDLK_h); break;
case KC_J: mGetString = SDL_GetKeyName(SDLK_j); break; case KC_J: mGetString = SDL_GetKeyName(SDLK_j); break;
case KC_K: mGetString = SDL_GetKeyName(SDLK_k); break; case KC_K: mGetString = SDL_GetKeyName(SDLK_k); break;
case KC_L: mGetString = SDL_GetKeyName(SDLK_l); break; case KC_L: mGetString = SDL_GetKeyName(SDLK_l); break;
case KC_SEMICOLON: mGetString = SDL_GetKeyName(SDLK_SEMICOLON); break; case KC_SEMICOLON: mGetString = SDL_GetKeyName(SDLK_SEMICOLON); break;
case KC_APOSTROPHE: mGetString = SDL_GetKeyName(SDLK_QUOTE); break; case KC_APOSTROPHE: mGetString = SDL_GetKeyName(SDLK_QUOTE); break;
case KC_GRAVE: mGetString = SDL_GetKeyName(SDLK_BACKQUOTE); break; case KC_GRAVE: mGetString = SDL_GetKeyName(SDLK_BACKQUOTE); break;
case KC_LSHIFT: mGetString = SDL_GetKeyName(SDLK_LSHIFT); break; case KC_LSHIFT: mGetString = SDL_GetKeyName(SDLK_LSHIFT); break;
case KC_BACKSLASH: mGetString = SDL_GetKeyName(SDLK_BACKSLASH); break; case KC_BACKSLASH: mGetString = SDL_GetKeyName(SDLK_BACKSLASH); break;
case KC_Z: mGetString = SDL_GetKeyName(SDLK_z); break; case KC_Z: mGetString = SDL_GetKeyName(SDLK_z); break;
case KC_X: mGetString = SDL_GetKeyName(SDLK_x); break; case KC_X: mGetString = SDL_GetKeyName(SDLK_x); break;
case KC_C: mGetString = SDL_GetKeyName(SDLK_c); break; case KC_C: mGetString = SDL_GetKeyName(SDLK_c); break;
case KC_V: mGetString = SDL_GetKeyName(SDLK_v); break; case KC_V: mGetString = SDL_GetKeyName(SDLK_v); break;
case KC_B: mGetString = SDL_GetKeyName(SDLK_b); break; case KC_B: mGetString = SDL_GetKeyName(SDLK_b); break;
case KC_N: mGetString = SDL_GetKeyName(SDLK_n); break; case KC_N: mGetString = SDL_GetKeyName(SDLK_n); break;
case KC_M: mGetString = SDL_GetKeyName(SDLK_m); break; case KC_M: mGetString = SDL_GetKeyName(SDLK_m); break;
case KC_COMMA: mGetString = SDL_GetKeyName(SDLK_COMMA); break; case KC_COMMA: mGetString = SDL_GetKeyName(SDLK_COMMA); break;
case KC_PERIOD: mGetString = SDL_GetKeyName(SDLK_PERIOD); break; case KC_PERIOD: mGetString = SDL_GetKeyName(SDLK_PERIOD); break;
case KC_SLASH: mGetString = SDL_GetKeyName(SDLK_SLASH); break; case KC_SLASH: mGetString = SDL_GetKeyName(SDLK_SLASH); break;
case KC_RSHIFT: mGetString = SDL_GetKeyName(SDLK_RSHIFT); break; case KC_RSHIFT: mGetString = SDL_GetKeyName(SDLK_RSHIFT); break;
case KC_MULTIPLY: mGetString = SDL_GetKeyName(SDLK_KP_MULTIPLY); break; case KC_MULTIPLY: mGetString = SDL_GetKeyName(SDLK_KP_MULTIPLY); break;
case KC_LMENU: mGetString = SDL_GetKeyName(SDLK_LALT); break; case KC_LMENU: mGetString = SDL_GetKeyName(SDLK_LALT); break;
case KC_SPACE: mGetString = SDL_GetKeyName(SDLK_SPACE); break; case KC_SPACE: mGetString = SDL_GetKeyName(SDLK_SPACE); break;
case KC_CAPITAL: mGetString = SDL_GetKeyName(SDLK_CAPSLOCK); break; case KC_CAPITAL: mGetString = SDL_GetKeyName(SDLK_CAPSLOCK); break;
case KC_F1: mGetString = SDL_GetKeyName(SDLK_F1); break; case KC_F1: mGetString = SDL_GetKeyName(SDLK_F1); break;
case KC_F2: mGetString = SDL_GetKeyName(SDLK_F2); break; case KC_F2: mGetString = SDL_GetKeyName(SDLK_F2); break;
case KC_F3: mGetString = SDL_GetKeyName(SDLK_F3); break; case KC_F3: mGetString = SDL_GetKeyName(SDLK_F3); break;
case KC_F4: mGetString = SDL_GetKeyName(SDLK_F4); break; case KC_F4: mGetString = SDL_GetKeyName(SDLK_F4); break;
case KC_F5: mGetString = SDL_GetKeyName(SDLK_F5); break; case KC_F5: mGetString = SDL_GetKeyName(SDLK_F5); break;
case KC_F6: mGetString = SDL_GetKeyName(SDLK_F6); break; case KC_F6: mGetString = SDL_GetKeyName(SDLK_F6); break;
case KC_F7: mGetString = SDL_GetKeyName(SDLK_F7); break; case KC_F7: mGetString = SDL_GetKeyName(SDLK_F7); break;
case KC_F8: mGetString = SDL_GetKeyName(SDLK_F8); break; case KC_F8: mGetString = SDL_GetKeyName(SDLK_F8); break;
case KC_F9: mGetString = SDL_GetKeyName(SDLK_F9); break; case KC_F9: mGetString = SDL_GetKeyName(SDLK_F9); break;
case KC_F10: mGetString = SDL_GetKeyName(SDLK_F10); break; case KC_F10: mGetString = SDL_GetKeyName(SDLK_F10); break;
case KC_NUMLOCK: mGetString = SDL_GetKeyName(SDLK_NUMLOCK); break; case KC_NUMLOCK: mGetString = SDL_GetKeyName(SDLK_NUMLOCK); break;
case KC_SCROLL: mGetString = SDL_GetKeyName(SDLK_SCROLLOCK); break; case KC_SCROLL: mGetString = SDL_GetKeyName(SDLK_SCROLLOCK); break;
case KC_NUMPAD7: mGetString = SDL_GetKeyName(SDLK_KP7); break; case KC_NUMPAD7: mGetString = SDL_GetKeyName(SDLK_KP7); break;
case KC_NUMPAD8: mGetString = SDL_GetKeyName(SDLK_KP8); break; case KC_NUMPAD8: mGetString = SDL_GetKeyName(SDLK_KP8); break;
case KC_NUMPAD9: mGetString = SDL_GetKeyName(SDLK_KP9); break; case KC_NUMPAD9: mGetString = SDL_GetKeyName(SDLK_KP9); break;
case KC_SUBTRACT: mGetString = SDL_GetKeyName(SDLK_KP_MINUS); break; case KC_SUBTRACT: mGetString = SDL_GetKeyName(SDLK_KP_MINUS); break;
case KC_NUMPAD4: mGetString = SDL_GetKeyName(SDLK_KP4); break; case KC_NUMPAD4: mGetString = SDL_GetKeyName(SDLK_KP4); break;
case KC_NUMPAD5: mGetString = SDL_GetKeyName(SDLK_KP5); break; case KC_NUMPAD5: mGetString = SDL_GetKeyName(SDLK_KP5); break;
case KC_NUMPAD6: mGetString = SDL_GetKeyName(SDLK_KP6); break; case KC_NUMPAD6: mGetString = SDL_GetKeyName(SDLK_KP6); break;
case KC_ADD: mGetString = SDL_GetKeyName(SDLK_KP_PLUS); break; case KC_ADD: mGetString = SDL_GetKeyName(SDLK_KP_PLUS); break;
case KC_NUMPAD1: mGetString = SDL_GetKeyName(SDLK_KP1); break; case KC_NUMPAD1: mGetString = SDL_GetKeyName(SDLK_KP1); break;
case KC_NUMPAD2: mGetString = SDL_GetKeyName(SDLK_KP2); break; case KC_NUMPAD2: mGetString = SDL_GetKeyName(SDLK_KP2); break;
case KC_NUMPAD3: mGetString = SDL_GetKeyName(SDLK_KP3); break; case KC_NUMPAD3: mGetString = SDL_GetKeyName(SDLK_KP3); break;
case KC_NUMPAD0: mGetString = SDL_GetKeyName(SDLK_KP0); break; case KC_NUMPAD0: mGetString = SDL_GetKeyName(SDLK_KP0); break;
case KC_DECIMAL: mGetString = SDL_GetKeyName(SDLK_KP_PERIOD); break; case KC_DECIMAL: mGetString = SDL_GetKeyName(SDLK_KP_PERIOD); break;
case KC_OEM_102: mGetString = "OEM_102"; break; case KC_OEM_102: mGetString = "OEM_102"; break;
case KC_F11: mGetString = SDL_GetKeyName(SDLK_F11); break; case KC_F11: mGetString = SDL_GetKeyName(SDLK_F11); break;
case KC_F12: mGetString = SDL_GetKeyName(SDLK_F12); break; case KC_F12: mGetString = SDL_GetKeyName(SDLK_F12); break;
case KC_F13: mGetString = SDL_GetKeyName(SDLK_F13); break; case KC_F13: mGetString = SDL_GetKeyName(SDLK_F13); break;
case KC_F14: mGetString = SDL_GetKeyName(SDLK_F14); break; case KC_F14: mGetString = SDL_GetKeyName(SDLK_F14); break;
case KC_F15: mGetString = SDL_GetKeyName(SDLK_F15); break; case KC_F15: mGetString = SDL_GetKeyName(SDLK_F15); break;
case KC_KANA: mGetString = "Kana"; break; case KC_KANA: mGetString = "Kana"; break;
case KC_ABNT_C1: mGetString = "ABNT_C1"; break; case KC_ABNT_C1: mGetString = "ABNT_C1"; break;
case KC_CONVERT: mGetString = "CONVERT"; break; case KC_CONVERT: mGetString = "CONVERT"; break;
case KC_NOCONVERT: mGetString = "NOCONVERT"; break; case KC_NOCONVERT: mGetString = "NOCONVERT"; break;
case KC_YEN: mGetString = "YEN"; break; case KC_YEN: mGetString = "YEN"; break;
case KC_ABNT_C2: mGetString = "ABNT_C2"; break; case KC_ABNT_C2: mGetString = "ABNT_C2"; break;
case KC_NUMPADEQUALS: mGetString = SDL_GetKeyName(SDLK_KP_EQUALS); break; case KC_NUMPADEQUALS: mGetString = SDL_GetKeyName(SDLK_KP_EQUALS); break;
case KC_PREVTRACK: mGetString = "KC_PREVTRACK"; break; case KC_PREVTRACK: mGetString = "KC_PREVTRACK"; break;
case KC_AT: mGetString = "KC_AT"; break; case KC_AT: mGetString = "KC_AT"; break;
case KC_COLON: mGetString = SDL_GetKeyName(SDLK_COLON); break; case KC_COLON: mGetString = SDL_GetKeyName(SDLK_COLON); break;
case KC_UNDERLINE: mGetString = "KC_UNDERLINE"; break; case KC_UNDERLINE: mGetString = "KC_UNDERLINE"; break;
case KC_KANJI: mGetString = "KC_KANJI"; break; case KC_KANJI: mGetString = "KC_KANJI"; break;
case KC_STOP: mGetString = "KC_STOP"; break; case KC_STOP: mGetString = "KC_STOP"; break;
case KC_AX: mGetString = "KC_AX"; break; case KC_AX: mGetString = "KC_AX"; break;
case KC_UNLABELED: mGetString = "KC_UNLABELED"; break; case KC_UNLABELED: mGetString = "KC_UNLABELED"; break;
case KC_NEXTTRACK: mGetString = "KC_NEXTTRACK"; break; case KC_NEXTTRACK: mGetString = "KC_NEXTTRACK"; break;
case KC_NUMPADENTER: mGetString = "KC_NUMPADENTER"; break; case KC_NUMPADENTER: mGetString = "KC_NUMPADENTER"; break;
case KC_RCONTROL: mGetString = "KC_RCONTROL"; break; case KC_RCONTROL: mGetString = "KC_RCONTROL"; break;
case KC_MUTE: mGetString = "KC_MUTE"; break; case KC_MUTE: mGetString = "KC_MUTE"; break;
case KC_CALCULATOR: mGetString = "KC_CALCULATOR"; break; case KC_CALCULATOR: mGetString = "KC_CALCULATOR"; break;
case KC_PLAYPAUSE: mGetString = "KC_PLAYPAUSE"; break; case KC_PLAYPAUSE: mGetString = "KC_PLAYPAUSE"; break;
case KC_MEDIASTOP: mGetString = "KC_MEDIASTOP"; break; case KC_MEDIASTOP: mGetString = "KC_MEDIASTOP"; break;
case KC_VOLUMEDOWN: mGetString = "KC_VOLUMEDOWN"; break; case KC_VOLUMEDOWN: mGetString = "KC_VOLUMEDOWN"; break;
case KC_VOLUMEUP: mGetString = "KC_VOLUMEUP"; break; case KC_VOLUMEUP: mGetString = "KC_VOLUMEUP"; break;
case KC_WEBHOME: mGetString = "KC_WEBHOME"; break; case KC_WEBHOME: mGetString = "KC_WEBHOME"; break;
case KC_NUMPADCOMMA: mGetString = "KC_NUMPADCOMMA"; break; case KC_NUMPADCOMMA: mGetString = "KC_NUMPADCOMMA"; break;
case KC_DIVIDE: mGetString = SDL_GetKeyName(SDLK_KP_DIVIDE); break; case KC_DIVIDE: mGetString = SDL_GetKeyName(SDLK_KP_DIVIDE); break;
case KC_SYSRQ: mGetString = SDL_GetKeyName(SDLK_SYSREQ); break; case KC_SYSRQ: mGetString = SDL_GetKeyName(SDLK_SYSREQ); break;
case KC_RMENU: mGetString = SDL_GetKeyName(SDLK_RALT); break; case KC_RMENU: mGetString = SDL_GetKeyName(SDLK_RALT); break;
case KC_PAUSE: mGetString = "Pause"; break; case KC_PAUSE: mGetString = "Pause"; break;
case KC_HOME: mGetString = SDL_GetKeyName(SDLK_HOME); break; case KC_HOME: mGetString = SDL_GetKeyName(SDLK_HOME); break;
case KC_UP: mGetString = SDL_GetKeyName(SDLK_UP); break; case KC_UP: mGetString = SDL_GetKeyName(SDLK_UP); break;
case KC_PGUP: mGetString = SDL_GetKeyName(SDLK_PAGEUP); break; case KC_PGUP: mGetString = SDL_GetKeyName(SDLK_PAGEUP); break;
case KC_LEFT: mGetString = SDL_GetKeyName(SDLK_LEFT); break; case KC_LEFT: mGetString = SDL_GetKeyName(SDLK_LEFT); break;
case KC_RIGHT: mGetString = SDL_GetKeyName(SDLK_RIGHT); break; case KC_RIGHT: mGetString = SDL_GetKeyName(SDLK_RIGHT); break;
case KC_END: mGetString = SDL_GetKeyName(SDLK_END); break; case KC_END: mGetString = SDL_GetKeyName(SDLK_END); break;
case KC_DOWN: mGetString = SDL_GetKeyName(SDLK_DOWN); break; case KC_DOWN: mGetString = SDL_GetKeyName(SDLK_DOWN); break;
case KC_PGDOWN: mGetString = SDL_GetKeyName(SDLK_PAGEDOWN); break; case KC_PGDOWN: mGetString = SDL_GetKeyName(SDLK_PAGEDOWN); break;
case KC_INSERT: mGetString = SDL_GetKeyName(SDLK_INSERT); break; case KC_INSERT: mGetString = SDL_GetKeyName(SDLK_INSERT); break;
case KC_DELETE: mGetString = SDL_GetKeyName(SDLK_DELETE); break; case KC_DELETE: mGetString = SDL_GetKeyName(SDLK_DELETE); break;
case KC_LWIN: mGetString = SDL_GetKeyName(SDLK_LSUPER); break; case KC_LWIN: mGetString = SDL_GetKeyName(SDLK_LSUPER); break;
case KC_RWIN: mGetString = SDL_GetKeyName(SDLK_RSUPER); break; case KC_RWIN: mGetString = SDL_GetKeyName(SDLK_RSUPER); break;
case KC_APPS: mGetString = "KC_APPS"; break; case KC_APPS: mGetString = "KC_APPS"; break;
case KC_POWER: mGetString = "KC_POWER"; break; case KC_POWER: mGetString = "KC_POWER"; break;
case KC_SLEEP: mGetString = "KC_SLEEP"; break; case KC_SLEEP: mGetString = "KC_SLEEP"; break;
case KC_WAKE: mGetString = "KC_WAKE"; break; case KC_WAKE: mGetString = "KC_WAKE"; break;
case KC_WEBSEARCH: mGetString = "KC_WEBSEARCH"; break; case KC_WEBSEARCH: mGetString = "KC_WEBSEARCH"; break;
case KC_WEBFAVORITES: mGetString = "KC_WEBFAVORITES"; break; case KC_WEBFAVORITES: mGetString = "KC_WEBFAVORITES"; break;
case KC_WEBREFRESH: mGetString = "KC_WEBREFRESH"; break; case KC_WEBREFRESH: mGetString = "KC_WEBREFRESH"; break;
case KC_WEBSTOP: mGetString = "KC_WEBSTOP"; break; case KC_WEBSTOP: mGetString = "KC_WEBSTOP"; break;
case KC_WEBFORWARD: mGetString = "KC_WEBFORWARD"; break; case KC_WEBFORWARD: mGetString = "KC_WEBFORWARD"; break;
case KC_WEBBACK: mGetString = "KC_WEBBACK"; break; case KC_WEBBACK: mGetString = "KC_WEBBACK"; break;
case KC_MYCOMPUTER: mGetString = "KC_MYCOMPUTER"; break; case KC_MYCOMPUTER: mGetString = "KC_MYCOMPUTER"; break;
case KC_MAIL: mGetString = "KC_MAIL"; break; case KC_MAIL: mGetString = "KC_MAIL"; break;
case KC_MEDIASELECT: mGetString = "KC_MEDIASELECT"; break; case KC_MEDIASELECT: mGetString = "KC_MEDIASELECT"; break;
default: mGetString = "Unknown"; break; default: mGetString = "Unknown"; break;
}; };
return mGetString; return mGetString;
} }
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
void SDLKeyboard::copyKeyStates( char keys[256] ) void SDLKeyboard::copyKeyStates( char keys[256] )
{ {
for(int i = 0; i < 256; ++i) for(int i = 0; i < 256; ++i)
keys[i] = KeyBuffer[i]; keys[i] = KeyBuffer[i];
} }
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
void SDLKeyboard::setBuffered(bool buffered) void SDLKeyboard::setBuffered(bool buffered)
{ {
mBuffered = buffered; mBuffered = buffered;
} }
//-------------------------------------------------------------------// //-------------------------------------------------------------------//
void SDLKeyboard::setTextTranslation( TextTranslationMode mode ) void SDLKeyboard::setTextTranslation( TextTranslationMode mode )
{ {
mTextMode = mode; mTextMode = mode;
if( mode == Off || mode == Ascii ) if( mode == Off || mode == Ascii )
SDL_EnableUNICODE(0); SDL_EnableUNICODE(0);
else if( mode == Unicode ) else if( mode == Unicode )
SDL_EnableUNICODE(1); SDL_EnableUNICODE(1);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment