- Removed the GDK input system
- Enabled SDL input
- SDL Keymaps are now loaded from the config files
- The keymap edit dialog is currently disabled

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@684 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2008-09-02 19:34:56 +00:00
parent caefe3bec2
commit 51f5510e0d
6 changed files with 82 additions and 199 deletions

View File

@ -82,8 +82,7 @@ bool systemReadJoypads()
u32 systemReadJoypad(int joy)
{
//return inputReadJoypad(joy);
return GUI()->uiReadJoypad();
return inputReadJoypad(joy);
}
void systemShowSpeed(int _iSpeed)

View File

@ -31,7 +31,6 @@
#include "../dmg/gbPrinter.h"
#include "../Sound.h"
#include "../Util.h"
#include "../sdl/inputSDL.h"
#include "tools.h"
#include "intl.h"
@ -61,6 +60,24 @@ using Gnome::Glade::Xml;
Window * Window::m_poInstance = NULL;
const Window::SJoypadKey Window::m_astJoypad[SDLBUTTONS_NUM] =
{
{ "left", KEY_LEFT },
{ "right", KEY_RIGHT },
{ "up", KEY_UP },
{ "down", KEY_DOWN },
{ "A", KEY_BUTTON_A },
{ "B", KEY_BUTTON_B },
{ "select", KEY_BUTTON_SELECT },
{ "start", KEY_BUTTON_START },
{ "L", KEY_BUTTON_L },
{ "R", KEY_BUTTON_R },
{ "speed", KEY_BUTTON_SPEED },
{ "capture", KEY_BUTTON_CAPTURE },
{ "speed", KEY_BUTTON_SPEED },
{ "capture", KEY_BUTTON_CAPTURE }
};
Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
Gtk::Window (_pstWindow),
m_iGBScreenWidth (160),
@ -89,8 +106,8 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
m_iFilter2xMax (LastFilter),
m_iFilterIBMin (FirstFilterIB),
m_iFilterIBMax (LastFilterIB),
m_iJoypadMin (1),
m_iJoypadMax (4),
m_iJoypadMin (PAD_1),
m_iJoypadMax (PAD_4),
m_iVideoOutputMin (OutputCairo),
m_iVideoOutputMax (OutputXvideo),
m_bFullscreen (false)
@ -100,8 +117,6 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
m_iScreenWidth = m_iGBAScreenWidth;
m_iScreenHeight = m_iGBAScreenHeight;
m_eCartridge = CartridgeNone;
m_uiJoypadState = 0;
m_uiAutofireState = 0;
vInitSDL();
vInitSystem();
@ -697,7 +712,7 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
poMI->signal_activate().connect(sigc::bind(
sigc::mem_fun(*this, &Window::vOnJoypadConfigure), 4));
int iDefaultJoypad = m_poInputConfig->oGetKey<int>("active_joypad");
/*int iDefaultJoypad = m_poInputConfig->oGetKey<int>("active_joypad");
for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++)
{
char csName[20];
@ -712,11 +727,11 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
poCMI->signal_toggled().connect(sigc::bind(
sigc::mem_fun(*this, &Window::vOnJoypadToggled),
poCMI, i));
}
}*/
// Autofire menu
//
struct
/*struct
{
const char * m_csName;
const char * m_csKey;
@ -737,7 +752,7 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
poCMI->signal_toggled().connect(sigc::bind(
sigc::mem_fun(*this, &Window::vOnAutofireToggled),
poCMI, astAutofire[i].m_eKeyFlag));
}
}*/
// Fullscreen menu
//
@ -991,27 +1006,19 @@ void Window::vInitConfig()
// Input section
//
JoypadConfig oJoypadConfig;
oJoypadConfig.vSetDefault();
m_poInputConfig = m_oConfig.poAddSection("Input");
m_poInputConfig->vSetKey("active_joypad", m_iJoypadMin );
for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++)
{
char csPrefix[20];
snprintf(csPrefix, sizeof(csPrefix), "joypad%d_", i);
snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i);
std::string sPrefix(csPrefix);
m_poInputConfig->vSetKey(sPrefix + "up", oJoypadConfig.m_uiUp );
m_poInputConfig->vSetKey(sPrefix + "down", oJoypadConfig.m_uiDown );
m_poInputConfig->vSetKey(sPrefix + "left", oJoypadConfig.m_uiLeft );
m_poInputConfig->vSetKey(sPrefix + "right", oJoypadConfig.m_uiRight );
m_poInputConfig->vSetKey(sPrefix + "A", oJoypadConfig.m_uiA );
m_poInputConfig->vSetKey(sPrefix + "B", oJoypadConfig.m_uiB );
m_poInputConfig->vSetKey(sPrefix + "L", oJoypadConfig.m_uiL );
m_poInputConfig->vSetKey(sPrefix + "R", oJoypadConfig.m_uiR );
m_poInputConfig->vSetKey(sPrefix + "select", oJoypadConfig.m_uiSelect );
m_poInputConfig->vSetKey(sPrefix + "start", oJoypadConfig.m_uiStart );
m_poInputConfig->vSetKey(sPrefix + "speed", oJoypadConfig.m_uiSpeed );
m_poInputConfig->vSetKey(sPrefix + "capture", oJoypadConfig.m_uiCapture );
for (int j = 0; j < SDLBUTTONS_NUM; j++)
{
m_poInputConfig->vSetKey(sPrefix + m_astJoypad[j].m_csKey,
inputGetKeymap(PAD_DEFAULT, m_astJoypad[j].m_eKeyFlag));
}
}
m_poInputConfig->vSetKey("autofire_A", false );
m_poInputConfig->vSetKey("autofire_B", false );
@ -1206,29 +1213,17 @@ void Window::vHistoryAdd(const std::string & _rsFile)
void Window::vLoadJoypadsFromConfig()
{
m_oJoypads.clear();
for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++)
{
char csPrefix[20];
snprintf(csPrefix, sizeof(csPrefix), "joypad%d_", i);
snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i);
std::string sPrefix(csPrefix);
JoypadConfig oJoypadConfig;
oJoypadConfig.m_uiUp = m_poInputConfig->oGetKey<guint>(sPrefix + "up");
oJoypadConfig.m_uiDown = m_poInputConfig->oGetKey<guint>(sPrefix + "down");
oJoypadConfig.m_uiLeft = m_poInputConfig->oGetKey<guint>(sPrefix + "left");
oJoypadConfig.m_uiRight = m_poInputConfig->oGetKey<guint>(sPrefix + "right");
oJoypadConfig.m_uiA = m_poInputConfig->oGetKey<guint>(sPrefix + "A");
oJoypadConfig.m_uiB = m_poInputConfig->oGetKey<guint>(sPrefix + "B");
oJoypadConfig.m_uiL = m_poInputConfig->oGetKey<guint>(sPrefix + "L");
oJoypadConfig.m_uiR = m_poInputConfig->oGetKey<guint>(sPrefix + "R");
oJoypadConfig.m_uiSelect = m_poInputConfig->oGetKey<guint>(sPrefix + "select");
oJoypadConfig.m_uiStart = m_poInputConfig->oGetKey<guint>(sPrefix + "start");
oJoypadConfig.m_uiSpeed = m_poInputConfig->oGetKey<guint>(sPrefix + "speed");
oJoypadConfig.m_uiCapture = m_poInputConfig->oGetKey<guint>(sPrefix + "capture");
m_oJoypads.push_back(oJoypadConfig);
for (int j = 0; j < SDLBUTTONS_NUM; j++)
{
inputSetKeymap((EPad)i, m_astJoypad[j].m_eKeyFlag,
m_poInputConfig->oGetKey<guint>(sPrefix + m_astJoypad[j].m_csKey));
}
}
}
@ -1237,21 +1232,14 @@ void Window::vSaveJoypadsToConfig()
for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++)
{
char csPrefix[20];
snprintf(csPrefix, sizeof(csPrefix), "joypad%d_", i);
snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i);
std::string sPrefix(csPrefix);
m_poInputConfig->vSetKey(sPrefix + "up", m_oJoypads[i - 1].m_uiUp );
m_poInputConfig->vSetKey(sPrefix + "down", m_oJoypads[i - 1].m_uiDown );
m_poInputConfig->vSetKey(sPrefix + "left", m_oJoypads[i - 1].m_uiLeft );
m_poInputConfig->vSetKey(sPrefix + "right", m_oJoypads[i - 1].m_uiRight );
m_poInputConfig->vSetKey(sPrefix + "A", m_oJoypads[i - 1].m_uiA );
m_poInputConfig->vSetKey(sPrefix + "B", m_oJoypads[i - 1].m_uiB );
m_poInputConfig->vSetKey(sPrefix + "L", m_oJoypads[i - 1].m_uiL );
m_poInputConfig->vSetKey(sPrefix + "R", m_oJoypads[i - 1].m_uiR );
m_poInputConfig->vSetKey(sPrefix + "select", m_oJoypads[i - 1].m_uiSelect );
m_poInputConfig->vSetKey(sPrefix + "start", m_oJoypads[i - 1].m_uiStart );
m_poInputConfig->vSetKey(sPrefix + "speed", m_oJoypads[i - 1].m_uiSpeed );
m_poInputConfig->vSetKey(sPrefix + "capture", m_oJoypads[i - 1].m_uiCapture );
for (int j = 0; j < SDLBUTTONS_NUM; j++)
{
m_poInputConfig->vSetKey(sPrefix + m_astJoypad[j].m_csKey,
inputGetKeymap((EPad)i, m_astJoypad[j].m_eKeyFlag));
}
}
}
@ -1551,23 +1539,6 @@ void Window::vCaptureScreen(int _iNum)
g_free(csFile);
}
u32 Window::uiReadJoypad()
{
u32 uiJoypad = m_uiJoypadState;
if (m_uiAutofireState != 0)
{
uiJoypad &= ~m_uiAutofireState;
if (m_bAutofireToggle)
{
uiJoypad |= m_uiAutofireState;
}
m_bAutofireToggle = ! m_bAutofireToggle;
}
return uiJoypad;
}
void Window::vCreateFileOpenDialog()
{
if (m_poFileOpenDialog != NULL)

View File

@ -31,12 +31,12 @@
#include <list>
#include "../System.h"
#include "../sdl/inputSDL.h"
#include "configfile.h"
#include "screenarea.h"
#include "filters.h"
#include "input.h"
#include "joypadconfig.h"
//#include "joypadconfig.h"
namespace VBA
{
@ -72,7 +72,6 @@ public:
void vComputeFrameskip(int _iRate);
void vShowSpeed(int _iSpeed);
void vCaptureScreen(int _iNum);
u32 uiReadJoypad();
inline ECartridge eGetCartridge() const { return m_eCartridge; }
@ -206,8 +205,8 @@ private:
const int m_iFilter2xMax;
const int m_iFilterIBMin;
const int m_iFilterIBMax;
const int m_iJoypadMin;
const int m_iJoypadMax;
const EPad m_iJoypadMin;
const EPad m_iJoypadMax;
const int m_iVideoOutputMin;
const int m_iVideoOutputMax;
@ -239,6 +238,14 @@ private:
time_t m_uiTime;
};
struct SJoypadKey
{
const char * m_csKey;
const EKey m_eKeyFlag;
};
static const SJoypadKey m_astJoypad[SDLBUTTONS_NUM];
Gtk::MenuItem * m_apoLoadGameItem[10];
Gtk::MenuItem * m_apoSaveGameItem[10];
SGameSlot m_astGameSlot[10];
@ -251,9 +258,6 @@ private:
sigc::connection m_oEmuSig;
std::vector<JoypadConfig> m_oJoypads;
Keymap m_oKeymap;
int m_bFullscreen;
int m_iScreenWidth;
int m_iScreenHeight;
@ -261,9 +265,6 @@ private:
std::string m_sRomFile;
ECartridge m_eCartridge;
EmulatedSystem m_stEmulator;
u32 m_uiJoypadState;
u32 m_uiAutofireState;
bool m_bAutofireToggle;
bool m_bPaused;
bool m_bWasEmulating;
bool m_bAutoFrameskip;

View File

@ -861,7 +861,7 @@ void Window::vOnFilterIBToggled(Gtk::CheckMenuItem * _poCMI, int _iFilterIB)
void Window::vOnJoypadConfigure(int _iJoypad)
{
Glib::RefPtr<Xml> poXml;
/* Glib::RefPtr<Xml> poXml;
poXml = Xml::create(PKGDATADIR "/vba.glade", "JoypadConfigDialog");
JoypadConfigDialog * poDialog = NULL;
@ -878,24 +878,24 @@ void Window::vOnJoypadConfigure(int _iJoypad)
}
}
delete poDialog;
delete poDialog;*/
}
void Window::vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, int _iJoypad)
{
if (! _poCMI->get_active())
/* if (! _poCMI->get_active())
{
return;
}
m_oKeymap = m_oJoypads[_iJoypad - 1].oCreateKeymap();
m_poInputConfig->vSetKey("active_joypad", _iJoypad);
m_poInputConfig->vSetKey("active_joypad", _iJoypad);*/
}
void Window::vOnAutofireToggled(Gtk::CheckMenuItem * _poCMI, u32 _uiKeyFlag)
{
if (_poCMI->get_active())
/* if (_poCMI->get_active())
{
m_uiAutofireState |= _uiKeyFlag;
}
@ -921,7 +921,7 @@ void Window::vOnAutofireToggled(Gtk::CheckMenuItem * _poCMI, u32 _uiKeyFlag)
{
sKey = "autofire_R";
}
m_poInputConfig->vSetKey(sKey, _poCMI->get_active());
m_poInputConfig->vSetKey(sKey, _poCMI->get_active());*/
}
#ifndef NO_DEBUGGER
@ -1168,8 +1168,6 @@ bool Window::on_focus_out_event(GdkEventFocus * _pstEvent)
bool Window::on_key_press_event(GdkEventKey * _pstEvent)
{
EKey eKey;
// The menu accelerators are disabled when it is hidden
if (_pstEvent->keyval == GDK_F11 && !m_poMenuBar->is_visible())
{
@ -1183,58 +1181,7 @@ bool Window::on_key_press_event(GdkEventKey * _pstEvent)
event.key.keysym.sym = (SDLKey)_pstEvent->keyval;
inputProcessSDLEvent(event);
if ((_pstEvent->state & Gtk::AccelGroup::get_default_mod_mask())
|| (eKey = m_oKeymap[_pstEvent->hardware_keycode]) == KeyNone)
{
return Gtk::Window::on_key_press_event(_pstEvent);
}
switch (eKey)
{
case KeyA:
m_uiJoypadState |= KeyFlagA;
break;
case KeyB:
m_uiJoypadState |= KeyFlagB;
break;
case KeySelect:
m_uiJoypadState |= KeyFlagSelect;
break;
case KeyStart:
m_uiJoypadState |= KeyFlagStart;
break;
case KeyRight:
m_uiJoypadState |= KeyFlagRight;
m_uiJoypadState &= ~KeyFlagLeft;
break;
case KeyLeft:
m_uiJoypadState |= KeyFlagLeft;
m_uiJoypadState &= ~KeyFlagRight;
break;
case KeyUp:
m_uiJoypadState |= KeyFlagUp;
m_uiJoypadState &= ~KeyFlagDown;
break;
case KeyDown:
m_uiJoypadState |= KeyFlagDown;
m_uiJoypadState &= ~KeyFlagUp;
break;
case KeyR:
m_uiJoypadState |= KeyFlagR;
break;
case KeyL:
m_uiJoypadState |= KeyFlagL;
break;
case KeySpeed:
m_uiJoypadState |= KeyFlagSpeed;
break;
case KeyCapture:
m_uiJoypadState |= KeyFlagCapture;
break;
case KeyNone:
break;
}
return true;
}
bool Window::on_key_release_event(GdkEventKey * _pstEvent)
@ -1245,56 +1192,8 @@ bool Window::on_key_release_event(GdkEventKey * _pstEvent)
event.key.keysym.sym = (SDLKey)_pstEvent->keyval;
inputProcessSDLEvent(event);
EKey eKey;
if ((_pstEvent->state & Gtk::AccelGroup::get_default_mod_mask())
|| (eKey = m_oKeymap[_pstEvent->hardware_keycode]) == KeyNone)
{
return Gtk::Window::on_key_release_event(_pstEvent);
}
switch (eKey)
{
case KeyA:
m_uiJoypadState &= ~KeyFlagA;
break;
case KeyB:
m_uiJoypadState &= ~KeyFlagB;
break;
case KeySelect:
m_uiJoypadState &= ~KeyFlagSelect;
break;
case KeyStart:
m_uiJoypadState &= ~KeyFlagStart;
break;
case KeyRight:
m_uiJoypadState &= ~KeyFlagRight;
break;
case KeyLeft:
m_uiJoypadState &= ~KeyFlagLeft;
break;
case KeyUp:
m_uiJoypadState &= ~KeyFlagUp;
break;
case KeyDown:
m_uiJoypadState &= ~KeyFlagDown;
break;
case KeyR:
m_uiJoypadState &= ~KeyFlagR;
break;
case KeyL:
m_uiJoypadState &= ~KeyFlagL;
break;
case KeySpeed:
m_uiJoypadState &= ~KeyFlagSpeed;
break;
case KeyCapture:
m_uiJoypadState &= ~KeyFlagCapture;
break;
case KeyNone:
break;
}
return true;
}
bool Window::on_window_state_event(GdkEventWindowState* _pstEvent)

View File

@ -17,8 +17,6 @@
#include "inputSDL.h"
#define SDLBUTTONS_NUM 14
static void sdlUpdateKey(uint32_t key, bool down);
static void sdlUpdateJoyButton(int which, int button, bool pressed);
static void sdlUpdateJoyHat(int which, int hat, int value);
@ -138,6 +136,11 @@ uint32_t inputGetEventCode(const SDL_Event &event)
}
}
uint32_t inputGetKeymap(EPad pad, EKey key)
{
return joypad[pad][key];
}
void inputSetKeymap(EPad pad, EKey key, uint32_t code)
{
joypad[pad][key] = code;

View File

@ -20,6 +20,8 @@
#include <SDL.h>
#define SDLBUTTONS_NUM 14
enum EKey {
KEY_LEFT,
KEY_RIGHT,
@ -54,12 +56,20 @@ void inputInitJoysticks();
/**
* Define which key controls an emulated joypad button
* @param joy Emulated joypad index (there may be up to 4 joypads for the SGB)
* @param pad Emulated joypad index (there may be up to 4 joypads for the SGB)
* @param key Emulated joypad button
* @param code Code defining an actual joypad / keyboard button
*/
void inputSetKeymap(EPad pad, EKey key, uint32_t code);
/**
* Get which key is associated to which emulated joypad button
* @param pad Emulated joypad index (there may be up to 4 joypads for the SGB)
* @param key Emulated joypad button
* @retunr Code defining an actual joypad / keyboard button
*/
uint32_t inputGetKeymap(EPad pad, EKey key);
/**
* Define which keys control motion detection emulation
* @param key Emulated joypad button