diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index 6b15a734f..403d9f9a5 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp @@ -2,32 +2,26 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + #include "common/common.h" #include "video_core/video_core.h" #include "core/hw/hid.h" -#include - #include "citra/citra.h" #include "citra/emu_window/emu_window_glfw.h" -typedef std::map 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(); } diff --git a/src/citra/emu_window/emu_window_glfw.h b/src/citra/emu_window/emu_window_glfw.h index 5898ec177..446e0b50e 100644 --- a/src/citra/emu_window/emu_window_glfw.h +++ b/src/citra/emu_window/emu_window_glfw.h @@ -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 GLFWKeyMapping; + + GLFWKeyMapping m_key_mapping; + + u32 m_button_reg; + + private: }; diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 74bd13f9e..619881e63 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -123,7 +123,7 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this BackupGeometry(); - buttonReg = 0x0; + button_reg = 0x0; } GRenderWindow::~GRenderWindow() @@ -197,16 +197,16 @@ void GRenderWindow::keyPressEvent(QKeyEvent* event) /* bool key_processed = false; for (unsigned int channel = 0; channel < 4 && controller_interface(); ++channel) - if (controller_interface()->SetControllerStatus(channel, event->key(), input_common::GCController::PRESSED)) - key_processed = true; + if (controller_interface()->SetControllerStatus(channel, event->key(), input_common::GCController::PRESSED)) + key_processed = true; if (!key_processed) - QWidget::keyPressEvent(event); + QWidget::keyPressEvent(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); } \ No newline at end of file diff --git a/src/citra_qt/bootmanager.hxx b/src/citra_qt/bootmanager.hxx index 84216cf2a..e9a736ff7 100644 --- a/src/citra_qt/bootmanager.hxx +++ b/src/citra_qt/bootmanager.hxx @@ -1,6 +1,6 @@ +#include #include #include -#include #include "common/common.h" #include "common/emu_window.h" @@ -111,5 +111,5 @@ private: QByteArray geometry; - u32 buttonReg; + u32 button_reg; }; diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp index 081c63ff0..c5c3d725c 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics_cmdlists.cpp @@ -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 diff --git a/src/citra_qt/key_bindings.cpp b/src/citra_qt/key_bindings.cpp index 305d7574b..58f61c261 100644 --- a/src/citra_qt/key_bindings.cpp +++ b/src/citra_qt/key_bindings.cpp @@ -2,39 +2,33 @@ // Licensed under GPLv2 // Refer to the license.txt file included. + +#include #include #include #include #include #include "key_bindings.hxx" -#include #include "core/hw/hid.h" -typedef std::map BindingsMap; - -BindingsMap bindings; - - -typedef std::map ReverseBindingsMap; - -ReverseBindingsMap reverseBindings; +typedef std::map KeyBindingsMap; +KeyBindingsMap bindings; +typedef std::map ReverseKeyBindingsMap; +ReverseKeyBindingsMap reverseBindings; typedef std::map NameMap; - NameMap names; - typedef std::map 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(); @@ -45,11 +39,11 @@ void LoadKeyBindings(QSettings& settings) settings.beginGroup("KeyBindings"); // Make sure NOT to use a reference here because it would become invalid once we call beginGroup() - QStringList keys = settings.allKeys(); - for (QList::iterator key = keys.begin(); key != keys.end(); ++key) + QStringList keys = settings.allKeys(); + for (QList::iterator key = keys.begin(); key != keys.end(); ++key) { - settings.beginGroup(*key); - QKeySequence keyseq = QKeySequence::fromString(settings.value("").toString()); + settings.beginGroup(*key); + QKeySequence keyseq = QKeySequence::fromString(settings.value("").toString()); } settings.endGroup(); @@ -57,22 +51,21 @@ void LoadKeyBindings(QSettings& settings) HID::PAD GetKeyBinding(QKeyEvent * event) { - QKeySequence keySeq = QKeySequence(event->text()); - return bindings[keySeq]; + QKeySequence keySeq = QKeySequence(event->text()); + return bindings[keySeq]; } void RegisterKeyBinding(const QKeySequence keySeq, const HID::PAD pad) { - bindings[keySeq] = pad; + bindings[keySeq] = pad; reverseBindings[pad] = keySeq; } void createNameMap() { - for (int i = 0; i < HID::g_num_pad_items; i++){ - names[(HID::PAD)(1 << i)] = QString(HID::PAD_NAMES[i]); + for (int i = 0; i < HID::g_num_pad_items; i++){ + names[(HID::PAD)(1 << i)] = QString(HID::PAD_NAMES[i]); reverseNames[QString(HID::PAD_NAMES[i])] = (HID::PAD)(1 << i); - } - + } } void setDefaultKeyBindings() { @@ -112,30 +105,24 @@ GKeyBindingsDialog::GKeyBindingsDialog(QWidget* parent) : QDialog(parent) { ui.setupUi(this); - createNameMap(); + createNameMap(); - for (NameMap::iterator key = names.begin(); key != names.end(); ++key) + for (NameMap::iterator key = names.begin(); key != names.end(); ++key) { QKeySequence keySeq = reverseBindings[key->first]; - QStringList columns; + QStringList columns; columns << key->second << keySeq.toString(); - QTreeWidgetItem* item = new QTreeWidgetItem(columns); + QTreeWidgetItem* item = new QTreeWidgetItem(columns); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable); - ui.treeWidget->addTopLevelItem(item); + ui.treeWidget->addTopLevelItem(item); } // 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); diff --git a/src/citra_qt/key_bindings.hxx b/src/citra_qt/key_bindings.hxx index fdcbbad63..9a809fb16 100644 --- a/src/citra_qt/key_bindings.hxx +++ b/src/citra_qt/key_bindings.hxx @@ -3,8 +3,8 @@ // Refer to the license.txt file included. #include -#include "ui_key_bindings.h" #include "core/hw/hid.h" +#include "ui_key_bindings.h" @@ -56,7 +56,7 @@ class GKeyBindingsDialog : public QDialog Q_OBJECT public: - GKeyBindingsDialog(QWidget* parent = NULL); + GKeyBindingsDialog(QWidget* parent = NULL); private: Ui::key_bindings ui; @@ -64,3 +64,4 @@ private: private slots: void updateItem(QTreeWidgetItem * item, int column); }; + diff --git a/src/citra_qt/key_bindings.ui b/src/citra_qt/key_bindings.ui index 0b97ec7d7..c676ce104 100644 --- a/src/citra_qt/key_bindings.ui +++ b/src/citra_qt/key_bindings.ui @@ -16,12 +16,18 @@ + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked + QAbstractItemView::SelectItems false + + 2 + Action @@ -29,12 +35,7 @@ - Key - - - - - Pad + 2 diff --git a/src/citra_qt/ui_key_bindings.h b/src/citra_qt/ui_key_bindings.h index 7e1a88946..2eeb8e8c1 100644 --- a/src/citra_qt/ui_key_bindings.h +++ b/src/citra_qt/ui_key_bindings.h @@ -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