@@ -0,0 +1,129 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "DolphinQt2/TAS/GCTASInputWindow.h"

#include <QCheckBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QSpinBox>
#include <QVBoxLayout>

#include "Common/CommonTypes.h"
#include "DolphinQt2/TAS/Shared.h"
#include "InputCommon/GCPadStatus.h"

GCTASInputWindow::GCTASInputWindow(QWidget* parent, int num) : QDialog(parent)
{
setWindowTitle(tr("GameCube TAS Input %1").arg(num + 1));
auto* main_stick_box = CreateStickInputs(this, tr("Main Stick (ALT+F/G)"), m_x_main_stick_value,
m_y_main_stick_value, 255, 255, Qt::Key_F, Qt::Key_G);
auto* c_stick_box = CreateStickInputs(this, tr("C Stick (ALT+H/J)"), m_x_c_stick_value,
m_y_c_stick_value, 255, 255, Qt::Key_H, Qt::Key_J);

auto* top_layout = new QHBoxLayout;
top_layout->addWidget(main_stick_box);
top_layout->addWidget(c_stick_box);

auto* triggers_box = new QGroupBox(tr("Triggers"));

auto* l_trigger_layout = CreateSliderValuePairLayout(this, tr("Left (ALT+N)"), m_l_trigger_value,
255, Qt::Key_N, triggers_box);
auto* r_trigger_layout = CreateSliderValuePairLayout(this, tr("Right (ALT+M)"), m_r_trigger_value,
255, Qt::Key_M, triggers_box);

auto* triggers_layout = new QVBoxLayout;
triggers_layout->addLayout(l_trigger_layout);
triggers_layout->addLayout(r_trigger_layout);
triggers_box->setLayout(triggers_layout);

m_a_button = new QCheckBox(QStringLiteral("&A"));
m_b_button = new QCheckBox(QStringLiteral("&B"));
m_x_button = new QCheckBox(QStringLiteral("&X"));
m_y_button = new QCheckBox(QStringLiteral("&Y"));
m_z_button = new QCheckBox(QStringLiteral("&Z"));
m_l_button = new QCheckBox(QStringLiteral("&L"));
m_r_button = new QCheckBox(QStringLiteral("&R"));
m_start_button = new QCheckBox(QStringLiteral("&START"));
m_left_button = new QCheckBox(QStringLiteral("L&eft"));
m_up_button = new QCheckBox(QStringLiteral("&Up"));
m_down_button = new QCheckBox(QStringLiteral("&Down"));
m_right_button = new QCheckBox(QStringLiteral("R&ight"));

auto* buttons_layout1 = new QHBoxLayout;
buttons_layout1->addWidget(m_a_button);
buttons_layout1->addWidget(m_b_button);
buttons_layout1->addWidget(m_x_button);
buttons_layout1->addWidget(m_y_button);
buttons_layout1->addWidget(m_z_button);
buttons_layout1->addWidget(m_l_button);
buttons_layout1->addWidget(m_r_button);

auto* buttons_layout2 = new QHBoxLayout;
buttons_layout2->addWidget(m_start_button);
buttons_layout2->addWidget(m_left_button);
buttons_layout2->addWidget(m_up_button);
buttons_layout2->addWidget(m_down_button);
buttons_layout2->addWidget(m_right_button);

auto* buttons_layout = new QVBoxLayout;
buttons_layout->setSizeConstraint(QLayout::SetFixedSize);
buttons_layout->addLayout(buttons_layout1);
buttons_layout->addLayout(buttons_layout2);

auto* buttons_box = new QGroupBox(tr("Buttons"));
buttons_box->setLayout(buttons_layout);

auto* layout = new QVBoxLayout;
layout->addLayout(top_layout);
layout->addWidget(triggers_box);
layout->addWidget(buttons_box);

setLayout(layout);
}

static void SetButton(QCheckBox* button, GCPadStatus* pad, u16 mask)
{
if (button->isChecked())
pad->button |= mask;
else
pad->button &= ~mask;
}

void GCTASInputWindow::GetValues(GCPadStatus* pad)
{
if (!isVisible())
return;

SetButton(m_a_button, pad, PAD_BUTTON_A);
SetButton(m_b_button, pad, PAD_BUTTON_B);
SetButton(m_x_button, pad, PAD_BUTTON_X);
SetButton(m_y_button, pad, PAD_BUTTON_Y);
SetButton(m_z_button, pad, PAD_TRIGGER_Z);
SetButton(m_l_button, pad, PAD_TRIGGER_L);
SetButton(m_r_button, pad, PAD_TRIGGER_R);
SetButton(m_left_button, pad, PAD_BUTTON_LEFT);
SetButton(m_up_button, pad, PAD_BUTTON_UP);
SetButton(m_down_button, pad, PAD_BUTTON_DOWN);
SetButton(m_right_button, pad, PAD_BUTTON_RIGHT);
SetButton(m_start_button, pad, PAD_BUTTON_START);

if (m_a_button->isChecked())
pad->analogA = 0xFF;
else
pad->analogA = 0x00;

if (m_b_button->isChecked())
pad->analogB = 0xFF;
else
pad->analogB = 0x00;

pad->triggerLeft = m_l_trigger_value->value();
pad->triggerRight = m_r_trigger_value->value();

pad->stickX = m_x_main_stick_value->value();
pad->stickY = m_y_main_stick_value->value();
pad->substickX = m_x_c_stick_value->value();
pad->substickY = m_y_c_stick_value->value();
}
@@ -0,0 +1,41 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <QDialog>

#include "Common/CommonTypes.h"

class QCheckBox;
class QSpinBox;
struct GCPadStatus;

class GCTASInputWindow : public QDialog
{
Q_OBJECT
public:
explicit GCTASInputWindow(QWidget* parent, int num);
void GetValues(GCPadStatus* pad);

private:
QCheckBox* m_a_button;
QCheckBox* m_b_button;
QCheckBox* m_x_button;
QCheckBox* m_y_button;
QCheckBox* m_z_button;
QCheckBox* m_l_button;
QCheckBox* m_r_button;
QCheckBox* m_start_button;
QCheckBox* m_left_button;
QCheckBox* m_up_button;
QCheckBox* m_down_button;
QCheckBox* m_right_button;
QSpinBox* m_l_trigger_value;
QSpinBox* m_r_trigger_value;
QSpinBox* m_x_main_stick_value;
QSpinBox* m_y_main_stick_value;
QSpinBox* m_x_c_stick_value;
QSpinBox* m_y_c_stick_value;
};
@@ -0,0 +1,77 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "DolphinQt2/TAS/IRWidget.h"

#include <algorithm>

#include <QMouseEvent>
#include <QPainter>

#include "Common/CommonTypes.h"

IRWidget::IRWidget(QWidget* parent) : QWidget(parent)
{
setMouseTracking(false);
}

void IRWidget::SetX(u16 x)
{
m_x = std::min(ir_max_x, x);

update();
}

void IRWidget::SetY(u16 y)
{
m_y = std::min(ir_max_y, y);

update();
}

void IRWidget::paintEvent(QPaintEvent* event)
{
QPainter painter(this);

painter.setBrush(Qt::white);
painter.drawRect(0, 0, width() - 1, height() - 1);

painter.drawLine(0, height() / 2, width(), height() / 2);
painter.drawLine(width() / 2, 0, width() / 2, height());

// convert from value space to widget space
u16 x = width() - (m_x * width()) / ir_max_x;
u16 y = (m_y * height()) / ir_max_y;

painter.drawLine(width() / 2, height() / 2, x, y);

painter.setBrush(Qt::blue);
int wh_avg = (width() + height()) / 2;
int radius = wh_avg / 30;
painter.drawEllipse(x - radius, y - radius, radius * 2, radius * 2);
}

void IRWidget::mousePressEvent(QMouseEvent* event)
{
handleMouseEvent(event);
}

void IRWidget::mouseMoveEvent(QMouseEvent* event)
{
handleMouseEvent(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));

emit ChangedX(m_x);
emit ChangedY(m_y);
update();
}
@@ -0,0 +1,38 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <QDialog>

#include "Common/CommonTypes.h"

class IRWidget : public QWidget
{
Q_OBJECT
public:
explicit IRWidget(QWidget* parent);

signals:
void ChangedX(u16 x);
void ChangedY(u16 y);

public slots:
void SetX(u16 x);
void SetY(u16 y);

protected:
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void handleMouseEvent(QMouseEvent* event);

private:
u16 m_x = 0;
u16 m_y = 0;
};

// Should be part of class but fails to compile on mac os
static const u16 ir_max_x = 1023;
static const u16 ir_max_y = 767;
@@ -0,0 +1,104 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "DolphinQt2/TAS/Shared.h"

#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QShortcut>
#include <QSlider>
#include <QSpinBox>
#include <QVBoxLayout>

#include "Common/CommonTypes.h"
#include "DolphinQt2/QtUtils/AspectRatioWidget.h"
#include "DolphinQt2/TAS/StickWidget.h"
#include "InputCommon/GCPadStatus.h"

QGroupBox* CreateStickInputs(QDialog* window, QString name, QSpinBox*& x_value, QSpinBox*& y_value,
u16 max_x, u16 max_y, Qt::Key x_shortcut_key, Qt::Key y_shortcut_key)
{
auto* box = new QGroupBox(name);

auto* x_layout = new QHBoxLayout;
x_value = CreateSliderValuePair(window, x_layout, max_x, x_shortcut_key, Qt::Horizontal, box);

auto* y_layout = new QVBoxLayout;
y_value = CreateSliderValuePair(window, y_layout, max_y, y_shortcut_key, Qt::Vertical, box);
y_value->setMaximumWidth(60);

auto* visual = new StickWidget(window, max_x, max_y);
window->connect(x_value, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), visual,
&StickWidget::SetX);
window->connect(y_value, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), visual,
&StickWidget::SetY);
window->connect(visual, &StickWidget::ChangedX, x_value, &QSpinBox::setValue);
window->connect(visual, &StickWidget::ChangedY, y_value, &QSpinBox::setValue);

x_value->setValue(max_x / 2);
y_value->setValue(max_y / 2);

auto* visual_ar = new AspectRatioWidget(visual, max_x, max_y);

auto* visual_layout = new QHBoxLayout;
visual_layout->addWidget(visual_ar);
visual_layout->addLayout(y_layout);

auto* layout = new QVBoxLayout;
layout->addLayout(x_layout);
layout->addLayout(visual_layout);
box->setLayout(layout);

return box;
}

QBoxLayout* CreateSliderValuePairLayout(QDialog* window, QString name, QSpinBox*& value, u16 max,
Qt::Key shortcut_key, QWidget* shortcut_widget, bool invert)
{
auto* label = new QLabel(name);

QBoxLayout* layout = new QHBoxLayout;
layout->addWidget(label);

value = CreateSliderValuePair(window, layout, max, shortcut_key, Qt::Horizontal, shortcut_widget,
invert);

return layout;
}

// The shortcut_widget argument needs to specify the container widget that will be hidden/shown.
// This is done to avoid ambigous shortcuts
QSpinBox* CreateSliderValuePair(QDialog* window, QBoxLayout* layout, u16 max, Qt::Key shortcut_key,
Qt::Orientation orientation, QWidget* shortcut_widget, bool invert)
{
auto* value = new QSpinBox();
value->setRange(0, 99999);
window->connect(value, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
[value, max](int i) {
if (i > max)
value->setValue(max);
});
auto* slider = new QSlider(orientation);
slider->setRange(0, max);
slider->setFocusPolicy(Qt::ClickFocus);
slider->setInvertedAppearance(invert);

window->connect(slider, &QSlider::valueChanged, value, &QSpinBox::setValue);
window->connect(value, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), slider,
&QSlider::setValue);

auto* shortcut = new QShortcut(QKeySequence(Qt::ALT + shortcut_key), shortcut_widget);
window->connect(shortcut, &QShortcut::activated, [value] {
value->setFocus();
value->selectAll();
});

layout->addWidget(slider);
layout->addWidget(value);
if (orientation == Qt::Vertical)
layout->setAlignment(slider, Qt::AlignRight);

return value;
}
@@ -0,0 +1,26 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <QWidget>

#include "Common/CommonTypes.h"

class QDialog;
class QString;
class QSpinBox;
class QCheckBox;
class QBoxLayout;
class QGroupBox;
struct GCPadStatus;

QGroupBox* CreateStickInputs(QDialog* window, QString name, QSpinBox*& x_value, QSpinBox*& y_value,
u16 max_x, u16 max_y, Qt::Key x_shortcut_key, Qt::Key y_shortcut_key);
QBoxLayout* CreateSliderValuePairLayout(QDialog* window, QString name, QSpinBox*& value, u16 max,
Qt::Key shortcut_key, QWidget* shortcut_widget,
bool invert = false);
QSpinBox* CreateSliderValuePair(QDialog* window, QBoxLayout* layout, u16 max, Qt::Key shortcut_key,
Qt::Orientation orientation, QWidget* shortcut_widget,
bool invert = false);
@@ -0,0 +1,78 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "DolphinQt2/TAS/StickWidget.h"

#include <algorithm>

#include <QMouseEvent>
#include <QPainter>

#include "Common/CommonTypes.h"

StickWidget::StickWidget(QWidget* parent, u16 max_x, u16 max_y)
: QWidget(parent), m_max_x(max_x), m_max_y(max_y)
{
setMouseTracking(false);
}

void StickWidget::SetX(u16 x)
{
m_x = std::min(m_max_x, x);

update();
}

void StickWidget::SetY(u16 y)
{
m_y = std::min(m_max_y, y);

update();
}

void StickWidget::paintEvent(QPaintEvent* event)
{
QPainter painter(this);

painter.setBrush(Qt::white);
painter.drawEllipse(0, 0, width() - 1, height() - 1);

painter.drawLine(0, height() / 2, width(), height() / 2);
painter.drawLine(width() / 2, 0, width() / 2, height());

// convert from value space to widget space
u16 x = (m_x * width()) / m_max_x;
u16 y = height() - (m_y * height()) / m_max_y;

painter.drawLine(width() / 2, height() / 2, x, y);

painter.setBrush(Qt::blue);
int wh_avg = (width() + height()) / 2;
int radius = wh_avg / 30;
painter.drawEllipse(x - radius, y - radius, radius * 2, radius * 2);
}

void StickWidget::mousePressEvent(QMouseEvent* event)
{
handleMouseEvent(event);
}

void StickWidget::mouseMoveEvent(QMouseEvent* event)
{
handleMouseEvent(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));

emit ChangedX(m_x);
emit ChangedY(m_y);
update();
}
@@ -0,0 +1,36 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <QDialog>

#include "Common/CommonTypes.h"

class StickWidget : public QWidget
{
Q_OBJECT
public:
explicit StickWidget(QWidget* parent, u16 width, u16 height);

signals:
void ChangedX(u16 x);
void ChangedY(u16 y);

public slots:
void SetX(u16 x);
void SetY(u16 y);

protected:
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void handleMouseEvent(QMouseEvent* event);

private:
u16 m_max_x;
u16 m_max_y;
u16 m_x = 0;
u16 m_y = 0;
};

Large diffs are not rendered by default.

@@ -0,0 +1,84 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <QDialog>

#include "Common/CommonTypes.h"

namespace WiimoteEmu
{
struct ReportFeatures;
}
class QCheckBox;
class QGroupBox;
class QSpinBox;
struct wiimote_key;

class WiiTASInputWindow : public QDialog
{
Q_OBJECT
public:
explicit WiiTASInputWindow(QWidget* parent, int num);
void GetValues(u8* input_data, WiimoteEmu::ReportFeatures rptf, int ext, wiimote_key key);

private:
void UpdateExt(u8 ext);
int m_num;
QCheckBox* m_a_button;
QCheckBox* m_b_button;
QCheckBox* m_1_button;
QCheckBox* m_2_button;
QCheckBox* m_plus_button;
QCheckBox* m_minus_button;
QCheckBox* m_home_button;
QCheckBox* m_left_button;
QCheckBox* m_up_button;
QCheckBox* m_down_button;
QCheckBox* m_right_button;
QCheckBox* m_c_button;
QCheckBox* m_z_button;
QCheckBox* m_classic_a_button;
QCheckBox* m_classic_b_button;
QCheckBox* m_classic_x_button;
QCheckBox* m_classic_y_button;
QCheckBox* m_classic_plus_button;
QCheckBox* m_classic_minus_button;
QCheckBox* m_classic_l_button;
QCheckBox* m_classic_r_button;
QCheckBox* m_classic_zl_button;
QCheckBox* m_classic_zr_button;
QCheckBox* m_classic_home_button;
QCheckBox* m_classic_left_button;
QCheckBox* m_classic_up_button;
QCheckBox* m_classic_down_button;
QCheckBox* m_classic_right_button;
QSpinBox* m_remote_orientation_x_value;
QSpinBox* m_remote_orientation_y_value;
QSpinBox* m_remote_orientation_z_value;
QSpinBox* m_nunchuk_orientation_x_value;
QSpinBox* m_nunchuk_orientation_y_value;
QSpinBox* m_nunchuk_orientation_z_value;
QSpinBox* m_ir_x_value;
QSpinBox* m_ir_y_value;
QSpinBox* m_nunchuk_stick_x_value;
QSpinBox* m_nunchuk_stick_y_value;
QSpinBox* m_classic_left_stick_x_value;
QSpinBox* m_classic_left_stick_y_value;
QSpinBox* m_classic_right_stick_x_value;
QSpinBox* m_classic_right_stick_y_value;
QSpinBox* m_left_trigger_value;
QSpinBox* m_right_trigger_value;
QGroupBox* m_remote_orientation_box;
QGroupBox* m_nunchuk_orientation_box;
QGroupBox* m_ir_box;
QGroupBox* m_nunchuk_stick_box;
QGroupBox* m_classic_left_stick_box;
QGroupBox* m_classic_right_stick_box;
QGroupBox* m_remote_buttons_box;
QGroupBox* m_nunchuk_buttons_box;
QGroupBox* m_classic_buttons_box;
QGroupBox* m_triggers_box;
};
@@ -819,7 +819,9 @@ void TASInputDlg::GetValues(u8* data, WiimoteEmu::ReportFeatures rptf, int ext,
}
else
{
memset(data, 0xFF, sizeof(wm_ir_extended) * 4);
// TODO: this code doesnt work, resulting in no IR TAS inputs in e.g. wii sports menu when
// no remote extension is used
memset(irData, 0xFF, sizeof(wm_ir_extended) * 4);
wm_ir_extended* const ir_data = (wm_ir_extended*)irData;
for (size_t i = 0; i < x.size(); ++i)
{