SDL Input :

- Added the ability to change the default keymap
- A bit of cleanup

GTK : The SDL Input is working great. Though the config dialog is not updated yet, so it is disabled by default.

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@683 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2008-09-02 17:15:30 +00:00
parent a5a44bf925
commit caefe3bec2
6 changed files with 105 additions and 82 deletions

View File

@ -25,6 +25,7 @@
#include "../dmg/gbGlobals.h"
#include "../Util.h"
#include "../Sound.h"
#include "../sdl/inputSDL.h"
#include "window.h"
#include "intl.h"
@ -79,8 +80,9 @@ bool systemReadJoypads()
return true;
}
u32 systemReadJoypad(int)
u32 systemReadJoypad(int joy)
{
//return inputReadJoypad(joy);
return GUI()->uiReadJoypad();
}

View File

@ -907,6 +907,21 @@ void Window::vInitSDL()
abort();
}
inputSetKeymap(PAD_DEFAULT, KEY_LEFT, GDK_Left);
inputSetKeymap(PAD_DEFAULT, KEY_RIGHT, GDK_Right);
inputSetKeymap(PAD_DEFAULT, KEY_UP, GDK_Up);
inputSetKeymap(PAD_DEFAULT, KEY_DOWN, GDK_Down);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_A, GDK_z);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_B, GDK_x);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_START, GDK_Return);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_SELECT, GDK_BackSpace);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_L, GDK_a);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_R, GDK_s);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_SPEED, GDK_space);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_CAPTURE, GDK_F12);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_AUTO_A, GDK_q);
inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_AUTO_B, GDK_w);
// TODO : remove
int sdlNumDevices = SDL_NumJoysticks();
for (int i = 0; i < sdlNumDevices; i++)

View File

@ -1241,7 +1241,7 @@ bool Window::on_key_release_event(GdkEventKey * _pstEvent)
{
// Forward the keyboard event to the input module by faking a SDL event
SDL_Event event;
event.type = SDL_KEYDOWN;
event.type = SDL_KEYUP;
event.key.keysym.sym = (SDLKey)_pstEvent->keyval;
inputProcessSDLEvent(event);

View File

@ -546,117 +546,117 @@ void sdlReadPreferences(FILE *f)
}
if(!strcmp(key,"Joy0_Left")) {
inputSetKeymap(0, KEY_LEFT, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_LEFT, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Right")) {
inputSetKeymap(0, KEY_RIGHT, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_RIGHT, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Up")) {
inputSetKeymap(0, KEY_UP, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_UP, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Down")) {
inputSetKeymap(0, KEY_DOWN, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_DOWN, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_A")) {
inputSetKeymap(0, KEY_BUTTON_A, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_B")) {
inputSetKeymap(0, KEY_BUTTON_B, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_L")) {
inputSetKeymap(0, KEY_BUTTON_L, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_L, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_R")) {
inputSetKeymap(0, KEY_BUTTON_R, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_R, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Start")) {
inputSetKeymap(0, KEY_BUTTON_START, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_START, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Select")) {
inputSetKeymap(0, KEY_BUTTON_SELECT, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_SELECT, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Speed")) {
inputSetKeymap(0, KEY_BUTTON_SPEED, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_SPEED, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Capture")) {
inputSetKeymap(0, KEY_BUTTON_CAPTURE, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_CAPTURE, sdlFromHex(value));
} else if(!strcmp(key,"Joy1_Left")) {
inputSetKeymap(1, KEY_LEFT, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_LEFT, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Right")) {
inputSetKeymap(1, KEY_RIGHT, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_RIGHT, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Up")) {
inputSetKeymap(1, KEY_UP, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_UP, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Down")) {
inputSetKeymap(1, KEY_DOWN, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_DOWN, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_A")) {
inputSetKeymap(1, KEY_BUTTON_A, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_B")) {
inputSetKeymap(1, KEY_BUTTON_B, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_L")) {
inputSetKeymap(1, KEY_BUTTON_L, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_L, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_R")) {
inputSetKeymap(1, KEY_BUTTON_R, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_R, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Start")) {
inputSetKeymap(1, KEY_BUTTON_START, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_START, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Select")) {
inputSetKeymap(1, KEY_BUTTON_SELECT, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_SELECT, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Speed")) {
inputSetKeymap(1, KEY_BUTTON_SPEED, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_SPEED, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Capture")) {
inputSetKeymap(1, KEY_BUTTON_CAPTURE, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_CAPTURE, sdlFromHex(value));
} else if(!strcmp(key,"Joy2_Left")) {
inputSetKeymap(2, KEY_LEFT, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_LEFT, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Right")) {
inputSetKeymap(2, KEY_RIGHT, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_RIGHT, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Up")) {
inputSetKeymap(2, KEY_UP, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_UP, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Down")) {
inputSetKeymap(2, KEY_DOWN, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_DOWN, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_A")) {
inputSetKeymap(2, KEY_BUTTON_A, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_B")) {
inputSetKeymap(2, KEY_BUTTON_B, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_L")) {
inputSetKeymap(2, KEY_BUTTON_L, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_L, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_R")) {
inputSetKeymap(2, KEY_BUTTON_R, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_R, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Start")) {
inputSetKeymap(2, KEY_BUTTON_START, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_START, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Select")) {
inputSetKeymap(2, KEY_BUTTON_SELECT, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_SELECT, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Speed")) {
inputSetKeymap(2, KEY_BUTTON_SPEED, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_SPEED, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Capture")) {
inputSetKeymap(2, KEY_BUTTON_CAPTURE, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_CAPTURE, sdlFromHex(value));
} else if(!strcmp(key,"Joy3_Left")) {
inputSetKeymap(3, KEY_LEFT, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_LEFT, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Right")) {
inputSetKeymap(3, KEY_RIGHT, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_RIGHT, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Up")) {
inputSetKeymap(3, KEY_UP, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_UP, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Down")) {
inputSetKeymap(3, KEY_DOWN, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_DOWN, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_A")) {
inputSetKeymap(3, KEY_BUTTON_A, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_B")) {
inputSetKeymap(3, KEY_BUTTON_B, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_L")) {
inputSetKeymap(3, KEY_BUTTON_L, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_L, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_R")) {
inputSetKeymap(3, KEY_BUTTON_R, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_R, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Start")) {
inputSetKeymap(3, KEY_BUTTON_START, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_START, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Select")) {
inputSetKeymap(3, KEY_BUTTON_SELECT, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_SELECT, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Speed")) {
inputSetKeymap(3, KEY_BUTTON_SPEED, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_SPEED, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Capture")) {
inputSetKeymap(3, KEY_BUTTON_CAPTURE, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_CAPTURE, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_AutoA")) {
inputSetKeymap(0, KEY_BUTTON_AUTO_A, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_AUTO_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_AutoB")) {
inputSetKeymap(0, KEY_BUTTON_AUTO_B, sdlFromHex(value));
inputSetKeymap(PAD_1, KEY_BUTTON_AUTO_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_AutoA")) {
inputSetKeymap(1, KEY_BUTTON_AUTO_A, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_AUTO_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_AutoB")) {
inputSetKeymap(1, KEY_BUTTON_AUTO_B, sdlFromHex(value));
inputSetKeymap(PAD_2, KEY_BUTTON_AUTO_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_AutoA")) {
inputSetKeymap(2, KEY_BUTTON_AUTO_A, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_AUTO_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_AutoB")) {
inputSetKeymap(2, KEY_BUTTON_AUTO_B, sdlFromHex(value));
inputSetKeymap(PAD_3, KEY_BUTTON_AUTO_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_AutoA")) {
inputSetKeymap(3, KEY_BUTTON_AUTO_A, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_AUTO_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_AutoB")) {
inputSetKeymap(3, KEY_BUTTON_AUTO_B, sdlFromHex(value));
inputSetKeymap(PAD_4, KEY_BUTTON_AUTO_B, sdlFromHex(value));
} else if(!strcmp(key, "openGL")) {
openGL = sdlFromHex(value);
} else if(!strcmp(key, "Motion_Left")) {
@ -1620,7 +1620,7 @@ void lircCheckInput(void)
if (!sdlSoundToggledOff) {
sdlSoundToggledOff = 0x3ff;
}
}
}
} else if( strcmp( CmdLIRC, "VOLUP" ) == 0 ) {
sdlChangeVolume(0.1);
} else if( strcmp( CmdLIRC, "VOLDOWN" ) == 0 ) {

View File

@ -54,7 +54,11 @@ static int sdlDefaultJoypad = 0;
static int autoFire = 0;
static bool autoFireToggle = false;
static uint32_t joypad[4][SDLBUTTONS_NUM] = {
static uint32_t joypad[5][SDLBUTTONS_NUM] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ SDLK_LEFT, SDLK_RIGHT,
SDLK_UP, SDLK_DOWN,
SDLK_z, SDLK_x,
@ -62,20 +66,7 @@ static uint32_t joypad[4][SDLBUTTONS_NUM] = {
SDLK_a, SDLK_s,
SDLK_SPACE, SDLK_F12,
SDLK_q, SDLK_w,
},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
static uint32_t defaultJoypad[SDLBUTTONS_NUM] = {
SDLK_LEFT, SDLK_RIGHT,
SDLK_UP, SDLK_DOWN,
SDLK_z, SDLK_x,
SDLK_RETURN,SDLK_BACKSPACE,
SDLK_a, SDLK_s,
SDLK_SPACE, SDLK_F12,
SDLK_q, SDLK_w
}
};
static uint32_t motion[4] = {
@ -147,9 +138,9 @@ uint32_t inputGetEventCode(const SDL_Event &event)
}
}
void inputSetKeymap(int joy, EKey key, uint32_t code)
void inputSetKeymap(EPad pad, EKey key, uint32_t code)
{
joypad[joy][key] = code;
joypad[pad][key] = code;
}
void inputSetMotionKeymap(EKey key, uint32_t code)
@ -365,17 +356,21 @@ static bool sdlCheckJoyKey(int key)
void inputInitJoysticks()
{
// The main joypad has to be entirely defined
for(int i = 0; i < SDLBUTTONS_NUM; i++) {
if (!joypad[PAD_MAIN][i])
joypad[PAD_MAIN][i] = joypad[PAD_DEFAULT][i];
}
sdlNumDevices = SDL_NumJoysticks();
if(sdlNumDevices)
sdlDevices = (SDL_Joystick **)calloc(1,sdlNumDevices *
sizeof(SDL_Joystick **));
int i;
bool usesJoy = false;
for(int j = 0; j < 4; j++) {
for(i = 0; i < SDLBUTTONS_NUM; i++) {
for(int i = 0; i < SDLBUTTONS_NUM; i++) {
int dev = joypad[j][i] >> 16;
if(dev) {
dev--;
@ -393,14 +388,14 @@ void inputInitJoysticks()
}
if(!ok)
joypad[j][i] = defaultJoypad[i];
joypad[j][i] = joypad[PAD_DEFAULT][i];
else
usesJoy = true;
}
}
}
for(i = 0; i < 4; i++) {
for(int i = 0; i < 4; i++) {
int dev = motion[i] >> 16;
if(dev) {
dev--;
@ -430,6 +425,8 @@ void inputInitJoysticks()
void inputProcessSDLEvent(const SDL_Event &event)
{
// fprintf(stdout, "%x\n", inputGetEventCode(event));
switch(event.type)
{
case SDL_KEYDOWN:

View File

@ -37,6 +37,15 @@ enum EKey {
KEY_BUTTON_AUTO_B
};
enum EPad {
PAD_MAIN,
PAD_1 = PAD_MAIN,
PAD_2,
PAD_3,
PAD_4,
PAD_DEFAULT
};
/**
* Init the joysticks needed by the keymap. Verify that the keymap is compatible
* with the joysticks. If it's not the case, revert to the default keymap.
@ -49,7 +58,7 @@ void inputInitJoysticks();
* @param key Emulated joypad button
* @param code Code defining an actual joypad / keyboard button
*/
void inputSetKeymap(int joy, EKey key, uint32_t code);
void inputSetKeymap(EPad pad, EKey key, uint32_t code);
/**
* Define which keys control motion detection emulation