1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Qt/input: add LED color picker to pad settings dialog

This commit is contained in:
Megamouse 2019-05-09 21:31:43 +02:00
parent 7ead021aa7
commit fce9d6a7b8
10 changed files with 136 additions and 10 deletions

View File

@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "PadHandler.h"
cfg_input g_cfg_input;
@ -263,6 +263,11 @@ bool PadHandlerBase::has_deadzones()
return b_has_deadzones;
}
bool PadHandlerBase::has_led()
{
return b_has_led;
}
std::string PadHandlerBase::get_config_dir(pad_handler type)
{
return fs::get_config_dir() + "/InputConfigs/" + fmt::format("%s", type) + "/";

View File

@ -385,6 +385,7 @@ protected:
int m_trigger_threshold = 0;
int m_thumb_threshold = 0;
bool b_has_led = false;
bool b_has_deadzones = false;
bool b_has_rumble = false;
bool b_has_config = false;
@ -457,6 +458,7 @@ public:
bool has_config();
bool has_rumble();
bool has_deadzones();
bool has_led();
static std::string get_config_dir(pad_handler type);
static std::string get_config_filename(int i);
@ -467,6 +469,7 @@ public:
//Sets window to config the controller(optional)
virtual void GetNextButtonPress(const std::string& /*padId*/, const std::function<void(u16, std::string, std::string, int[])>& /*callback*/, const std::function<void(std::string)>& /*fail_callback*/, bool /*get_blacklist*/ = false, const std::vector<std::string>& /*buttons*/ = {}) {};
virtual void TestVibration(const std::string& /*padId*/, u32 /*largeMotor*/, u32 /*smallMotor*/) {};
virtual void SetLED(const std::string& /*padId*/, s32 /*r*/, s32 /*g*/, s32 /*b*/){};
//Return list of devices for that handler
virtual std::vector<std::string> ListDevices() = 0;
//Callback called during pad_thread::ThreadFunc

View File

@ -95,6 +95,7 @@ ds4_pad_handler::ds4_pad_handler() : PadHandlerBase(pad_handler::ds4)
b_has_config = true;
b_has_rumble = true;
b_has_deadzones = true;
b_has_led = true;
m_name_string = "DS4 Pad #";
m_max_devices = CELL_PAD_MAX_PORT_NUM;
@ -250,6 +251,40 @@ void ds4_pad_handler::TestVibration(const std::string& padId, u32 largeMotor, u3
SendVibrateData(device);
}
void ds4_pad_handler::SetLED(const std::string& padId, s32 r, s32 g, s32 b)
{
std::shared_ptr<DS4Device> device = GetDevice(padId);
if (device == nullptr || device->hidDevice == nullptr)
return;
int index = 0;
for (int i = 0; i < MAX_GAMEPADS; i++)
{
if (g_cfg_input.player[i]->handler == pad_handler::ds4)
{
if (g_cfg_input.player[i]->device.to_string() == padId)
{
m_pad_configs[index].load();
device->config = &m_pad_configs[index];
break;
}
index++;
}
}
// disable pulse
device->led_delay_on = 0;
device->led_delay_off = 0;
// set new color
device->config->colorR.set(r);
device->config->colorG.set(g);
device->config->colorB.set(b);
// Show new color :)
SendVibrateData(device);
}
std::shared_ptr<ds4_pad_handler::DS4Device> ds4_pad_handler::GetDevice(const std::string& padId, bool try_reconnect)
{
if (!Init())

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "Emu/Io/PadHandler.h"
#include "Utilities/Thread.h"
@ -144,6 +144,7 @@ public:
void ThreadProc() override;
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, std::string, int[])>& buttonCallback, const std::function<void(std::string)>& fail_callback, bool get_blacklist = false, const std::vector<std::string>& buttons = {}) override;
void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override;
void SetLED(const std::string& padId, s32 r, s32 g, s32 b) override;
void init_config(pad_config* cfg, const std::string& name) override;
private:

View File

@ -1282,7 +1282,7 @@ void main_window::CreateConnects()
auto openPadSettings = [this]
{
auto resetPadHandlers = [this]
auto resetPadHandlers = [this](int/* result*/)
{
if (Emu.IsStopped())
{
@ -1295,7 +1295,7 @@ void main_window::CreateConnects()
Emu.GetCallbacks().enable_pads(false);
}
pad_settings_dialog dlg(this);
connect(&dlg, &QDialog::accepted, resetPadHandlers);
connect(&dlg, &QDialog::finished, resetPadHandlers);
dlg.exec();
if (!Emu.IsStopped())
{

View File

@ -1,10 +1,11 @@
#include <QCheckBox>
#include <QCheckBox>
#include <QGroupBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QPainter>
#include <QInputDialog>
#include <QMessageBox>
#include <QColorDialog>
#include "qt_utils.h"
#include "pad_settings_dialog.h"
@ -246,6 +247,7 @@ void pad_settings_dialog::InitButtons()
insertButton(button_ids::id_pad_rstick_right, ui->b_rstick_right);
insertButton(button_ids::id_pad_rstick_up, ui->b_rstick_up);
m_padButtons->addButton(ui->b_led, button_ids::id_led);
m_padButtons->addButton(ui->b_reset, button_ids::id_reset_parameters);
m_padButtons->addButton(ui->b_blacklist, button_ids::id_blacklist);
m_padButtons->addButton(ui->b_refresh, button_ids::id_refresh);
@ -324,6 +326,19 @@ void pad_settings_dialog::InitButtons()
RepaintPreviewLabel(ui->preview_stick_right, value, ui->slider_stick_right->size().width(), rx, ry);
});
connect(ui->b_led, &QPushButton::clicked, [=]()
{
QColorDialog dlg(QColor(m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB), this);
dlg.setWindowTitle(tr("LED Color"));
if (dlg.exec() == QColorDialog::Accepted)
{
const QColor newColor = dlg.selectedColor();
m_handler->SetLED(m_device_name, newColor.red(), newColor.green(), newColor.blue());
ui->b_led->setIcon(gui::utils::get_colorized_icon(QIcon(":/Icons/controllers.png"), Qt::black, newColor));
ui->b_led->setProperty("led", newColor);
}
});
// Enable Button Remapping
const auto& callback = [=](u16 val, std::string name, std::string pad_name, int preview_values[6])
{
@ -529,6 +544,15 @@ void pad_settings_dialog::ReloadButtons()
RepaintPreviewLabel(ui->preview_stick_left, ui->slider_stick_left->value(), ui->slider_stick_left->size().width(), lx, ly);
RepaintPreviewLabel(ui->preview_stick_right, ui->slider_stick_right->value(), ui->slider_stick_right->size().width(), rx, ry);
// Enable and repaint the LED Button
m_enable_led = m_handler->has_led();
m_handler->SetLED(m_device_name, m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB);
const QColor led_color(m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB);
ui->b_led->setIcon(gui::utils::get_colorized_icon(QIcon(":/Icons/controllers.png"), Qt::black, led_color));
ui->b_led->setProperty("led", led_color);
ui->gb_led->setVisible(m_enable_led);
}
void pad_settings_dialog::ReactivateButtons()
@ -725,6 +749,14 @@ void pad_settings_dialog::UpdateLabel(bool is_reset)
ui->slider_stick_left->setValue(m_handler_cfg.lstickdeadzone);
ui->slider_stick_right->setValue(m_handler_cfg.rstickdeadzone);
}
if (m_handler->has_led())
{
const QColor led_color(m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB);
ui->b_led->setProperty("led", led_color);
ui->b_led->setIcon(gui::utils::get_colorized_icon(QIcon(":/Icons/controllers.png"), Qt::black, led_color));
m_handler->SetLED(m_device_name, m_handler_cfg.colorR, m_handler_cfg.colorG, m_handler_cfg.colorB);
}
}
for (auto& entry : m_cfg_entries)
@ -748,6 +780,7 @@ void pad_settings_dialog::SwitchButtons(bool is_enabled)
ui->gb_vibration->setEnabled(is_enabled && m_enable_rumble);
ui->gb_sticks->setEnabled(is_enabled && m_enable_deadzones);
ui->gb_triggers->setEnabled(is_enabled && m_enable_deadzones);
ui->gb_led->setEnabled(is_enabled && m_enable_led);
ui->gb_mouse_accel->setEnabled(is_enabled && m_handler->m_type == pad_handler::keyboard);
ui->gb_mouse_dz->setEnabled(is_enabled && m_handler->m_type == pad_handler::keyboard);
ui->gb_stick_lerp->setEnabled(is_enabled && m_handler->m_type == pad_handler::keyboard);
@ -762,6 +795,7 @@ void pad_settings_dialog::OnPadButtonClicked(int id)
{
switch (id)
{
case button_ids::id_led:
case button_ids::id_pad_begin:
case button_ids::id_pad_end:
case button_ids::id_add_profile:
@ -1074,6 +1108,14 @@ void pad_settings_dialog::SaveProfile()
m_handler_cfg.rstickdeadzone.set(ui->slider_stick_right->value());
}
if (m_handler->has_led() && ui->b_led->property("led").canConvert<QColor>())
{
const QColor led_color = ui->b_led->property("led").value<QColor>();
m_handler_cfg.colorR.set(led_color.red());
m_handler_cfg.colorG.set(led_color.green());
m_handler_cfg.colorB.set(led_color.blue());
}
if (m_handler->m_type == pad_handler::keyboard)
{
m_handler_cfg.mouse_acceleration_x.set(ui->mouse_accel_x->value() * 100);

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <QButtonGroup>
#include <QDialog>
@ -66,6 +66,7 @@ class pad_settings_dialog : public QDialog
id_pad_end, // end
id_led,
id_reset_parameters,
id_blacklist,
id_refresh,
@ -107,6 +108,7 @@ private:
bool m_enable_buttons{ false };
bool m_enable_rumble{ false };
bool m_enable_deadzones{ false };
bool m_enable_led{ false };
// Button Mapping
QButtonGroup* m_padButtons;

View File

@ -25,8 +25,8 @@
<rect>
<x>60</x>
<y>10</y>
<width>878</width>
<height>624</height>
<width>886</width>
<height>612</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@ -1172,6 +1172,9 @@
<item>
<widget class="QWidget" name="widget_9" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<property name="spacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
@ -1412,6 +1415,41 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_led">
<property name="title">
<string>LED</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_39">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QPushButton" name="b_led">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/Icons/controllers.png</normaloff>:/Icons/controllers.png</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_14">
<property name="title">

View File

@ -1,4 +1,4 @@

#include "qt_utils.h"
#include <QApplication>
#include <QBitmap>

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "stdafx.h"
#include <QtCore>