GTK :
- The Joypad config dialog can now display the key associations, but it's read only for now.
This commit is contained in:
parent
2ac54204fa
commit
1785eeb5f9
|
@ -1,70 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
|
||||
// Copyright (C) 1999-2003 Forgotten
|
||||
// Copyright (C) 2004 Forgotten and the VBA development team
|
||||
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2, or(at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software Foundation,
|
||||
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef __VBA_INPUT_H__
|
||||
#define __VBA_INPUT_H__
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace VBA
|
||||
{
|
||||
|
||||
enum EKey
|
||||
{
|
||||
KeyNone,
|
||||
// GBA keys
|
||||
KeyA,
|
||||
KeyB,
|
||||
KeySelect,
|
||||
KeyStart,
|
||||
KeyRight,
|
||||
KeyLeft,
|
||||
KeyUp,
|
||||
KeyDown,
|
||||
KeyR,
|
||||
KeyL,
|
||||
// VBA extension
|
||||
KeySpeed,
|
||||
KeyCapture
|
||||
};
|
||||
|
||||
enum EKeyFlag
|
||||
{
|
||||
// GBA keys
|
||||
KeyFlagA = 1 << 0,
|
||||
KeyFlagB = 1 << 1,
|
||||
KeyFlagSelect = 1 << 2,
|
||||
KeyFlagStart = 1 << 3,
|
||||
KeyFlagRight = 1 << 4,
|
||||
KeyFlagLeft = 1 << 5,
|
||||
KeyFlagUp = 1 << 6,
|
||||
KeyFlagDown = 1 << 7,
|
||||
KeyFlagR = 1 << 8,
|
||||
KeyFlagL = 1 << 9,
|
||||
// VBA extension
|
||||
KeyFlagSpeed = 1 << 10,
|
||||
KeyFlagCapture = 1 << 11,
|
||||
};
|
||||
|
||||
typedef std::map<int, EKey> Keymap;
|
||||
|
||||
} // namespace VBA
|
||||
|
||||
|
||||
#endif // __VBA_INPUT_H__
|
|
@ -21,142 +21,27 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "intl.h"
|
||||
#include "../sdl/inputSDL.h"
|
||||
|
||||
namespace VBA
|
||||
{
|
||||
|
||||
guint * JoypadConfig::puiAt(int _iIndex)
|
||||
{
|
||||
guint * puiMember;
|
||||
|
||||
switch (_iIndex)
|
||||
{
|
||||
case 0:
|
||||
puiMember = &m_uiUp;
|
||||
break;
|
||||
case 1:
|
||||
puiMember = &m_uiDown;
|
||||
break;
|
||||
case 2:
|
||||
puiMember = &m_uiLeft;
|
||||
break;
|
||||
case 3:
|
||||
puiMember = &m_uiRight;
|
||||
break;
|
||||
case 4:
|
||||
puiMember = &m_uiA;
|
||||
break;
|
||||
case 5:
|
||||
puiMember = &m_uiB;
|
||||
break;
|
||||
case 6:
|
||||
puiMember = &m_uiL;
|
||||
break;
|
||||
case 7:
|
||||
puiMember = &m_uiR;
|
||||
break;
|
||||
case 8:
|
||||
puiMember = &m_uiSelect;
|
||||
break;
|
||||
case 9:
|
||||
puiMember = &m_uiStart;
|
||||
break;
|
||||
case 10:
|
||||
puiMember = &m_uiSpeed;
|
||||
break;
|
||||
case 11:
|
||||
puiMember = &m_uiCapture;
|
||||
break;
|
||||
default:
|
||||
puiMember = NULL;
|
||||
}
|
||||
|
||||
return puiMember;
|
||||
}
|
||||
|
||||
int JoypadConfig::iFind(guint _uiKeycode)
|
||||
{
|
||||
for (guint i = 0; i < 12; i++)
|
||||
{
|
||||
if (*puiAt(i) == _uiKeycode)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void JoypadConfig::vSetDefault()
|
||||
{
|
||||
guint auiKeyval[] =
|
||||
{
|
||||
GDK_Up, GDK_Down, GDK_Left, GDK_Right,
|
||||
GDK_z, GDK_x, GDK_a, GDK_s,
|
||||
GDK_BackSpace, GDK_Return,
|
||||
GDK_space, GDK_F12
|
||||
};
|
||||
|
||||
for (guint i = 0; i < G_N_ELEMENTS(auiKeyval); i++)
|
||||
{
|
||||
GdkKeymapKey * pstKeys;
|
||||
int iKeys;
|
||||
|
||||
if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(),
|
||||
auiKeyval[i],
|
||||
&pstKeys,
|
||||
&iKeys))
|
||||
{
|
||||
*puiAt(i) = pstKeys[0].keycode;
|
||||
g_free(pstKeys);
|
||||
}
|
||||
else
|
||||
{
|
||||
*puiAt(i) = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Keymap JoypadConfig::oCreateKeymap() const
|
||||
{
|
||||
Keymap oKeymap;
|
||||
|
||||
oKeymap[m_uiUp] = KeyUp;
|
||||
oKeymap[m_uiDown] = KeyDown;
|
||||
oKeymap[m_uiLeft] = KeyLeft;
|
||||
oKeymap[m_uiRight] = KeyRight;
|
||||
oKeymap[m_uiA] = KeyA;
|
||||
oKeymap[m_uiB] = KeyB;
|
||||
oKeymap[m_uiL] = KeyL;
|
||||
oKeymap[m_uiR] = KeyR;
|
||||
oKeymap[m_uiSelect] = KeySelect;
|
||||
oKeymap[m_uiStart] = KeyStart;
|
||||
oKeymap[m_uiSpeed] = KeySpeed;
|
||||
oKeymap[m_uiCapture] = KeyCapture;
|
||||
|
||||
return oKeymap;
|
||||
}
|
||||
|
||||
JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog,
|
||||
const Glib::RefPtr<Gnome::Glade::Xml> & _poXml) :
|
||||
Gtk::Dialog(_pstDialog)
|
||||
{
|
||||
m_puiCurrentKeyCode = NULL;
|
||||
|
||||
memset(&m_oConfig, 0, sizeof(m_oConfig));
|
||||
|
||||
m_poOkButton = dynamic_cast<Gtk::Button *>(_poXml->get_widget("JoypadOkButton"));
|
||||
|
||||
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("JoypadUpEntry")));
|
||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadDownEntry")));
|
||||
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("JoypadLEntry")));
|
||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadREntry")));
|
||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadSpeedEntry")));
|
||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadCaptureEntry")));
|
||||
|
||||
|
@ -177,27 +62,48 @@ JoypadConfigDialog::~JoypadConfigDialog()
|
|||
{
|
||||
}
|
||||
|
||||
void JoypadConfigDialog::vSetConfig(const JoypadConfig & _roConfig)
|
||||
{
|
||||
m_oConfig = _roConfig;
|
||||
vUpdateEntries();
|
||||
}
|
||||
|
||||
void JoypadConfigDialog::vUpdateEntries()
|
||||
{
|
||||
for (guint i = 0; i < m_oEntries.size(); i++)
|
||||
{
|
||||
guint uiKeyval = 0;
|
||||
gdk_keymap_translate_keyboard_state(gdk_keymap_get_default(),
|
||||
*m_oConfig.puiAt(i),
|
||||
(GdkModifierType)0,
|
||||
0,
|
||||
&uiKeyval,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
const char * csName = gdk_keyval_name(uiKeyval);
|
||||
if (csName == NULL)
|
||||
const char * csName = 0;
|
||||
|
||||
guint uiKeyval = inputGetKeymap(PAD_MAIN, (EKey)i);
|
||||
int dev = uiKeyval >> 16;
|
||||
if (dev == 0)
|
||||
{
|
||||
csName = gdk_keyval_name(uiKeyval);
|
||||
}
|
||||
else
|
||||
{
|
||||
int what = uiKeyval & 0xffff;
|
||||
std::stringstream os;
|
||||
os << "Joy " << dev;
|
||||
|
||||
if(what >= 128)
|
||||
{
|
||||
// joystick button
|
||||
int button = what - 128;
|
||||
os << " Button " << button;
|
||||
}
|
||||
else if (what < 0x20)
|
||||
{
|
||||
// joystick axis
|
||||
what >>= 1;
|
||||
os << " Axis " << what;
|
||||
}
|
||||
else if (what < 0x30)
|
||||
{
|
||||
// joystick hat
|
||||
what = (what & 15);
|
||||
what >>= 2;
|
||||
os << " Hat " << what;
|
||||
}
|
||||
|
||||
csName = os.str().c_str();
|
||||
}
|
||||
|
||||
if (csName == 0)
|
||||
{
|
||||
m_oEntries[i]->set_text(_("<Undefined>"));
|
||||
}
|
||||
|
@ -212,21 +118,19 @@ bool JoypadConfigDialog::bOnEntryFocusIn(GdkEventFocus * _pstEvent,
|
|||
guint _uiEntry)
|
||||
{
|
||||
m_uiCurrentEntry = _uiEntry;
|
||||
m_puiCurrentKeyCode = m_oConfig.puiAt(_uiEntry);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JoypadConfigDialog::bOnEntryFocusOut(GdkEventFocus * _pstEvent)
|
||||
{
|
||||
m_puiCurrentKeyCode = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent)
|
||||
{
|
||||
if (m_puiCurrentKeyCode == NULL)
|
||||
/* if (m_puiCurrentKeyCode == NULL)
|
||||
{
|
||||
return Gtk::Dialog::on_key_press_event(_pstEvent);
|
||||
}
|
||||
|
@ -268,7 +172,7 @@ bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent)
|
|||
else
|
||||
{
|
||||
m_poOkButton->grab_focus();
|
||||
}
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -25,33 +25,9 @@
|
|||
#include <libglademm.h>
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
namespace VBA
|
||||
{
|
||||
|
||||
class JoypadConfig
|
||||
{
|
||||
public:
|
||||
guint m_uiUp;
|
||||
guint m_uiDown;
|
||||
guint m_uiLeft;
|
||||
guint m_uiRight;
|
||||
guint m_uiA;
|
||||
guint m_uiB;
|
||||
guint m_uiL;
|
||||
guint m_uiR;
|
||||
guint m_uiSelect;
|
||||
guint m_uiStart;
|
||||
guint m_uiSpeed;
|
||||
guint m_uiCapture;
|
||||
|
||||
guint * puiAt(int _iIndex);
|
||||
int iFind(guint _uiKeycode);
|
||||
void vSetDefault();
|
||||
Keymap oCreateKeymap() const;
|
||||
};
|
||||
|
||||
class JoypadConfigDialog : public Gtk::Dialog
|
||||
{
|
||||
public:
|
||||
|
@ -59,9 +35,6 @@ public:
|
|||
const Glib::RefPtr<Gnome::Glade::Xml> & _poXml);
|
||||
virtual ~JoypadConfigDialog();
|
||||
|
||||
void vSetConfig(const JoypadConfig & _roConfig);
|
||||
inline JoypadConfig stGetConfig() const { return m_oConfig; }
|
||||
|
||||
protected:
|
||||
bool bOnEntryFocusIn(GdkEventFocus * _pstEvent, guint _uiEntry);
|
||||
bool bOnEntryFocusOut(GdkEventFocus * _pstEvent);
|
||||
|
@ -69,10 +42,8 @@ protected:
|
|||
bool on_key_press_event(GdkEventKey * _pstEvent);
|
||||
|
||||
private:
|
||||
JoypadConfig m_oConfig;
|
||||
Gtk::Button * m_poOkButton;
|
||||
std::vector<Gtk::Entry *> m_oEntries;
|
||||
guint * m_puiCurrentKeyCode;
|
||||
guint m_uiCurrentEntry;
|
||||
|
||||
void vUpdateEntries();
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#include "configfile.h"
|
||||
#include "screenarea.h"
|
||||
#include "filters.h"
|
||||
//#include "joypadconfig.h"
|
||||
|
||||
namespace VBA
|
||||
{
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include "tools.h"
|
||||
#include "intl.h"
|
||||
#include "joypadconfig.h"
|
||||
|
||||
extern int systemRenderedFrames;
|
||||
extern int systemFPS;
|
||||
|
@ -861,24 +862,23 @@ 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;
|
||||
poXml->get_widget_derived<JoypadConfigDialog>("JoypadConfigDialog", poDialog);
|
||||
poDialog->set_transient_for(*this);
|
||||
poDialog->vSetConfig(m_oJoypads[_iJoypad - 1]);
|
||||
|
||||
if (poDialog->run() == Gtk::RESPONSE_OK)
|
||||
{
|
||||
m_oJoypads[_iJoypad - 1] = poDialog->stGetConfig();
|
||||
/*m_oJoypads[_iJoypad - 1] = poDialog->stGetConfig();
|
||||
if (_iJoypad == m_poInputConfig->oGetKey<int>("active_joypad"))
|
||||
{
|
||||
m_oKeymap = m_oJoypads[_iJoypad - 1].oCreateKeymap();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
delete poDialog;*/
|
||||
delete poDialog;
|
||||
}
|
||||
|
||||
void Window::vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, int _iJoypad)
|
||||
|
|
Loading…
Reference in New Issue