mirror of
https://github.com/ARMSX2/ARMSX3.git
synced 2026-08-24 16:58:52 -07:00
Qt: Allow to select ps move hue by mouse click
This commit is contained in:
@@ -17,6 +17,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <numbers>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <set>
|
||||
@@ -292,16 +293,14 @@ public:
|
||||
virtual void get_motion_sensors(const std::string& pad_id, const motion_callback& callback, const motion_fail_callback& fail_callback, motion_preview_values preview_values, const std::array<AnalogSensor, 4>& sensors);
|
||||
virtual std::unordered_map<u32, std::string> get_motion_axis_list() const { return {}; }
|
||||
|
||||
static constexpr f32 PI = 3.14159265f;
|
||||
|
||||
static f32 degree_to_rad(f32 degree)
|
||||
{
|
||||
return degree * PI / 180.0f;
|
||||
return degree * std::numbers::pi_v<f32> / 180.0f;
|
||||
}
|
||||
|
||||
static f32 rad_to_degree(f32 radians)
|
||||
{
|
||||
return radians * 180.0f / PI;
|
||||
return radians * 180.0f / std::numbers::pi_v<f32>;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "Utilities/File.h"
|
||||
#include "Emu/Cell/timers.hpp"
|
||||
|
||||
#include <numbers>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
@@ -350,9 +352,8 @@ namespace rsx
|
||||
{
|
||||
if (sinus_modifier >= 0)
|
||||
{
|
||||
static constexpr f32 PI = 3.14159265f;
|
||||
const f32 pulse_sinus_x = static_cast<f32>(get_system_time() / 1000) * pulse_speed_modifier;
|
||||
pulse_sinus_offset = fmod(pulse_sinus_x + sinus_modifier * PI, 2.0f * PI);
|
||||
pulse_sinus_offset = fmod(pulse_sinus_x + sinus_modifier * std::numbers::pi_v<f32>, 2.0f * std::numbers::pi_v<f32>);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "stdafx.h"
|
||||
#include "ps_move_calibration.h"
|
||||
|
||||
#include <numbers>
|
||||
|
||||
LOG_CHANNEL(move_log, "Move");
|
||||
|
||||
// This is basically the same as in ps move api
|
||||
@@ -176,8 +178,7 @@ void psmove_calibration_get_usb_gyro_values(const reports::ps_move_calibration_b
|
||||
{
|
||||
const u8* data = calibration.data.data();
|
||||
|
||||
constexpr f32 PI = 3.14159265f;
|
||||
constexpr f32 rpm_to_rad_per_sec = (2.0f * PI) / 60.0f;
|
||||
constexpr f32 rpm_to_rad_per_sec = (2.0f * std::numbers::pi_v<f32>) / 60.0f;
|
||||
|
||||
switch (device.model)
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QSlider>
|
||||
#include <QMessageBox>
|
||||
#include <QMouseEvent>
|
||||
|
||||
LOG_CHANNEL(ps_move);
|
||||
|
||||
@@ -252,6 +253,8 @@ ps_move_tracker_dialog::ps_move_tracker_dialog(QWidget* parent)
|
||||
QMessageBox::warning(this, QObject::tr("Tracking not supported!"), QObject::tr("The PS Move tracking is not yet supported on this operating system."));
|
||||
});
|
||||
}
|
||||
|
||||
ui->imageLabel->installEventFilter(this);
|
||||
}
|
||||
|
||||
ps_move_tracker_dialog::~ps_move_tracker_dialog()
|
||||
@@ -273,6 +276,69 @@ ps_move_tracker_dialog::~ps_move_tracker_dialog()
|
||||
m_input_thread.reset();
|
||||
}
|
||||
|
||||
bool ps_move_tracker_dialog::eventFilter(QObject* object, QEvent* event)
|
||||
{
|
||||
if (event && object == ui->imageLabel && event->type() == QEvent::Type::MouseButtonRelease && m_view_mode == view_mode::contours)
|
||||
{
|
||||
const QMouseEvent* me = reinterpret_cast<QMouseEvent*>(event);
|
||||
|
||||
if (me->button() == Qt::MouseButton::LeftButton)
|
||||
{
|
||||
ps_move.notice("Selecting color with mouse click.");
|
||||
|
||||
f32 r = 0.0f;
|
||||
f32 g = 0.0f;
|
||||
f32 b = 0.0f;
|
||||
u32 count = 0;
|
||||
|
||||
{
|
||||
std::lock_guard lock(m_image_mutex);
|
||||
|
||||
const auto pos = me->localPos().toPoint();
|
||||
const QPixmap pixmap = ui->imageLabel->pixmap();
|
||||
|
||||
if (pixmap.rect().contains(pos))
|
||||
{
|
||||
const QImage image = pixmap.toImage();
|
||||
constexpr int radius = 3;
|
||||
|
||||
for (int y = pos.y() - radius; y <= pos.y() + radius; ++y)
|
||||
{
|
||||
for (int x = pos.x() - radius; x <= pos.x() + radius; ++x)
|
||||
{
|
||||
if (!image.rect().contains(x, y))
|
||||
continue;
|
||||
|
||||
const QColor color = image.pixelColor(x, y);
|
||||
|
||||
r += color.redF();
|
||||
g += color.greenF();
|
||||
b += color.blueF();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
r /= count;
|
||||
g /= count;
|
||||
b /= count;
|
||||
|
||||
ps_move.notice("Selected new color with mouse click (r=%f, b=%f, g=%f)", r, g, b);
|
||||
|
||||
cfg_ps_move* config = ::at32(g_cfg_move.move, m_index);
|
||||
const auto [hue, saturation, value] = ps_move_tracker<true>::rgb_to_hsv(r, g, b);
|
||||
config->hue.set(std::clamp<u32>(hue, config->hue.min, config->hue.max));
|
||||
update_hue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QDialog::eventFilter(object, event);
|
||||
}
|
||||
|
||||
void ps_move_tracker_dialog::update_color(bool update_sliders)
|
||||
{
|
||||
cfg_ps_move* config = ::at32(g_cfg_move.move, m_index);
|
||||
|
||||
@@ -26,6 +26,8 @@ public:
|
||||
virtual ~ps_move_tracker_dialog();
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
|
||||
void update_color(bool update_sliders = false);
|
||||
void update_hue(bool update_slider = false);
|
||||
void update_hue_threshold(bool update_slider = false);
|
||||
|
||||
Reference in New Issue
Block a user