Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fengzch-das
OIS
Commits
24236447
Commit
24236447
authored
Sep 17, 2015
by
TheOnlyJoey
Browse files
Merge pull request #5 from hymerman/tidying
General tidy-up
parents
c546989f
ed6e1ba6
Changes
136
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
2135 additions
and
2142 deletions
+2135
-2142
includes/mac/MacJoyStick.h
includes/mac/MacJoyStick.h
+76
-76
includes/mac/MacKeyboard.h
includes/mac/MacKeyboard.h
+102
-102
includes/mac/MacMouse.h
includes/mac/MacMouse.h
+51
-51
includes/mac/MacPrereqs.h
includes/mac/MacPrereqs.h
+57
-57
includes/win32/Win32ForceFeedback.h
includes/win32/Win32ForceFeedback.h
+108
-108
includes/win32/Win32InputManager.h
includes/win32/Win32InputManager.h
+113
-113
includes/win32/Win32JoyStick.h
includes/win32/Win32JoyStick.h
+88
-88
includes/win32/Win32KeyBoard.h
includes/win32/Win32KeyBoard.h
+87
-87
includes/win32/Win32Mouse.h
includes/win32/Win32Mouse.h
+59
-59
includes/win32/Win32Prereqs.h
includes/win32/Win32Prereqs.h
+71
-71
src/OISEffect.cpp
src/OISEffect.cpp
+119
-128
src/OISException.cpp
src/OISException.cpp
+32
-32
src/OISForceFeedback.cpp
src/OISForceFeedback.cpp
+74
-74
src/OISInputManager.cpp
src/OISInputManager.cpp
+292
-290
src/OISJoyStick.cpp
src/OISJoyStick.cpp
+73
-73
src/OISKeyboard.cpp
src/OISKeyboard.cpp
+45
-45
src/OISObject.cpp
src/OISObject.cpp
+23
-23
src/SDL/SDLInputManager.cpp
src/SDL/SDLInputManager.cpp
+114
-114
src/SDL/SDLKeyboard.cpp
src/SDL/SDLKeyboard.cpp
+377
-377
src/SDL/SDLMouse.cpp
src/SDL/SDLMouse.cpp
+174
-174
No files found.
includes/mac/MacJoyStick.h
View file @
24236447
/*
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
{
struct
AxisInfo
{
int
min
;
int
max
;
AxisInfo
(
int
min
,
int
max
)
:
min
(
min
),
max
(
max
)
{}
};
typedef
struct
cookie_struct
{
std
::
map
<
IOHIDElementCookie
,
AxisInfo
>
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
,
int
devID
);
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
/*
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
{
struct
AxisInfo
{
int
min
;
int
max
;
AxisInfo
(
int
min
,
int
max
)
:
min
(
min
),
max
(
max
)
{}
};
typedef
struct
cookie_struct
{
std
::
map
<
IOHIDElementCookie
,
AxisInfo
>
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
,
int
devID
);
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
includes/mac/MacKeyboard.h
View file @
24236447
/*
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_MacKeyboard_H
#define OIS_MacKeyboard_H
#include "OISKeyboard.h"
#include "mac/MacHelpers.h"
#include "mac/MacPrereqs.h"
#include <Carbon/Carbon.h>
namespace
OIS
{
class
MacKeyboard
:
public
Keyboard
{
public:
MacKeyboard
(
InputManager
*
creator
,
bool
buffered
,
bool
repeat
);
virtual
~
MacKeyboard
();
// Sets buffered mode
virtual
void
setBuffered
(
bool
buffered
);
// unbuffered keydown check
virtual
bool
isKeyDown
(
KeyCode
key
)
const
;
// This will send listener events if buffered is on.
// Note that in the mac implementation, unbuffered input is
// automatically updated without calling this.
virtual
void
capture
();
// Copies the current key buffer
virtual
void
copyKeyStates
(
char
keys
[
256
]
)
const
;
// Returns a description of the given key
virtual
std
::
string
&
getAsString
(
KeyCode
key
);
virtual
Interface
*
queryInterface
(
Interface
::
IType
type
)
{
return
0
;
}
// Public but reserved for internal use:
virtual
void
_initialize
();
void
_keyDownCallback
(
EventRef
theEvent
);
void
_keyUpCallback
(
EventRef
theEvent
);
void
_modChangeCallback
(
EventRef
theEvent
);
protected:
// 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
);
typedef
std
::
map
<
UInt32
,
KeyCode
>
VirtualtoOIS_KeyMap
;
VirtualtoOIS_KeyMap
keyConversion
;
std
::
string
getString
;
char
KeyBuffer
[
256
];
UInt32
prevModMask
;
// "universal procedure pointers" - required reference for callbacks
EventHandlerUPP
keyDownUPP
;
EventHandlerUPP
keyUpUPP
;
EventHandlerUPP
keyModUPP
;
// so we can delete the handlers on destruction
EventHandlerRef
keyDownEventRef
;
EventHandlerRef
keyUpEventRef
;
EventHandlerRef
keyModEventRef
;
// buffered events, fifo stack
typedef
std
::
list
<
MacKeyStackEvent
>
eventStack
;
eventStack
pendingEvents
;
bool
useRepeat
;
};
}
#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_MacKeyboard_H
#define OIS_MacKeyboard_H
#include "OISKeyboard.h"
#include "mac/MacHelpers.h"
#include "mac/MacPrereqs.h"
#include <Carbon/Carbon.h>
namespace
OIS
{
class
MacKeyboard
:
public
Keyboard
{
public:
MacKeyboard
(
InputManager
*
creator
,
bool
buffered
,
bool
repeat
);
virtual
~
MacKeyboard
();
// Sets buffered mode
virtual
void
setBuffered
(
bool
buffered
);
// unbuffered keydown check
virtual
bool
isKeyDown
(
KeyCode
key
)
const
;
// This will send listener events if buffered is on.
// Note that in the mac implementation, unbuffered input is
// automatically updated without calling this.
virtual
void
capture
();
// Copies the current key buffer
virtual
void
copyKeyStates
(
char
keys
[
256
]
)
const
;
// Returns a description of the given key
virtual
std
::
string
&
getAsString
(
KeyCode
key
);
virtual
Interface
*
queryInterface
(
Interface
::
IType
type
)
{
return
0
;
}
// Public but reserved for internal use:
virtual
void
_initialize
();
void
_keyDownCallback
(
EventRef
theEvent
);
void
_keyUpCallback
(
EventRef
theEvent
);
void
_modChangeCallback
(
EventRef
theEvent
);
protected:
// 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
);
typedef
std
::
map
<
UInt32
,
KeyCode
>
VirtualtoOIS_KeyMap
;
VirtualtoOIS_KeyMap
keyConversion
;
std
::
string
getString
;
char
KeyBuffer
[
256
];
UInt32
prevModMask
;
// "universal procedure pointers" - required reference for callbacks
EventHandlerUPP
keyDownUPP
;
EventHandlerUPP
keyUpUPP
;
EventHandlerUPP
keyModUPP
;
// so we can delete the handlers on destruction
EventHandlerRef
keyDownEventRef
;
EventHandlerRef
keyUpEventRef
;
EventHandlerRef
keyModEventRef
;
// buffered events, fifo stack
typedef
std
::
list
<
MacKeyStackEvent
>
eventStack
;
eventStack
pendingEvents
;
bool
useRepeat
;
};
}
#endif
includes/mac/MacMouse.h
View file @
24236447
#ifndef OIS_MacMouse_H
#define OIS_MacMouse_H
#include "OISMouse.h"
#include "mac/MacHelpers.h"
#include "mac/MacPrereqs.h"
#include <Carbon/Carbon.h>
namespace
OIS
{
class
MacMouse
:
public
Mouse
{
public:
MacMouse
(
InputManager
*
creator
,
bool
buffered
);
virtual
~
MacMouse
();
/** @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
();
public:
void
_mouseCallback
(
EventRef
theEvent
);
protected:
static
OSStatus
WindowFocusChanged
(
EventHandlerCallRef
nextHandler
,
EventRef
event
,
void
*
macMouse
);
// "universal procedure pointers" - required reference for callbacks
EventHandlerUPP
mouseUPP
;
EventHandlerRef
mouseEventRef
;
EventHandlerUPP
mWindowFocusListener
;
EventHandlerRef
mWindowFocusHandler
;
bool
mNeedsToRegainFocus
;
bool
mMouseWarped
;
MouseState
mTempState
;
};
}
#endif // OIS_MacMouse_H
#ifndef OIS_MacMouse_H
#define OIS_MacMouse_H
#include "OISMouse.h"
#include "mac/MacHelpers.h"
#include "mac/MacPrereqs.h"
#include <Carbon/Carbon.h>
namespace
OIS
{
class
MacMouse
:
public
Mouse
{
public:
MacMouse
(
InputManager
*
creator
,
bool
buffered
);
virtual
~
MacMouse
();
/** @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
();
public:
void
_mouseCallback
(
EventRef
theEvent
);
protected:
static
OSStatus
WindowFocusChanged
(
EventHandlerCallRef
nextHandler
,
EventRef
event
,
void
*
macMouse
);
// "universal procedure pointers" - required reference for callbacks
EventHandlerUPP
mouseUPP
;
EventHandlerRef
mouseEventRef
;
EventHandlerUPP
mWindowFocusListener
;
EventHandlerRef
mWindowFocusHandler
;
bool
mNeedsToRegainFocus
;
bool
mMouseWarped
;
MouseState
mTempState
;
};
}
#endif // OIS_MacMouse_H
includes/mac/MacPrereqs.h
View file @
24236447
/*
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_MacPrereqs_H
#define OIS_MacPrereqs_H
#include <string>
#include <list>
#include <CoreFoundation/CoreFoundation.h>
namespace
OIS
{
class
MacInputManager
;
class
MacHIDManager
;
class
MacMouse
;
class
MacKeyboard
;
/**
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) 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_MacPrereqs_H
#define OIS_MacPrereqs_H
#include <string>
#include <list>
#include <CoreFoundation/CoreFoundation.h>
namespace
OIS
{
class
MacInputManager
;
class
MacHIDManager
;
class
MacMouse
;
class
MacKeyboard
;
/**
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
includes/win32/Win32ForceFeedback.h
View file @
24236447
/*
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_Win32ForceFeedBack_H
#define OIS_Win32ForceFeedBack_H
#include "OISPrereqs.h"
#include "OISForceFeedback.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
class
Win32ForceFeedback
:
public
ForceFeedback
{
Win32ForceFeedback
()
{}
public:
Win32ForceFeedback
(
IDirectInputDevice8
*
pDIJoy
,
const
DIDEVCAPS
*
pDIJoyCaps
);
~
Win32ForceFeedback
();
/** @copydoc ForceFeedback::upload */
void
upload
(
const
Effect
*
effect
);
/** @copydoc ForceFeedback::modify */
void
modify
(
const
Effect
*
effect
);
/** @copydoc ForceFeedback::remove */
void
remove
(
const
Effect
*
effect
);
/** @copydoc ForceFeedback::setMasterGain */
void
setMasterGain
(
float
level
);
/** @copydoc ForceFeedback::setAutoCenterMode */
void
setAutoCenterMode
(
bool
auto_on
);
/** @copydoc ForceFeedback::getFFAxesNumber */
short
getFFAxesNumber
();
/** @copydoc ForceFeedback::getFFMemoryLoad */
unsigned
short
getFFMemoryLoad
();
/**
@remarks
Internal use.. Used during enumeration to build a list of a devices
support effects.
*/
void
_addEffectSupport
(
LPCDIEFFECTINFO
pdei
);
/**
@remarks
Internal use.. Used during axis enumeration to get number of FF axes
support effects.
*/
void
_addFFAxis
();
protected:
//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
);
//Sets the common properties to all effects
void
_setCommonProperties
(
DIEFFECT
*
diEffect
,
DWORD
*
rgdwAxes
,
LONG
*
rglDirection
,
DIENVELOPE
*
diEnvelope
,
DWORD
struct_size
,
LPVOID
struct_type
,
const
Effect
*
effect
,
const
Envelope
*
envelope
);
//Actually do the upload
void
_upload
(
GUID
,
DIEFFECT
*
,
const
Effect
*
);
// Map of currently uploaded effects (handle => effect)
typedef
std
::
map
<
int
,
LPDIRECTINPUTEFFECT
>
EffectList
;
EffectList
mEffectList
;
//Simple unique handle creation - allows for upto 2+ billion effects
//during the lifetime of application. Hopefully, that is enough.
int
mHandles
;
// Joystick device descriptor.
IDirectInputDevice8
*
mJoyStick
;
// Joystick capabilities.
const
DIDEVCAPS
*
mpDIJoyCaps
;
// Number of axis supporting FF.
short
mFFAxes
;
};
}
#endif //OIS_Win32ForceFeedBack_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_Win32ForceFeedBack_H
#define OIS_Win32ForceFeedBack_H
#include "OISPrereqs.h"
#include "OISForceFeedback.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
class
Win32ForceFeedback
:
public
ForceFeedback
{
Win32ForceFeedback
()
{}
public:
Win32ForceFeedback
(
IDirectInputDevice8
*
pDIJoy
,
const
DIDEVCAPS
*
pDIJoyCaps
);
~
Win32ForceFeedback
();
/** @copydoc ForceFeedback::upload */
void
upload
(
const
Effect
*
effect
);
/** @copydoc ForceFeedback::modify */
void
modify
(
const
Effect
*
effect
);
/** @copydoc ForceFeedback::remove */
void
remove
(
const
Effect
*
effect
);
/** @copydoc ForceFeedback::setMasterGain */
void
setMasterGain
(
float
level
);
/** @copydoc ForceFeedback::setAutoCenterMode */
void
setAutoCenterMode
(
bool
auto_on
);
/** @copydoc ForceFeedback::getFFAxesNumber */
short
getFFAxesNumber
();
/** @copydoc ForceFeedback::getFFMemoryLoad */
unsigned
short
getFFMemoryLoad
();
/**
@remarks
Internal use.. Used during enumeration to build a list of a devices
support effects.
*/
void
_addEffectSupport
(
LPCDIEFFECTINFO
pdei
);
/**
@remarks
Internal use.. Used during axis enumeration to get number of FF axes
support effects.
*/
void
_addFFAxis
();
protected:
//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
);
//Sets the common properties to all effects
void
_setCommonProperties
(
DIEFFECT
*
diEffect
,
DWORD
*
rgdwAxes
,
LONG
*
rglDirection
,
DIENVELOPE
*
diEnvelope
,
DWORD
struct_size
,
LPVOID
struct_type
,
const
Effect
*
effect
,
const
Envelope
*
envelope
);
//Actually do the upload
void
_upload
(
GUID
,
DIEFFECT
*
,
const
Effect
*
);
// Map of currently uploaded effects (handle => effect)
typedef
std
::
map
<
int
,
LPDIRECTINPUTEFFECT
>
EffectList
;
EffectList
mEffectList
;
//Simple unique handle creation - allows for upto 2+ billion effects
//during the lifetime of application. Hopefully, that is enough.
int
mHandles
;
// Joystick device descriptor.
IDirectInputDevice8
*
mJoyStick
;
// Joystick capabilities.
const
DIDEVCAPS
*
mpDIJoyCaps
;
// Number of axis supporting FF.
short
mFFAxes
;
};
}
#endif //OIS_Win32ForceFeedBack_H
includes/win32/Win32InputManager.h
View file @
24236447
/*
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_Win32InputManager_H
#define OIS_Win32InputManager_H
#include "OISInputManager.h"
#include "OISFactoryCreator.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
/** Win32InputManager specialization - Using DirectInput8 */
class
Win32InputManager
:
public
InputManager
,
public
FactoryCreator
{
public:
Win32InputManager
();
virtual
~
Win32InputManager
();
//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
;
}
//! Internal method, return unused joystick to queue
void
_returnJoyStick
(
const
JoyStickInfo
&
joystick
);
//! Returns HWND needed by DirectInput Device Object
HWND
getWindowHandle
()
{
return
hWnd
;
}
protected:
//! internal class method for dealing with param list
void
_parseConfigSettings
(
ParamList
&
paramList
);
//! internal class method for finding attached devices
void
_enumerateDevices
();
//! Used during device enumeration
static
BOOL
CALLBACK
_DIEnumDevCallback
(
LPCDIDEVICEINSTANCE
lpddi
,
LPVOID
pvRef
);
//! Keep a list of all joysticks enumerated, but not in use
JoyStickInfoList
unusedJoyStickList
;
//! The window handle we are using
HWND
hWnd
;
//! Direct Input Interface
IDirectInput8
*
mDirectInput
;
//! Used for keyboard device settings
DWORD
kbSettings
;
//! Used for mouse device settings
DWORD
mouseSettings
;
//! Used for joystick device settings
DWORD
joySettings
;
//! Number of total joysticks (inuse or not)
char
joySticks
;
//! Used to know if we used up keyboard
bool
keyboardUsed
;
//! Used to know if we used up mouse
bool
mouseUsed
;
};
}
#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_Win32InputManager_H
#define OIS_Win32InputManager_H
#include "OISInputManager.h"
#include "OISFactoryCreator.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
/** Win32InputManager specialization - Using DirectInput8 */
class
Win32InputManager
:
public
InputManager
,
public
FactoryCreator
{
public:
Win32InputManager
();
virtual
~
Win32InputManager
();
//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
;
}
//! Internal method, return unused joystick to queue
void
_returnJoyStick
(
const
JoyStickInfo
&
joystick
);
//! Returns HWND needed by DirectInput Device Object
HWND
getWindowHandle
()
{
return
hWnd
;
}
protected:
//! internal class method for dealing with param list
void
_parseConfigSettings
(
ParamList
&
paramList
);
//! internal class method for finding attached devices
void
_enumerateDevices
();
//! Used during device enumeration
static
BOOL
CALLBACK
_DIEnumDevCallback
(
LPCDIDEVICEINSTANCE
lpddi
,
LPVOID
pvRef
);
//! Keep a list of all joysticks enumerated, but not in use
JoyStickInfoList
unusedJoyStickList
;
//! The window handle we are using
HWND
hWnd
;
//! Direct Input Interface
IDirectInput8
*
mDirectInput
;
//! Used for keyboard device settings
DWORD
kbSettings
;
//! Used for mouse device settings
DWORD
mouseSettings
;
//! Used for joystick device settings
DWORD
joySettings
;
//! Number of total joysticks (inuse or not)
char
joySticks
;
//! Used to know if we used up keyboard
bool
keyboardUsed
;
//! Used to know if we used up mouse
bool
mouseUsed
;
};
}
#endif
includes/win32/Win32JoyStick.h
View file @
24236447
/*
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 _WIN32_JOYSTICK_H_EADER_
#define _WIN32_JOYSTICK_H_EADER_
#include "OISJoyStick.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
class
Win32JoyStick
:
public
JoyStick
{
public:
Win32JoyStick
(
InputManager
*
creator
,
IDirectInput8
*
pDI
,
bool
buffered
,
DWORD
coopSettings
,
const
JoyStickInfo
&
info
);
virtual
~
Win32JoyStick
();
/** @copydoc Object::setBuffered */
virtual
void
setBuffered
(
bool
buffered
);
/** @copydoc Object::capture */
virtual
void
capture
();
//! hanlde xinput
void
captureXInput
();
/** @copydoc Object::queryInterface */
virtual
Interface
*
queryInterface
(
Interface
::
IType
type
);
/** @copydoc Object::_initialize */
virtual
void
_initialize
();
#ifdef OIS_WIN32_XINPUT_SUPPORT
/**
@remarks
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
Unfortunately this information can not be found by just using DirectInput
*/
static
void
CheckXInputDevices
(
JoyStickInfoList
&
joys
);
#endif
protected:
//! Enumerates all things
void
_enumerate
();
//! Enumerate axis callback
static
BOOL
CALLBACK
DIEnumDeviceObjectsCallback
(
LPCDIDEVICEOBJECTINSTANCE
lpddoi
,
LPVOID
pvRef
);
//! Enumerate Force Feedback callback
static
BOOL
CALLBACK
DIEnumEffectsCallback
(
LPCDIEFFECTINFO
pdei
,
LPVOID
pvRef
);
bool
_doButtonClick
(
int
button
,
DIDEVICEOBJECTDATA
&
di
);
bool
_changePOV
(
int
pov
,
DIDEVICEOBJECTDATA
&
di
);
IDirectInput8
*
mDirectInput
;
IDirectInputDevice8
*
mJoyStick
;
DIDEVCAPS
mDIJoyCaps
;
DWORD
coopSetting
;
JoyStickInfo
mJoyInfo
;
//! A force feedback device
Win32ForceFeedback
*
mFfDevice
;
//! Mapping
int
_AxisNumber
;
};
}
#endif //_WIN32_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 _WIN32_JOYSTICK_H_EADER_
#define _WIN32_JOYSTICK_H_EADER_
#include "OISJoyStick.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
class
Win32JoyStick
:
public
JoyStick
{
public:
Win32JoyStick
(
InputManager
*
creator
,
IDirectInput8
*
pDI
,
bool
buffered
,
DWORD
coopSettings
,
const
JoyStickInfo
&
info
);
virtual
~
Win32JoyStick
();
/** @copydoc Object::setBuffered */
virtual
void
setBuffered
(
bool
buffered
);
/** @copydoc Object::capture */
virtual
void
capture
();
//! hanlde xinput
void
captureXInput
();
/** @copydoc Object::queryInterface */
virtual
Interface
*
queryInterface
(
Interface
::
IType
type
);
/** @copydoc Object::_initialize */
virtual
void
_initialize
();
#ifdef OIS_WIN32_XINPUT_SUPPORT
/**
@remarks
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
Unfortunately this information can not be found by just using DirectInput
*/
static
void
CheckXInputDevices
(
JoyStickInfoList
&
joys
);
#endif
protected:
//! Enumerates all things
void
_enumerate
();
//! Enumerate axis callback
static
BOOL
CALLBACK
DIEnumDeviceObjectsCallback
(
LPCDIDEVICEOBJECTINSTANCE
lpddoi
,
LPVOID
pvRef
);
//! Enumerate Force Feedback callback
static
BOOL
CALLBACK
DIEnumEffectsCallback
(
LPCDIEFFECTINFO
pdei
,
LPVOID
pvRef
);
bool
_doButtonClick
(
int
button
,
DIDEVICEOBJECTDATA
&
di
);
bool
_changePOV
(
int
pov
,
DIDEVICEOBJECTDATA
&
di
);
IDirectInput8
*
mDirectInput
;
IDirectInputDevice8
*
mJoyStick
;
DIDEVCAPS
mDIJoyCaps
;
DWORD
coopSetting
;
JoyStickInfo
mJoyInfo
;
//! A force feedback device
Win32ForceFeedback
*
mFfDevice
;
//! Mapping
int
_AxisNumber
;
};
}
#endif //_WIN32_JOYSTICK_H_EADER_
includes/win32/Win32KeyBoard.h
View file @
24236447
/*
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 _WIN32_KEYBOARD_H_EADER_
#define _WIN32_KEYBOARD_H_EADER_
#include "OISKeyboard.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
class
Win32Keyboard
:
public
Keyboard
{
public:
/**
@remarks
Constructor
@param pDI
Valid DirectInput8 Interface
@param buffered
True for buffered input mode
@param coopSettings
A combination of DI Flags (see DX Help for info on input device settings)
*/
Win32Keyboard
(
InputManager
*
creator
,
IDirectInput8
*
pDI
,
bool
buffered
,
DWORD
coopSettings
);
virtual
~
Win32Keyboard
();
/** @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
type
)
{
return
0
;}
/** @copydoc Object::_initialize */
virtual
void
_initialize
();
protected:
void
_readBuffered
();
void
_read
();
IDirectInput8
*
mDirectInput
;
IDirectInputDevice8
*
mKeyboard
;
DWORD
coopSetting
;
unsigned
char
KeyBuffer
[
256
];
//! Internal method for translating KeyCodes to Text
int
_translateText
(
KeyCode
kc
);
//! Stored dead key from last translation
WCHAR
deadKey
;
//! used for getAsString
std
::
string
mGetString
;
};
}
#endif //_WIN32_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 _WIN32_KEYBOARD_H_EADER_
#define _WIN32_KEYBOARD_H_EADER_
#include "OISKeyboard.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
class
Win32Keyboard
:
public
Keyboard
{
public:
/**
@remarks
Constructor
@param pDI
Valid DirectInput8 Interface
@param buffered
True for buffered input mode
@param coopSettings
A combination of DI Flags (see DX Help for info on input device settings)
*/
Win32Keyboard
(
InputManager
*
creator
,
IDirectInput8
*
pDI
,
bool
buffered
,
DWORD
coopSettings
);
virtual
~
Win32Keyboard
();
/** @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
type
)
{
OIS_UNUSED
(
type
);
return
0
;
}
/** @copydoc Object::_initialize */
virtual
void
_initialize
();
protected:
void
_readBuffered
();
void
_read
();
IDirectInput8
*
mDirectInput
;
IDirectInputDevice8
*
mKeyboard
;
DWORD
coopSetting
;
unsigned
char
KeyBuffer
[
256
];
//! Internal method for translating KeyCodes to Text
int
_translateText
(
KeyCode
kc
);
//! Stored dead key from last translation
WCHAR
deadKey
;
//! used for getAsString
std
::
string
mGetString
;
};
}
#endif //_WIN32_KEYBOARD_H_EADER_
includes/win32/Win32Mouse.h
View file @
24236447
/*
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 _WIN32_MOUSE_H_EADER_
#define _WIN32_MOUSE_H_EADER_
#include "OISMouse.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
class
Win32Mouse
:
public
Mouse
{
public:
Win32Mouse
(
InputManager
*
creator
,
IDirectInput8
*
pDI
,
bool
buffered
,
DWORD
coopSettings
);
virtual
~
Win32Mouse
();
/** @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
();
protected:
bool
_doMouseClick
(
int
mouseButton
,
DIDEVICEOBJECTDATA
&
di
);
IDirectInput8
*
mDirectInput
;
IDirectInputDevice8
*
mMouse
;
DWORD
coopSetting
;
HWND
mHwnd
;
};
}
#endif //_WIN32_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 _WIN32_MOUSE_H_EADER_
#define _WIN32_MOUSE_H_EADER_
#include "OISMouse.h"
#include "win32/Win32Prereqs.h"
namespace
OIS
{
class
Win32Mouse
:
public
Mouse
{
public:
Win32Mouse
(
InputManager
*
creator
,
IDirectInput8
*
pDI
,
bool
buffered
,
DWORD
coopSettings
);
virtual
~
Win32Mouse
();
/** @copydoc Object::setBuffered */
virtual
void
setBuffered
(
bool
buffered
);
/** @copydoc Object::capture */
virtual
void
capture
();
/** @copydoc Object::queryInterface */
virtual
Interface
*
queryInterface
(
Interface
::
IType
type
)
{
OIS_UNUSED
(
type
);
return
0
;}
/** @copydoc Object::_initialize */
virtual
void
_initialize
();
protected:
bool
_doMouseClick
(
int
mouseButton
,
DIDEVICEOBJECTDATA
&
di
);
IDirectInput8
*
mDirectInput
;
IDirectInputDevice8
*
mMouse
;
DWORD
coopSetting
;
HWND
mHwnd
;
};
}
#endif //_WIN32_MOUSE_H_EADER_
includes/win32/Win32Prereqs.h
View file @
24236447
/*
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 _WIN32_INPUTSYSTEM_PREREQS_H
#define _WIN32_INPUTSYSTEM_PREREQS_H
#include <cstddef>
#define WIN32_LEAN_AND_MEAN
#define DIRECTINPUT_VERSION 0x0800
#include <windows.h>
#include <dinput.h>
#ifdef OIS_WIN32_XINPUT_SUPPORT
# include <XInput.h>
#endif
//Max number of elements to collect from buffered DirectInput
#define KEYBOARD_DX_BUFFERSIZE 17
#define MOUSE_DX_BUFFERSIZE 128
#define JOYSTICK_DX_BUFFERSIZE 129
//MinGW defines
#if defined(OIS_MINGW_COMPILER)
# undef FIELD_OFFSET
# define FIELD_OFFSET offsetof
#endif
namespace
OIS
{
//Local Forward declarations
class
Win32InputManager
;
class
Win32Keyboard
;
class
Win32JoyStick
;
class
Win32Mouse
;
class
Win32ForceFeedback
;
//Information needed to create DirectInput joysticks
class
JoyStickInfo
{
public:
int
devId
;
GUID
deviceID
;
GUID
productGuid
;
std
::
string
vendor
;
bool
isXInput
;
int
xInputDev
;
};
typedef
std
::
vector
<
JoyStickInfo
>
JoyStickInfoList
;
}
#endif //_WIN32_INPUTSYSTEM_PREREQS_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 _WIN32_INPUTSYSTEM_PREREQS_H
#define _WIN32_INPUTSYSTEM_PREREQS_H
#include <cstddef>
#define WIN32_LEAN_AND_MEAN
#define DIRECTINPUT_VERSION 0x0800
#include <windows.h>
#include <dinput.h>
#ifdef OIS_WIN32_XINPUT_SUPPORT
# include <XInput.h>
#endif
//Max number of elements to collect from buffered DirectInput
#define KEYBOARD_DX_BUFFERSIZE 17
#define MOUSE_DX_BUFFERSIZE 128
#define JOYSTICK_DX_BUFFERSIZE 129
//MinGW defines
#if defined(OIS_MINGW_COMPILER)
# undef FIELD_OFFSET
# define FIELD_OFFSET offsetof
#endif
namespace
OIS
{
//Local Forward declarations
class
Win32InputManager
;
class
Win32Keyboard
;
class
Win32JoyStick
;
class
Win32Mouse
;
class
Win32ForceFeedback
;
//Information needed to create DirectInput joysticks
class
JoyStickInfo
{
public:
int
devId
;
GUID
deviceID
;
GUID
productGuid
;
std
::
string
vendor
;
bool
isXInput
;
int
xInputDev
;
};
typedef
std
::
vector
<
JoyStickInfo
>
JoyStickInfoList
;
}
#endif //_WIN32_INPUTSYSTEM_PREREQS_H
src/OISEffect.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISEffect.h"
#include "OISException.h"
using
namespace
OIS
;
//VC7.1 had a problem with these not getting included..
//Perhaps a case of a crazy extreme optimizer :/ (moved to header)
//const unsigned int Effect::OIS_INFINITE = 0xFFFFFFFF;
//------------------------------------------------------------------------------//
static
const
char
*
pszEForceString
[]
=
{
"UnknownForce"
,
"ConstantForce"
,
"RampForce"
,
"PeriodicForce"
,
"ConditionalForce"
,
"CustomForce"
};
const
char
*
Effect
::
getForceTypeName
(
Effect
::
EForce
eValue
)
{
return
(
eValue
>=
0
&&
eValue
<
_ForcesNumber
)
?
pszEForceString
[
eValue
]
:
"<Bad force type>"
;
}
static
const
char
*
pszETypeString
[]
=
{
"Unknown"
,
"Constant"
,
"Ramp"
,
"Square"
,
"Triangle"
,
"Sine"
,
"SawToothUp"
,
"SawToothDown"
,
"Friction"
,
"Damper"
,
"Inertia"
,
"Spring"
,
"Custom"
};
const
char
*
Effect
::
getEffectTypeName
(
Effect
::
EType
eValue
)
{
return
(
eValue
>=
0
&&
eValue
<
_TypesNumber
)
?
pszETypeString
[
eValue
]
:
"<Bad effect type>"
;
}
static
const
char
*
pszEDirectionString
[]
=
{
"NorthWest"
,
"North"
,
"NorthEast"
,
"East"
,
"SouthEast"
,
"South"
,
"SouthWest"
,
"West"
};
const
char
*
Effect
::
getDirectionName
(
Effect
::
EDirection
eValue
)
{
return
(
eValue
>=
0
&&
eValue
<
_DirectionsNumber
)
?
pszEDirectionString
[
eValue
]
:
"<Bad direction>"
;
}
//------------------------------------------------------------------------------//
Effect
::
Effect
()
:
force
(
UnknownForce
),
type
(
Unknown
),
effect
(
0
),
axes
(
1
)
{
}
//------------------------------------------------------------------------------//
Effect
::
Effect
(
EForce
ef
,
EType
et
)
:
force
(
ef
),
type
(
et
),
direction
(
North
),
trigger_button
(
-
1
),
trigger_interval
(
0
),
replay_length
(
Effect
::
OIS_INFINITE
),
replay_delay
(
0
),
_handle
(
-
1
),
axes
(
1
)
{
effect
=
0
;
switch
(
ef
)
{
case
ConstantForce
:
effect
=
new
ConstantEffect
();
break
;
case
RampForce
:
effect
=
new
RampEffect
();
break
;
case
PeriodicForce
:
effect
=
new
PeriodicEffect
();
break
;
case
ConditionalForce
:
effect
=
new
ConditionalEffect
();
break
;
default:
break
;
}
}
//------------------------------------------------------------------------------//
Effect
::~
Effect
()
{
delete
effect
;
}
//------------------------------------------------------------------------------//
ForceEffect
*
Effect
::
getForceEffect
()
const
{
//If no effect was created in constructor, then we raise an error here
if
(
effect
==
0
)
OIS_EXCEPT
(
E_NotSupported
,
"Requested ForceEffect is null!"
);
return
effect
;
}
//------------------------------------------------------------------------------//
void
Effect
::
setNumAxes
(
short
nAxes
)
{
//Can only be set before a handle was assigned (effect created)
if
(
_handle
!=
-
1
)
axes
=
nAxes
;
}
//------------------------------------------------------------------------------//
short
Effect
::
getNumAxes
()
const
{
return
axes
;
}
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISEffect.h"
#include "OISException.h"
using
namespace
OIS
;
//VC7.1 had a problem with these not getting included..
//Perhaps a case of a crazy extreme optimizer :/ (moved to header)
//const unsigned int Effect::OIS_INFINITE = 0xFFFFFFFF;
//------------------------------------------------------------------------------//
static
const
char
*
pszEForceString
[]
=
{
"UnknownForce"
,
"ConstantForce"
,
"RampForce"
,
"PeriodicForce"
,
"ConditionalForce"
,
"CustomForce"
};
const
char
*
Effect
::
getForceTypeName
(
Effect
::
EForce
eValue
)
{
return
(
eValue
>=
0
&&
eValue
<
_ForcesNumber
)
?
pszEForceString
[
eValue
]
:
"<Bad force type>"
;
}
static
const
char
*
pszETypeString
[]
=
{
"Unknown"
,
"Constant"
,
"Ramp"
,
"Square"
,
"Triangle"
,
"Sine"
,
"SawToothUp"
,
"SawToothDown"
,
"Friction"
,
"Damper"
,
"Inertia"
,
"Spring"
,
"Custom"
};
const
char
*
Effect
::
getEffectTypeName
(
Effect
::
EType
eValue
)
{
return
(
eValue
>=
0
&&
eValue
<
_TypesNumber
)
?
pszETypeString
[
eValue
]
:
"<Bad effect type>"
;
}
static
const
char
*
pszEDirectionString
[]
=
{
"NorthWest"
,
"North"
,
"NorthEast"
,
"East"
,
"SouthEast"
,
"South"
,
"SouthWest"
,
"West"
};
const
char
*
Effect
::
getDirectionName
(
Effect
::
EDirection
eValue
)
{
return
(
eValue
>=
0
&&
eValue
<
_DirectionsNumber
)
?
pszEDirectionString
[
eValue
]
:
"<Bad direction>"
;
}
//------------------------------------------------------------------------------//
Effect
::
Effect
(
EForce
ef
,
EType
et
)
:
force
(
ef
),
type
(
et
),
direction
(
North
),
trigger_button
(
-
1
),
trigger_interval
(
0
),
replay_length
(
Effect
::
OIS_INFINITE
),
replay_delay
(
0
),
_handle
(
-
1
),
axes
(
1
)
{
effect
=
0
;
switch
(
ef
)
{
case
ConstantForce
:
effect
=
new
ConstantEffect
();
break
;
case
RampForce
:
effect
=
new
RampEffect
();
break
;
case
PeriodicForce
:
effect
=
new
PeriodicEffect
();
break
;
case
ConditionalForce
:
effect
=
new
ConditionalEffect
();
break
;
default:
break
;
}
}
//------------------------------------------------------------------------------//
Effect
::~
Effect
()
{
delete
effect
;
}
//------------------------------------------------------------------------------//
ForceEffect
*
Effect
::
getForceEffect
()
const
{
//If no effect was created in constructor, then we raise an error here
if
(
effect
==
0
)
OIS_EXCEPT
(
E_NotSupported
,
"Requested ForceEffect is null!"
);
return
effect
;
}
//------------------------------------------------------------------------------//
void
Effect
::
setNumAxes
(
short
nAxes
)
{
//Can only be set before a handle was assigned (effect created)
if
(
_handle
!=
-
1
)
axes
=
nAxes
;
}
//------------------------------------------------------------------------------//
short
Effect
::
getNumAxes
()
const
{
return
axes
;
}
src/OISException.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISException.h"
using
namespace
OIS
;
//----------------------------------------------------------------------------//
const
char
*
Exception
::
what
()
const
throw
()
{
return
eText
;
}
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISException.h"
using
namespace
OIS
;
//----------------------------------------------------------------------------//
const
char
*
Exception
::
what
()
const
throw
()
{
return
eText
;
}
src/OISForceFeedback.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISForceFeedback.h"
#include "OISException.h"
using
namespace
OIS
;
//-------------------------------------------------------------//
ForceFeedback
::
ForceFeedback
()
:
mSetGainSupport
(
false
),
mSetAutoCenterSupport
(
false
)
{
}
//-------------------------------------------------------------//
void
ForceFeedback
::
_addEffectTypes
(
Effect
::
EForce
force
,
Effect
::
EType
type
)
{
if
(
force
<=
Effect
::
UnknownForce
||
force
>=
Effect
::
_ForcesNumber
||
type
<=
Effect
::
Unknown
||
type
>=
Effect
::
_TypesNumber
)
OIS_EXCEPT
(
E_General
,
"Can't add unknown effect Force/Type to the supported list"
);
mSupportedEffects
.
insert
(
std
::
pair
<
Effect
::
EForce
,
Effect
::
EType
>
(
force
,
type
));
}
//-------------------------------------------------------------//
void
ForceFeedback
::
_setGainSupport
(
bool
on
)
{
mSetGainSupport
=
on
;
}
//-------------------------------------------------------------//
void
ForceFeedback
::
_setAutoCenterSupport
(
bool
on
)
{
mSetAutoCenterSupport
=
on
;
}
//-------------------------------------------------------------//
const
ForceFeedback
::
SupportedEffectList
&
ForceFeedback
::
getSupportedEffects
()
const
{
return
mSupportedEffects
;
}
//-------------------------------------------------------------//
bool
ForceFeedback
::
supportsEffect
(
Effect
::
EForce
force
,
Effect
::
EType
type
)
const
{
const
std
::
pair
<
SupportedEffectList
::
const_iterator
,
SupportedEffectList
::
const_iterator
>
iterRange
=
mSupportedEffects
.
equal_range
(
force
);
SupportedEffectList
::
const_iterator
iter
;
for
(
iter
=
iterRange
.
first
;
iter
!=
iterRange
.
second
;
iter
++
)
{
if
((
*
iter
).
second
==
type
)
return
true
;
}
return
false
;
}
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISForceFeedback.h"
#include "OISException.h"
using
namespace
OIS
;
//-------------------------------------------------------------//
ForceFeedback
::
ForceFeedback
()
:
mSetGainSupport
(
false
),
mSetAutoCenterSupport
(
false
)
{
}
//-------------------------------------------------------------//
void
ForceFeedback
::
_addEffectTypes
(
Effect
::
EForce
force
,
Effect
::
EType
type
)
{
if
(
force
<=
Effect
::
UnknownForce
||
force
>=
Effect
::
_ForcesNumber
||
type
<=
Effect
::
Unknown
||
type
>=
Effect
::
_TypesNumber
)
OIS_EXCEPT
(
E_General
,
"Can't add unknown effect Force/Type to the supported list"
);
mSupportedEffects
.
insert
(
std
::
pair
<
Effect
::
EForce
,
Effect
::
EType
>
(
force
,
type
));
}
//-------------------------------------------------------------//
void
ForceFeedback
::
_setGainSupport
(
bool
on
)
{
mSetGainSupport
=
on
;
}
//-------------------------------------------------------------//
void
ForceFeedback
::
_setAutoCenterSupport
(
bool
on
)
{
mSetAutoCenterSupport
=
on
;
}
//-------------------------------------------------------------//
const
ForceFeedback
::
SupportedEffectList
&
ForceFeedback
::
getSupportedEffects
()
const
{
return
mSupportedEffects
;
}
//-------------------------------------------------------------//
bool
ForceFeedback
::
supportsEffect
(
Effect
::
EForce
force
,
Effect
::
EType
type
)
const
{
const
std
::
pair
<
SupportedEffectList
::
const_iterator
,
SupportedEffectList
::
const_iterator
>
iterRange
=
mSupportedEffects
.
equal_range
(
force
);
SupportedEffectList
::
const_iterator
iter
;
for
(
iter
=
iterRange
.
first
;
iter
!=
iterRange
.
second
;
iter
++
)
{
if
((
*
iter
).
second
==
type
)
return
true
;
}
return
false
;
}
src/OISInputManager.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISInputManager.h"
#include "OISException.h"
#include "OISFactoryCreator.h"
#include "OISObject.h"
#include <sstream>
#include <algorithm>
//Bring in correct Header / InputManager for current build platform
#if defined OIS_SDL_PLATFORM
# include "SDL/SDLInputManager.h"
#elif defined OIS_WIN32_PLATFORM
# include "win32/Win32InputManager.h"
#elif defined OIS_LINUX_PLATFORM
# include "linux/LinuxInputManager.h"
#elif defined OIS_APPLE_PLATFORM
# include "mac/MacInputManager.h"
#elif defined OIS_IPHONE_PLATFORM
# include "iphone/iPhoneInputManager.h"
#elif defined OIS_XBOX_PLATFORM
# include "xbox/XBoxInputManager.h"
#endif
//Bring in extra controls
#if defined OIS_LIRC_SUPPORT
# include "extras/LIRC/OISLIRCFactoryCreator.h"
#endif
#if defined OIS_WIN32_WIIMOTE_SUPPORT
# include "win32/extras/WiiMote/OISWiiMoteFactoryCreator.h"
#endif
using
namespace
OIS
;
//----------------------------------------------------------------------------//
InputManager
::
InputManager
(
const
std
::
string
&
name
)
:
m_VersionName
(
OIS_VERSION_NAME
),
mInputSystemName
(
name
),
m_lircSupport
(
0
),
m_wiiMoteSupport
(
0
)
{
mFactories
.
clear
();
mFactoryObjects
.
clear
();
}
//----------------------------------------------------------------------------//
InputManager
::~
InputManager
()
{
#if defined OIS_LIRC_SUPPORT
delete
m_lircSupport
;
#endif
#if defined OIS_WIN32_WIIMOTE_SUPPORT
delete
m_wiiMoteSupport
;
#endif
}
//----------------------------------------------------------------------------//
unsigned
int
InputManager
::
getVersionNumber
()
{
return
OIS_VERSION
;
}
//----------------------------------------------------------------------------//
const
std
::
string
&
InputManager
::
getVersionName
()
{
return
m_VersionName
;
}
//----------------------------------------------------------------------------//
InputManager
*
InputManager
::
createInputSystem
(
std
::
size_t
windowhandle
)
{
ParamList
pl
;
std
::
ostringstream
wnd
;
wnd
<<
windowhandle
;
pl
.
insert
(
std
::
make_pair
(
std
::
string
(
"WINDOW"
),
wnd
.
str
()
));
return
createInputSystem
(
pl
);
}
//----------------------------------------------------------------------------//
InputManager
*
InputManager
::
createInputSystem
(
ParamList
&
paramList
)
{
InputManager
*
im
=
0
;
#if defined OIS_SDL_PLATFORM
im
=
new
SDLInputManager
();
#elif defined OIS_WIN32_PLATFORM
im
=
new
Win32InputManager
();
#elif defined OIS_XBOX_PLATFORM
im
=
new
XBoxInputManager
();
#elif defined OIS_LINUX_PLATFORM
im
=
new
LinuxInputManager
();
#elif defined OIS_APPLE_PLATFORM
im
=
new
MacInputManager
();
#elif defined OIS_IPHONE_PLATFORM
im
=
new
iPhoneInputManager
();
#else
OIS_EXCEPT
(
E_General
,
"No platform library.. check build platform defines!"
);
#endif
try
{
im
->
_initialize
(
paramList
);
}
catch
(...)
{
delete
im
;
throw
;
//rethrow
}
return
im
;
}
//----------------------------------------------------------------------------//
void
InputManager
::
destroyInputSystem
(
InputManager
*
manager
)
{
if
(
manager
==
0
)
return
;
//Cleanup before deleting...
for
(
FactoryCreatedObject
::
iterator
i
=
manager
->
mFactoryObjects
.
begin
();
i
!=
manager
->
mFactoryObjects
.
end
();
++
i
)
{
i
->
second
->
destroyObject
(
i
->
first
);
}
manager
->
mFactoryObjects
.
clear
();
delete
manager
;
}
//--------------------------------------------------------------------------------//
const
std
::
string
&
InputManager
::
inputSystemName
()
{
return
mInputSystemName
;
}
//--------------------------------------------------------------------------------//
int
InputManager
::
getNumberOfDevices
(
Type
iType
)
{
//Count up all the factories devices
int
factoyObjects
=
0
;
FactoryList
::
iterator
i
=
mFactories
.
begin
(),
e
=
mFactories
.
end
();
for
(
;
i
!=
e
;
++
i
)
factoyObjects
+=
(
*
i
)
->
totalDevices
(
iType
);
return
factoyObjects
;
}
//----------------------------------------------------------------------------//
DeviceList
InputManager
::
listFreeDevices
()
{
DeviceList
list
;
FactoryList
::
iterator
i
=
mFactories
.
begin
(),
e
=
mFactories
.
end
();
for
(
;
i
!=
e
;
++
i
)
{
DeviceList
temp
=
(
*
i
)
->
freeDeviceList
();
list
.
insert
(
temp
.
begin
(),
temp
.
end
());
}
return
list
;
}
//----------------------------------------------------------------------------//
Object
*
InputManager
::
createInputObject
(
Type
iType
,
bool
bufferMode
,
const
std
::
string
&
vendor
)
{
Object
*
obj
=
0
;
FactoryList
::
iterator
i
=
mFactories
.
begin
(),
e
=
mFactories
.
end
();
for
(
;
i
!=
e
;
++
i
)
{
if
(
(
*
i
)
->
freeDevices
(
iType
)
>
0
)
{
if
(
vendor
==
""
||
(
*
i
)
->
vendorExist
(
iType
,
vendor
)
)
{
obj
=
(
*
i
)
->
createObject
(
this
,
iType
,
bufferMode
,
vendor
);
mFactoryObjects
[
obj
]
=
(
*
i
);
break
;
}
}
}
if
(
!
obj
)
OIS_EXCEPT
(
E_InputDeviceNonExistant
,
"No devices match requested type."
);
try
{
//Intialize device
obj
->
_initialize
();
}
catch
(...)
{
//Somekind of error, cleanup and rethrow
destroyInputObject
(
obj
);
throw
;
}
return
obj
;
}
//----------------------------------------------------------------------------//
void
InputManager
::
destroyInputObject
(
Object
*
obj
)
{
if
(
obj
==
0
)
return
;
FactoryCreatedObject
::
iterator
i
=
mFactoryObjects
.
find
(
obj
);
if
(
i
!=
mFactoryObjects
.
end
()
)
{
i
->
second
->
destroyObject
(
obj
);
mFactoryObjects
.
erase
(
i
);
}
else
{
OIS_EXCEPT
(
E_General
,
"Object creator not known."
);
}
}
//----------------------------------------------------------------------------//
void
InputManager
::
addFactoryCreator
(
FactoryCreator
*
factory
)
{
if
(
factory
!=
0
)
mFactories
.
push_back
(
factory
);
}
//----------------------------------------------------------------------------//
void
InputManager
::
removeFactoryCreator
(
FactoryCreator
*
factory
)
{
if
(
factory
!=
0
)
{
//First, destroy all devices created with the factory
for
(
FactoryCreatedObject
::
iterator
i
=
mFactoryObjects
.
begin
();
i
!=
mFactoryObjects
.
end
();
++
i
)
{
if
(
i
->
second
==
factory
)
{
i
->
second
->
destroyObject
(
i
->
first
);
mFactoryObjects
.
erase
(
i
++
);
}
}
//Now, remove the factory itself
FactoryList
::
iterator
fact
=
std
::
find
(
mFactories
.
begin
(),
mFactories
.
end
(),
factory
);
if
(
fact
!=
mFactories
.
end
()
)
mFactories
.
erase
(
fact
);
}
}
//----------------------------------------------------------------------------//
void
InputManager
::
enableAddOnFactory
(
AddOnFactories
factory
)
{
#if defined OIS_LIRC_SUPPORT
if
(
factory
==
AddOn_LIRC
||
factory
==
AddOn_All
)
{
if
(
m_lircSupport
==
0
)
{
m_lircSupport
=
new
LIRCFactoryCreator
();
addFactoryCreator
(
m_lircSupport
);
}
}
#endif
#if defined OIS_WIN32_WIIMOTE_SUPPORT
if
(
factory
==
AddOn_WiiMote
||
factory
==
AddOn_All
)
{
if
(
m_wiiMoteSupport
==
0
)
{
m_wiiMoteSupport
=
new
WiiMoteFactoryCreator
();
addFactoryCreator
(
m_wiiMoteSupport
);
}
}
#endif
}
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISInputManager.h"
#include "OISException.h"
#include "OISFactoryCreator.h"
#include "OISObject.h"
#include <sstream>
#include <algorithm>
//Bring in correct Header / InputManager for current build platform
#if defined OIS_SDL_PLATFORM
# include "SDL/SDLInputManager.h"
#elif defined OIS_WIN32_PLATFORM
# include "win32/Win32InputManager.h"
#elif defined OIS_LINUX_PLATFORM
# include "linux/LinuxInputManager.h"
#elif defined OIS_APPLE_PLATFORM
# include "mac/MacInputManager.h"
#elif defined OIS_IPHONE_PLATFORM
# include "iphone/iPhoneInputManager.h"
#elif defined OIS_XBOX_PLATFORM
# include "xbox/XBoxInputManager.h"
#endif
//Bring in extra controls
#if defined OIS_LIRC_SUPPORT
# include "extras/LIRC/OISLIRCFactoryCreator.h"
#endif
#if defined OIS_WIN32_WIIMOTE_SUPPORT
# include "win32/extras/WiiMote/OISWiiMoteFactoryCreator.h"
#endif
using
namespace
OIS
;
//----------------------------------------------------------------------------//
InputManager
::
InputManager
(
const
std
::
string
&
name
)
:
m_VersionName
(
OIS_VERSION_NAME
),
mInputSystemName
(
name
),
m_lircSupport
(
0
),
m_wiiMoteSupport
(
0
)
{
mFactories
.
clear
();
mFactoryObjects
.
clear
();
}
//----------------------------------------------------------------------------//
InputManager
::~
InputManager
()
{
#if defined OIS_LIRC_SUPPORT
delete
m_lircSupport
;
#endif
#if defined OIS_WIN32_WIIMOTE_SUPPORT
delete
m_wiiMoteSupport
;
#endif
}
//----------------------------------------------------------------------------//
unsigned
int
InputManager
::
getVersionNumber
()
{
return
OIS_VERSION
;
}
//----------------------------------------------------------------------------//
const
std
::
string
&
InputManager
::
getVersionName
()
{
return
m_VersionName
;
}
//----------------------------------------------------------------------------//
InputManager
*
InputManager
::
createInputSystem
(
std
::
size_t
windowhandle
)
{
ParamList
pl
;
std
::
ostringstream
wnd
;
wnd
<<
windowhandle
;
pl
.
insert
(
std
::
make_pair
(
std
::
string
(
"WINDOW"
),
wnd
.
str
()
));
return
createInputSystem
(
pl
);
}
//----------------------------------------------------------------------------//
InputManager
*
InputManager
::
createInputSystem
(
ParamList
&
paramList
)
{
InputManager
*
im
=
0
;
#if defined OIS_SDL_PLATFORM
im
=
new
SDLInputManager
();
#elif defined OIS_WIN32_PLATFORM
im
=
new
Win32InputManager
();
#elif defined OIS_XBOX_PLATFORM
im
=
new
XBoxInputManager
();
#elif defined OIS_LINUX_PLATFORM
im
=
new
LinuxInputManager
();
#elif defined OIS_APPLE_PLATFORM
im
=
new
MacInputManager
();
#elif defined OIS_IPHONE_PLATFORM
im
=
new
iPhoneInputManager
();
#else
OIS_EXCEPT
(
E_General
,
"No platform library.. check build platform defines!"
);
#endif
try
{
im
->
_initialize
(
paramList
);
}
catch
(...)
{
delete
im
;
throw
;
//rethrow
}
return
im
;
}
//----------------------------------------------------------------------------//
void
InputManager
::
destroyInputSystem
(
InputManager
*
manager
)
{
if
(
manager
==
0
)
return
;
//Cleanup before deleting...
for
(
FactoryCreatedObject
::
iterator
i
=
manager
->
mFactoryObjects
.
begin
();
i
!=
manager
->
mFactoryObjects
.
end
();
++
i
)
{
i
->
second
->
destroyObject
(
i
->
first
);
}
manager
->
mFactoryObjects
.
clear
();
delete
manager
;
}
//--------------------------------------------------------------------------------//
const
std
::
string
&
InputManager
::
inputSystemName
()
{
return
mInputSystemName
;
}
//--------------------------------------------------------------------------------//
int
InputManager
::
getNumberOfDevices
(
Type
iType
)
{
//Count up all the factories devices
int
factoyObjects
=
0
;
FactoryList
::
iterator
i
=
mFactories
.
begin
(),
e
=
mFactories
.
end
();
for
(
;
i
!=
e
;
++
i
)
factoyObjects
+=
(
*
i
)
->
totalDevices
(
iType
);
return
factoyObjects
;
}
//----------------------------------------------------------------------------//
DeviceList
InputManager
::
listFreeDevices
()
{
DeviceList
list
;
FactoryList
::
iterator
i
=
mFactories
.
begin
(),
e
=
mFactories
.
end
();
for
(
;
i
!=
e
;
++
i
)
{
DeviceList
temp
=
(
*
i
)
->
freeDeviceList
();
list
.
insert
(
temp
.
begin
(),
temp
.
end
());
}
return
list
;
}
//----------------------------------------------------------------------------//
Object
*
InputManager
::
createInputObject
(
Type
iType
,
bool
bufferMode
,
const
std
::
string
&
vendor
)
{
Object
*
obj
=
0
;
FactoryList
::
iterator
i
=
mFactories
.
begin
(),
e
=
mFactories
.
end
();
for
(
;
i
!=
e
;
++
i
)
{
if
(
(
*
i
)
->
freeDevices
(
iType
)
>
0
)
{
if
(
vendor
==
""
||
(
*
i
)
->
vendorExist
(
iType
,
vendor
)
)
{
obj
=
(
*
i
)
->
createObject
(
this
,
iType
,
bufferMode
,
vendor
);
mFactoryObjects
[
obj
]
=
(
*
i
);
break
;
}
}
}
if
(
!
obj
)
OIS_EXCEPT
(
E_InputDeviceNonExistant
,
"No devices match requested type."
);
try
{
//Intialize device
obj
->
_initialize
();
}
catch
(...)
{
//Somekind of error, cleanup and rethrow
destroyInputObject
(
obj
);
throw
;
}
return
obj
;
}
//----------------------------------------------------------------------------//
void
InputManager
::
destroyInputObject
(
Object
*
obj
)
{
if
(
obj
==
0
)
return
;
FactoryCreatedObject
::
iterator
i
=
mFactoryObjects
.
find
(
obj
);
if
(
i
!=
mFactoryObjects
.
end
()
)
{
i
->
second
->
destroyObject
(
obj
);
mFactoryObjects
.
erase
(
i
);
}
else
{
OIS_EXCEPT
(
E_General
,
"Object creator not known."
);
}
}
//----------------------------------------------------------------------------//
void
InputManager
::
addFactoryCreator
(
FactoryCreator
*
factory
)
{
if
(
factory
!=
0
)
mFactories
.
push_back
(
factory
);
}
//----------------------------------------------------------------------------//
void
InputManager
::
removeFactoryCreator
(
FactoryCreator
*
factory
)
{
if
(
factory
!=
0
)
{
//First, destroy all devices created with the factory
for
(
FactoryCreatedObject
::
iterator
i
=
mFactoryObjects
.
begin
();
i
!=
mFactoryObjects
.
end
();
++
i
)
{
if
(
i
->
second
==
factory
)
{
i
->
second
->
destroyObject
(
i
->
first
);
mFactoryObjects
.
erase
(
i
++
);
}
}
//Now, remove the factory itself
FactoryList
::
iterator
fact
=
std
::
find
(
mFactories
.
begin
(),
mFactories
.
end
(),
factory
);
if
(
fact
!=
mFactories
.
end
()
)
mFactories
.
erase
(
fact
);
}
}
//----------------------------------------------------------------------------//
void
InputManager
::
enableAddOnFactory
(
AddOnFactories
factory
)
{
OIS_UNUSED
(
factory
);
#if defined OIS_LIRC_SUPPORT
if
(
factory
==
AddOn_LIRC
||
factory
==
AddOn_All
)
{
if
(
m_lircSupport
==
0
)
{
m_lircSupport
=
new
LIRCFactoryCreator
();
addFactoryCreator
(
m_lircSupport
);
}
}
#endif
#if defined OIS_WIN32_WIIMOTE_SUPPORT
if
(
factory
==
AddOn_WiiMote
||
factory
==
AddOn_All
)
{
if
(
m_wiiMoteSupport
==
0
)
{
m_wiiMoteSupport
=
new
WiiMoteFactoryCreator
();
addFactoryCreator
(
m_wiiMoteSupport
);
}
}
#endif
}
src/OISJoyStick.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISJoyStick.h"
using
namespace
OIS
;
//----------------------------------------------------------------------------//
JoyStick
::
JoyStick
(
const
std
::
string
&
vendor
,
bool
buffered
,
int
devID
,
InputManager
*
creator
)
:
Object
(
vendor
,
OISJoyStick
,
buffered
,
devID
,
creator
),
mSliders
(
0
),
mPOVs
(
0
),
mListener
(
0
),
mVector3Sensitivity
(
OIS_JOYSTICK_VECTOR3_DEFAULT
)
{
}
//----------------------------------------------------------------------------//
int
JoyStick
::
getNumberOfComponents
(
ComponentType
cType
)
const
{
switch
(
cType
)
{
case
OIS_Button
:
return
(
int
)
mState
.
mButtons
.
size
();
case
OIS_Axis
:
return
(
int
)
mState
.
mAxes
.
size
();
case
OIS_Slider
:
return
mSliders
;
case
OIS_POV
:
return
mPOVs
;
case
OIS_Vector3
:
return
(
int
)
mState
.
mVectors
.
size
();
default:
return
0
;
}
}
//----------------------------------------------------------------------------//
void
JoyStick
::
setVector3Sensitivity
(
float
degrees
)
{
mVector3Sensitivity
=
degrees
;
}
//----------------------------------------------------------------------------//
float
JoyStick
::
getVector3Sensitivity
()
const
{
return
mVector3Sensitivity
;
}
//----------------------------------------------------------------------------//
void
JoyStick
::
setEventCallback
(
JoyStickListener
*
joyListener
)
{
mListener
=
joyListener
;
}
//----------------------------------------------------------------------------//
JoyStickListener
*
JoyStick
::
getEventCallback
()
const
{
return
mListener
;
}
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISJoyStick.h"
using
namespace
OIS
;
//----------------------------------------------------------------------------//
JoyStick
::
JoyStick
(
const
std
::
string
&
vendor
,
bool
buffered
,
int
devID
,
InputManager
*
creator
)
:
Object
(
vendor
,
OISJoyStick
,
buffered
,
devID
,
creator
),
mSliders
(
0
),
mPOVs
(
0
),
mListener
(
0
),
mVector3Sensitivity
(
OIS_JOYSTICK_VECTOR3_DEFAULT
)
{
}
//----------------------------------------------------------------------------//
int
JoyStick
::
getNumberOfComponents
(
ComponentType
cType
)
const
{
switch
(
cType
)
{
case
OIS_Button
:
return
(
int
)
mState
.
mButtons
.
size
();
case
OIS_Axis
:
return
(
int
)
mState
.
mAxes
.
size
();
case
OIS_Slider
:
return
mSliders
;
case
OIS_POV
:
return
mPOVs
;
case
OIS_Vector3
:
return
(
int
)
mState
.
mVectors
.
size
();
default:
return
0
;
}
}
//----------------------------------------------------------------------------//
void
JoyStick
::
setVector3Sensitivity
(
float
degrees
)
{
mVector3Sensitivity
=
degrees
;
}
//----------------------------------------------------------------------------//
float
JoyStick
::
getVector3Sensitivity
()
const
{
return
mVector3Sensitivity
;
}
//----------------------------------------------------------------------------//
void
JoyStick
::
setEventCallback
(
JoyStickListener
*
joyListener
)
{
mListener
=
joyListener
;
}
//----------------------------------------------------------------------------//
JoyStickListener
*
JoyStick
::
getEventCallback
()
const
{
return
mListener
;
}
src/OISKeyboard.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISKeyboard.h"
#include "OISException.h"
using
namespace
OIS
;
//----------------------------------------------------------------------//
void
Keyboard
::
setTextTranslation
(
TextTranslationMode
mode
)
{
mTextMode
=
mode
;
}
//----------------------------------------------------------------------//
bool
Keyboard
::
isModifierDown
(
Modifier
mod
)
const
{
#if defined(OIS_MSVC_COMPILER)
#pragma warning (push)
#pragma warning (disable : 4800)
#endif
return
(
mModifiers
&
mod
);
#if defined(OIS_MSVC_COMPILER)
#pragma warning (pop)
#endif
}
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "OISKeyboard.h"
#include "OISException.h"
using
namespace
OIS
;
//----------------------------------------------------------------------//
void
Keyboard
::
setTextTranslation
(
TextTranslationMode
mode
)
{
mTextMode
=
mode
;
}
//----------------------------------------------------------------------//
bool
Keyboard
::
isModifierDown
(
Modifier
mod
)
const
{
#if defined(OIS_MSVC_COMPILER)
#pragma warning (push)
#pragma warning (disable : 4800)
#endif
return
(
mModifiers
&
mod
);
#if defined(OIS_MSVC_COMPILER)
#pragma warning (pop)
#endif
}
src/OISObject.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
//#include "OISObject.h"
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
//#include "OISObject.h"
src/SDL/SDLInputManager.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL/SDLInputManager.h"
#include "SDL/SDLKeyboard.h"
#include "SDL/SDLMouse.h"
#include "SDL/SDLJoyStick.h"
#include "OISException.h"
#include "OISObject.h"
using
namespace
OIS
;
const
std
::
string
SDLInputManager
::
iName
=
"SDL Input Wrapper"
;
//--------------------------------------------------------------------------------//
SDLInputManager
::
SDLInputManager
()
:
mGrabbed
(
false
)
{
}
//--------------------------------------------------------------------------------//
SDLInputManager
::~
SDLInputManager
()
{
}
//--------------------------------------------------------------------------------//
void
SDLInputManager
::
_initialize
(
ParamList
&
paramList
)
{
Uint32
flags
=
SDL_WasInit
(
0
);
if
(
flags
==
0
)
OIS_EXCEPT
(
E_General
,
"SDLInputManager::SDLInputManager >> SDL Not Initialized already!"
);
//Ok, now we have DirectInput, parse whatever extra settings were sent to us
_parseConfigSettings
(
paramList
);
_enumerateDevices
();
}
//--------------------------------------------------------------------------------//
void
SDLInputManager
::
_parseConfigSettings
(
ParamList
&
paramList
)
{
}
//--------------------------------------------------------------------------------//
void
SDLInputManager
::
_enumerateDevices
()
{
}
//--------------------------------------------------------------------------------//
int
SDLInputManager
::
numJoySticks
()
{
return
0
;
}
//--------------------------------------------------------------------------------//
int
SDLInputManager
::
numMice
()
{
return
1
;
}
//--------------------------------------------------------------------------------//
int
SDLInputManager
::
numKeyboards
()
{
return
1
;
}
//----------------------------------------------------------------------------//
Object
*
SDLInputManager
::
createInputObject
(
Type
iType
,
bool
bufferMode
)
{
Object
*
obj
=
0
;
switch
(
iType
)
{
case
OISKeyboard
:
obj
=
new
SDLKeyboard
(
bufferMode
);
break
;
case
OISMouse
:
obj
=
new
SDLMouse
(
bufferMode
);
break
;
case
OISJoyStick
:
default:
OIS_EXCEPT
(
E_InputDeviceNotSupported
,
"Type not implemented"
);
}
try
{
obj
->
_initialize
();
}
catch
(...)
{
delete
obj
;
throw
;
//rethrow
}
return
obj
;
}
//----------------------------------------------------------------------------//
void
SDLInputManager
::
destroyInputObject
(
Object
*
obj
)
{
if
(
obj
==
0
)
return
;
delete
obj
;
}
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL/SDLInputManager.h"
#include "SDL/SDLKeyboard.h"
#include "SDL/SDLMouse.h"
#include "SDL/SDLJoyStick.h"
#include "OISException.h"
#include "OISObject.h"
using
namespace
OIS
;
const
std
::
string
SDLInputManager
::
iName
=
"SDL Input Wrapper"
;
//--------------------------------------------------------------------------------//
SDLInputManager
::
SDLInputManager
()
:
mGrabbed
(
false
)
{
}
//--------------------------------------------------------------------------------//
SDLInputManager
::~
SDLInputManager
()
{
}
//--------------------------------------------------------------------------------//
void
SDLInputManager
::
_initialize
(
ParamList
&
paramList
)
{
Uint32
flags
=
SDL_WasInit
(
0
);
if
(
flags
==
0
)
OIS_EXCEPT
(
E_General
,
"SDLInputManager::SDLInputManager >> SDL Not Initialized already!"
);
//Ok, now we have DirectInput, parse whatever extra settings were sent to us
_parseConfigSettings
(
paramList
);
_enumerateDevices
();
}
//--------------------------------------------------------------------------------//
void
SDLInputManager
::
_parseConfigSettings
(
ParamList
&
paramList
)
{
}
//--------------------------------------------------------------------------------//
void
SDLInputManager
::
_enumerateDevices
()
{
}
//--------------------------------------------------------------------------------//
int
SDLInputManager
::
numJoySticks
()
{
return
0
;
}
//--------------------------------------------------------------------------------//
int
SDLInputManager
::
numMice
()
{
return
1
;
}
//--------------------------------------------------------------------------------//
int
SDLInputManager
::
numKeyboards
()
{
return
1
;
}
//----------------------------------------------------------------------------//
Object
*
SDLInputManager
::
createInputObject
(
Type
iType
,
bool
bufferMode
)
{
Object
*
obj
=
0
;
switch
(
iType
)
{
case
OISKeyboard
:
obj
=
new
SDLKeyboard
(
bufferMode
);
break
;
case
OISMouse
:
obj
=
new
SDLMouse
(
bufferMode
);
break
;
case
OISJoyStick
:
default:
OIS_EXCEPT
(
E_InputDeviceNotSupported
,
"Type not implemented"
);
}
try
{
obj
->
_initialize
();
}
catch
(...)
{
delete
obj
;
throw
;
//rethrow
}
return
obj
;
}
//----------------------------------------------------------------------------//
void
SDLInputManager
::
destroyInputObject
(
Object
*
obj
)
{
if
(
obj
==
0
)
return
;
delete
obj
;
}
src/SDL/SDLKeyboard.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL/SDLKeyboard.h"
#include "SDL/SDLInputManager.h"
#include "OISException.h"
#include "OISEvents.h"
#include <sstream>
using
namespace
OIS
;
//-------------------------------------------------------------------//
SDLKeyboard
::
SDLKeyboard
(
bool
buffered
)
{
mBuffered
=
buffered
;
mType
=
OISKeyboard
;
listener
=
0
;
//Clear our keyboard state buffer
memset
(
&
KeyBuffer
,
0
,
256
);
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
_initialize
()
{
mModifiers
=
0
;
mSDLBuff
=
0
;
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_ESCAPE
,
KC_ESCAPE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_1
,
KC_1
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_2
,
KC_2
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_3
,
KC_3
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_4
,
KC_4
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_5
,
KC_5
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_6
,
KC_6
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_7
,
KC_7
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_8
,
KC_8
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_9
,
KC_9
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_0
,
KC_0
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_MINUS
,
KC_MINUS
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_EQUALS
,
KC_EQUALS
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_BACKSPACE
,
KC_BACK
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_TAB
,
KC_TAB
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_q
,
KC_Q
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_w
,
KC_W
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_e
,
KC_E
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_r
,
KC_R
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_t
,
KC_T
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_y
,
KC_Y
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_u
,
KC_U
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_i
,
KC_I
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_o
,
KC_O
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_p
,
KC_P
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RETURN
,
KC_RETURN
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LCTRL
,
KC_LCONTROL
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_a
,
KC_A
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_s
,
KC_S
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_d
,
KC_D
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_f
,
KC_F
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_g
,
KC_G
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_h
,
KC_H
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_j
,
KC_J
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_k
,
KC_K
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_l
,
KC_L
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SEMICOLON
,
KC_SEMICOLON
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_COLON
,
KC_COLON
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_QUOTE
,
KC_APOSTROPHE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_BACKQUOTE
,
KC_GRAVE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LSHIFT
,
KC_LSHIFT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_BACKSLASH
,
KC_BACKSLASH
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SLASH
,
KC_SLASH
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_z
,
KC_Z
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_x
,
KC_X
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_c
,
KC_C
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_v
,
KC_V
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_b
,
KC_B
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_n
,
KC_N
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_m
,
KC_M
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_COMMA
,
KC_COMMA
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_PERIOD
,
KC_PERIOD
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RSHIFT
,
KC_RSHIFT
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_MULTIPLY
,
KC_MULTIPLY
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LALT
,
KC_LMENU
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SPACE
,
KC_SPACE
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_CAPSLOCK
,
KC_CAPITAL
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F1
,
KC_F1
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F2
,
KC_F2
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F3
,
KC_F3
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F4
,
KC_F4
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F5
,
KC_F5
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F6
,
KC_F6
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F7
,
KC_F7
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F8
,
KC_F8
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F9
,
KC_F9
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F10
,
KC_F10
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_NUMLOCK
,
KC_NUMLOCK
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SCROLLOCK
,
KC_SCROLL
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP7
,
KC_NUMPAD7
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP8
,
KC_NUMPAD8
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP9
,
KC_NUMPAD9
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_MINUS
,
KC_SUBTRACT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP4
,
KC_NUMPAD4
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP5
,
KC_NUMPAD5
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP6
,
KC_NUMPAD6
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_PLUS
,
KC_ADD
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP1
,
KC_NUMPAD1
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP2
,
KC_NUMPAD2
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP3
,
KC_NUMPAD3
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP0
,
KC_NUMPAD0
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_PERIOD
,
KC_DECIMAL
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F11
,
KC_F11
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F12
,
KC_F12
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F13
,
KC_F13
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F14
,
KC_F14
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F15
,
KC_F15
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_EQUALS
,
KC_NUMPADEQUALS
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_DIVIDE
,
KC_DIVIDE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SYSREQ
,
KC_SYSRQ
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RALT
,
KC_RMENU
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_HOME
,
KC_HOME
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_UP
,
KC_UP
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_PAGEUP
,
KC_PGUP
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LEFT
,
KC_LEFT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RIGHT
,
KC_RIGHT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_END
,
KC_END
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_DOWN
,
KC_DOWN
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_PAGEDOWN
,
KC_PGDOWN
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_INSERT
,
KC_INSERT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_DELETE
,
KC_DELETE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LSUPER
,
KC_LWIN
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RSUPER
,
KC_RWIN
)
);
SDL_EnableUNICODE
(
1
);
}
//-------------------------------------------------------------------//
SDLKeyboard
::~
SDLKeyboard
()
{
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
capture
()
{
SDL_Event
events
[
OIS_SDL_KEY_BUFF
];
int
count
=
SDL_PeepEvents
(
events
,
OIS_SDL_KEY_BUFF
,
SDL_GETEVENT
,
SDL_EVENTMASK
(
SDL_KEYDOWN
)
|
SDL_EVENTMASK
(
SDL_KEYUP
));
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
KeyCode
kc
=
mKeyMap
[
events
[
i
].
key
.
keysym
.
sym
];
KeyBuffer
[
kc
]
=
events
[
i
].
key
.
state
;
if
(
mBuffered
&&
listener
)
{
if
(
events
[
i
].
key
.
state
==
SDL_PRESSED
)
{
if
(
listener
->
keyPressed
(
KeyEvent
(
this
,
0
,
kc
,
events
[
i
].
key
.
keysym
.
unicode
))
==
false
)
break
;
}
else
{
if
(
listener
->
keyReleased
(
KeyEvent
(
this
,
0
,
kc
,
events
[
i
].
key
.
keysym
.
unicode
))
==
false
)
break
;
}
}
}
//Release Grab mode on Alt-Tab combinations (for non-window systems)
if
(
KeyBuffer
[
KC_RMENU
]
||
KeyBuffer
[
KC_LMENU
])
{
if
(
KeyBuffer
[
KC_TAB
]
)
static_cast
<
SDLInputManager
*>
(
InputManager
::
getSingletonPtr
())
->
_setGrabMode
(
false
);
}
}
//-------------------------------------------------------------------//
bool
SDLKeyboard
::
isKeyDown
(
KeyCode
key
)
{
return
KeyBuffer
[
key
]
==
1
?
true
:
false
;
}
//-------------------------------------------------------------------//
const
std
::
string
&
SDLKeyboard
::
getAsString
(
KeyCode
kc
)
{
switch
(
kc
)
{
case
KC_ESCAPE
:
mGetString
=
SDL_GetKeyName
(
SDLK_ESCAPE
);
break
;
case
KC_1
:
mGetString
=
SDL_GetKeyName
(
SDLK_1
);
break
;
case
KC_2
:
mGetString
=
SDL_GetKeyName
(
SDLK_2
);
break
;
case
KC_3
:
mGetString
=
SDL_GetKeyName
(
SDLK_3
);
break
;
case
KC_4
:
mGetString
=
SDL_GetKeyName
(
SDLK_4
);
break
;
case
KC_5
:
mGetString
=
SDL_GetKeyName
(
SDLK_5
);
break
;
case
KC_6
:
mGetString
=
SDL_GetKeyName
(
SDLK_6
);
break
;
case
KC_7
:
mGetString
=
SDL_GetKeyName
(
SDLK_7
);
break
;
case
KC_8
:
mGetString
=
SDL_GetKeyName
(
SDLK_8
);
break
;
case
KC_9
:
mGetString
=
SDL_GetKeyName
(
SDLK_9
);
break
;
case
KC_0
:
mGetString
=
SDL_GetKeyName
(
SDLK_0
);
break
;
case
KC_MINUS
:
mGetString
=
SDL_GetKeyName
(
SDLK_MINUS
);
break
;
case
KC_EQUALS
:
mGetString
=
SDL_GetKeyName
(
SDLK_EQUALS
);
break
;
case
KC_BACK
:
mGetString
=
SDL_GetKeyName
(
SDLK_BACKSPACE
);
break
;
case
KC_TAB
:
mGetString
=
SDL_GetKeyName
(
SDLK_TAB
);
break
;
case
KC_Q
:
mGetString
=
SDL_GetKeyName
(
SDLK_q
);
break
;
case
KC_W
:
mGetString
=
SDL_GetKeyName
(
SDLK_w
);
break
;
case
KC_E
:
mGetString
=
SDL_GetKeyName
(
SDLK_e
);
break
;
case
KC_R
:
mGetString
=
SDL_GetKeyName
(
SDLK_r
);
break
;
case
KC_T
:
mGetString
=
SDL_GetKeyName
(
SDLK_t
);
break
;
case
KC_Y
:
mGetString
=
SDL_GetKeyName
(
SDLK_y
);
break
;
case
KC_U
:
mGetString
=
SDL_GetKeyName
(
SDLK_u
);
break
;
case
KC_I
:
mGetString
=
SDL_GetKeyName
(
SDLK_i
);
break
;
case
KC_O
:
mGetString
=
SDL_GetKeyName
(
SDLK_o
);
break
;
case
KC_P
:
mGetString
=
SDL_GetKeyName
(
SDLK_p
);
break
;
case
KC_LBRACKET
:
mGetString
=
"["
;
break
;
case
KC_RBRACKET
:
mGetString
=
"]"
;
break
;
case
KC_RETURN
:
mGetString
=
SDL_GetKeyName
(
SDLK_RETURN
);
break
;
case
KC_LCONTROL
:
mGetString
=
SDL_GetKeyName
(
SDLK_LCTRL
);
break
;
case
KC_A
:
mGetString
=
SDL_GetKeyName
(
SDLK_a
);
break
;
case
KC_S
:
mGetString
=
SDL_GetKeyName
(
SDLK_s
);
break
;
case
KC_D
:
mGetString
=
SDL_GetKeyName
(
SDLK_d
);
break
;
case
KC_F
:
mGetString
=
SDL_GetKeyName
(
SDLK_f
);
break
;
case
KC_G
:
mGetString
=
SDL_GetKeyName
(
SDLK_g
);
break
;
case
KC_H
:
mGetString
=
SDL_GetKeyName
(
SDLK_h
);
break
;
case
KC_J
:
mGetString
=
SDL_GetKeyName
(
SDLK_j
);
break
;
case
KC_K
:
mGetString
=
SDL_GetKeyName
(
SDLK_k
);
break
;
case
KC_L
:
mGetString
=
SDL_GetKeyName
(
SDLK_l
);
break
;
case
KC_SEMICOLON
:
mGetString
=
SDL_GetKeyName
(
SDLK_SEMICOLON
);
break
;
case
KC_APOSTROPHE
:
mGetString
=
SDL_GetKeyName
(
SDLK_QUOTE
);
break
;
case
KC_GRAVE
:
mGetString
=
SDL_GetKeyName
(
SDLK_BACKQUOTE
);
break
;
case
KC_LSHIFT
:
mGetString
=
SDL_GetKeyName
(
SDLK_LSHIFT
);
break
;
case
KC_BACKSLASH
:
mGetString
=
SDL_GetKeyName
(
SDLK_BACKSLASH
);
break
;
case
KC_Z
:
mGetString
=
SDL_GetKeyName
(
SDLK_z
);
break
;
case
KC_X
:
mGetString
=
SDL_GetKeyName
(
SDLK_x
);
break
;
case
KC_C
:
mGetString
=
SDL_GetKeyName
(
SDLK_c
);
break
;
case
KC_V
:
mGetString
=
SDL_GetKeyName
(
SDLK_v
);
break
;
case
KC_B
:
mGetString
=
SDL_GetKeyName
(
SDLK_b
);
break
;
case
KC_N
:
mGetString
=
SDL_GetKeyName
(
SDLK_n
);
break
;
case
KC_M
:
mGetString
=
SDL_GetKeyName
(
SDLK_m
);
break
;
case
KC_COMMA
:
mGetString
=
SDL_GetKeyName
(
SDLK_COMMA
);
break
;
case
KC_PERIOD
:
mGetString
=
SDL_GetKeyName
(
SDLK_PERIOD
);
break
;
case
KC_SLASH
:
mGetString
=
SDL_GetKeyName
(
SDLK_SLASH
);
break
;
case
KC_RSHIFT
:
mGetString
=
SDL_GetKeyName
(
SDLK_RSHIFT
);
break
;
case
KC_MULTIPLY
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_MULTIPLY
);
break
;
case
KC_LMENU
:
mGetString
=
SDL_GetKeyName
(
SDLK_LALT
);
break
;
case
KC_SPACE
:
mGetString
=
SDL_GetKeyName
(
SDLK_SPACE
);
break
;
case
KC_CAPITAL
:
mGetString
=
SDL_GetKeyName
(
SDLK_CAPSLOCK
);
break
;
case
KC_F1
:
mGetString
=
SDL_GetKeyName
(
SDLK_F1
);
break
;
case
KC_F2
:
mGetString
=
SDL_GetKeyName
(
SDLK_F2
);
break
;
case
KC_F3
:
mGetString
=
SDL_GetKeyName
(
SDLK_F3
);
break
;
case
KC_F4
:
mGetString
=
SDL_GetKeyName
(
SDLK_F4
);
break
;
case
KC_F5
:
mGetString
=
SDL_GetKeyName
(
SDLK_F5
);
break
;
case
KC_F6
:
mGetString
=
SDL_GetKeyName
(
SDLK_F6
);
break
;
case
KC_F7
:
mGetString
=
SDL_GetKeyName
(
SDLK_F7
);
break
;
case
KC_F8
:
mGetString
=
SDL_GetKeyName
(
SDLK_F8
);
break
;
case
KC_F9
:
mGetString
=
SDL_GetKeyName
(
SDLK_F9
);
break
;
case
KC_F10
:
mGetString
=
SDL_GetKeyName
(
SDLK_F10
);
break
;
case
KC_NUMLOCK
:
mGetString
=
SDL_GetKeyName
(
SDLK_NUMLOCK
);
break
;
case
KC_SCROLL
:
mGetString
=
SDL_GetKeyName
(
SDLK_SCROLLOCK
);
break
;
case
KC_NUMPAD7
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP7
);
break
;
case
KC_NUMPAD8
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP8
);
break
;
case
KC_NUMPAD9
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP9
);
break
;
case
KC_SUBTRACT
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_MINUS
);
break
;
case
KC_NUMPAD4
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP4
);
break
;
case
KC_NUMPAD5
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP5
);
break
;
case
KC_NUMPAD6
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP6
);
break
;
case
KC_ADD
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_PLUS
);
break
;
case
KC_NUMPAD1
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP1
);
break
;
case
KC_NUMPAD2
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP2
);
break
;
case
KC_NUMPAD3
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP3
);
break
;
case
KC_NUMPAD0
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP0
);
break
;
case
KC_DECIMAL
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_PERIOD
);
break
;
case
KC_OEM_102
:
mGetString
=
"OEM_102"
;
break
;
case
KC_F11
:
mGetString
=
SDL_GetKeyName
(
SDLK_F11
);
break
;
case
KC_F12
:
mGetString
=
SDL_GetKeyName
(
SDLK_F12
);
break
;
case
KC_F13
:
mGetString
=
SDL_GetKeyName
(
SDLK_F13
);
break
;
case
KC_F14
:
mGetString
=
SDL_GetKeyName
(
SDLK_F14
);
break
;
case
KC_F15
:
mGetString
=
SDL_GetKeyName
(
SDLK_F15
);
break
;
case
KC_KANA
:
mGetString
=
"Kana"
;
break
;
case
KC_ABNT_C1
:
mGetString
=
"ABNT_C1"
;
break
;
case
KC_CONVERT
:
mGetString
=
"CONVERT"
;
break
;
case
KC_NOCONVERT
:
mGetString
=
"NOCONVERT"
;
break
;
case
KC_YEN
:
mGetString
=
"YEN"
;
break
;
case
KC_ABNT_C2
:
mGetString
=
"ABNT_C2"
;
break
;
case
KC_NUMPADEQUALS
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_EQUALS
);
break
;
case
KC_PREVTRACK
:
mGetString
=
"KC_PREVTRACK"
;
break
;
case
KC_AT
:
mGetString
=
"KC_AT"
;
break
;
case
KC_COLON
:
mGetString
=
SDL_GetKeyName
(
SDLK_COLON
);
break
;
case
KC_UNDERLINE
:
mGetString
=
"KC_UNDERLINE"
;
break
;
case
KC_KANJI
:
mGetString
=
"KC_KANJI"
;
break
;
case
KC_STOP
:
mGetString
=
"KC_STOP"
;
break
;
case
KC_AX
:
mGetString
=
"KC_AX"
;
break
;
case
KC_UNLABELED
:
mGetString
=
"KC_UNLABELED"
;
break
;
case
KC_NEXTTRACK
:
mGetString
=
"KC_NEXTTRACK"
;
break
;
case
KC_NUMPADENTER
:
mGetString
=
"KC_NUMPADENTER"
;
break
;
case
KC_RCONTROL
:
mGetString
=
"KC_RCONTROL"
;
break
;
case
KC_MUTE
:
mGetString
=
"KC_MUTE"
;
break
;
case
KC_CALCULATOR
:
mGetString
=
"KC_CALCULATOR"
;
break
;
case
KC_PLAYPAUSE
:
mGetString
=
"KC_PLAYPAUSE"
;
break
;
case
KC_MEDIASTOP
:
mGetString
=
"KC_MEDIASTOP"
;
break
;
case
KC_VOLUMEDOWN
:
mGetString
=
"KC_VOLUMEDOWN"
;
break
;
case
KC_VOLUMEUP
:
mGetString
=
"KC_VOLUMEUP"
;
break
;
case
KC_WEBHOME
:
mGetString
=
"KC_WEBHOME"
;
break
;
case
KC_NUMPADCOMMA
:
mGetString
=
"KC_NUMPADCOMMA"
;
break
;
case
KC_DIVIDE
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_DIVIDE
);
break
;
case
KC_SYSRQ
:
mGetString
=
SDL_GetKeyName
(
SDLK_SYSREQ
);
break
;
case
KC_RMENU
:
mGetString
=
SDL_GetKeyName
(
SDLK_RALT
);
break
;
case
KC_PAUSE
:
mGetString
=
"Pause"
;
break
;
case
KC_HOME
:
mGetString
=
SDL_GetKeyName
(
SDLK_HOME
);
break
;
case
KC_UP
:
mGetString
=
SDL_GetKeyName
(
SDLK_UP
);
break
;
case
KC_PGUP
:
mGetString
=
SDL_GetKeyName
(
SDLK_PAGEUP
);
break
;
case
KC_LEFT
:
mGetString
=
SDL_GetKeyName
(
SDLK_LEFT
);
break
;
case
KC_RIGHT
:
mGetString
=
SDL_GetKeyName
(
SDLK_RIGHT
);
break
;
case
KC_END
:
mGetString
=
SDL_GetKeyName
(
SDLK_END
);
break
;
case
KC_DOWN
:
mGetString
=
SDL_GetKeyName
(
SDLK_DOWN
);
break
;
case
KC_PGDOWN
:
mGetString
=
SDL_GetKeyName
(
SDLK_PAGEDOWN
);
break
;
case
KC_INSERT
:
mGetString
=
SDL_GetKeyName
(
SDLK_INSERT
);
break
;
case
KC_DELETE
:
mGetString
=
SDL_GetKeyName
(
SDLK_DELETE
);
break
;
case
KC_LWIN
:
mGetString
=
SDL_GetKeyName
(
SDLK_LSUPER
);
break
;
case
KC_RWIN
:
mGetString
=
SDL_GetKeyName
(
SDLK_RSUPER
);
break
;
case
KC_APPS
:
mGetString
=
"KC_APPS"
;
break
;
case
KC_POWER
:
mGetString
=
"KC_POWER"
;
break
;
case
KC_SLEEP
:
mGetString
=
"KC_SLEEP"
;
break
;
case
KC_WAKE
:
mGetString
=
"KC_WAKE"
;
break
;
case
KC_WEBSEARCH
:
mGetString
=
"KC_WEBSEARCH"
;
break
;
case
KC_WEBFAVORITES
:
mGetString
=
"KC_WEBFAVORITES"
;
break
;
case
KC_WEBREFRESH
:
mGetString
=
"KC_WEBREFRESH"
;
break
;
case
KC_WEBSTOP
:
mGetString
=
"KC_WEBSTOP"
;
break
;
case
KC_WEBFORWARD
:
mGetString
=
"KC_WEBFORWARD"
;
break
;
case
KC_WEBBACK
:
mGetString
=
"KC_WEBBACK"
;
break
;
case
KC_MYCOMPUTER
:
mGetString
=
"KC_MYCOMPUTER"
;
break
;
case
KC_MAIL
:
mGetString
=
"KC_MAIL"
;
break
;
case
KC_MEDIASELECT
:
mGetString
=
"KC_MEDIASELECT"
;
break
;
default:
mGetString
=
"Unknown"
;
break
;
};
return
mGetString
;
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
copyKeyStates
(
char
keys
[
256
]
)
{
for
(
int
i
=
0
;
i
<
256
;
++
i
)
keys
[
i
]
=
KeyBuffer
[
i
];
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
setBuffered
(
bool
buffered
)
{
mBuffered
=
buffered
;
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
setTextTranslation
(
TextTranslationMode
mode
)
{
mTextMode
=
mode
;
if
(
mode
==
Off
||
mode
==
Ascii
)
SDL_EnableUNICODE
(
0
);
else
if
(
mode
==
Unicode
)
SDL_EnableUNICODE
(
1
);
}
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL/SDLKeyboard.h"
#include "SDL/SDLInputManager.h"
#include "OISException.h"
#include "OISEvents.h"
#include <sstream>
using
namespace
OIS
;
//-------------------------------------------------------------------//
SDLKeyboard
::
SDLKeyboard
(
bool
buffered
)
{
mBuffered
=
buffered
;
mType
=
OISKeyboard
;
listener
=
0
;
//Clear our keyboard state buffer
memset
(
&
KeyBuffer
,
0
,
256
);
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
_initialize
()
{
mModifiers
=
0
;
mSDLBuff
=
0
;
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_ESCAPE
,
KC_ESCAPE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_1
,
KC_1
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_2
,
KC_2
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_3
,
KC_3
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_4
,
KC_4
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_5
,
KC_5
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_6
,
KC_6
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_7
,
KC_7
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_8
,
KC_8
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_9
,
KC_9
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_0
,
KC_0
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_MINUS
,
KC_MINUS
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_EQUALS
,
KC_EQUALS
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_BACKSPACE
,
KC_BACK
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_TAB
,
KC_TAB
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_q
,
KC_Q
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_w
,
KC_W
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_e
,
KC_E
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_r
,
KC_R
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_t
,
KC_T
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_y
,
KC_Y
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_u
,
KC_U
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_i
,
KC_I
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_o
,
KC_O
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_p
,
KC_P
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RETURN
,
KC_RETURN
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LCTRL
,
KC_LCONTROL
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_a
,
KC_A
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_s
,
KC_S
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_d
,
KC_D
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_f
,
KC_F
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_g
,
KC_G
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_h
,
KC_H
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_j
,
KC_J
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_k
,
KC_K
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_l
,
KC_L
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SEMICOLON
,
KC_SEMICOLON
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_COLON
,
KC_COLON
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_QUOTE
,
KC_APOSTROPHE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_BACKQUOTE
,
KC_GRAVE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LSHIFT
,
KC_LSHIFT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_BACKSLASH
,
KC_BACKSLASH
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SLASH
,
KC_SLASH
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_z
,
KC_Z
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_x
,
KC_X
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_c
,
KC_C
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_v
,
KC_V
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_b
,
KC_B
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_n
,
KC_N
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_m
,
KC_M
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_COMMA
,
KC_COMMA
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_PERIOD
,
KC_PERIOD
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RSHIFT
,
KC_RSHIFT
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_MULTIPLY
,
KC_MULTIPLY
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LALT
,
KC_LMENU
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SPACE
,
KC_SPACE
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_CAPSLOCK
,
KC_CAPITAL
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F1
,
KC_F1
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F2
,
KC_F2
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F3
,
KC_F3
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F4
,
KC_F4
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F5
,
KC_F5
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F6
,
KC_F6
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F7
,
KC_F7
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F8
,
KC_F8
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F9
,
KC_F9
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F10
,
KC_F10
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_NUMLOCK
,
KC_NUMLOCK
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SCROLLOCK
,
KC_SCROLL
));
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP7
,
KC_NUMPAD7
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP8
,
KC_NUMPAD8
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP9
,
KC_NUMPAD9
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_MINUS
,
KC_SUBTRACT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP4
,
KC_NUMPAD4
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP5
,
KC_NUMPAD5
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP6
,
KC_NUMPAD6
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_PLUS
,
KC_ADD
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP1
,
KC_NUMPAD1
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP2
,
KC_NUMPAD2
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP3
,
KC_NUMPAD3
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP0
,
KC_NUMPAD0
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_PERIOD
,
KC_DECIMAL
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F11
,
KC_F11
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F12
,
KC_F12
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F13
,
KC_F13
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F14
,
KC_F14
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_F15
,
KC_F15
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_EQUALS
,
KC_NUMPADEQUALS
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_KP_DIVIDE
,
KC_DIVIDE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_SYSREQ
,
KC_SYSRQ
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RALT
,
KC_RMENU
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_HOME
,
KC_HOME
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_UP
,
KC_UP
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_PAGEUP
,
KC_PGUP
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LEFT
,
KC_LEFT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RIGHT
,
KC_RIGHT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_END
,
KC_END
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_DOWN
,
KC_DOWN
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_PAGEDOWN
,
KC_PGDOWN
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_INSERT
,
KC_INSERT
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_DELETE
,
KC_DELETE
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_LSUPER
,
KC_LWIN
)
);
mKeyMap
.
insert
(
KeyMap
::
value_type
(
SDLK_RSUPER
,
KC_RWIN
)
);
SDL_EnableUNICODE
(
1
);
}
//-------------------------------------------------------------------//
SDLKeyboard
::~
SDLKeyboard
()
{
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
capture
()
{
SDL_Event
events
[
OIS_SDL_KEY_BUFF
];
int
count
=
SDL_PeepEvents
(
events
,
OIS_SDL_KEY_BUFF
,
SDL_GETEVENT
,
SDL_EVENTMASK
(
SDL_KEYDOWN
)
|
SDL_EVENTMASK
(
SDL_KEYUP
));
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
KeyCode
kc
=
mKeyMap
[
events
[
i
].
key
.
keysym
.
sym
];
KeyBuffer
[
kc
]
=
events
[
i
].
key
.
state
;
if
(
mBuffered
&&
listener
)
{
if
(
events
[
i
].
key
.
state
==
SDL_PRESSED
)
{
if
(
listener
->
keyPressed
(
KeyEvent
(
this
,
0
,
kc
,
events
[
i
].
key
.
keysym
.
unicode
))
==
false
)
break
;
}
else
{
if
(
listener
->
keyReleased
(
KeyEvent
(
this
,
0
,
kc
,
events
[
i
].
key
.
keysym
.
unicode
))
==
false
)
break
;
}
}
}
//Release Grab mode on Alt-Tab combinations (for non-window systems)
if
(
KeyBuffer
[
KC_RMENU
]
||
KeyBuffer
[
KC_LMENU
])
{
if
(
KeyBuffer
[
KC_TAB
]
)
static_cast
<
SDLInputManager
*>
(
InputManager
::
getSingletonPtr
())
->
_setGrabMode
(
false
);
}
}
//-------------------------------------------------------------------//
bool
SDLKeyboard
::
isKeyDown
(
KeyCode
key
)
{
return
KeyBuffer
[
key
]
==
1
?
true
:
false
;
}
//-------------------------------------------------------------------//
const
std
::
string
&
SDLKeyboard
::
getAsString
(
KeyCode
kc
)
{
switch
(
kc
)
{
case
KC_ESCAPE
:
mGetString
=
SDL_GetKeyName
(
SDLK_ESCAPE
);
break
;
case
KC_1
:
mGetString
=
SDL_GetKeyName
(
SDLK_1
);
break
;
case
KC_2
:
mGetString
=
SDL_GetKeyName
(
SDLK_2
);
break
;
case
KC_3
:
mGetString
=
SDL_GetKeyName
(
SDLK_3
);
break
;
case
KC_4
:
mGetString
=
SDL_GetKeyName
(
SDLK_4
);
break
;
case
KC_5
:
mGetString
=
SDL_GetKeyName
(
SDLK_5
);
break
;
case
KC_6
:
mGetString
=
SDL_GetKeyName
(
SDLK_6
);
break
;
case
KC_7
:
mGetString
=
SDL_GetKeyName
(
SDLK_7
);
break
;
case
KC_8
:
mGetString
=
SDL_GetKeyName
(
SDLK_8
);
break
;
case
KC_9
:
mGetString
=
SDL_GetKeyName
(
SDLK_9
);
break
;
case
KC_0
:
mGetString
=
SDL_GetKeyName
(
SDLK_0
);
break
;
case
KC_MINUS
:
mGetString
=
SDL_GetKeyName
(
SDLK_MINUS
);
break
;
case
KC_EQUALS
:
mGetString
=
SDL_GetKeyName
(
SDLK_EQUALS
);
break
;
case
KC_BACK
:
mGetString
=
SDL_GetKeyName
(
SDLK_BACKSPACE
);
break
;
case
KC_TAB
:
mGetString
=
SDL_GetKeyName
(
SDLK_TAB
);
break
;
case
KC_Q
:
mGetString
=
SDL_GetKeyName
(
SDLK_q
);
break
;
case
KC_W
:
mGetString
=
SDL_GetKeyName
(
SDLK_w
);
break
;
case
KC_E
:
mGetString
=
SDL_GetKeyName
(
SDLK_e
);
break
;
case
KC_R
:
mGetString
=
SDL_GetKeyName
(
SDLK_r
);
break
;
case
KC_T
:
mGetString
=
SDL_GetKeyName
(
SDLK_t
);
break
;
case
KC_Y
:
mGetString
=
SDL_GetKeyName
(
SDLK_y
);
break
;
case
KC_U
:
mGetString
=
SDL_GetKeyName
(
SDLK_u
);
break
;
case
KC_I
:
mGetString
=
SDL_GetKeyName
(
SDLK_i
);
break
;
case
KC_O
:
mGetString
=
SDL_GetKeyName
(
SDLK_o
);
break
;
case
KC_P
:
mGetString
=
SDL_GetKeyName
(
SDLK_p
);
break
;
case
KC_LBRACKET
:
mGetString
=
"["
;
break
;
case
KC_RBRACKET
:
mGetString
=
"]"
;
break
;
case
KC_RETURN
:
mGetString
=
SDL_GetKeyName
(
SDLK_RETURN
);
break
;
case
KC_LCONTROL
:
mGetString
=
SDL_GetKeyName
(
SDLK_LCTRL
);
break
;
case
KC_A
:
mGetString
=
SDL_GetKeyName
(
SDLK_a
);
break
;
case
KC_S
:
mGetString
=
SDL_GetKeyName
(
SDLK_s
);
break
;
case
KC_D
:
mGetString
=
SDL_GetKeyName
(
SDLK_d
);
break
;
case
KC_F
:
mGetString
=
SDL_GetKeyName
(
SDLK_f
);
break
;
case
KC_G
:
mGetString
=
SDL_GetKeyName
(
SDLK_g
);
break
;
case
KC_H
:
mGetString
=
SDL_GetKeyName
(
SDLK_h
);
break
;
case
KC_J
:
mGetString
=
SDL_GetKeyName
(
SDLK_j
);
break
;
case
KC_K
:
mGetString
=
SDL_GetKeyName
(
SDLK_k
);
break
;
case
KC_L
:
mGetString
=
SDL_GetKeyName
(
SDLK_l
);
break
;
case
KC_SEMICOLON
:
mGetString
=
SDL_GetKeyName
(
SDLK_SEMICOLON
);
break
;
case
KC_APOSTROPHE
:
mGetString
=
SDL_GetKeyName
(
SDLK_QUOTE
);
break
;
case
KC_GRAVE
:
mGetString
=
SDL_GetKeyName
(
SDLK_BACKQUOTE
);
break
;
case
KC_LSHIFT
:
mGetString
=
SDL_GetKeyName
(
SDLK_LSHIFT
);
break
;
case
KC_BACKSLASH
:
mGetString
=
SDL_GetKeyName
(
SDLK_BACKSLASH
);
break
;
case
KC_Z
:
mGetString
=
SDL_GetKeyName
(
SDLK_z
);
break
;
case
KC_X
:
mGetString
=
SDL_GetKeyName
(
SDLK_x
);
break
;
case
KC_C
:
mGetString
=
SDL_GetKeyName
(
SDLK_c
);
break
;
case
KC_V
:
mGetString
=
SDL_GetKeyName
(
SDLK_v
);
break
;
case
KC_B
:
mGetString
=
SDL_GetKeyName
(
SDLK_b
);
break
;
case
KC_N
:
mGetString
=
SDL_GetKeyName
(
SDLK_n
);
break
;
case
KC_M
:
mGetString
=
SDL_GetKeyName
(
SDLK_m
);
break
;
case
KC_COMMA
:
mGetString
=
SDL_GetKeyName
(
SDLK_COMMA
);
break
;
case
KC_PERIOD
:
mGetString
=
SDL_GetKeyName
(
SDLK_PERIOD
);
break
;
case
KC_SLASH
:
mGetString
=
SDL_GetKeyName
(
SDLK_SLASH
);
break
;
case
KC_RSHIFT
:
mGetString
=
SDL_GetKeyName
(
SDLK_RSHIFT
);
break
;
case
KC_MULTIPLY
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_MULTIPLY
);
break
;
case
KC_LMENU
:
mGetString
=
SDL_GetKeyName
(
SDLK_LALT
);
break
;
case
KC_SPACE
:
mGetString
=
SDL_GetKeyName
(
SDLK_SPACE
);
break
;
case
KC_CAPITAL
:
mGetString
=
SDL_GetKeyName
(
SDLK_CAPSLOCK
);
break
;
case
KC_F1
:
mGetString
=
SDL_GetKeyName
(
SDLK_F1
);
break
;
case
KC_F2
:
mGetString
=
SDL_GetKeyName
(
SDLK_F2
);
break
;
case
KC_F3
:
mGetString
=
SDL_GetKeyName
(
SDLK_F3
);
break
;
case
KC_F4
:
mGetString
=
SDL_GetKeyName
(
SDLK_F4
);
break
;
case
KC_F5
:
mGetString
=
SDL_GetKeyName
(
SDLK_F5
);
break
;
case
KC_F6
:
mGetString
=
SDL_GetKeyName
(
SDLK_F6
);
break
;
case
KC_F7
:
mGetString
=
SDL_GetKeyName
(
SDLK_F7
);
break
;
case
KC_F8
:
mGetString
=
SDL_GetKeyName
(
SDLK_F8
);
break
;
case
KC_F9
:
mGetString
=
SDL_GetKeyName
(
SDLK_F9
);
break
;
case
KC_F10
:
mGetString
=
SDL_GetKeyName
(
SDLK_F10
);
break
;
case
KC_NUMLOCK
:
mGetString
=
SDL_GetKeyName
(
SDLK_NUMLOCK
);
break
;
case
KC_SCROLL
:
mGetString
=
SDL_GetKeyName
(
SDLK_SCROLLOCK
);
break
;
case
KC_NUMPAD7
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP7
);
break
;
case
KC_NUMPAD8
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP8
);
break
;
case
KC_NUMPAD9
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP9
);
break
;
case
KC_SUBTRACT
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_MINUS
);
break
;
case
KC_NUMPAD4
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP4
);
break
;
case
KC_NUMPAD5
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP5
);
break
;
case
KC_NUMPAD6
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP6
);
break
;
case
KC_ADD
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_PLUS
);
break
;
case
KC_NUMPAD1
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP1
);
break
;
case
KC_NUMPAD2
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP2
);
break
;
case
KC_NUMPAD3
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP3
);
break
;
case
KC_NUMPAD0
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP0
);
break
;
case
KC_DECIMAL
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_PERIOD
);
break
;
case
KC_OEM_102
:
mGetString
=
"OEM_102"
;
break
;
case
KC_F11
:
mGetString
=
SDL_GetKeyName
(
SDLK_F11
);
break
;
case
KC_F12
:
mGetString
=
SDL_GetKeyName
(
SDLK_F12
);
break
;
case
KC_F13
:
mGetString
=
SDL_GetKeyName
(
SDLK_F13
);
break
;
case
KC_F14
:
mGetString
=
SDL_GetKeyName
(
SDLK_F14
);
break
;
case
KC_F15
:
mGetString
=
SDL_GetKeyName
(
SDLK_F15
);
break
;
case
KC_KANA
:
mGetString
=
"Kana"
;
break
;
case
KC_ABNT_C1
:
mGetString
=
"ABNT_C1"
;
break
;
case
KC_CONVERT
:
mGetString
=
"CONVERT"
;
break
;
case
KC_NOCONVERT
:
mGetString
=
"NOCONVERT"
;
break
;
case
KC_YEN
:
mGetString
=
"YEN"
;
break
;
case
KC_ABNT_C2
:
mGetString
=
"ABNT_C2"
;
break
;
case
KC_NUMPADEQUALS
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_EQUALS
);
break
;
case
KC_PREVTRACK
:
mGetString
=
"KC_PREVTRACK"
;
break
;
case
KC_AT
:
mGetString
=
"KC_AT"
;
break
;
case
KC_COLON
:
mGetString
=
SDL_GetKeyName
(
SDLK_COLON
);
break
;
case
KC_UNDERLINE
:
mGetString
=
"KC_UNDERLINE"
;
break
;
case
KC_KANJI
:
mGetString
=
"KC_KANJI"
;
break
;
case
KC_STOP
:
mGetString
=
"KC_STOP"
;
break
;
case
KC_AX
:
mGetString
=
"KC_AX"
;
break
;
case
KC_UNLABELED
:
mGetString
=
"KC_UNLABELED"
;
break
;
case
KC_NEXTTRACK
:
mGetString
=
"KC_NEXTTRACK"
;
break
;
case
KC_NUMPADENTER
:
mGetString
=
"KC_NUMPADENTER"
;
break
;
case
KC_RCONTROL
:
mGetString
=
"KC_RCONTROL"
;
break
;
case
KC_MUTE
:
mGetString
=
"KC_MUTE"
;
break
;
case
KC_CALCULATOR
:
mGetString
=
"KC_CALCULATOR"
;
break
;
case
KC_PLAYPAUSE
:
mGetString
=
"KC_PLAYPAUSE"
;
break
;
case
KC_MEDIASTOP
:
mGetString
=
"KC_MEDIASTOP"
;
break
;
case
KC_VOLUMEDOWN
:
mGetString
=
"KC_VOLUMEDOWN"
;
break
;
case
KC_VOLUMEUP
:
mGetString
=
"KC_VOLUMEUP"
;
break
;
case
KC_WEBHOME
:
mGetString
=
"KC_WEBHOME"
;
break
;
case
KC_NUMPADCOMMA
:
mGetString
=
"KC_NUMPADCOMMA"
;
break
;
case
KC_DIVIDE
:
mGetString
=
SDL_GetKeyName
(
SDLK_KP_DIVIDE
);
break
;
case
KC_SYSRQ
:
mGetString
=
SDL_GetKeyName
(
SDLK_SYSREQ
);
break
;
case
KC_RMENU
:
mGetString
=
SDL_GetKeyName
(
SDLK_RALT
);
break
;
case
KC_PAUSE
:
mGetString
=
"Pause"
;
break
;
case
KC_HOME
:
mGetString
=
SDL_GetKeyName
(
SDLK_HOME
);
break
;
case
KC_UP
:
mGetString
=
SDL_GetKeyName
(
SDLK_UP
);
break
;
case
KC_PGUP
:
mGetString
=
SDL_GetKeyName
(
SDLK_PAGEUP
);
break
;
case
KC_LEFT
:
mGetString
=
SDL_GetKeyName
(
SDLK_LEFT
);
break
;
case
KC_RIGHT
:
mGetString
=
SDL_GetKeyName
(
SDLK_RIGHT
);
break
;
case
KC_END
:
mGetString
=
SDL_GetKeyName
(
SDLK_END
);
break
;
case
KC_DOWN
:
mGetString
=
SDL_GetKeyName
(
SDLK_DOWN
);
break
;
case
KC_PGDOWN
:
mGetString
=
SDL_GetKeyName
(
SDLK_PAGEDOWN
);
break
;
case
KC_INSERT
:
mGetString
=
SDL_GetKeyName
(
SDLK_INSERT
);
break
;
case
KC_DELETE
:
mGetString
=
SDL_GetKeyName
(
SDLK_DELETE
);
break
;
case
KC_LWIN
:
mGetString
=
SDL_GetKeyName
(
SDLK_LSUPER
);
break
;
case
KC_RWIN
:
mGetString
=
SDL_GetKeyName
(
SDLK_RSUPER
);
break
;
case
KC_APPS
:
mGetString
=
"KC_APPS"
;
break
;
case
KC_POWER
:
mGetString
=
"KC_POWER"
;
break
;
case
KC_SLEEP
:
mGetString
=
"KC_SLEEP"
;
break
;
case
KC_WAKE
:
mGetString
=
"KC_WAKE"
;
break
;
case
KC_WEBSEARCH
:
mGetString
=
"KC_WEBSEARCH"
;
break
;
case
KC_WEBFAVORITES
:
mGetString
=
"KC_WEBFAVORITES"
;
break
;
case
KC_WEBREFRESH
:
mGetString
=
"KC_WEBREFRESH"
;
break
;
case
KC_WEBSTOP
:
mGetString
=
"KC_WEBSTOP"
;
break
;
case
KC_WEBFORWARD
:
mGetString
=
"KC_WEBFORWARD"
;
break
;
case
KC_WEBBACK
:
mGetString
=
"KC_WEBBACK"
;
break
;
case
KC_MYCOMPUTER
:
mGetString
=
"KC_MYCOMPUTER"
;
break
;
case
KC_MAIL
:
mGetString
=
"KC_MAIL"
;
break
;
case
KC_MEDIASELECT
:
mGetString
=
"KC_MEDIASELECT"
;
break
;
default:
mGetString
=
"Unknown"
;
break
;
};
return
mGetString
;
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
copyKeyStates
(
char
keys
[
256
]
)
{
for
(
int
i
=
0
;
i
<
256
;
++
i
)
keys
[
i
]
=
KeyBuffer
[
i
];
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
setBuffered
(
bool
buffered
)
{
mBuffered
=
buffered
;
}
//-------------------------------------------------------------------//
void
SDLKeyboard
::
setTextTranslation
(
TextTranslationMode
mode
)
{
mTextMode
=
mode
;
if
(
mode
==
Off
||
mode
==
Ascii
)
SDL_EnableUNICODE
(
0
);
else
if
(
mode
==
Unicode
)
SDL_EnableUNICODE
(
1
);
}
src/SDL/SDLMouse.cpp
View file @
24236447
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL/SDLMouse.h"
#include "SDL/SDLInputManager.h"
#include "OISException.h"
#include "OISEvents.h"
using
namespace
OIS
;
//-------------------------------------------------------------------//
SDLMouse
::
SDLMouse
(
bool
buffered
)
:
mGrabbed
(
false
),
mRegainFocus
(
false
)
{
mBuffered
=
buffered
;
mType
=
OISMouse
;
listener
=
0
;
}
//-------------------------------------------------------------------//
void
SDLMouse
::
_initialize
()
{
//Clear old state
mState
.
clear
();
mRegainFocus
=
false
;
_setGrab
(
true
);
_setVisible
(
false
);
static_cast
<
SDLInputManager
*>
(
InputManager
::
getSingletonPtr
())
->
_setGrabMode
(
true
);
}
//-------------------------------------------------------------------//
SDLMouse
::~
SDLMouse
()
{
_setGrab
(
true
);
_setVisible
(
true
);
static_cast
<
SDLInputManager
*>
(
InputManager
::
getSingletonPtr
())
->
_setGrabMode
(
false
);
}
//-------------------------------------------------------------------//
void
SDLMouse
::
capture
()
{
//Used for going from SDL Button to OIS button
static
const
MouseButtonID
ButtonMask
[
4
]
=
{
MB_Left
,
MB_Left
,
MB_Middle
,
MB_Right
};
//Clear old relative values
mState
.
relX
=
mState
.
relY
=
mState
.
relZ
=
0
;
SDL_Event
events
[
OIS_SDL_MOUSE_BUFF
];
int
count
=
SDL_PeepEvents
(
events
,
OIS_SDL_MOUSE_BUFF
,
SDL_GETEVENT
,
SDL_MOUSEEVENTMASK
);
bool
mouseXYMoved
=
false
;
bool
mouseZMoved
=
false
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
switch
(
events
[
i
].
type
)
{
case
SDL_MOUSEMOTION
:
mouseXYMoved
=
true
;
break
;
case
SDL_MOUSEBUTTONDOWN
:
{
mRegainFocus
=
true
;
int
sdlButton
=
events
[
i
].
button
.
button
;
if
(
sdlButton
<=
SDL_BUTTON_RIGHT
)
{
//Left, Right, or Middle
mState
.
buttons
|=
(
1
<<
ButtonMask
[
sdlButton
]);
if
(
mBuffered
&&
listener
)
if
(
listener
->
mousePressed
(
MouseEvent
(
this
,
0
,
mState
),
ButtonMask
[
sdlButton
])
==
false
)
return
;
}
else
{
//mouse Wheel
mouseZMoved
=
true
;
if
(
sdlButton
==
SDL_BUTTON_WHEELUP
)
mState
.
relZ
+=
120
;
else
if
(
sdlButton
==
SDL_BUTTON_WHEELDOWN
)
mState
.
relZ
-=
120
;
}
break
;
}
case
SDL_MOUSEBUTTONUP
:
{
int
sdlButton
=
events
[
i
].
button
.
button
;
if
(
sdlButton
<=
SDL_BUTTON_RIGHT
)
{
//Left, Right, or Middle
mState
.
buttons
&=
~
(
1
<<
ButtonMask
[
sdlButton
]);
if
(
mBuffered
&&
listener
)
if
(
listener
->
mouseReleased
(
MouseEvent
(
this
,
0
,
mState
),
ButtonMask
[
sdlButton
])
==
false
)
return
;
}
break
;
}
}
}
//Handle X/Y axis move
if
(
mouseXYMoved
)
{
SDL_GetMouseState
(
&
mState
.
abX
,
&
mState
.
abY
);
SDL_GetRelativeMouseState
(
&
mState
.
relX
,
&
mState
.
relY
);
if
(
mBuffered
&&
listener
)
listener
->
mouseMoved
(
MouseEvent
(
this
,
0
,
mState
));
}
//Handle Z Motion
if
(
mouseZMoved
)
{
mState
.
abZ
+=
mState
.
relZ
;
if
(
mBuffered
&&
listener
)
listener
->
mouseMoved
(
MouseEvent
(
this
,
0
,
mState
));
}
//Handle Alt-Tabbing
SDLInputManager
*
man
=
static_cast
<
SDLInputManager
*>
(
InputManager
::
getSingletonPtr
());
if
(
man
->
_getGrabMode
()
==
false
)
{
if
(
mRegainFocus
==
false
&&
mGrabbed
==
true
)
{
//We had focus, but must release it now
_setGrab
(
false
);
_setVisible
(
true
);
}
else
if
(
mRegainFocus
==
true
&&
mGrabbed
==
false
)
{
//We are gaining focus back (mouse clicked in window)
_setGrab
(
true
);
_setVisible
(
false
);
man
->
_setGrabMode
(
true
);
//Notify manager
}
}
}
//-------------------------------------------------------------------//
void
SDLMouse
::
setBuffered
(
bool
buffered
)
{
mBuffered
=
buffered
;
}
//-------------------------------------------------------------------//
void
SDLMouse
::
_setGrab
(
bool
grabbed
)
{
if
(
grabbed
)
SDL_WM_GrabInput
(
SDL_GRAB_ON
);
else
SDL_WM_GrabInput
(
SDL_GRAB_OFF
);
mGrabbed
=
grabbed
;
}
//-------------------------------------------------------------------//
void
SDLMouse
::
_setVisible
(
bool
visible
)
{
if
(
visible
)
SDL_ShowCursor
(
SDL_ENABLE
);
else
SDL_ShowCursor
(
SDL_DISABLE
);
}
/*
The zlib/libpng License
Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL/SDLMouse.h"
#include "SDL/SDLInputManager.h"
#include "OISException.h"
#include "OISEvents.h"
using
namespace
OIS
;
//-------------------------------------------------------------------//
SDLMouse
::
SDLMouse
(
bool
buffered
)
:
mGrabbed
(
false
),
mRegainFocus
(
false
)
{
mBuffered
=
buffered
;
mType
=
OISMouse
;
listener
=
0
;
}
//-------------------------------------------------------------------//
void
SDLMouse
::
_initialize
()
{
//Clear old state
mState
.
clear
();
mRegainFocus
=
false
;
_setGrab
(
true
);
_setVisible
(
false
);
static_cast
<
SDLInputManager
*>
(
InputManager
::
getSingletonPtr
())
->
_setGrabMode
(
true
);
}
//-------------------------------------------------------------------//
SDLMouse
::~
SDLMouse
()
{
_setGrab
(
true
);
_setVisible
(
true
);
static_cast
<
SDLInputManager
*>
(
InputManager
::
getSingletonPtr
())
->
_setGrabMode
(
false
);
}
//-------------------------------------------------------------------//
void
SDLMouse
::
capture
()
{
//Used for going from SDL Button to OIS button
static
const
MouseButtonID
ButtonMask
[
4
]
=
{
MB_Left
,
MB_Left
,
MB_Middle
,
MB_Right
};
//Clear old relative values
mState
.
relX
=
mState
.
relY
=
mState
.
relZ
=
0
;
SDL_Event
events
[
OIS_SDL_MOUSE_BUFF
];
int
count
=
SDL_PeepEvents
(
events
,
OIS_SDL_MOUSE_BUFF
,
SDL_GETEVENT
,
SDL_MOUSEEVENTMASK
);
bool
mouseXYMoved
=
false
;
bool
mouseZMoved
=
false
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
switch
(
events
[
i
].
type
)
{
case
SDL_MOUSEMOTION
:
mouseXYMoved
=
true
;
break
;
case
SDL_MOUSEBUTTONDOWN
:
{
mRegainFocus
=
true
;
int
sdlButton
=
events
[
i
].
button
.
button
;
if
(
sdlButton
<=
SDL_BUTTON_RIGHT
)
{
//Left, Right, or Middle
mState
.
buttons
|=
(
1
<<
ButtonMask
[
sdlButton
]);
if
(
mBuffered
&&
listener
)
if
(
listener
->
mousePressed
(
MouseEvent
(
this
,
0
,
mState
),
ButtonMask
[
sdlButton
])
==
false
)
return
;
}
else
{
//mouse Wheel
mouseZMoved
=
true
;
if
(
sdlButton
==
SDL_BUTTON_WHEELUP
)
mState
.
relZ
+=
120
;
else
if
(
sdlButton
==
SDL_BUTTON_WHEELDOWN
)
mState
.
relZ
-=
120
;
}
break
;
}
case
SDL_MOUSEBUTTONUP
:
{
int
sdlButton
=
events
[
i
].
button
.
button
;
if
(
sdlButton
<=
SDL_BUTTON_RIGHT
)
{
//Left, Right, or Middle
mState
.
buttons
&=
~
(
1
<<
ButtonMask
[
sdlButton
]);
if
(
mBuffered
&&
listener
)
if
(
listener
->
mouseReleased
(
MouseEvent
(
this
,
0
,
mState
),
ButtonMask
[
sdlButton
])
==
false
)
return
;
}
break
;
}
}
}
//Handle X/Y axis move
if
(
mouseXYMoved
)
{
SDL_GetMouseState
(
&
mState
.
abX
,
&
mState
.
abY
);
SDL_GetRelativeMouseState
(
&
mState
.
relX
,
&
mState
.
relY
);
if
(
mBuffered
&&
listener
)
listener
->
mouseMoved
(
MouseEvent
(
this
,
0
,
mState
));
}
//Handle Z Motion
if
(
mouseZMoved
)
{
mState
.
abZ
+=
mState
.
relZ
;
if
(
mBuffered
&&
listener
)
listener
->
mouseMoved
(
MouseEvent
(
this
,
0
,
mState
));
}
//Handle Alt-Tabbing
SDLInputManager
*
man
=
static_cast
<
SDLInputManager
*>
(
InputManager
::
getSingletonPtr
());
if
(
man
->
_getGrabMode
()
==
false
)
{
if
(
mRegainFocus
==
false
&&
mGrabbed
==
true
)
{
//We had focus, but must release it now
_setGrab
(
false
);
_setVisible
(
true
);
}
else
if
(
mRegainFocus
==
true
&&
mGrabbed
==
false
)
{
//We are gaining focus back (mouse clicked in window)
_setGrab
(
true
);
_setVisible
(
false
);
man
->
_setGrabMode
(
true
);
//Notify manager
}
}
}
//-------------------------------------------------------------------//
void
SDLMouse
::
setBuffered
(
bool
buffered
)
{
mBuffered
=
buffered
;
}
//-------------------------------------------------------------------//
void
SDLMouse
::
_setGrab
(
bool
grabbed
)
{
if
(
grabbed
)
SDL_WM_GrabInput
(
SDL_GRAB_ON
);
else
SDL_WM_GrabInput
(
SDL_GRAB_OFF
);
mGrabbed
=
grabbed
;
}
//-------------------------------------------------------------------//
void
SDLMouse
::
_setVisible
(
bool
visible
)
{
if
(
visible
)
SDL_ShowCursor
(
SDL_ENABLE
);
else
SDL_ShowCursor
(
SDL_DISABLE
);
}
Prev
1
2
3
4
5
6
7
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment