mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-23 15:20:09 +00:00
Added fixes from PR comments
This commit is contained in:
parent
26f789c92a
commit
28e5bff419
@ -2,32 +2,26 @@
|
|||||||
// Licensed under GPLv2
|
// Licensed under GPLv2
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
|
||||||
#include "video_core/video_core.h"
|
#include "video_core/video_core.h"
|
||||||
#include "core/hw/hid.h"
|
#include "core/hw/hid.h"
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include "citra/citra.h"
|
#include "citra/citra.h"
|
||||||
#include "citra/emu_window/emu_window_glfw.h"
|
#include "citra/emu_window/emu_window_glfw.h"
|
||||||
|
|
||||||
typedef std::map<int, HID::PAD> GLFWKeyMapping;
|
|
||||||
|
|
||||||
GLFWKeyMapping g_key_mapping;
|
|
||||||
|
|
||||||
u32 g_button_reg;
|
|
||||||
|
|
||||||
static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods ) {
|
static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods ) {
|
||||||
try {
|
try {
|
||||||
HID::PAD button = g_key_mapping.at(key);
|
HID::PAD button = ((EmuWindow_GLFW*)win)->m_key_mapping.at(key);
|
||||||
if (action == GLFW_RELEASE) {
|
if (action == GLFW_RELEASE) {
|
||||||
g_button_reg &= 0xffffffff ^ button;
|
((EmuWindow_GLFW*)win)->m_button_reg &= ~button;
|
||||||
}
|
}
|
||||||
else if (action == GLFW_PRESS){
|
else if (action == GLFW_PRESS){
|
||||||
g_button_reg |= button;
|
((EmuWindow_GLFW*)win)->m_button_reg |= button;
|
||||||
}
|
}
|
||||||
HID::SetButtonReg(g_button_reg);
|
HID::SetButtonReg(((EmuWindow_GLFW*)win)->m_button_reg);
|
||||||
}
|
}
|
||||||
catch (std::out_of_range& e){
|
catch (std::out_of_range& e){
|
||||||
|
|
||||||
@ -40,21 +34,21 @@ static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) {
|
|||||||
emu_window->SetClientAreaHeight(height);
|
emu_window->SetClientAreaHeight(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetKeyDefaults() {
|
void EmuWindow_GLFW::SetKeyDefaults() {
|
||||||
g_key_mapping['Y'] = HID::PAD::PAD_A;
|
m_key_mapping['Y'] = HID::PAD::PAD_A;
|
||||||
g_key_mapping['H'] = HID::PAD::PAD_B;
|
m_key_mapping['H'] = HID::PAD::PAD_B;
|
||||||
g_key_mapping['Z'] = HID::PAD::PAD_START;
|
m_key_mapping['Z'] = HID::PAD::PAD_START;
|
||||||
g_key_mapping['X'] = HID::PAD::PAD_SELECT;
|
m_key_mapping['X'] = HID::PAD::PAD_SELECT;
|
||||||
|
|
||||||
g_key_mapping['W'] = HID::PAD::PAD_UP;
|
m_key_mapping['W'] = HID::PAD::PAD_UP;
|
||||||
g_key_mapping['A'] = HID::PAD::PAD_LEFT;
|
m_key_mapping['A'] = HID::PAD::PAD_LEFT;
|
||||||
g_key_mapping['S'] = HID::PAD::PAD_DOWN;
|
m_key_mapping['S'] = HID::PAD::PAD_DOWN;
|
||||||
g_key_mapping['D'] = HID::PAD::PAD_RIGHT;
|
m_key_mapping['D'] = HID::PAD::PAD_RIGHT;
|
||||||
|
|
||||||
g_key_mapping['6'] = HID::PAD::PAD_R;
|
m_key_mapping['6'] = HID::PAD::PAD_R;
|
||||||
g_key_mapping['7'] = HID::PAD::PAD_L;
|
m_key_mapping['7'] = HID::PAD::PAD_L;
|
||||||
g_key_mapping['U'] = HID::PAD::PAD_X;
|
m_key_mapping['U'] = HID::PAD::PAD_X;
|
||||||
g_key_mapping['J'] = HID::PAD::PAD_Y;
|
m_key_mapping['J'] = HID::PAD::PAD_Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,10 +79,10 @@ EmuWindow_GLFW::EmuWindow_GLFW() {
|
|||||||
|
|
||||||
// Setup callbacks
|
// Setup callbacks
|
||||||
glfwSetWindowUserPointer(m_render_window, this);
|
glfwSetWindowUserPointer(m_render_window, this);
|
||||||
glfwSetKeyCallback(m_render_window, (GLFWkeyfun)OnKeyEvent);
|
|
||||||
//glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent);
|
|
||||||
|
|
||||||
SetKeyDefaults();
|
SetKeyDefaults();
|
||||||
|
glfwSetKeyCallback(m_render_window, (GLFWkeyfun)OnKeyEvent);
|
||||||
|
//glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent);
|
||||||
|
|
||||||
DoneCurrent();
|
DoneCurrent();
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,18 @@ public:
|
|||||||
/// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
|
/// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
|
||||||
void DoneCurrent();
|
void DoneCurrent();
|
||||||
|
|
||||||
|
//used to set the key mappings to their default values
|
||||||
|
void SetKeyDefaults();
|
||||||
|
|
||||||
GLFWwindow* m_render_window; ///< Internal GLFW render window
|
GLFWwindow* m_render_window; ///< Internal GLFW render window
|
||||||
|
|
||||||
|
typedef std::map<int, HID::PAD> GLFWKeyMapping;
|
||||||
|
|
||||||
|
GLFWKeyMapping m_key_mapping;
|
||||||
|
|
||||||
|
u32 m_button_reg;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -123,7 +123,7 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this
|
|||||||
|
|
||||||
BackupGeometry();
|
BackupGeometry();
|
||||||
|
|
||||||
buttonReg = 0x0;
|
button_reg = 0x0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GRenderWindow::~GRenderWindow()
|
GRenderWindow::~GRenderWindow()
|
||||||
@ -205,8 +205,8 @@ void GRenderWindow::keyPressEvent(QKeyEvent* event)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
buttonReg |= GetKeyBinding(event);
|
button_reg |= GetKeyBinding(event);
|
||||||
HID::SetButtonReg(buttonReg);
|
HID::SetButtonReg(button_reg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,6 +222,6 @@ void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
|
|||||||
QWidget::keyPressEvent(event);
|
QWidget::keyPressEvent(event);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
buttonReg &= 0xffffffff ^ GetKeyBinding(event);
|
button_reg &= ~GetKeyBinding(event);
|
||||||
HID::SetButtonReg(buttonReg);
|
HID::SetButtonReg(button_reg);
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
|
#include <map>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QGLWidget>
|
#include <QGLWidget>
|
||||||
#include <map>
|
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
#include "common/emu_window.h"
|
#include "common/emu_window.h"
|
||||||
|
|
||||||
@ -111,5 +111,5 @@ private:
|
|||||||
|
|
||||||
QByteArray geometry;
|
QByteArray geometry;
|
||||||
|
|
||||||
u32 buttonReg;
|
u32 button_reg;
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,6 @@ GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractItemModel(p
|
|||||||
QModelIndex GPUCommandListModel::index(int row, int column, const QModelIndex& parent) const
|
QModelIndex GPUCommandListModel::index(int row, int column, const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
TreeItem* item;
|
TreeItem* item;
|
||||||
TreeItem* internal;
|
|
||||||
|
|
||||||
if (!parent.isValid()) {
|
if (!parent.isValid()) {
|
||||||
item = root_item;
|
item = root_item;
|
||||||
@ -25,13 +24,10 @@ QModelIndex GPUCommandListModel::index(int row, int column, const QModelIndex& p
|
|||||||
item = (TreeItem*)parent.internalPointer();
|
item = (TreeItem*)parent.internalPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item->children.size() <= row) {
|
|
||||||
internal = item;
|
|
||||||
}
|
|
||||||
else { internal = item->children[row]; }
|
|
||||||
|
|
||||||
|
TreeItem* internal_item = (item->children.size() <= row) ? item : item->children[row];
|
||||||
|
|
||||||
return createIndex(row, column, internal);
|
return createIndex(row, column, internal_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex GPUCommandListModel::parent(const QModelIndex& child) const
|
QModelIndex GPUCommandListModel::parent(const QModelIndex& child) const
|
||||||
|
@ -2,39 +2,33 @@
|
|||||||
// Licensed under GPLv2
|
// Licensed under GPLv2
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include "key_bindings.hxx"
|
#include "key_bindings.hxx"
|
||||||
#include <map>
|
|
||||||
#include "core/hw/hid.h"
|
#include "core/hw/hid.h"
|
||||||
|
|
||||||
typedef std::map<QKeySequence, HID::PAD> BindingsMap;
|
typedef std::map<QKeySequence, HID::PAD> KeyBindingsMap;
|
||||||
|
KeyBindingsMap bindings;
|
||||||
BindingsMap bindings;
|
typedef std::map<HID::PAD, QKeySequence> ReverseKeyBindingsMap;
|
||||||
|
ReverseKeyBindingsMap reverseBindings;
|
||||||
|
|
||||||
typedef std::map<HID::PAD, QKeySequence> ReverseBindingsMap;
|
|
||||||
|
|
||||||
ReverseBindingsMap reverseBindings;
|
|
||||||
|
|
||||||
|
|
||||||
typedef std::map<HID::PAD, QString> NameMap;
|
typedef std::map<HID::PAD, QString> NameMap;
|
||||||
|
|
||||||
NameMap names;
|
NameMap names;
|
||||||
|
|
||||||
typedef std::map<QString, HID::PAD> ReverseNameMap;
|
typedef std::map<QString, HID::PAD> ReverseNameMap;
|
||||||
|
|
||||||
ReverseNameMap reverseNames;
|
ReverseNameMap reverseNames;
|
||||||
|
|
||||||
void SaveKeyBindings(QSettings& settings)
|
void SaveKeyBindings(QSettings& settings)
|
||||||
{
|
{
|
||||||
settings.beginGroup("KeyBindings");
|
settings.beginGroup("KeyBindings");
|
||||||
|
|
||||||
for (BindingsMap::iterator group = bindings.begin(); group != bindings.end(); ++group)
|
for (auto key : bindings)
|
||||||
{
|
{
|
||||||
settings.setValue(group->first.toString(), group->second);
|
settings.setValue(key.first.toString(), key.second);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
@ -72,7 +66,6 @@ void createNameMap() {
|
|||||||
names[(HID::PAD)(1 << i)] = QString(HID::PAD_NAMES[i]);
|
names[(HID::PAD)(1 << i)] = QString(HID::PAD_NAMES[i]);
|
||||||
reverseNames[QString(HID::PAD_NAMES[i])] = (HID::PAD)(1 << i);
|
reverseNames[QString(HID::PAD_NAMES[i])] = (HID::PAD)(1 << i);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDefaultKeyBindings() {
|
void setDefaultKeyBindings() {
|
||||||
@ -126,16 +119,10 @@ GKeyBindingsDialog::GKeyBindingsDialog(QWidget* parent) : QDialog(parent)
|
|||||||
}
|
}
|
||||||
// TODO: Make context configurable as well (hiding the column for now)
|
// TODO: Make context configurable as well (hiding the column for now)
|
||||||
|
|
||||||
ui.treeWidget->setEditTriggers(
|
|
||||||
QAbstractItemView::EditKeyPressed
|
|
||||||
| QAbstractItemView::SelectedClicked
|
|
||||||
| QAbstractItemView::AnyKeyPressed
|
|
||||||
);
|
|
||||||
connect(
|
connect(
|
||||||
this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
|
this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
|
||||||
this, SLOT(OnMouseDoubleClicked(QTreeWidgetItem*, int))
|
this, SLOT(OnMouseDoubleClicked(QTreeWidgetItem*, int))
|
||||||
);
|
);
|
||||||
ui.treeWidget->setColumnCount(2);
|
|
||||||
|
|
||||||
ui.treeWidget->resizeColumnToContents(0);
|
ui.treeWidget->resizeColumnToContents(0);
|
||||||
ui.treeWidget->resizeColumnToContents(1);
|
ui.treeWidget->resizeColumnToContents(1);
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "ui_key_bindings.h"
|
|
||||||
#include "core/hw/hid.h"
|
#include "core/hw/hid.h"
|
||||||
|
#include "ui_key_bindings.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -64,3 +64,4 @@ private:
|
|||||||
private slots:
|
private slots:
|
||||||
void updateItem(QTreeWidgetItem * item, int column);
|
void updateItem(QTreeWidgetItem * item, int column);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,12 +16,18 @@
|
|||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeWidget" name="treeWidget">
|
<widget class="QTreeWidget" name="treeWidget">
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
|
||||||
|
</property>
|
||||||
<property name="selectionBehavior">
|
<property name="selectionBehavior">
|
||||||
<enum>QAbstractItemView::SelectItems</enum>
|
<enum>QAbstractItemView::SelectItems</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="headerHidden">
|
<property name="headerHidden">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="columnCount">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Action</string>
|
<string>Action</string>
|
||||||
@ -29,12 +35,7 @@
|
|||||||
</column>
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Key</string>
|
<string notr="true">2</string>
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Pad</string>
|
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -36,9 +36,14 @@ public:
|
|||||||
verticalLayout = new QVBoxLayout(key_bindings);
|
verticalLayout = new QVBoxLayout(key_bindings);
|
||||||
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
||||||
treeWidget = new QTreeWidget(key_bindings);
|
treeWidget = new QTreeWidget(key_bindings);
|
||||||
|
QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
|
||||||
|
__qtreewidgetitem->setText(1, QString::fromUtf8("2"));
|
||||||
|
treeWidget->setHeaderItem(__qtreewidgetitem);
|
||||||
treeWidget->setObjectName(QString::fromUtf8("treeWidget"));
|
treeWidget->setObjectName(QString::fromUtf8("treeWidget"));
|
||||||
|
treeWidget->setEditTriggers(QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked);
|
||||||
treeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
|
treeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||||
treeWidget->setHeaderHidden(false);
|
treeWidget->setHeaderHidden(false);
|
||||||
|
treeWidget->setColumnCount(2);
|
||||||
|
|
||||||
verticalLayout->addWidget(treeWidget);
|
verticalLayout->addWidget(treeWidget);
|
||||||
|
|
||||||
@ -61,8 +66,6 @@ public:
|
|||||||
{
|
{
|
||||||
key_bindings->setWindowTitle(QApplication::translate("key_bindings", "Key Bindings", 0, QApplication::UnicodeUTF8));
|
key_bindings->setWindowTitle(QApplication::translate("key_bindings", "Key Bindings", 0, QApplication::UnicodeUTF8));
|
||||||
QTreeWidgetItem *___qtreewidgetitem = treeWidget->headerItem();
|
QTreeWidgetItem *___qtreewidgetitem = treeWidget->headerItem();
|
||||||
___qtreewidgetitem->setText(2, QApplication::translate("key_bindings", "Pad", 0, QApplication::UnicodeUTF8));
|
|
||||||
___qtreewidgetitem->setText(1, QApplication::translate("key_bindings", "Key", 0, QApplication::UnicodeUTF8));
|
|
||||||
___qtreewidgetitem->setText(0, QApplication::translate("key_bindings", "Action", 0, QApplication::UnicodeUTF8));
|
___qtreewidgetitem->setText(0, QApplication::translate("key_bindings", "Action", 0, QApplication::UnicodeUTF8));
|
||||||
} // retranslateUi
|
} // retranslateUi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user