Random stuff (#9589)

* minor coding style adjustment

* Qt: simplify osk dialog buttons

* replace std::find_if with convenience functions

* RSX: use sv in swizzle comparison

idk, I'll remove this if it was intentional.

* overlays/osk: rename enter to return

This one confused me and make me look for a bug that caused the "enter" key to be disabled, while it was actually the return key (obviously xD).
This commit is contained in:
Megamouse 2021-01-12 10:59:50 +01:00 committed by GitHub
parent 838cbe1840
commit 52deff06ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 72 additions and 88 deletions

View file

@ -95,10 +95,10 @@ std::string CgBinaryDisasm::GetCondDisAsm()
swizzle += f[src0.cond_swizzle_z]; swizzle += f[src0.cond_swizzle_z];
swizzle += f[src0.cond_swizzle_w]; swizzle += f[src0.cond_swizzle_w];
if (swizzle == ".xxxx") swizzle = ".x"; if (swizzle == ".xxxx"sv) swizzle = ".x";
else if (swizzle == ".yyyy") swizzle = ".y"; else if (swizzle == ".yyyy"sv) swizzle = ".y";
else if (swizzle == ".zzzz") swizzle = ".z"; else if (swizzle == ".zzzz"sv) swizzle = ".z";
else if (swizzle == ".wwww") swizzle = ".w"; else if (swizzle == ".wwww"sv) swizzle = ".w";
if (swizzle == ".xyzw"sv) if (swizzle == ".xyzw"sv)
{ {
@ -129,7 +129,6 @@ std::string CgBinaryDisasm::GetCondDisAsm()
{ {
cond = "FL"; cond = "FL";
} }
else else
{ {
cond = "TR"; cond = "TR";
@ -212,10 +211,10 @@ template<typename T> std::string CgBinaryDisasm::GetSrcDisAsm(T src)
swizzle += f[src.swizzle_z]; swizzle += f[src.swizzle_z];
swizzle += f[src.swizzle_w]; swizzle += f[src.swizzle_w];
if (swizzle == ".xxxx") swizzle = ".x"; if (swizzle == ".xxxx"sv) swizzle = ".x";
else if (swizzle == ".yyyy") swizzle = ".y"; else if (swizzle == ".yyyy"sv) swizzle = ".y";
else if (swizzle == ".zzzz") swizzle = ".z"; else if (swizzle == ".zzzz"sv) swizzle = ".z";
else if (swizzle == ".wwww") swizzle = ".w"; else if (swizzle == ".wwww"sv) swizzle = ".w";
if (swizzle != ".xyzw"sv) if (swizzle != ".xyzw"sv)
{ {
@ -404,9 +403,8 @@ void CgBinaryDisasm::TaskFP()
m_else_offsets.push_back(src1.else_offset << 2); m_else_offsets.push_back(src1.else_offset << 2);
m_end_offsets.push_back(src2.end_offset << 2); m_end_offsets.push_back(src2.end_offset << 2);
AddCodeAsm("($cond)"); AddCodeAsm("($cond)");
}
break; break;
}
case RSX_FP_OPCODE_LOOP: case RSX_FP_OPCODE_LOOP:
{ {
if (!src0.exec_if_eq && !src0.exec_if_gr && !src0.exec_if_lt) if (!src0.exec_if_eq && !src0.exec_if_gr && !src0.exec_if_lt)
@ -418,9 +416,8 @@ void CgBinaryDisasm::TaskFP()
m_loop_end_offsets.push_back(src2.end_offset << 2); m_loop_end_offsets.push_back(src2.end_offset << 2);
AddCodeAsm(fmt::format("{ %u, %u, %u }", src1.end_counter, src1.init_counter, src1.increment)); AddCodeAsm(fmt::format("{ %u, %u, %u }", src1.end_counter, src1.init_counter, src1.increment));
} }
}
break; break;
}
case RSX_FP_OPCODE_REP: case RSX_FP_OPCODE_REP:
{ {
if (!src0.exec_if_eq && !src0.exec_if_gr && !src0.exec_if_lt) if (!src0.exec_if_eq && !src0.exec_if_gr && !src0.exec_if_lt)
@ -432,9 +429,8 @@ void CgBinaryDisasm::TaskFP()
m_end_offsets.push_back(src2.end_offset << 2); m_end_offsets.push_back(src2.end_offset << 2);
m_arb_shader += "# RSX_FP_OPCODE_REP_2\n"; m_arb_shader += "# RSX_FP_OPCODE_REP_2\n";
} }
}
break; break;
}
case RSX_FP_OPCODE_RET: AddCodeAsm("$cond"); break; case RSX_FP_OPCODE_RET: AddCodeAsm("$cond"); break;
default: default:

View file

@ -39,16 +39,12 @@ namespace rsx
if (m_panels.size() < 7) if (m_panels.size() < 7)
{ {
// Don't add this panel if there already exists one with the same panel mode // Don't add this panel if there already exists one with the same panel mode
for (const auto& existing : m_panels) if (std::none_of(m_panels.begin(), m_panels.end(), [&panel](const osk_panel& existing) { return existing.osk_panel_mode == panel.osk_panel_mode; }))
{ {
if (existing.osk_panel_mode == panel.osk_panel_mode)
{
return;
}
}
m_panels.push_back(panel); m_panels.push_back(panel);
} }
} }
}
void osk_dialog::step_panel(bool next_panel) void osk_dialog::step_panel(bool next_panel)
{ {

View file

@ -9,7 +9,7 @@ namespace rsx
{ {
osk_panel_mode = panel_mode; osk_panel_mode = panel_mode;
// TODO: Use proper translations for Space/Backspace/Enter etc. and make sure they fit in the grid. // TODO: Use proper translations for Space/Backspace/Return etc. and make sure they fit in the grid.
switch (panel_mode) switch (panel_mode)
{ {
case CELL_OSKDIALOG_PANELMODE_DEFAULT: case CELL_OSKDIALOG_PANELMODE_DEFAULT:
@ -46,7 +46,7 @@ namespace rsx
{ {
space = U"Space"; space = U"Space";
backspace = U"Backspace"; backspace = U"Backspace";
enter = U"Enter"; enter = U"Return";
} }
} }
} }

View file

@ -47,7 +47,7 @@ namespace rsx
protected: protected:
std::u32string space; std::u32string space;
std::u32string backspace; std::u32string backspace;
std::u32string enter; std::u32string enter; // Return key. Named 'enter' because 'return' is a reserved statement in cpp.
}; };
struct osk_panel_latin : public osk_panel struct osk_panel_latin : public osk_panel

View file

@ -656,12 +656,11 @@ int evdev_joystick_handler::add_device(const std::string& device, const std::sha
name == device) name == device)
{ {
// It's a joystick. Now let's make sure we don't already have this one. // It's a joystick. Now let's make sure we don't already have this one.
auto it = std::find_if(bindings.begin(), bindings.end(), [&path](std::pair<std::shared_ptr<PadDevice>, std::shared_ptr<Pad>> binding) if (std::any_of(bindings.begin(), bindings.end(), [&path](std::pair<std::shared_ptr<PadDevice>, std::shared_ptr<Pad>> binding)
{ {
auto device = std::static_pointer_cast<EvdevDevice>(binding.first); const auto device = std::static_pointer_cast<EvdevDevice>(binding.first);
return device && path == device->path; return device && path == device->path;
}); }))
if (it != bindings.end())
{ {
libevdev_free(dev); libevdev_free(dev);
close(fd); close(fd);
@ -1017,7 +1016,7 @@ bool evdev_joystick_handler::check_button(const EvdevButton& b, const u32 code)
bool evdev_joystick_handler::check_buttons(const std::vector<EvdevButton>& b, const u32 code) bool evdev_joystick_handler::check_buttons(const std::vector<EvdevButton>& b, const u32 code)
{ {
return std::find_if(b.begin(), b.end(), [this, code](const EvdevButton& b) { return check_button(b, code); }) != b.end(); return std::any_of(b.begin(), b.end(), [this, code](const EvdevButton& b) { return check_button(b, code); });
}; };
bool evdev_joystick_handler::get_is_left_trigger(u64 keyCode) bool evdev_joystick_handler::get_is_left_trigger(u64 keyCode)

View file

@ -2,12 +2,12 @@
#include "custom_dialog.h" #include "custom_dialog.h"
#include "Emu/Cell/Modules/cellMsgDialog.h" #include "Emu/Cell/Modules/cellMsgDialog.h"
#include <QDialogButtonBox>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QTextEdit> #include <QTextEdit>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QFormLayout> #include <QFormLayout>
#include <QPushButton>
#include <QRegExpValidator> #include <QRegExpValidator>
constexpr auto qstr = QString::fromStdString; constexpr auto qstr = QString::fromStdString;
@ -47,17 +47,10 @@ void osk_dialog_frame::Create(const std::string& title, const std::u16string& me
// Text Input Counter // Text Input Counter
const QString text = QString::fromStdU16String(std::u16string(init_text)); const QString text = QString::fromStdU16String(std::u16string(init_text));
QLabel* inputCount = new QLabel(QString("%1/%2").arg(text.length()).arg(charlimit)); QLabel* input_count_label = new QLabel(QString("%1/%2").arg(text.length()).arg(charlimit));
// Ok Button
QPushButton* button_ok = new QPushButton(tr("OK"), m_dialog);
// Button Layout // Button Layout
QHBoxLayout* buttonsLayout = new QHBoxLayout; QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok);
buttonsLayout->setAlignment(Qt::AlignCenter);
buttonsLayout->addStretch();
buttonsLayout->addWidget(button_ok);
buttonsLayout->addStretch();
// Input Layout // Input Layout
QHBoxLayout* inputLayout = new QHBoxLayout; QHBoxLayout* inputLayout = new QHBoxLayout;
@ -79,7 +72,7 @@ void osk_dialog_frame::Create(const std::string& title, const std::u16string& me
connect(input, &QLineEdit::textChanged, [=, this](const QString& text) connect(input, &QLineEdit::textChanged, [=, this](const QString& text)
{ {
inputCount->setText(QString("%1/%2").arg(text.length()).arg(charlimit)); input_count_label->setText(QString("%1/%2").arg(text.length()).arg(charlimit));
SetOskText(text); SetOskText(text);
on_osk_input_entered(); on_osk_input_entered();
}); });
@ -143,7 +136,7 @@ void osk_dialog_frame::Create(const std::string& title, const std::u16string& me
m_text_old = text; m_text_old = text;
inputCount->setText(QString("%1/%2").arg(text.length()).arg(charlimit)); input_count_label->setText(QString("%1/%2").arg(text.length()).arg(charlimit));
SetOskText(text); SetOskText(text);
on_osk_input_entered(); on_osk_input_entered();
}); });
@ -151,17 +144,17 @@ void osk_dialog_frame::Create(const std::string& title, const std::u16string& me
inputLayout->addWidget(input); inputLayout->addWidget(input);
} }
inputLayout->addWidget(inputCount); inputLayout->addWidget(input_count_label);
QFormLayout* layout = new QFormLayout(m_dialog); QFormLayout* layout = new QFormLayout(m_dialog);
layout->setFormAlignment(Qt::AlignHCenter); layout->setFormAlignment(Qt::AlignHCenter);
layout->addRow(message_label); layout->addRow(message_label);
layout->addRow(inputLayout); layout->addRow(inputLayout);
layout->addRow(buttonsLayout); layout->addWidget(button_box);
m_dialog->setLayout(layout); m_dialog->setLayout(layout);
// Events // Events
connect(button_ok, &QAbstractButton::clicked, m_dialog, &QDialog::accept); connect(button_box, &QDialogButtonBox::accepted, m_dialog, &QDialog::accept);
connect(m_dialog, &QDialog::accepted, [this]() connect(m_dialog, &QDialog::accepted, [this]()
{ {

View file

@ -258,51 +258,51 @@ pad_settings_dialog::~pad_settings_dialog()
void pad_settings_dialog::InitButtons() void pad_settings_dialog::InitButtons()
{ {
m_padButtons = new QButtonGroup(this); m_pad_buttons = new QButtonGroup(this);
m_palette = ui->b_left->palette(); // save normal palette m_palette = ui->b_left->palette(); // save normal palette
auto insertButton = [this](int id, QPushButton* button) const auto insert_button = [this](int id, QPushButton* button)
{ {
m_padButtons->addButton(button, id); m_pad_buttons->addButton(button, id);
button->installEventFilter(this); button->installEventFilter(this);
}; };
insertButton(button_ids::id_pad_lstick_left, ui->b_lstick_left); insert_button(button_ids::id_pad_lstick_left, ui->b_lstick_left);
insertButton(button_ids::id_pad_lstick_down, ui->b_lstick_down); insert_button(button_ids::id_pad_lstick_down, ui->b_lstick_down);
insertButton(button_ids::id_pad_lstick_right, ui->b_lstick_right); insert_button(button_ids::id_pad_lstick_right, ui->b_lstick_right);
insertButton(button_ids::id_pad_lstick_up, ui->b_lstick_up); insert_button(button_ids::id_pad_lstick_up, ui->b_lstick_up);
insertButton(button_ids::id_pad_left, ui->b_left); insert_button(button_ids::id_pad_left, ui->b_left);
insertButton(button_ids::id_pad_down, ui->b_down); insert_button(button_ids::id_pad_down, ui->b_down);
insertButton(button_ids::id_pad_right, ui->b_right); insert_button(button_ids::id_pad_right, ui->b_right);
insertButton(button_ids::id_pad_up, ui->b_up); insert_button(button_ids::id_pad_up, ui->b_up);
insertButton(button_ids::id_pad_l1, ui->b_shift_l1); insert_button(button_ids::id_pad_l1, ui->b_shift_l1);
insertButton(button_ids::id_pad_l2, ui->b_shift_l2); insert_button(button_ids::id_pad_l2, ui->b_shift_l2);
insertButton(button_ids::id_pad_l3, ui->b_shift_l3); insert_button(button_ids::id_pad_l3, ui->b_shift_l3);
insertButton(button_ids::id_pad_start, ui->b_start); insert_button(button_ids::id_pad_start, ui->b_start);
insertButton(button_ids::id_pad_select, ui->b_select); insert_button(button_ids::id_pad_select, ui->b_select);
insertButton(button_ids::id_pad_ps, ui->b_ps); insert_button(button_ids::id_pad_ps, ui->b_ps);
insertButton(button_ids::id_pad_r1, ui->b_shift_r1); insert_button(button_ids::id_pad_r1, ui->b_shift_r1);
insertButton(button_ids::id_pad_r2, ui->b_shift_r2); insert_button(button_ids::id_pad_r2, ui->b_shift_r2);
insertButton(button_ids::id_pad_r3, ui->b_shift_r3); insert_button(button_ids::id_pad_r3, ui->b_shift_r3);
insertButton(button_ids::id_pad_square, ui->b_square); insert_button(button_ids::id_pad_square, ui->b_square);
insertButton(button_ids::id_pad_cross, ui->b_cross); insert_button(button_ids::id_pad_cross, ui->b_cross);
insertButton(button_ids::id_pad_circle, ui->b_circle); insert_button(button_ids::id_pad_circle, ui->b_circle);
insertButton(button_ids::id_pad_triangle, ui->b_triangle); insert_button(button_ids::id_pad_triangle, ui->b_triangle);
insertButton(button_ids::id_pad_rstick_left, ui->b_rstick_left); insert_button(button_ids::id_pad_rstick_left, ui->b_rstick_left);
insertButton(button_ids::id_pad_rstick_down, ui->b_rstick_down); insert_button(button_ids::id_pad_rstick_down, ui->b_rstick_down);
insertButton(button_ids::id_pad_rstick_right, ui->b_rstick_right); insert_button(button_ids::id_pad_rstick_right, ui->b_rstick_right);
insertButton(button_ids::id_pad_rstick_up, ui->b_rstick_up); insert_button(button_ids::id_pad_rstick_up, ui->b_rstick_up);
m_padButtons->addButton(ui->b_refresh, button_ids::id_refresh); m_pad_buttons->addButton(ui->b_refresh, button_ids::id_refresh);
m_padButtons->addButton(ui->b_addProfile, button_ids::id_add_profile); m_pad_buttons->addButton(ui->b_addProfile, button_ids::id_add_profile);
connect(m_padButtons, &QButtonGroup::idClicked, this, &pad_settings_dialog::OnPadButtonClicked); connect(m_pad_buttons, &QButtonGroup::idClicked, this, &pad_settings_dialog::OnPadButtonClicked);
connect(&m_timer, &QTimer::timeout, [this]() connect(&m_timer, &QTimer::timeout, [this]()
{ {
@ -311,7 +311,7 @@ void pad_settings_dialog::InitButtons()
ReactivateButtons(); ReactivateButtons();
return; return;
} }
m_padButtons->button(m_button_id)->setText(tr("[ Waiting %1 ]").arg(m_seconds)); m_pad_buttons->button(m_button_id)->setText(tr("[ Waiting %1 ]").arg(m_seconds));
}); });
connect(ui->chb_vibration_large, &QCheckBox::clicked, [this](bool checked) connect(ui->chb_vibration_large, &QCheckBox::clicked, [this](bool checked)
@ -597,17 +597,17 @@ void pad_settings_dialog::ReactivateButtons()
return; return;
} }
if (m_padButtons->button(m_button_id)) if (m_pad_buttons->button(m_button_id))
{ {
m_padButtons->button(m_button_id)->setPalette(m_palette); m_pad_buttons->button(m_button_id)->setPalette(m_palette);
m_padButtons->button(m_button_id)->releaseMouse(); m_pad_buttons->button(m_button_id)->releaseMouse();
} }
m_button_id = button_ids::id_pad_begin; m_button_id = button_ids::id_pad_begin;
UpdateLabels(); UpdateLabels();
SwitchButtons(true); SwitchButtons(true);
for (auto but : m_padButtons->buttons()) for (auto but : m_pad_buttons->buttons())
{ {
but->setFocusPolicy(Qt::StrongFocus); but->setFocusPolicy(Qt::StrongFocus);
} }
@ -1029,7 +1029,7 @@ void pad_settings_dialog::UpdateLabels(bool is_reset)
} }
// The button has to contain at least one character, because it would be square'ish otherwise // The button has to contain at least one character, because it would be square'ish otherwise
m_padButtons->button(entry.first)->setText(entry.second.text.isEmpty() ? QStringLiteral("-") : entry.second.text); m_pad_buttons->button(entry.first)->setText(entry.second.text.isEmpty() ? QStringLiteral("-") : entry.second.text);
} }
} }
@ -1050,7 +1050,7 @@ void pad_settings_dialog::SwitchButtons(bool is_enabled)
for (int i = button_ids::id_pad_begin + 1; i < button_ids::id_pad_end; i++) for (int i = button_ids::id_pad_begin + 1; i < button_ids::id_pad_end; i++)
{ {
m_padButtons->button(i)->setEnabled(is_enabled); m_pad_buttons->button(i)->setEnabled(is_enabled);
} }
} }
@ -1078,7 +1078,7 @@ void pad_settings_dialog::OnPadButtonClicked(int id)
break; break;
} }
for (auto but : m_padButtons->buttons()) for (auto but : m_pad_buttons->buttons())
{ {
but->setFocusPolicy(Qt::ClickFocus); but->setFocusPolicy(Qt::ClickFocus);
} }
@ -1100,9 +1100,9 @@ void pad_settings_dialog::OnPadButtonClicked(int id)
m_last_pos = QCursor::pos(); m_last_pos = QCursor::pos();
m_button_id = id; m_button_id = id;
m_padButtons->button(m_button_id)->setText(tr("[ Waiting %1 ]").arg(MAX_SECONDS)); m_pad_buttons->button(m_button_id)->setText(tr("[ Waiting %1 ]").arg(MAX_SECONDS));
m_padButtons->button(m_button_id)->setPalette(QPalette(Qt::blue)); m_pad_buttons->button(m_button_id)->setPalette(QPalette(Qt::blue));
m_padButtons->button(m_button_id)->grabMouse(); m_pad_buttons->button(m_button_id)->grabMouse();
SwitchButtons(false); // disable all buttons, needed for using Space, Enter and other specific buttons SwitchButtons(false); // disable all buttons, needed for using Space, Enter and other specific buttons
m_timer.start(1000); m_timer.start(1000);
} }

View file

@ -120,7 +120,7 @@ private:
bool m_enable_battery{ false }; bool m_enable_battery{ false };
// Button Mapping // Button Mapping
QButtonGroup* m_padButtons = nullptr; QButtonGroup* m_pad_buttons = nullptr;
u32 m_button_id = id_pad_begin; u32 m_button_id = id_pad_begin;
std::map<int /*id*/, pad_button /*info*/> m_cfg_entries; std::map<int /*id*/, pad_button /*info*/> m_cfg_entries;