Commit 4b11dd5a authored by Phillip Castaneda's avatar Phillip Castaneda
Browse files

Adding OIS sources to SVN

parents
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _OIS_SDLKEYBOARD_H
#define _OIS_SDLKEYBOARD_H
#include "OISKeyboard.h"
#include "SDL/SDLPrereqs.h"
namespace OIS
{
class SDLKeyboard : public Keyboard
{
public:
/**
@remarks
Constructor
@param buffered
True for buffered input mode
*/
SDLKeyboard( bool buffered );
virtual ~SDLKeyboard();
/** @copydoc Keyboard::isKeyDown */
virtual bool isKeyDown( KeyCode key );
/** @copydoc Keyboard::getAsString */
virtual const std::string& getAsString( KeyCode kc );
/** @copydoc Keyboard::copyKeyStates */
virtual void copyKeyStates( char keys[256] );
/** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */
virtual void capture();
/** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type) {return 0;}
/** @copydoc Object::_initialize */
virtual void _initialize();
/** @copydoc Object::setTextTranslation */
virtual void setTextTranslation( TextTranslationMode mode );
protected:
SDLKeyboard() {}
typedef std::map<SDLKey, KeyCode> KeyMap;
KeyMap mKeyMap;
unsigned char KeyBuffer[256];
Uint8* mSDLBuff;
std::string mGetString;
};
}
#endif
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _OIS_SDLMOUSE_H
#define _OIS_SDLMOUSE_H
#include "OISMouse.h"
#include "SDL/SDLPrereqs.h"
namespace OIS
{
class SDLMouse : public Mouse
{
public:
SDLMouse( bool buffered );
virtual ~SDLMouse();
/** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */
virtual void capture();
/** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type) {return 0;}
/** @copydoc Object::_initialize */
virtual void _initialize();
void _setGrab(bool grabbed);
void _setVisible(bool visible);
protected:
SDLMouse() {}
bool mGrabbed;
bool mRegainFocus;
};
}
#endif
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_SDLPrereqs_H
#define OIS_SDLPrereqs_H
#include "OISPrereqs.h"
#ifdef OIS_APPLE_PLATFORM
# include <SDL/SDL.h>
#else
# include <SDL.h>
#endif
#define OIS_SDL_KEY_BUFF 16
#define OIS_SDL_MOUSE_BUFF 50
#define OIS_SDL_JOY_BUFF 80
#endif
#ifndef OIS_iPhoneAccelerometer_H
#define OIS_iPhoneAccelerometer_H
#include "OISJoystick.h"
#include "iphone/iPhonePrereqs.h"
#import <UIKit/UIKit.h>
@class iPhoneAccelerometerDelegate;
class JoyStickState;
namespace OIS
{
class iPhoneAccelerometer : public JoyStick
{
public:
iPhoneAccelerometer(InputManager* creator, bool buffered);
virtual ~iPhoneAccelerometer();
/** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered);
void setUpdateInterval(float interval) {
mUpdateInterval = interval;
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0f / mUpdateInterval)];
}
Vector3 getAccelerometerVector3(void) { return mState.mVectors[0]; }
/** @copydoc Object::capture */
virtual void capture();
/** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type) {return 0;}
/** @copydoc Object::_initialize */
virtual void _initialize();
void didAccelerate(UIAcceleration *acceleration);
protected:
iPhoneAccelerometerDelegate *accelerometerDelegate;
/** The update frequency of the accelerometer. Represented in times per second. */
float mUpdateInterval;
Vector3 mTempState;
};
}
#endif // OIS_iPhoneAccelerometer_H
/*
The zlib/libpng License
Copyright (c) 2006 Chris Snyder
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_iPhoneHelpers_H
#define OIS_iPhoneHelpers_H
#include "iphone/iPhonePrereqs.h"
#include "OISMultiTouch.h"
// This is needed for keeping an event stack for keyboard and mouse
namespace OIS
{
// used in the eventStack to store the type
enum iPhone_EventType { iPhone_KEYUP = 0,
iPhone_KEYDOWN = 1,
iPhone_KEYREPEAT,
iPhone_MOUSEDOWN,
iPhone_MOUSEUP,
iPhone_MOUSEMOVED,
iPhone_MOUSESCROLL};
typedef enum iPhone_EventType iPhoneEventType;
// only used by iPhoneMultiTouch
typedef class iPhoneMultiTouchStackEvent
{
friend class iPhoneMultiTouch;
private:
iPhoneMultiTouchStackEvent( MultiTouchEvent event, iPhoneEventType type) : Event(event), Type(type) {}
iPhoneEventType Type;
MultiTouchEvent Event;
} iPhoneMultiTouchStackEvent;
}
#endif
/*
The zlib/libpng License
Copyright (c) 2006 Chris Snyder
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_iPhoneInputManager_H
#define OIS_iPhoneInputManager_H
#include "OISInputManager.h"
#include "OISFactoryCreator.h"
#include "iphone/iPhonePrereqs.h"
#import <UIKit/UIKit.h>
namespace OIS {
class iPhoneAccelerometer;
class iPhoneMultiTouch;
}
@interface InputDelegate : UIView <UIAccelerometerDelegate> {
OIS::iPhoneAccelerometer *accelerometerObject;
OIS::iPhoneMultiTouch *touchObject;
}
@property (assign) OIS::iPhoneAccelerometer *accelerometerObject;
@property (assign) OIS::iPhoneMultiTouch *touchObject;
@end
namespace OIS
{
class iPhoneInputManager : public InputManager, public FactoryCreator
{
public:
iPhoneInputManager();
virtual ~iPhoneInputManager();
//InputManager Overrides
/** @copydoc InputManager::_initialize */
void _initialize( ParamList &paramList );
//FactoryCreator Overrides
/** @copydoc FactoryCreator::deviceList */
DeviceList freeDeviceList();
/** @copydoc FactoryCreator::totalDevices */
int totalDevices(Type iType);
/** @copydoc FactoryCreator::freeDevices */
int freeDevices(Type iType);
/** @copydoc FactoryCreator::vendorExist */
bool vendorExist(Type iType, const std::string & vendor);
/** @copydoc FactoryCreator::createObject */
Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = "");
/** @copydoc FactoryCreator::destroyObject */
void destroyObject(Object* obj);
//Internal Items
//! Internal method, used for flagging multi-touch as available/unavailable for creation
void _setMultiTouchUsed(bool used) { bMultiTouchUsed = used; }
//! Internal method, used for flagging accelerometer as available/unavailable for creation
void _setAccelerometerUsed(bool used) { bAccelerometerUsed = used; }
//! methodfor getting the delegate
InputDelegate * _getDelegate() { return mDelegate; }
//! method for getting window
UIWindow * _getWindow() { return mWindow; }
protected:
void _parseConfigSettings( ParamList& paramList );
// iPhone stuff
UIWindow *mWindow;
InputDelegate *mDelegate;
// settings
bool mHideMouse;
//! Used to know if we used up multi-touch device
bool bMultiTouchUsed;
//! Used to know if we used up accelerometer
bool bAccelerometerUsed;
};
}
#endif
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_iPhoneMultiTouch_H
#define OIS_iPhoneMultiTouch_H
#include "OISMultiTouch.h"
#include "iphone/iPhonePrereqs.h"
#import <UIKit/UIKit.h>
struct CGPoint;
namespace OIS
{
class iPhoneMultiTouch : public MultiTouch
{
public:
iPhoneMultiTouch( InputManager* creator, bool buffered );
virtual ~iPhoneMultiTouch();
/** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */
virtual void capture();
/** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type) {return 0;}
/** @copydoc Object::_initialize */
virtual void _initialize();
void _touchBegan(UITouch *touch);
void _touchEnded(UITouch *touch);
void _touchMoved(UITouch *touch);
void _touchCancelled(UITouch *touch);
protected:
MultiTouchState mTempState;
};
}
#endif // OIS_iPhoneTouch_H
/*
The zlib/libpng License
Copyright (c) 2006 Chris Snyder
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_iPhonePrereqs_H
#define OIS_iPhonePrereqs_H
#include <string>
#include <list>
#include <CoreFoundation/CoreFoundation.h>
namespace OIS
{
class iPhoneInputManager;
class iPhoneAccelerometer;
class iPhoneMouse;
/**
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
*/
class OIS_CFString
{
public:
OIS_CFString() { m_StringRef = CFStringCreateWithCString(NULL, "", 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() { CFRelease(m_StringRef); }
//Allow this class to be autoconverted to base class of StringRef (void*)
operator void*() { return (void*)m_StringRef; }
CFStringRef cf_str() { return m_StringRef; }
private:
CFStringRef m_StringRef;
};
}
#endif
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _LINUX_OISEVENT_HEADER_
#define _LINUX_OISEVENT_HEADER_
#include "linux/LinuxPrereqs.h"
#define OIS_MAX_DEVICES 32
#define OIS_DEVICE_NAME 128
namespace OIS
{
class EventUtils
{
public:
static bool isJoyStick( int deviceID, JoyStickInfo &js );
static bool isMouse( int ) {return false;}
static bool isKeyboard( int ) {return false;}
//Double pointer is so that we can set the value of the sent pointer
static void enumerateForceFeedback( int deviceID, LinuxForceFeedback** ff );
static void removeForceFeedback( LinuxForceFeedback** ff );
static std::string getName( int deviceID );
static std::string getUniqueId( int deviceID );
static std::string getPhysicalLocation( int deviceID );
};
}
#endif
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_LinuxForceFeedBack_H
#define OIS_LinuxForceFeedBack_H
#include "linux/LinuxPrereqs.h"
#include "OISForceFeedback.h"
#include <linux/input.h>
namespace OIS
{
class LinuxForceFeedback : public ForceFeedback
{
public:
LinuxForceFeedback(int deviceID);
~LinuxForceFeedback();
/** @copydoc ForceFeedback::setMasterGain */
void setMasterGain(float);
/** @copydoc ForceFeedback::setAutoCenterMode */
void setAutoCenterMode(bool);
/** @copydoc ForceFeedback::upload */
void upload( const Effect* effect );
/** @copydoc ForceFeedback::modify */
void modify( const Effect* effect );
/** @copydoc ForceFeedback::remove */
void remove( const Effect* effect );
/** FF is not yet implemented fully on Linux.. just return -1 for now. todo, xxx */
short int getFFAxesNumber() { return -1; }
/** @copydoc ForceFeedback::getFFMemoryLoad */
unsigned short getFFMemoryLoad();
protected:
//Sets the common properties to all effects
void _setCommonProperties(struct ff_effect *event, struct ff_envelope *ffenvelope,
const Effect* effect, const Envelope *envelope );
//Specific Effect Settings
void _updateConstantEffect( const Effect* effect );
void _updateRampEffect( const Effect* effect );
void _updatePeriodicEffect( const Effect* effect );
void _updateConditionalEffect( const Effect* effect );
//void _updateCustomEffect( const Effect* effect );
void _upload( struct ff_effect* ffeffect, const Effect* effect);
void _stop( int handle);
void _start( int handle);
void _unload( int handle);
// Map of currently uploaded effects (handle => effect)
typedef std::map<int, struct ff_effect *> EffectList;
EffectList mEffectList;
// Joystick device (file) descriptor.
int mJoyStick;
};
}
#endif //OIS_LinuxForceFeedBack_H
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_LinuxInputManager_H
#define OIS_LinuxInputManager_H
#include "linux/LinuxPrereqs.h"
#include "OISFactoryCreator.h"
#include "OISInputManager.h"
#include <X11/Xlib.h>
namespace OIS
{
/**
Linux X11 InputManager specialization - Using lowlevel joys
*/
class LinuxInputManager : public InputManager, public FactoryCreator
{
public:
LinuxInputManager();
virtual ~LinuxInputManager();
//InputManager Overrides
/** @copydoc InputManager::_initialize */
void _initialize( ParamList &paramList );
//FactoryCreator Overrides
/** @copydoc FactoryCreator::deviceList */
DeviceList freeDeviceList();
/** @copydoc FactoryCreator::totalDevices */
int totalDevices(Type iType);
/** @copydoc FactoryCreator::freeDevices */
int freeDevices(Type iType);
/** @copydoc FactoryCreator::vendorExist */
bool vendorExist(Type iType, const std::string & vendor);
/** @copydoc FactoryCreator::createObject */
Object* createObject(InputManager *creator, Type iType, bool bufferMode, const std::string & vendor = "");
/** @copydoc FactoryCreator::destroyObject */
void destroyObject(Object* obj);
//Internal Items
//! Method for retrieving the XWindow Handle
Window _getWindow() {return window;}
//! Internal method for checking if regrabbing is needed
void _setGrabState(bool grab) {mGrabs = grab;}
bool _getGrabState() {return mGrabs;}
//! Internal method, used for flaggin keyboard as available/unavailable for creation
void _setKeyboardUsed(bool used) {keyboardUsed = used; }
//! Internal method, used for flaggin mouse as available/unavailable for creation
void _setMouseUsed(bool used) { mouseUsed = used; }
protected:
//! internal class method for dealing with param list
void _parseConfigSettings( ParamList &paramList );
//! internal class method for finding attached devices
void _enumerateDevices();
//! List of unused joysticks ready to be used
JoyStickInfoList unusedJoyStickList;
//! Number of joysticks found
char joySticks;
//! Used to know if we used up keyboard
bool keyboardUsed;
//! Used to know if we used up mouse
bool mouseUsed;
//! X11 Stuff
Window window;
/// Keyboard, Mouse Settings
bool grabMouse, grabKeyboard;
bool mGrabs;
bool hideMouse;
//! By default, keyboard disables XRepeatRate
bool useXRepeat;
};
}
#endif
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _LINUX_JOYSTICK_H_EADER_
#define _LINUX_JOYSTICK_H_EADER_
#include "linux/LinuxPrereqs.h"
#include "OISJoyStick.h"
namespace OIS
{
/**
Linux specialization of JoyStick class.. This version is favored over the other.. and has the
*possibility* of Force Feedback.. notice I say possibility, i make no gaurantees under linux,
as FF support is sketchy at best AFAIK.
*/
class LinuxJoyStick : public JoyStick
{
public:
LinuxJoyStick(InputManager* creator, bool buffered, const JoyStickInfo& js);
virtual ~LinuxJoyStick();
/** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */
virtual void capture();
/** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type);
/** @copydoc Object::_initialize */
virtual void _initialize();
/**
@remarks
For internal use only... Returns a structure to the manager, to make the device
availiable for use again
*/
JoyStickInfo _getJoyInfo();
static JoyStickInfoList _scanJoys();
static void _clearJoys(JoyStickInfoList &joys);
protected:
int mJoyStick;
LinuxForceFeedback* ff_effect;
std::map <int, int> mButtonMap;
std::map <int, int> mAxisMap;
std::map <int, Range> mRanges;
};
}
#endif //_LINUX_JOYSTICK_H_EADER_
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _LINUX_KEYBOARD_H_EADER_
#define _LINUX_KEYBOARD_H_EADER_
#include "linux/LinuxPrereqs.h"
#include "OISKeyboard.h"
#include <X11/Xlib.h>
namespace OIS
{
/** Linux implementation of Keyboard object - uses x11 */
class LinuxKeyboard : public Keyboard
{
public:
LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat );
virtual ~LinuxKeyboard();
/** @copydoc Keyboard::isKeyDown */
virtual bool isKeyDown( KeyCode key ) const;
/** @copydoc Keyboard::getAsString */
virtual const std::string& getAsString( KeyCode kc );
/** @copydoc Keyboard::copyKeyStates */
virtual void copyKeyStates( char keys[256] ) const;
/** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */
virtual void capture();
/** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType) {return 0;}
/** @copydoc Object::_initialize */
virtual void _initialize();
protected:
bool _injectKeyDown( KeySym key, int text );
bool _injectKeyUp( KeySym key );
//! 1:1 Conversion Map between X Key Events and OIS KeyCodes
typedef std::map<KeySym, KeyCode> XtoOIS_KeyMap;
XtoOIS_KeyMap keyConversion;
//! Depressed Key List
char KeyBuffer[256];
//! X11 Stuff
Window window;
Display *display;
bool grabKeyboard;
bool keyFocusLost;
bool xAutoRepeat;
bool oldXAutoRepeat;
std::string mGetString;
};
}
#endif //_LINUX_KEYBOARD_H_EADER_
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _LINUX_MOUSE_H_EADER_
#define _LINUX_MOUSE_H_EADER_
#include "linux/LinuxPrereqs.h"
#include "OISMouse.h"
#include <X11/Xlib.h>
namespace OIS
{
class LinuxMouse : public Mouse
{
public:
LinuxMouse(InputManager* creator, bool buffered, bool grab, bool hide);
virtual ~LinuxMouse();
/** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered);
/**
@remarks
Note: Calling this will also update the keyboard (X11 updates in a single
event queue). Updates State and/or raises event for buffered mode..
*/
virtual void capture();
/** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType) {return 0;}
/** @copydoc Object::_initialize */
virtual void _initialize();
void grab(bool grab);
void hide(bool hide);
protected:
void _processXEvents();
bool mMoved, mWarped;
//Since X11 provides us with absolute values, we need to keep track of relative values
long oldXMouseX, oldXMouseY, oldXMouseZ;
Window window; //The X Window
Display *display; //The X display
Cursor cursor; //A blank cursor
bool grabMouse; //Are we grabbing the mouse to the window?
bool hideMouse; //Are we hiding OS mouse?
bool mouseFocusLost;//Has the mouse just lost focus?
};
}
#endif //_LINUX_MOUSE_H_EADER_
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _LINUX_INPUTSYSTEM_PREREQS_H
#define _LINUX_INPUTSYSTEM_PREREQS_H
//Bring in any auto generated config files
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "OISPrereqs.h"
//! Max number of elements to collect from buffered input
#define JOY_BUFFERSIZE 10
namespace OIS
{
class LinuxInputManager;
class LinuxKeyboard;
class LinuxJoyStick;
class LinuxMouse;
class LinuxForceFeedback;
class Range
{
public:
Range() {};
Range(int _min, int _max) : min(_min), max(_max) {};
int min, max;
};
class JoyStickInfo
{
public:
JoyStickInfo(): devId(-1),joyFileD(-1),version(0),axes(0),buttons(0),hats(0) {}
//! Device number (/dev/input/j#) or /dev/input/event#
int devId;
//! File descriptor
int joyFileD;
//! Driver version
int version;
//! Joy vendor
std::string vendor;
//! Number of axes
unsigned char axes;
//! Number of buttons
unsigned char buttons;
//! Number of hats
unsigned char hats;
//! Maps Linux button values to OIS buttons values
std::map<int, int> button_map;
//! Maps Linux axis values to OIS axis
std::map<int, int> axis_map;
//! Maps OIS axis values to it's range
std::map<int, Range> axis_range;
};
typedef std::vector< JoyStickInfo > JoyStickInfoList;
}
#endif //_LINUX_INPUTSYSTEM_PREREQS_H
/*
The zlib/libpng License
Copyright (c) 2007 Phillip
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_MacHIDManager_Header
#define OIS_MacHIDManager_Header
#include "OISPrereqs.h"
#include "mac/MacPrereqs.h"
#include "OISFactoryCreator.h"
#import <CoreFoundation/CFString.h>
#import <IOKit/IOKitLib.h>
#import <IOKit/IOCFPlugIn.h>
#import <IOKit/hid/IOHIDLib.h>
#import <IOKit/hid/IOHIDKeys.h>
#import <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
namespace OIS
{
//Information needed to create Mac HID Devices
class HidInfo
{
public:
HidInfo() : type(OISUnknown), numButtons(0), numHats(0), numAxes(0), inUse(false), interface(0)
{
}
//Useful tracking information
Type type;
std::string vendor;
std::string productKey;
std::string combinedKey;
//Retain some count information for recreating devices without having to reparse
int numButtons;
int numHats;
int numAxes;
bool inUse;
//Used for opening a read/write/tracking interface to device
IOHIDDeviceInterface **interface;
};
typedef std::vector<HidInfo*> HidInfoList;
class MacHIDManager : public FactoryCreator
{
public:
MacHIDManager();
~MacHIDManager();
void initialize();
void iterateAndOpenDevices(io_iterator_t iterator);
io_iterator_t lookUpDevices(int usage, int page);
//FactoryCreator Overrides
/** @copydoc FactoryCreator::deviceList */
DeviceList freeDeviceList();
/** @copydoc FactoryCreator::totalDevices */
int totalDevices(Type iType);
/** @copydoc FactoryCreator::freeDevices */
int freeDevices(Type iType);
/** @copydoc FactoryCreator::vendorExist */
bool vendorExist(Type iType, const std::string & vendor);
/** @copydoc FactoryCreator::createObject */
Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = "");
/** @copydoc FactoryCreator::destroyObject */
void destroyObject(Object* obj);
private:
HidInfo* enumerateDeviceProperties(CFMutableDictionaryRef propertyMap);
void parseDeviceProperties(CFDictionaryRef properties);
void parseDevicePropertiesGroup(CFDictionaryRef properties);
HidInfoList mDeviceList;
};
}
#endif
/*
The zlib/libpng License
Copyright (c) 2006 Chris Snyder
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_MacHelpers_H
#define OIS_MacHelpers_H
#include "mac/MacPrereqs.h"
#include "OISEvents.h"
#include "OISKeyboard.h"
#include "OISMouse.h"
#include <Carbon/Carbon.h>
// This is a hack needed to get the event handler working.
// The carbon lib expects a "OSStatus (*)(EventHandlerCallRef, EventRef, void*)",
// so I cannot give it a class member function (unless it is static which is pointless)
// Instead, I just pass the class* through the last paramter that gets passed to the
// callback every time an event occurs. Then I dereference it and call the member function.
OSStatus KeyDownWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass );
OSStatus KeyUpWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass );
OSStatus KeyModWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass );
OSStatus MouseWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass );
// This is needed for keeping an event stack for keyboard and mouse
namespace OIS
{
// used in the eventStack to store the type
enum Mac_EventType { MAC_KEYUP = 0,
MAC_KEYDOWN = 1,
MAC_KEYREPEAT,
MAC_MOUSEDOWN,
MAC_MOUSEUP,
MAC_MOUSEMOVED,
MAC_MOUSESCROLL};
typedef enum Mac_EventType MacEventType;
// only used by MacKeyboard
typedef class Mac_KeyStackEvent
{
friend class MacKeyboard;
private:
Mac_KeyStackEvent( KeyEvent event, MacEventType type ) : Event(event), Type(type) {}
MacEventType Type;
KeyEvent Event;
} MacKeyStackEvent;
// only used by MacMouse
typedef class Mac_MouseStackEvent
{
friend class MacMouse;
private:
Mac_MouseStackEvent( MouseEvent event, MacEventType type, MouseButtonID button) : Event(event), Type(type), Button(button) {}
MacEventType Type;
MouseEvent Event;
MouseButtonID Button;
} MacMouseStackEvent;
}
#endif
/*
The zlib/libpng License
Copyright (c) 2006 Chris Snyder
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_MacInputManager_H
#define OIS_MacInputManager_H
#include "OISInputManager.h"
#include "OISFactoryCreator.h"
#include "mac/MacPrereqs.h"
#include <Carbon/Carbon.h>
namespace OIS
{
class MacInputManager : public InputManager, public FactoryCreator
{
public:
MacInputManager();
virtual ~MacInputManager();
//InputManager Overrides
/** @copydoc InputManager::_initialize */
void _initialize( ParamList &paramList );
//FactoryCreator Overrides
/** @copydoc FactoryCreator::deviceList */
DeviceList freeDeviceList();
/** @copydoc FactoryCreator::totalDevices */
int totalDevices(Type iType);
/** @copydoc FactoryCreator::freeDevices */
int freeDevices(Type iType);
/** @copydoc FactoryCreator::vendorExist */
bool vendorExist(Type iType, const std::string & vendor);
/** @copydoc FactoryCreator::createObject */
Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = "");
/** @copydoc FactoryCreator::destroyObject */
void destroyObject(Object* obj);
//Internal Items
//! Internal method, used for flaggin keyboard as available/unavailable for creation
void _setKeyboardUsed(bool used) {keyboardUsed = used; }
//! Internal method, used for flaggin mouse as available/unavailable for creation
void _setMouseUsed(bool used) { mouseUsed = used; }
//! methodfor getting the event target
EventTargetRef _getEventTarget() {return mEventTargetRef;}
//! method for getting window
WindowRef _getWindow() {return mWindow;}
protected:
void _parseConfigSettings( ParamList& paramList );
void _enumerateDevices();
static const std::string iName;
// Mac stuff
EventTargetRef mEventTargetRef;
WindowRef mWindow;
// settings
bool mHideMouse;
bool mUseRepeat;
//! Used to know if we used up keyboard
bool keyboardUsed;
//! Used to know if we used up mouse
bool mouseUsed;
//! HID Manager class handling devices other than keyboard/mouse
MacHIDManager *mHIDManager;
};
}
#endif
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef MAC_Joystick_H
#define MAC_Joystick_H
#include "OISJoyStick.h"
#include "mac/MacPrereqs.h"
#include "mac/MacHIDManager.h"
namespace OIS
{
typedef struct cookie_struct
{
std::vector<IOHIDElementCookie> axisCookies;
std::vector<IOHIDElementCookie> buttonCookies;
} cookie_struct_t;
//class HidDeviceInfo
class MacJoyStick : public JoyStick
{
public:
MacJoyStick(const std::string& vendor, bool buffered, HidInfo* info, InputManager* creator);
virtual ~MacJoyStick();
/** @copydoc Object::setBuffered */
virtual void setBuffered(bool buffered);
/** @copydoc Object::capture */
virtual void capture();
/** @copydoc Object::queryInterface */
virtual Interface* queryInterface(Interface::IType type);
/** @copydoc Object::_initialize */
virtual void _initialize();
void _enumerateCookies();
IOHIDQueueInterface** _createQueue(unsigned int depth = 8);
protected:
HidInfo* mInfo;
cookie_struct_t mCookies;
IOHIDQueueInterface** mQueue;
};
}
#endif
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