Permalink
Browse files

Qt/TAS: Implement recentering feature

  • Loading branch information...
spycrab committed Aug 13, 2018
1 parent 84c2451 commit 1c793503b145cdcac505cf2c7bf36d73f295d2e6
Showing with 34 additions and 12 deletions.
  1. +17 −6 Source/Core/DolphinQt/TAS/IRWidget.cpp
  2. +17 −6 Source/Core/DolphinQt/TAS/StickWidget.cpp
@@ -5,6 +5,7 @@
#include "DolphinQt/TAS/IRWidget.h"
#include <algorithm>
#include <cmath>
#include <QMouseEvent>
#include <QPainter>
@@ -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();
m_x = std::max(0, std::min(static_cast<int>(ir_max_x), new_x));
m_y = std::max(0, std::min(static_cast<int>(ir_max_y), new_y));
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<int>(ir_max_x), new_x));
m_y = std::max(0, std::min(static_cast<int>(ir_max_y), new_y));
}
emit ChangedX(m_x);
emit ChangedY(m_y);
@@ -5,6 +5,7 @@
#include "DolphinQt/TAS/StickWidget.h"
#include <algorithm>
#include <cmath>
#include <QMouseEvent>
#include <QPainter>
@@ -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();
m_x = std::max(0, std::min(static_cast<int>(m_max_x), new_x));
m_y = std::max(0, std::min(static_cast<int>(m_max_y), new_y));
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<int>(m_max_x), new_x));
m_y = std::max(0, std::min(static_cast<int>(m_max_y), new_y));
}
emit ChangedX(m_x);
emit ChangedY(m_y);

0 comments on commit 1c79350

Please sign in to comment.