SDL Input : Added a function to compute the keymap value from a SDL event. Will be used in the config dialog.

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@673 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2008-08-31 17:21:27 +00:00
parent b1d136df32
commit f67af04ed7
2 changed files with 66 additions and 1 deletions

View File

@ -89,6 +89,64 @@ uint16_t defaultMotion[4] = {
int sensorX = 2047;
int sensorY = 2047;
static uint16_t sdlGetHatCode(const SDL_Event &event)
{
return (
((event.jhat.which + 1) << 12) |
(event.jhat.hat << 2) |
(
event.jhat.value & SDL_HAT_UP ? 0 :
event.jhat.value & SDL_HAT_DOWN ? 1 :
event.jhat.value & SDL_HAT_RIGHT ? 2 :
event.jhat.value & SDL_HAT_LEFT ? 3 : 0
)
);
}
static uint16_t sdlGetButtonCode(const SDL_Event &event)
{
return (
((event.jbutton.which + 1) << 12) |
(event.jbutton.button + 0x80)
);
}
static uint16_t sdlGetAxisCode(const SDL_Event &event)
{
return (
((event.jaxis.which + 1) << 12) |
(event.jaxis.axis << 1) |
(
event.jaxis.value > 16384 ? 1 :
event.jaxis.value < -16384 ? 0 : 0
)
);
}
uint16_t inputGetEventCode(const SDL_Event &event)
{
switch(event.type)
{
case SDL_KEYDOWN:
case SDL_KEYUP:
return event.key.keysym.sym;
break;
case SDL_JOYHATMOTION:
return sdlGetHatCode(event);
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
return sdlGetButtonCode(event);
break;
case SDL_JOYAXISMOTION:
return sdlGetAxisCode(event);
break;
default:
return 0;
break;
}
}
void inputSetKeymap(int joy, EKey key, uint16_t code)
{
joypad[joy][key] = code;

View File

@ -66,11 +66,18 @@ void inputSetMotionKeymap(EKey key, uint16_t code);
bool inputToggleAutoFire(EKey key);
/**
* Update the emulated pads state with an SDL event
* Update the emulated pads state with a SDL event
* @param SDL_Event An event that has just occured
*/
void inputProcessSDLEvent(const SDL_Event &event);
/**
* Get the keymap code corresponding to a SDL event
* @param SDL_Event An event that has just occured
* @return Keymap code
*/
uint16_t inputGetEventCode(const SDL_Event &event);
/**
* Read the state of an emulated joypad
* @param which Emulated joypad index