From 1c793503b145cdcac505cf2c7bf36d73f295d2e6 Mon Sep 17 00:00:00 2001 From: spycrab Date: Mon, 13 Aug 2018 14:41:53 +0200 Subject: [PATCH] Qt/TAS: Implement recentering feature --- Source/Core/DolphinQt/TAS/IRWidget.cpp | 21 ++++++++++++++++----- Source/Core/DolphinQt/TAS/StickWidget.cpp | 21 ++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Source/Core/DolphinQt/TAS/IRWidget.cpp b/Source/Core/DolphinQt/TAS/IRWidget.cpp index 9e4a7d14ae..14a1176504 100644 --- a/Source/Core/DolphinQt/TAS/IRWidget.cpp +++ b/Source/Core/DolphinQt/TAS/IRWidget.cpp @@ -5,6 +5,7 @@ #include "DolphinQt/TAS/IRWidget.h" #include +#include #include #include @@ -14,6 +15,8 @@ IRWidget::IRWidget(QWidget* parent) : QWidget(parent) { setMouseTracking(false); + setToolTip(tr("Left click to set the IR value.\n" + "Right click to re-center it.")); } void IRWidget::SetX(u16 x) @@ -64,12 +67,20 @@ void IRWidget::mouseMoveEvent(QMouseEvent* event) void IRWidget::handleMouseEvent(QMouseEvent* event) { - // convert from widget space to value space - int new_x = ir_max_x - (event->x() * ir_max_x) / width(); - int new_y = (event->y() * ir_max_y) / height(); + if (event->button() == Qt::RightButton) + { + m_x = std::round(ir_max_x / 2.); + m_y = std::round(ir_max_y / 2.); + } + else + { + // convert from widget space to value space + int new_x = ir_max_x - (event->x() * ir_max_x) / width(); + int new_y = (event->y() * ir_max_y) / height(); - m_x = std::max(0, std::min(static_cast(ir_max_x), new_x)); - m_y = std::max(0, std::min(static_cast(ir_max_y), new_y)); + m_x = std::max(0, std::min(static_cast(ir_max_x), new_x)); + m_y = std::max(0, std::min(static_cast(ir_max_y), new_y)); + } emit ChangedX(m_x); emit ChangedY(m_y); diff --git a/Source/Core/DolphinQt/TAS/StickWidget.cpp b/Source/Core/DolphinQt/TAS/StickWidget.cpp index b9d6a104bc..2f21685425 100644 --- a/Source/Core/DolphinQt/TAS/StickWidget.cpp +++ b/Source/Core/DolphinQt/TAS/StickWidget.cpp @@ -5,6 +5,7 @@ #include "DolphinQt/TAS/StickWidget.h" #include +#include #include #include @@ -15,6 +16,8 @@ StickWidget::StickWidget(QWidget* parent, u16 max_x, u16 max_y) : QWidget(parent), m_max_x(max_x), m_max_y(max_y) { setMouseTracking(false); + setToolTip(tr("Left click to set the stick value.\n" + "Right click to re-center it.")); } void StickWidget::SetX(u16 x) @@ -65,12 +68,20 @@ void StickWidget::mouseMoveEvent(QMouseEvent* event) void StickWidget::handleMouseEvent(QMouseEvent* event) { - // convert from widget space to value space - int new_x = (event->x() * m_max_x) / width(); - int new_y = m_max_y - (event->y() * m_max_y) / height(); + if (event->button() == Qt::RightButton) + { + m_x = std::round(m_max_x / 2.); + m_y = std::round(m_max_y / 2.); + } + else + { + // convert from widget space to value space + int new_x = (event->x() * m_max_x) / width(); + int new_y = m_max_y - (event->y() * m_max_y) / height(); - m_x = std::max(0, std::min(static_cast(m_max_x), new_x)); - m_y = std::max(0, std::min(static_cast(m_max_y), new_y)); + m_x = std::max(0, std::min(static_cast(m_max_x), new_x)); + m_y = std::max(0, std::min(static_cast(m_max_y), new_y)); + } emit ChangedX(m_x); emit ChangedY(m_y);