GTK :
- Rewrote the joypad config dialog in plain gtkmm instead of libglade - A bit of cleanup git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@705 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
parent
0f7da3dfdd
commit
0cf6786458
|
@ -25,45 +25,34 @@
|
||||||
namespace VBA
|
namespace VBA
|
||||||
{
|
{
|
||||||
|
|
||||||
const EKey JoypadConfigDialog::m_aeKeys[] =
|
const JoypadConfigDialog::SJoypadKey JoypadConfigDialog::m_astKeys[] =
|
||||||
{
|
{
|
||||||
KEY_UP,
|
{ KEY_UP, "Up :" },
|
||||||
KEY_DOWN,
|
{ KEY_DOWN, "Down :" },
|
||||||
KEY_LEFT,
|
{ KEY_LEFT, "Left :" },
|
||||||
KEY_RIGHT,
|
{ KEY_RIGHT, "Right :" },
|
||||||
KEY_BUTTON_A,
|
{ KEY_BUTTON_A, "Button A :" },
|
||||||
KEY_BUTTON_B,
|
{ KEY_BUTTON_B, "Button B :" },
|
||||||
KEY_BUTTON_L,
|
{ KEY_BUTTON_L, "Button L :" },
|
||||||
KEY_BUTTON_R,
|
{ KEY_BUTTON_R, "Button R :" },
|
||||||
KEY_BUTTON_SELECT,
|
{ KEY_BUTTON_SELECT, "Select :" },
|
||||||
KEY_BUTTON_START,
|
{ KEY_BUTTON_START, "Start :" },
|
||||||
KEY_BUTTON_SPEED,
|
{ KEY_BUTTON_SPEED, "Speed :" },
|
||||||
KEY_BUTTON_CAPTURE
|
{ KEY_BUTTON_CAPTURE, "Capture :" }
|
||||||
};
|
};
|
||||||
|
|
||||||
JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog,
|
JoypadConfigDialog::JoypadConfigDialog() :
|
||||||
const Glib::RefPtr<Gnome::Glade::Xml> & _poXml) :
|
Gtk::Dialog("Joypad config", true, true),
|
||||||
Gtk::Dialog(_pstDialog),
|
m_oTable(G_N_ELEMENTS(m_astKeys), 2, false),
|
||||||
m_ePad(PAD_MAIN)
|
m_ePad(PAD_MAIN)
|
||||||
{
|
{
|
||||||
m_poOkButton = dynamic_cast<Gtk::Button *>(_poXml->get_widget("JoypadOkButton"));
|
for (guint i = 0; i < G_N_ELEMENTS(m_astKeys); i++)
|
||||||
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadUpEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadDownEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadLeftEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadRightEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadAEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadBEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadLEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadREntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadSelectEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadStartEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadSpeedEntry")));
|
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadCaptureEntry")));
|
|
||||||
|
|
||||||
for (guint i = 0; i < m_oEntries.size(); i++)
|
|
||||||
{
|
{
|
||||||
Gtk::Entry * poEntry = m_oEntries[i];
|
Gtk::Label * poLabel = Gtk::manage( new Gtk::Label(m_astKeys[i].m_csKeyName, Gtk::ALIGN_RIGHT) );
|
||||||
|
Gtk::Entry * poEntry = Gtk::manage( new Gtk::Entry() );
|
||||||
|
m_oTable.attach(* poLabel, 0, 1, i, i + 1);
|
||||||
|
m_oTable.attach(* poEntry, 1, 2, i, i + 1);
|
||||||
|
m_oEntries.push_back(poEntry);
|
||||||
|
|
||||||
poEntry->signal_focus_in_event().connect(sigc::bind(
|
poEntry->signal_focus_in_event().connect(sigc::bind(
|
||||||
sigc::mem_fun(*this, &JoypadConfigDialog::bOnEntryFocusIn),
|
sigc::mem_fun(*this, &JoypadConfigDialog::bOnEntryFocusIn),
|
||||||
|
@ -71,9 +60,18 @@ JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog,
|
||||||
poEntry->signal_focus_out_event().connect(sigc::mem_fun(*this, &JoypadConfigDialog::bOnEntryFocusOut));
|
poEntry->signal_focus_out_event().connect(sigc::mem_fun(*this, &JoypadConfigDialog::bOnEntryFocusOut));
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&m_oPreviousEvent, 0, sizeof(m_oPreviousEvent));
|
Gtk::VBox* poVBox = get_vbox();
|
||||||
|
poVBox->pack_start(m_oTable);
|
||||||
|
|
||||||
|
m_oTable.set_border_width(5);
|
||||||
|
m_oTable.set_spacings(5);
|
||||||
|
|
||||||
|
m_poOkButton = add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
|
||||||
|
|
||||||
|
show_all();
|
||||||
|
|
||||||
vEmptyEventQueue();
|
vEmptyEventQueue();
|
||||||
|
memset(&m_oPreviousEvent, 0, sizeof(m_oPreviousEvent));
|
||||||
|
|
||||||
m_oConfigSig = Glib::signal_idle().connect(sigc::mem_fun(*this, &JoypadConfigDialog::bOnConfigIdle),
|
m_oConfigSig = Glib::signal_idle().connect(sigc::mem_fun(*this, &JoypadConfigDialog::bOnConfigIdle),
|
||||||
Glib::PRIORITY_DEFAULT_IDLE);
|
Glib::PRIORITY_DEFAULT_IDLE);
|
||||||
|
@ -96,7 +94,7 @@ void JoypadConfigDialog::vUpdateEntries()
|
||||||
{
|
{
|
||||||
const char * csName = 0;
|
const char * csName = 0;
|
||||||
|
|
||||||
guint uiKeyval = inputGetKeymap(m_ePad, m_aeKeys[i]);
|
guint uiKeyval = inputGetKeymap(m_ePad, m_astKeys[i].m_eKeyFlag);
|
||||||
int dev = uiKeyval >> 16;
|
int dev = uiKeyval >> 16;
|
||||||
if (dev == 0)
|
if (dev == 0)
|
||||||
{
|
{
|
||||||
|
@ -182,7 +180,7 @@ void JoypadConfigDialog::vOnInputEvent(const SDL_Event &event)
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = inputGetEventCode(event);
|
int code = inputGetEventCode(event);
|
||||||
inputSetKeymap(m_ePad, m_aeKeys[m_iCurrentEntry], code);
|
inputSetKeymap(m_ePad, m_astKeys[m_iCurrentEntry].m_eKeyFlag, code);
|
||||||
vUpdateEntries();
|
vUpdateEntries();
|
||||||
|
|
||||||
if (m_iCurrentEntry + 1 < (gint)m_oEntries.size())
|
if (m_iCurrentEntry + 1 < (gint)m_oEntries.size())
|
||||||
|
|
|
@ -33,8 +33,7 @@ namespace VBA
|
||||||
class JoypadConfigDialog : public Gtk::Dialog
|
class JoypadConfigDialog : public Gtk::Dialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JoypadConfigDialog(GtkDialog * _pstDialog,
|
JoypadConfigDialog();
|
||||||
const Glib::RefPtr<Gnome::Glade::Xml> & _poXml);
|
|
||||||
virtual ~JoypadConfigDialog();
|
virtual ~JoypadConfigDialog();
|
||||||
|
|
||||||
void vInitDialog(EPad _ePad);
|
void vInitDialog(EPad _ePad);
|
||||||
|
@ -46,10 +45,17 @@ protected:
|
||||||
bool on_key_press_event(GdkEventKey * _pstEvent);
|
bool on_key_press_event(GdkEventKey * _pstEvent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct SJoypadKey
|
||||||
|
{
|
||||||
|
const EKey m_eKeyFlag;
|
||||||
|
const char * m_csKeyName;
|
||||||
|
};
|
||||||
|
|
||||||
|
Gtk::Table m_oTable;
|
||||||
Gtk::Button * m_poOkButton;
|
Gtk::Button * m_poOkButton;
|
||||||
std::vector<Gtk::Entry *> m_oEntries;
|
std::vector<Gtk::Entry *> m_oEntries;
|
||||||
gint m_iCurrentEntry;
|
gint m_iCurrentEntry;
|
||||||
static const EKey m_aeKeys[];
|
static const SJoypadKey m_astKeys[];
|
||||||
sigc::connection m_oConfigSig;
|
sigc::connection m_oConfigSig;
|
||||||
SDL_Event m_oPreviousEvent;
|
SDL_Event m_oPreviousEvent;
|
||||||
EPad m_ePad;
|
EPad m_ePad;
|
||||||
|
|
|
@ -61,7 +61,7 @@ using Gnome::Glade::Xml;
|
||||||
|
|
||||||
Window * Window::m_poInstance = NULL;
|
Window * Window::m_poInstance = NULL;
|
||||||
|
|
||||||
const Window::SJoypadKey Window::m_astJoypad[SDLBUTTONS_NUM] =
|
const Window::SJoypadKey Window::m_astJoypad[] =
|
||||||
{
|
{
|
||||||
{ "left", KEY_LEFT },
|
{ "left", KEY_LEFT },
|
||||||
{ "right", KEY_RIGHT },
|
{ "right", KEY_RIGHT },
|
||||||
|
@ -1015,7 +1015,7 @@ void Window::vInitConfig()
|
||||||
snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i);
|
snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i);
|
||||||
std::string sPrefix(csPrefix);
|
std::string sPrefix(csPrefix);
|
||||||
|
|
||||||
for (int j = 0; j < SDLBUTTONS_NUM; j++)
|
for (guint j = 0; j < G_N_ELEMENTS(m_astJoypad); j++)
|
||||||
{
|
{
|
||||||
m_poInputConfig->vSetKey(sPrefix + m_astJoypad[j].m_csKey,
|
m_poInputConfig->vSetKey(sPrefix + m_astJoypad[j].m_csKey,
|
||||||
inputGetKeymap(PAD_DEFAULT, m_astJoypad[j].m_eKeyFlag));
|
inputGetKeymap(PAD_DEFAULT, m_astJoypad[j].m_eKeyFlag));
|
||||||
|
@ -1220,7 +1220,7 @@ void Window::vLoadJoypadsFromConfig()
|
||||||
snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i);
|
snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i);
|
||||||
std::string sPrefix(csPrefix);
|
std::string sPrefix(csPrefix);
|
||||||
|
|
||||||
for (int j = 0; j < SDLBUTTONS_NUM; j++)
|
for (guint j = 0; j < G_N_ELEMENTS(m_astJoypad); j++)
|
||||||
{
|
{
|
||||||
inputSetKeymap((EPad)i, m_astJoypad[j].m_eKeyFlag,
|
inputSetKeymap((EPad)i, m_astJoypad[j].m_eKeyFlag,
|
||||||
m_poInputConfig->oGetKey<guint>(sPrefix + m_astJoypad[j].m_csKey));
|
m_poInputConfig->oGetKey<guint>(sPrefix + m_astJoypad[j].m_csKey));
|
||||||
|
@ -1236,7 +1236,7 @@ void Window::vSaveJoypadsToConfig()
|
||||||
snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i);
|
snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i);
|
||||||
std::string sPrefix(csPrefix);
|
std::string sPrefix(csPrefix);
|
||||||
|
|
||||||
for (int j = 0; j < SDLBUTTONS_NUM; j++)
|
for (guint j = 0; j < G_N_ELEMENTS(m_astJoypad); j++)
|
||||||
{
|
{
|
||||||
m_poInputConfig->vSetKey(sPrefix + m_astJoypad[j].m_csKey,
|
m_poInputConfig->vSetKey(sPrefix + m_astJoypad[j].m_csKey,
|
||||||
inputGetKeymap((EPad)i, m_astJoypad[j].m_eKeyFlag));
|
inputGetKeymap((EPad)i, m_astJoypad[j].m_eKeyFlag));
|
||||||
|
|
|
@ -243,7 +243,7 @@ private:
|
||||||
const EKey m_eKeyFlag;
|
const EKey m_eKeyFlag;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const SJoypadKey m_astJoypad[SDLBUTTONS_NUM];
|
static const SJoypadKey m_astJoypad[];
|
||||||
|
|
||||||
Gtk::MenuItem * m_apoLoadGameItem[10];
|
Gtk::MenuItem * m_apoLoadGameItem[10];
|
||||||
Gtk::MenuItem * m_apoSaveGameItem[10];
|
Gtk::MenuItem * m_apoSaveGameItem[10];
|
||||||
|
|
|
@ -863,17 +863,11 @@ void Window::vOnFilterIBToggled(Gtk::CheckMenuItem * _poCMI, int _iFilterIB)
|
||||||
|
|
||||||
void Window::vOnJoypadConfigure(EPad _eJoypad)
|
void Window::vOnJoypadConfigure(EPad _eJoypad)
|
||||||
{
|
{
|
||||||
Glib::RefPtr<Xml> poXml;
|
JoypadConfigDialog oDialog;
|
||||||
poXml = Xml::create(PKGDATADIR "/vba.glade", "JoypadConfigDialog");
|
oDialog.set_transient_for(*this);
|
||||||
|
oDialog.vInitDialog(_eJoypad);
|
||||||
|
|
||||||
JoypadConfigDialog * poDialog = NULL;
|
oDialog.run();
|
||||||
poXml->get_widget_derived<JoypadConfigDialog>("JoypadConfigDialog", poDialog);
|
|
||||||
poDialog->set_transient_for(*this);
|
|
||||||
poDialog->vInitDialog(_eJoypad);
|
|
||||||
|
|
||||||
poDialog->run();
|
|
||||||
|
|
||||||
delete poDialog;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, EPad _eJoypad)
|
void Window::vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, EPad _eJoypad)
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#include "inputSDL.h"
|
#include "inputSDL.h"
|
||||||
|
|
||||||
|
#define SDLBUTTONS_NUM 14
|
||||||
|
|
||||||
static void sdlUpdateKey(uint32_t key, bool down);
|
static void sdlUpdateKey(uint32_t key, bool down);
|
||||||
static void sdlUpdateJoyButton(int which, int button, bool pressed);
|
static void sdlUpdateJoyButton(int which, int button, bool pressed);
|
||||||
static void sdlUpdateJoyHat(int which, int hat, int value);
|
static void sdlUpdateJoyHat(int which, int hat, int value);
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#define SDLBUTTONS_NUM 14
|
|
||||||
|
|
||||||
enum EKey {
|
enum EKey {
|
||||||
KEY_LEFT,
|
KEY_LEFT,
|
||||||
KEY_RIGHT,
|
KEY_RIGHT,
|
||||||
|
|
Loading…
Reference in New Issue