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