Successful test of virtual family keyboard.
This commit is contained in:
parent
db10fcb6bc
commit
a6c6dd048c
|
@ -18,10 +18,21 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
// FamilyKeyboard.cpp
|
||||
#include <SDL.h>
|
||||
#include <QHeaderView>
|
||||
#include <QCloseEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QGroupBox>
|
||||
#include <QPainter>
|
||||
#include <QFontMetrics>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "Qt/main.h"
|
||||
#include "Qt/dface.h"
|
||||
#include "Qt/input.h"
|
||||
#include "Qt/config.h"
|
||||
#include "Qt/keyscan.h"
|
||||
#include "Qt/fceuWrapper.h"
|
||||
#include "Qt/FamilyKeyboard.h"
|
||||
|
||||
|
@ -101,6 +112,35 @@ static const char *keyNames[] =
|
|||
"DOWN",
|
||||
NULL
|
||||
};
|
||||
|
||||
static FKBConfigDialog *fkbWin = NULL;
|
||||
//*********************************************************************************
|
||||
int openFamilyKeyboardDialog(QWidget *parent)
|
||||
{
|
||||
if (fkbWin != NULL)
|
||||
{
|
||||
fkbWin->activateWindow();
|
||||
fkbWin->raise();
|
||||
fkbWin->setFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
fkbWin = new FKBConfigDialog(parent);
|
||||
fkbWin->show();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//*********************************************************************************
|
||||
char getFamilyKeyboardVirtualKey( int idx )
|
||||
{
|
||||
char state = 0;
|
||||
|
||||
if (fkbWin != NULL)
|
||||
{
|
||||
state = fkbWin->keyboard->key[idx].vState;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
//*********************************************************************************
|
||||
FamilyKeyboardWidget::FamilyKeyboardWidget( QWidget *parent )
|
||||
{
|
||||
|
@ -173,9 +213,21 @@ void FamilyKeyboardWidget::calcFontData(void)
|
|||
//*********************************************************************************
|
||||
void FamilyKeyboardWidget::updatePeriodic(void)
|
||||
{
|
||||
updateHardwareStatus();
|
||||
|
||||
update();
|
||||
}
|
||||
//*********************************************************************************
|
||||
void FamilyKeyboardWidget::updateHardwareStatus(void)
|
||||
{
|
||||
const uint8 *hwKeyState = getFamilyKeyboardState();
|
||||
|
||||
for (int i=0; i<FAMILYKEYBOARD_NUM_BUTTONS; i++)
|
||||
{
|
||||
key[i].hwState = hwKeyState[i];
|
||||
}
|
||||
}
|
||||
//*********************************************************************************
|
||||
int FamilyKeyboardWidget::getKeyAtPoint( QPoint p )
|
||||
{
|
||||
for (int i=0; i<NUM_KEYS; i++)
|
||||
|
@ -416,3 +468,111 @@ void FamilyKeyboardWidget::paintEvent(QPaintEvent *event)
|
|||
drawButton( painter, 71, x, y, w*2, h );
|
||||
}
|
||||
//*********************************************************************************
|
||||
//----------------------------------------------------------------------------
|
||||
//--- Family Keyboard Config Dialog
|
||||
//----------------------------------------------------------------------------
|
||||
FKBConfigDialog::FKBConfigDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
QVBoxLayout *mainVbox;
|
||||
QHBoxLayout *hbox;
|
||||
QPushButton *closeButton;
|
||||
QTreeWidgetItem *item;
|
||||
|
||||
setWindowTitle( "Family Keyboard Config" );
|
||||
|
||||
mainVbox = new QVBoxLayout();
|
||||
|
||||
mainVbox->addWidget( keyboard = new FamilyKeyboardWidget() );
|
||||
|
||||
setLayout( mainVbox );
|
||||
|
||||
keyTree = new QTreeWidget();
|
||||
|
||||
keyTree->setColumnCount(2);
|
||||
keyTree->setSelectionMode( QAbstractItemView::SingleSelection );
|
||||
keyTree->setAlternatingRowColors(true);
|
||||
|
||||
item = new QTreeWidgetItem();
|
||||
item->setText(0, QString::fromStdString("FKB Key"));
|
||||
item->setText(1, QString::fromStdString("SDL Binding"));
|
||||
item->setTextAlignment(0, Qt::AlignLeft);
|
||||
item->setTextAlignment(1, Qt::AlignCenter);
|
||||
|
||||
keyTree->setHeaderItem(item);
|
||||
|
||||
keyTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
|
||||
for (int i=0; i<FAMILYKEYBOARD_NUM_BUTTONS; i++)
|
||||
{
|
||||
item = new QTreeWidgetItem();
|
||||
|
||||
item->setText(0, tr(FamilyKeyBoardNames[i]));
|
||||
//item->setText(1, tr(FamilyKeyBoardNames[i]));
|
||||
|
||||
item->setTextAlignment(0, Qt::AlignLeft);
|
||||
item->setTextAlignment(1, Qt::AlignCenter);
|
||||
|
||||
keyTree->addTopLevelItem(item);
|
||||
}
|
||||
updateBindingList();
|
||||
|
||||
mainVbox->addWidget( keyTree );
|
||||
|
||||
hbox = new QHBoxLayout();
|
||||
|
||||
mainVbox->addLayout( hbox );
|
||||
|
||||
closeButton = new QPushButton( tr("Close") );
|
||||
closeButton->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
|
||||
|
||||
hbox->addStretch(5);
|
||||
hbox->addWidget( closeButton, 1);
|
||||
|
||||
connect(closeButton , SIGNAL(clicked(void)), this, SLOT(closeWindow(void)));
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
FKBConfigDialog::~FKBConfigDialog(void)
|
||||
{
|
||||
fkbWin = NULL;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void FKBConfigDialog::updateBindingList(void)
|
||||
{
|
||||
char keyNameStr[128];
|
||||
|
||||
for (int i=0; i<FAMILYKEYBOARD_NUM_BUTTONS; i++)
|
||||
{
|
||||
QTreeWidgetItem *item = keyTree->topLevelItem(i);
|
||||
|
||||
item->setText(0, tr(FamilyKeyBoardNames[i]));
|
||||
|
||||
if (fkbmap[i].ButtType == BUTTC_KEYBOARD)
|
||||
{
|
||||
snprintf(keyNameStr, sizeof(keyNameStr), "%s",
|
||||
SDL_GetKeyName(fkbmap[i].ButtonNum));
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(keyNameStr, ButtonName(&fkbmap[i]));
|
||||
}
|
||||
item->setText(1, tr(keyNameStr));
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void FKBConfigDialog::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
printf("FKB Config Close Window Event\n");
|
||||
done(0);
|
||||
deleteLater();
|
||||
event->accept();
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void FKBConfigDialog::closeWindow(void)
|
||||
{
|
||||
//printf("Close Window\n");
|
||||
done(0);
|
||||
deleteLater();
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
//*********************************************************************************
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#include <QRect>
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
#include <QMouseEvent>
|
||||
#include <QTreeWidget>
|
||||
#include <QTimer>
|
||||
#include <QFont>
|
||||
|
||||
#include "Qt/main.h"
|
||||
|
||||
class FKB_Key_t
|
||||
{
|
||||
|
@ -11,13 +15,13 @@ class FKB_Key_t
|
|||
public:
|
||||
FKB_Key_t(void)
|
||||
{
|
||||
vState = kState = 0;
|
||||
vState = hwState = 0;
|
||||
toggleOnPress = 0;
|
||||
}
|
||||
|
||||
char isDown(void)
|
||||
{
|
||||
return vState || kState;
|
||||
return vState || hwState;
|
||||
}
|
||||
|
||||
char pressed(void)
|
||||
|
@ -44,7 +48,7 @@ class FKB_Key_t
|
|||
|
||||
QRect rect;
|
||||
char vState;
|
||||
char kState;
|
||||
char hwState;
|
||||
char toggleOnPress;
|
||||
};
|
||||
|
||||
|
@ -58,6 +62,8 @@ public:
|
|||
|
||||
static const unsigned int NUM_KEYS = 0x48;
|
||||
|
||||
FKB_Key_t key[NUM_KEYS];
|
||||
|
||||
protected:
|
||||
//void keyPressEvent(QKeyEvent *event);
|
||||
//void kepaintEvent(QPaintEvent *event);
|
||||
|
@ -69,6 +75,7 @@ protected:
|
|||
|
||||
int getKeyAtPoint( QPoint p );
|
||||
void calcFontData(void);
|
||||
void updateHardwareStatus(void);
|
||||
void drawButton( QPainter &painter, int idx, int x, int y, int w, int h );
|
||||
|
||||
int keyUnderMouse;
|
||||
|
@ -78,10 +85,33 @@ protected:
|
|||
int pxBtnGridX;
|
||||
int pxBtnGridY;
|
||||
|
||||
FKB_Key_t key[NUM_KEYS];
|
||||
|
||||
QTimer *updateTimer;
|
||||
|
||||
private slots:
|
||||
void updatePeriodic(void);
|
||||
};
|
||||
|
||||
class FKBConfigDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FKBConfigDialog(QWidget *parent = 0);
|
||||
~FKBConfigDialog(void);
|
||||
|
||||
FamilyKeyboardWidget *keyboard;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void updateBindingList(void);
|
||||
|
||||
QTreeWidget *keyTree;
|
||||
|
||||
|
||||
public slots:
|
||||
void closeWindow(void);
|
||||
};
|
||||
|
||||
int openFamilyKeyboardDialog( QWidget *parent );
|
||||
|
||||
char getFamilyKeyboardVirtualKey( int idx );
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
#include "Qt/InputConf.h"
|
||||
|
||||
static InputConfDialog_t *win = NULL;
|
||||
static FKBConfigDialog *fkbCfgWin = NULL;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void openInputConfWindow(QWidget *parent)
|
||||
|
@ -438,11 +437,7 @@ void InputConfDialog_t::expPortConfigure(void)
|
|||
{
|
||||
if ( curNesInput[2] == SIFC_FKB )
|
||||
{
|
||||
if ( fkbCfgWin == NULL )
|
||||
{
|
||||
fkbCfgWin = new FKBConfigDialog(this);
|
||||
fkbCfgWin->show();
|
||||
}
|
||||
openFamilyKeyboardDialog( consoleWindow );
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -605,109 +600,3 @@ void InputConfDialog_t::updatePeriodic(void)
|
|||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
//--- Family Keyboard Config Dialog
|
||||
//----------------------------------------------------------------------------
|
||||
FKBConfigDialog::FKBConfigDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
QVBoxLayout *mainVbox;
|
||||
QHBoxLayout *hbox;
|
||||
QPushButton *closeButton;
|
||||
QTreeWidgetItem *item;
|
||||
|
||||
setWindowTitle( "Family Keyboard Config" );
|
||||
|
||||
mainVbox = new QVBoxLayout();
|
||||
|
||||
mainVbox->addWidget( new FamilyKeyboardWidget() );
|
||||
|
||||
setLayout( mainVbox );
|
||||
|
||||
keyTree = new QTreeWidget();
|
||||
|
||||
keyTree->setColumnCount(2);
|
||||
keyTree->setSelectionMode( QAbstractItemView::SingleSelection );
|
||||
keyTree->setAlternatingRowColors(true);
|
||||
|
||||
item = new QTreeWidgetItem();
|
||||
item->setText(0, QString::fromStdString("FKB Key"));
|
||||
item->setText(1, QString::fromStdString("SDL Binding"));
|
||||
item->setTextAlignment(0, Qt::AlignLeft);
|
||||
item->setTextAlignment(1, Qt::AlignCenter);
|
||||
|
||||
keyTree->setHeaderItem(item);
|
||||
|
||||
keyTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
|
||||
for (int i=0; i<FAMILYKEYBOARD_NUM_BUTTONS; i++)
|
||||
{
|
||||
item = new QTreeWidgetItem();
|
||||
|
||||
item->setText(0, tr(FamilyKeyBoardNames[i]));
|
||||
//item->setText(1, tr(FamilyKeyBoardNames[i]));
|
||||
|
||||
item->setTextAlignment(0, Qt::AlignLeft);
|
||||
item->setTextAlignment(1, Qt::AlignCenter);
|
||||
|
||||
keyTree->addTopLevelItem(item);
|
||||
}
|
||||
updateBindingList();
|
||||
|
||||
mainVbox->addWidget( keyTree );
|
||||
|
||||
hbox = new QHBoxLayout();
|
||||
|
||||
mainVbox->addLayout( hbox );
|
||||
|
||||
closeButton = new QPushButton( tr("Close") );
|
||||
closeButton->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
|
||||
|
||||
hbox->addStretch(5);
|
||||
hbox->addWidget( closeButton, 1);
|
||||
|
||||
connect(closeButton , SIGNAL(clicked(void)), this, SLOT(closeWindow(void)));
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
FKBConfigDialog::~FKBConfigDialog(void)
|
||||
{
|
||||
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void FKBConfigDialog::updateBindingList(void)
|
||||
{
|
||||
char keyNameStr[128];
|
||||
|
||||
for (int i=0; i<FAMILYKEYBOARD_NUM_BUTTONS; i++)
|
||||
{
|
||||
QTreeWidgetItem *item = keyTree->topLevelItem(i);
|
||||
|
||||
item->setText(0, tr(FamilyKeyBoardNames[i]));
|
||||
|
||||
if (fkbmap[i].ButtType == BUTTC_KEYBOARD)
|
||||
{
|
||||
snprintf(keyNameStr, sizeof(keyNameStr), "%s",
|
||||
SDL_GetKeyName(fkbmap[i].ButtonNum));
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(keyNameStr, ButtonName(&fkbmap[i]));
|
||||
}
|
||||
item->setText(1, tr(keyNameStr));
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void FKBConfigDialog::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
printf("FKB Config Close Window Event\n");
|
||||
done(0);
|
||||
deleteLater();
|
||||
event->accept();
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
void FKBConfigDialog::closeWindow(void)
|
||||
{
|
||||
//printf("Close Window\n");
|
||||
done(0);
|
||||
deleteLater();
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -20,25 +20,6 @@
|
|||
|
||||
#include "Qt/main.h"
|
||||
|
||||
class FKBConfigDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FKBConfigDialog(QWidget *parent = 0);
|
||||
~FKBConfigDialog(void);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void updateBindingList(void);
|
||||
|
||||
QTreeWidget *keyTree;
|
||||
|
||||
|
||||
public slots:
|
||||
void closeWindow(void);
|
||||
};
|
||||
|
||||
class InputConfDialog_t : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "Qt/ConsoleWindow.h"
|
||||
#include "Qt/ConsoleUtilities.h"
|
||||
#include "Qt/CheatsConf.h"
|
||||
#include "Qt/FamilyKeyboard.h"
|
||||
#include "Qt/TasEditor/TasEditorWindow.h"
|
||||
|
||||
#include "Qt/sdl.h"
|
||||
|
@ -1862,13 +1863,15 @@ ButtConfig fkbmap[FAMILYKEYBOARD_NUM_BUTTONS] = {
|
|||
/**
|
||||
* Update the status of the Family KeyBoard.
|
||||
*/
|
||||
static void UpdateFKB()
|
||||
static void UpdateFKB(void)
|
||||
{
|
||||
int x;
|
||||
char leftShiftDown;
|
||||
char leftShiftDown, vkeyDown;
|
||||
//static char lp[0x48];
|
||||
|
||||
leftShiftDown = DTestButton(&fkbmap[50]);
|
||||
vkeyDown = getFamilyKeyboardVirtualKey(50);
|
||||
|
||||
leftShiftDown = DTestButton(&fkbmap[50]) || vkeyDown;
|
||||
|
||||
for (x = 0; x < FAMILYKEYBOARD_NUM_BUTTONS; x++)
|
||||
{
|
||||
|
@ -1882,7 +1885,9 @@ static void UpdateFKB()
|
|||
continue;
|
||||
}
|
||||
|
||||
if (DTestButton(&fkbmap[x]))
|
||||
vkeyDown = getFamilyKeyboardVirtualKey(x);
|
||||
|
||||
if (DTestButton(&fkbmap[x]) || vkeyDown)
|
||||
{
|
||||
fkbkeys[x] = 1;
|
||||
|
||||
|
@ -1904,6 +1909,11 @@ static void UpdateFKB()
|
|||
}
|
||||
}
|
||||
|
||||
const uint8 *getFamilyKeyboardState(void)
|
||||
{
|
||||
return fkbkeys;
|
||||
}
|
||||
|
||||
static ButtConfig HyperShotButtons[4] = {
|
||||
MK(SDLK_Q), MK(SDLK_W), MK(SDLK_E), MK(SDLK_R)};
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ int saveInputSettingsToFile( const char *fileBase = NULL );
|
|||
int loadInputSettingsFromFile( const char *filename = NULL );
|
||||
void toggleFamilyKeyboardFunc(void);
|
||||
bool isFamilyKeyboardActv(void);
|
||||
const uint8 *getFamilyKeyboardState(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue