Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt/Input: add color picker for DS4 Controller LEDs #5929

Merged
merged 1 commit into from May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion rpcs3/Emu/Io/PadHandler.cpp
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "PadHandler.h"

cfg_input g_cfg_input;
Expand Down Expand Up @@ -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) + "/";
Expand Down
3 changes: 3 additions & 0 deletions rpcs3/Emu/Io/PadHandler.h
Expand Up @@ -385,6 +385,7 @@ class PadHandlerBase
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;
Expand Down Expand Up @@ -457,6 +458,7 @@ class PadHandlerBase
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);
Expand All @@ -467,6 +469,7 @@ class PadHandlerBase
//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
Expand Down
35 changes: 35 additions & 0 deletions rpcs3/ds4_pad_handler.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/ds4_pad_handler.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "Emu/Io/PadHandler.h"
#include "Utilities/Thread.h"
Expand Down Expand Up @@ -144,6 +144,7 @@ class ds4_pad_handler final : public PadHandlerBase
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:
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/rpcs3qt/main_window.cpp
Expand Up @@ -1282,7 +1282,7 @@ void main_window::CreateConnects()

auto openPadSettings = [this]
{
auto resetPadHandlers = [this]
auto resetPadHandlers = [this](int/* result*/)
{
if (Emu.IsStopped())
{
Expand All @@ -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())
{
Expand Down
44 changes: 43 additions & 1 deletion rpcs3/rpcs3qt/pad_settings_dialog.cpp
@@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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])
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion rpcs3/rpcs3qt/pad_settings_dialog.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QButtonGroup>
#include <QDialog>
Expand Down Expand Up @@ -66,6 +66,7 @@ class pad_settings_dialog : public QDialog

id_pad_end, // end

id_led,
id_reset_parameters,
id_blacklist,
id_refresh,
Expand Down Expand Up @@ -107,6 +108,7 @@ private Q_SLOTS:
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;
Expand Down
42 changes: 40 additions & 2 deletions rpcs3/rpcs3qt/pad_settings_dialog.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/qt_utils.cpp
@@ -1,4 +1,4 @@


#include "qt_utils.h"
#include <QApplication>
#include <QBitmap>
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/qt_utils.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "stdafx.h"
#include <QtCore>
Expand Down