2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2011 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:43:35 -06:00
|
|
|
// Refer to the license.txt file included.
|
2011-06-27 13:44:27 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <cstddef>
|
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/dcmemory.h>
|
|
|
|
#include <wx/dialog.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/slider.h>
|
|
|
|
#include <wx/statbmp.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
|
2016-01-12 20:34:13 -07:00
|
|
|
#include "Common/Assert.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Common/CommonTypes.h"
|
2016-01-12 20:34:13 -07:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
#include "Core/Core.h"
|
2014-10-31 02:34:30 -06:00
|
|
|
#include "Core/HW/Wiimote.h"
|
2015-04-10 20:14:21 -06:00
|
|
|
#include "Core/HW/WiimoteEmu/Attachment/Classic.h"
|
2014-10-31 02:34:30 -06:00
|
|
|
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
2014-10-31 02:34:30 -06:00
|
|
|
#include "Core/HW/WiimoteReal/WiimoteReal.h"
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "Core/Movie.h"
|
2016-08-02 00:22:53 -06:00
|
|
|
#include "DolphinWX/DolphinSlider.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DolphinWX/TASInputDlg.h"
|
2016-08-02 00:22:53 -06:00
|
|
|
#include "DolphinWX/WxUtils.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "InputCommon/GCPadStatus.h"
|
2014-10-31 02:34:30 -06:00
|
|
|
#include "InputCommon/InputConfig.h"
|
|
|
|
|
2015-09-07 03:15:23 -06:00
|
|
|
wxDEFINE_EVENT(INVALIDATE_BUTTON_EVENT, wxCommandEvent);
|
|
|
|
wxDEFINE_EVENT(INVALIDATE_CONTROL_EVENT, wxCommandEvent);
|
2016-05-01 06:09:58 -06:00
|
|
|
wxDEFINE_EVENT(INVALIDATE_EXTENSION_EVENT, wxThreadEvent);
|
2015-08-11 23:05:18 -06:00
|
|
|
|
|
|
|
struct TASWiimoteReport
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
u8* data;
|
|
|
|
WiimoteEmu::ReportFeatures rptf;
|
|
|
|
int ext;
|
|
|
|
const wiimote_key key;
|
2015-08-11 23:05:18 -06:00
|
|
|
};
|
2011-06-27 13:44:27 -06:00
|
|
|
|
2017-04-02 04:43:57 -06:00
|
|
|
constexpr std::array<int, 12> s_gc_pad_buttons_bitmask{{
|
|
|
|
PAD_BUTTON_DOWN, PAD_BUTTON_UP, PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_A, PAD_BUTTON_B,
|
|
|
|
PAD_BUTTON_X, PAD_BUTTON_Y, PAD_TRIGGER_Z, PAD_TRIGGER_L, PAD_TRIGGER_R, PAD_BUTTON_START,
|
|
|
|
}};
|
|
|
|
|
|
|
|
constexpr std::array<int, 11> s_wii_buttons_bitmask{{
|
|
|
|
WiimoteEmu::Wiimote::PAD_DOWN, WiimoteEmu::Wiimote::PAD_UP, WiimoteEmu::Wiimote::PAD_LEFT,
|
|
|
|
WiimoteEmu::Wiimote::PAD_RIGHT, WiimoteEmu::Wiimote::BUTTON_A, WiimoteEmu::Wiimote::BUTTON_B,
|
|
|
|
WiimoteEmu::Wiimote::BUTTON_ONE, WiimoteEmu::Wiimote::BUTTON_TWO,
|
|
|
|
WiimoteEmu::Wiimote::BUTTON_PLUS, WiimoteEmu::Wiimote::BUTTON_MINUS,
|
|
|
|
WiimoteEmu::Wiimote::BUTTON_HOME,
|
|
|
|
}};
|
|
|
|
|
|
|
|
constexpr std::array<int, 15> s_cc_buttons_bitmask{{
|
|
|
|
WiimoteEmu::Classic::PAD_DOWN, WiimoteEmu::Classic::PAD_UP, WiimoteEmu::Classic::PAD_LEFT,
|
|
|
|
WiimoteEmu::Classic::PAD_RIGHT, WiimoteEmu::Classic::BUTTON_A, WiimoteEmu::Classic::BUTTON_B,
|
|
|
|
WiimoteEmu::Classic::BUTTON_X, WiimoteEmu::Classic::BUTTON_Y, WiimoteEmu::Classic::BUTTON_PLUS,
|
|
|
|
WiimoteEmu::Classic::BUTTON_MINUS, WiimoteEmu::Classic::TRIGGER_L,
|
|
|
|
WiimoteEmu::Classic::TRIGGER_R, WiimoteEmu::Classic::BUTTON_ZR, WiimoteEmu::Classic::BUTTON_ZL,
|
|
|
|
WiimoteEmu::Classic::BUTTON_HOME,
|
|
|
|
}};
|
|
|
|
|
2014-08-13 15:42:11 -06:00
|
|
|
TASInputDlg::TASInputDlg(wxWindow* parent, wxWindowID id, const wxString& title,
|
2014-09-14 21:42:32 -06:00
|
|
|
const wxPoint& position, const wxSize& size, long style)
|
2016-06-24 02:43:46 -06:00
|
|
|
: wxDialog(parent, id, title, position, size, style)
|
2011-06-27 13:44:27 -06:00
|
|
|
{
|
2014-10-31 02:34:30 -06:00
|
|
|
}
|
2014-10-17 21:42:46 -06:00
|
|
|
|
2014-10-31 02:34:30 -06:00
|
|
|
void TASInputDlg::CreateBaseLayout()
|
|
|
|
{
|
2017-04-02 04:43:57 -06:00
|
|
|
m_controls = {};
|
|
|
|
m_buttons = {};
|
|
|
|
m_cc_controls = {};
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
m_buttons[0] = &m_dpad_down;
|
|
|
|
m_buttons[1] = &m_dpad_up;
|
|
|
|
m_buttons[2] = &m_dpad_left;
|
|
|
|
m_buttons[3] = &m_dpad_right;
|
|
|
|
m_buttons[4] = &m_a;
|
|
|
|
m_buttons[5] = &m_b;
|
|
|
|
m_controls[0] = &m_main_stick.x_cont;
|
|
|
|
m_controls[1] = &m_main_stick.y_cont;
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
m_a = CreateButton(_("A"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_a.checkbox->SetClientData(&m_a);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_b = CreateButton(_("B"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_b.checkbox->SetClientData(&m_b);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_dpad_up = CreateButton(_("Up"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_dpad_up.checkbox->SetClientData(&m_dpad_up);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_dpad_right = CreateButton(_("Right"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_dpad_right.checkbox->SetClientData(&m_dpad_right);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_dpad_down = CreateButton(_("Down"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_dpad_down.checkbox->SetClientData(&m_dpad_down);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_dpad_left = CreateButton(_("Left"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_dpad_left.checkbox->SetClientData(&m_dpad_left);
|
|
|
|
|
|
|
|
m_buttons_dpad = new wxGridSizer(3);
|
2016-08-02 00:22:53 -06:00
|
|
|
const int space20 = FromDIP(20);
|
|
|
|
m_buttons_dpad->Add(space20, space20);
|
2016-06-24 02:43:46 -06:00
|
|
|
m_buttons_dpad->Add(m_dpad_up.checkbox);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_buttons_dpad->Add(space20, space20);
|
2016-06-24 02:43:46 -06:00
|
|
|
m_buttons_dpad->Add(m_dpad_left.checkbox);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_buttons_dpad->Add(space20, space20);
|
2016-06-24 02:43:46 -06:00
|
|
|
m_buttons_dpad->Add(m_dpad_right.checkbox);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_buttons_dpad->Add(space20, space20);
|
2016-06-24 02:43:46 -06:00
|
|
|
m_buttons_dpad->Add(m_dpad_down.checkbox);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_buttons_dpad->Add(space20, space20);
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
|
|
|
|
2014-10-31 02:34:30 -06:00
|
|
|
void TASInputDlg::CreateWiiLayout(int num)
|
2014-09-14 21:42:32 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_has_layout)
|
|
|
|
return;
|
2016-08-02 00:22:53 -06:00
|
|
|
const int space5 = FromDIP(5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
CreateBaseLayout();
|
|
|
|
|
|
|
|
m_buttons[6] = &m_one;
|
|
|
|
m_buttons[7] = &m_two;
|
|
|
|
m_buttons[8] = &m_plus;
|
|
|
|
m_buttons[9] = &m_minus;
|
|
|
|
m_buttons[10] = &m_home;
|
|
|
|
|
|
|
|
m_controls[4] = &m_x_cont;
|
|
|
|
m_controls[5] = &m_y_cont;
|
|
|
|
m_controls[6] = &m_z_cont;
|
|
|
|
|
|
|
|
m_main_stick = CreateStick(ID_MAIN_STICK, 1024, 768, 512, 384, true, false);
|
|
|
|
m_main_stick_szr = CreateStickLayout(&m_main_stick, _("IR"));
|
|
|
|
|
|
|
|
m_x_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 1023, 512);
|
|
|
|
m_y_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 1023, 512);
|
|
|
|
m_z_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 1023, 616);
|
|
|
|
wxStaticBoxSizer* const axisBox =
|
|
|
|
CreateAccelLayout(&m_x_cont, &m_y_cont, &m_z_cont, _("Orientation"));
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
m_plus = CreateButton(_("+"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_plus.checkbox->SetClientData(&m_plus);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_minus = CreateButton(_("-"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_minus.checkbox->SetClientData(&m_minus);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_one = CreateButton(_("1"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_one.checkbox->SetClientData(&m_one);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_two = CreateButton(_("2"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_two.checkbox->SetClientData(&m_two);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_home = CreateButton(_("Home"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_home.checkbox->SetClientData(&m_home);
|
|
|
|
|
|
|
|
m_cc_szr = CreateCCLayout();
|
|
|
|
|
|
|
|
if (Core::IsRunning())
|
|
|
|
{
|
|
|
|
m_ext = static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(num))
|
|
|
|
->CurrentExtension();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(File::GetUserPath(D_CONFIG_IDX) + "WiimoteNew.ini");
|
|
|
|
std::string extension;
|
|
|
|
ini.GetIfExists("Wiimote" + std::to_string(num + 1), "Extension", &extension);
|
|
|
|
|
|
|
|
if (extension == "Nunchuk")
|
|
|
|
m_ext = 1;
|
|
|
|
if (extension == "Classic")
|
|
|
|
m_ext = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_buttons[11] = &m_c;
|
|
|
|
m_buttons[12] = &m_z;
|
|
|
|
m_controls[2] = &m_c_stick.x_cont;
|
|
|
|
m_controls[3] = &m_c_stick.y_cont;
|
|
|
|
m_controls[7] = &m_nx_cont;
|
|
|
|
m_controls[8] = &m_ny_cont;
|
|
|
|
m_controls[9] = &m_nz_cont;
|
|
|
|
|
|
|
|
m_c_stick = CreateStick(ID_C_STICK, 255, 255, 128, 128, false, true);
|
|
|
|
m_c_stick_szr = CreateStickLayout(&m_c_stick, _("Nunchuk stick"));
|
|
|
|
|
|
|
|
m_nx_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 1023, 512);
|
|
|
|
m_ny_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 1023, 512);
|
|
|
|
m_nz_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 1023, 512);
|
|
|
|
wxStaticBoxSizer* const nunchukaxisBox =
|
|
|
|
CreateAccelLayout(&m_nx_cont, &m_ny_cont, &m_nz_cont, _("Nunchuk orientation"));
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
m_c = CreateButton(_("C"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_c.checkbox->SetClientData(&m_c);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_z = CreateButton(_("Z"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_z.checkbox->SetClientData(&m_z);
|
|
|
|
|
|
|
|
for (Control* const control : m_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr)
|
|
|
|
control->slider->Bind(wxEVT_RIGHT_UP, &TASInputDlg::OnRightClickSlider, this);
|
|
|
|
}
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
m_ext_szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
m_ext_szr->Add(m_c_stick_szr, 0, wxBOTTOM, space5);
|
|
|
|
m_ext_szr->AddSpacer(space5);
|
|
|
|
m_ext_szr->Add(nunchukaxisBox, 0, wxBOTTOM, space5);
|
|
|
|
|
2017-04-02 04:43:57 -06:00
|
|
|
// Add non-DPad related buttons first.
|
2016-08-02 00:22:53 -06:00
|
|
|
wxGridSizer* const buttons_grid = new wxGridSizer(4);
|
2017-04-02 04:43:57 -06:00
|
|
|
for (size_t i = 4; i < m_buttons.size(); ++i)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_buttons[i] != nullptr)
|
2016-08-02 00:22:53 -06:00
|
|
|
buttons_grid->Add(m_buttons[i]->checkbox);
|
2017-04-02 04:43:57 -06:00
|
|
|
}
|
2016-08-02 00:22:53 -06:00
|
|
|
buttons_grid->Add(space5, space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
wxStaticBoxSizer* const buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
|
|
|
|
buttons_box->Add(buttons_grid);
|
|
|
|
buttons_box->Add(m_buttons_dpad, 0, wxTOP, space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
m_wiimote_szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
m_wiimote_szr->AddSpacer(space5);
|
|
|
|
m_wiimote_szr->Add(m_main_stick_szr);
|
|
|
|
m_wiimote_szr->Add(axisBox, 0, wxLEFT, space5);
|
|
|
|
m_wiimote_szr->Add(buttons_box, 0, wxLEFT, space5);
|
|
|
|
m_wiimote_szr->AddSpacer(space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
// NOTE: Not all of these are visible at the same time.
|
|
|
|
m_main_szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
m_main_szr->Add(m_wiimote_szr, 0, wxTOP | wxBOTTOM, space5);
|
|
|
|
m_main_szr->Add(m_ext_szr, 0, wxLEFT | wxRIGHT, space5);
|
|
|
|
m_main_szr->Add(m_cc_szr, 0, wxLEFT | wxRIGHT, space5);
|
|
|
|
|
|
|
|
SetSizer(m_main_szr);
|
2016-06-24 02:43:46 -06:00
|
|
|
HandleExtensionChange();
|
|
|
|
FinishLayout();
|
2015-08-11 23:05:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::FinishLayout()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
Bind(wxEVT_CLOSE_WINDOW, &TASInputDlg::OnCloseWindow, this);
|
|
|
|
Bind(INVALIDATE_BUTTON_EVENT, &TASInputDlg::UpdateFromInvalidatedButton, this);
|
|
|
|
Bind(INVALIDATE_CONTROL_EVENT, &TASInputDlg::UpdateFromInvalidatedControl, this);
|
|
|
|
Bind(INVALIDATE_EXTENSION_EVENT, &TASInputDlg::UpdateFromInvalidatedExtension, this);
|
|
|
|
m_has_layout = true;
|
2015-04-10 20:14:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
wxBoxSizer* TASInputDlg::CreateCCLayout()
|
|
|
|
{
|
2016-08-02 00:22:53 -06:00
|
|
|
const std::array<wxString, 15> button_names{{_("Down"), _("Up"), _("Left"), _("Right"), _("A"),
|
|
|
|
_("B"), _("X"), _("Y"), _("+"), _("-"), _("L"),
|
|
|
|
_("R"), _("ZR"), _("ZL"), _("Home")}};
|
|
|
|
for (size_t i = 0; i < button_names.size(); ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-02 00:22:53 -06:00
|
|
|
m_cc_buttons[i] = CreateButton(button_names[i]);
|
2016-06-24 02:43:46 -06:00
|
|
|
m_cc_buttons[i].checkbox->SetClientData(&m_cc_buttons[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cc_l_stick = CreateStick(ID_CC_L_STICK, 63, 63, WiimoteEmu::Classic::LEFT_STICK_CENTER_X,
|
|
|
|
WiimoteEmu::Classic::LEFT_STICK_CENTER_Y, false, true);
|
|
|
|
m_cc_r_stick = CreateStick(ID_CC_R_STICK, 31, 31, WiimoteEmu::Classic::RIGHT_STICK_CENTER_X,
|
|
|
|
WiimoteEmu::Classic::RIGHT_STICK_CENTER_Y, false, true);
|
|
|
|
|
|
|
|
m_cc_controls[CC_L_STICK_X] = &m_cc_l_stick.x_cont;
|
|
|
|
m_cc_controls[CC_L_STICK_Y] = &m_cc_l_stick.y_cont;
|
|
|
|
m_cc_controls[CC_R_STICK_X] = &m_cc_r_stick.x_cont;
|
|
|
|
m_cc_controls[CC_R_STICK_Y] = &m_cc_r_stick.y_cont;
|
|
|
|
m_cc_controls[CC_L_TRIGGER] = &m_cc_l;
|
|
|
|
m_cc_controls[CC_R_TRIGGER] = &m_cc_r;
|
|
|
|
|
|
|
|
m_cc_l_stick_szr = CreateStickLayout(&m_cc_l_stick, _("Left stick"));
|
|
|
|
m_cc_r_stick_szr = CreateStickLayout(&m_cc_r_stick, _("Right stick"));
|
|
|
|
|
|
|
|
m_cc_l = CreateControl(wxSL_VERTICAL, -1, 100, false, 31, 0);
|
|
|
|
m_cc_r = CreateControl(wxSL_VERTICAL, -1, 100, false, 31, 0);
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
const int space5 = FromDIP(5);
|
|
|
|
const int space20 = FromDIP(20);
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
wxStaticBoxSizer* const shoulder_box =
|
|
|
|
new wxStaticBoxSizer(wxHORIZONTAL, this, _("Shoulder Buttons"));
|
|
|
|
shoulder_box->Add(m_cc_l.slider, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
shoulder_box->Add(m_cc_l.text, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
shoulder_box->Add(m_cc_r.slider, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
shoulder_box->Add(m_cc_r.text, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
|
|
|
|
wxGridSizer* const cc_buttons_dpad = new wxGridSizer(3);
|
2016-08-02 00:22:53 -06:00
|
|
|
cc_buttons_dpad->Add(space20, space20);
|
2016-06-24 02:43:46 -06:00
|
|
|
cc_buttons_dpad->Add(m_cc_buttons[1].checkbox);
|
2016-08-02 00:22:53 -06:00
|
|
|
cc_buttons_dpad->Add(space20, space20);
|
2016-06-24 02:43:46 -06:00
|
|
|
cc_buttons_dpad->Add(m_cc_buttons[2].checkbox);
|
2016-08-02 00:22:53 -06:00
|
|
|
cc_buttons_dpad->Add(space20, space20);
|
2016-06-24 02:43:46 -06:00
|
|
|
cc_buttons_dpad->Add(m_cc_buttons[3].checkbox);
|
2016-08-02 00:22:53 -06:00
|
|
|
cc_buttons_dpad->Add(space20, space20);
|
2016-06-24 02:43:46 -06:00
|
|
|
cc_buttons_dpad->Add(m_cc_buttons[0].checkbox);
|
2016-08-02 00:22:53 -06:00
|
|
|
cc_buttons_dpad->Add(space20, space20);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
wxGridSizer* const cc_buttons_grid = new wxGridSizer(4);
|
|
|
|
for (auto& button : m_cc_buttons)
|
2016-06-25 23:25:29 -06:00
|
|
|
if (!button.checkbox->GetContainingSizer())
|
|
|
|
cc_buttons_grid->Add(button.checkbox);
|
2016-08-02 00:22:53 -06:00
|
|
|
cc_buttons_grid->Add(space5, space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
wxStaticBoxSizer* const cc_buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
|
2016-06-24 02:43:46 -06:00
|
|
|
cc_buttons_box->Add(cc_buttons_grid);
|
2016-08-02 00:22:53 -06:00
|
|
|
cc_buttons_box->Add(cc_buttons_dpad, 0, wxTOP, space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
szr->AddSpacer(space5);
|
|
|
|
szr->Add(m_cc_l_stick_szr, 0, wxTOP | wxBOTTOM, space5);
|
|
|
|
szr->AddSpacer(space5);
|
|
|
|
szr->Add(m_cc_r_stick_szr, 0, wxTOP | wxBOTTOM, space5);
|
|
|
|
szr->AddSpacer(space5);
|
|
|
|
szr->Add(shoulder_box, 0, wxTOP | wxBOTTOM, space5);
|
|
|
|
szr->AddSpacer(space5);
|
|
|
|
szr->Add(cc_buttons_box, 0, wxTOP | wxBOTTOM, space5);
|
|
|
|
szr->AddSpacer(space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
for (Control* const control : m_cc_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr)
|
|
|
|
control->slider->Bind(wxEVT_RIGHT_UP, &TASInputDlg::OnRightClickSlider, this);
|
|
|
|
}
|
|
|
|
return szr;
|
2015-04-10 20:14:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::HandleExtensionChange()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_ext == 1)
|
|
|
|
{
|
|
|
|
m_main_szr->Hide(m_cc_szr);
|
|
|
|
m_main_szr->Show(m_wiimote_szr);
|
|
|
|
m_main_szr->Show(m_ext_szr);
|
|
|
|
}
|
|
|
|
else if (m_ext == 2)
|
|
|
|
{
|
|
|
|
m_main_szr->Hide(m_ext_szr);
|
|
|
|
m_main_szr->Hide(m_wiimote_szr);
|
|
|
|
m_main_szr->Show(m_cc_szr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_main_szr->Hide(m_ext_szr);
|
|
|
|
m_main_szr->Hide(m_cc_szr);
|
|
|
|
m_main_szr->Show(m_wiimote_szr);
|
|
|
|
}
|
|
|
|
ResetValues();
|
2016-08-02 00:22:53 -06:00
|
|
|
m_main_szr->SetSizeHints(this);
|
|
|
|
Layout();
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::CreateGCLayout()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_has_layout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CreateBaseLayout();
|
|
|
|
|
|
|
|
m_buttons[6] = &m_x;
|
|
|
|
m_buttons[7] = &m_y;
|
|
|
|
m_buttons[8] = &m_z;
|
|
|
|
m_buttons[9] = &m_l;
|
|
|
|
m_buttons[10] = &m_r;
|
|
|
|
m_buttons[11] = &m_start;
|
|
|
|
|
|
|
|
m_controls[2] = &m_c_stick.x_cont;
|
|
|
|
m_controls[3] = &m_c_stick.y_cont;
|
|
|
|
m_controls[4] = &m_l_cont;
|
|
|
|
m_controls[5] = &m_r_cont;
|
|
|
|
|
|
|
|
m_main_stick = CreateStick(ID_MAIN_STICK, 255, 255, 128, 128, false, true);
|
|
|
|
wxStaticBoxSizer* const main_box = CreateStickLayout(&m_main_stick, _("Main Stick"));
|
|
|
|
|
|
|
|
m_c_stick = CreateStick(ID_C_STICK, 255, 255, 128, 128, false, true);
|
|
|
|
wxStaticBoxSizer* const c_box = CreateStickLayout(&m_c_stick, _("C Stick"));
|
|
|
|
|
|
|
|
wxStaticBoxSizer* const shoulder_box =
|
|
|
|
new wxStaticBoxSizer(wxHORIZONTAL, this, _("Shoulder Buttons"));
|
|
|
|
m_l_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 255, 0);
|
|
|
|
m_r_cont = CreateControl(wxSL_VERTICAL, -1, 100, false, 255, 0);
|
|
|
|
shoulder_box->Add(m_l_cont.slider, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
shoulder_box->Add(m_l_cont.text, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
shoulder_box->Add(m_r_cont.slider, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
shoulder_box->Add(m_r_cont.text, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
|
|
|
|
for (Control* const control : m_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr)
|
|
|
|
control->slider->Bind(wxEVT_RIGHT_UP, &TASInputDlg::OnRightClickSlider, this);
|
|
|
|
}
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
m_x = CreateButton(_("X"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_x.checkbox->SetClientData(&m_x);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_y = CreateButton(_("Y"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_y.checkbox->SetClientData(&m_y);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_l = CreateButton(_("L"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_l.checkbox->SetClientData(&m_l);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_r = CreateButton(_("R"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_r.checkbox->SetClientData(&m_r);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_z = CreateButton(_("Z"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_z.checkbox->SetClientData(&m_z);
|
2016-08-02 00:22:53 -06:00
|
|
|
m_start = CreateButton(_("Start"));
|
2016-06-24 02:43:46 -06:00
|
|
|
m_start.checkbox->SetClientData(&m_start);
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
const int space5 = FromDIP(5);
|
|
|
|
|
2017-04-02 04:43:57 -06:00
|
|
|
// Add non-DPad related buttons first.
|
2016-08-02 00:22:53 -06:00
|
|
|
wxGridSizer* const buttons_grid = new wxGridSizer(4);
|
2017-04-02 04:43:57 -06:00
|
|
|
for (size_t i = 4; i < m_buttons.size(); ++i)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (m_buttons[i] != nullptr)
|
2016-08-02 00:22:53 -06:00
|
|
|
buttons_grid->Add(m_buttons[i]->checkbox, false);
|
2017-04-02 04:43:57 -06:00
|
|
|
}
|
2016-08-02 00:22:53 -06:00
|
|
|
buttons_grid->Add(space5, space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
wxStaticBoxSizer* const buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
|
|
|
|
buttons_box->Add(buttons_grid);
|
|
|
|
buttons_box->Add(m_buttons_dpad);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
wxBoxSizer* const top_box = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
top_box->Add(main_box);
|
|
|
|
top_box->Add(c_box, 0, wxLEFT, space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
wxBoxSizer* const bottom_box = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
bottom_box->Add(shoulder_box);
|
|
|
|
bottom_box->Add(buttons_box, 0, wxLEFT, space5);
|
|
|
|
|
|
|
|
wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
main_szr->AddSpacer(space5);
|
|
|
|
main_szr->Add(top_box, 0, wxLEFT | wxRIGHT, space5);
|
|
|
|
main_szr->AddSpacer(space5);
|
|
|
|
main_szr->Add(bottom_box, 0, wxLEFT | wxRIGHT, space5);
|
|
|
|
main_szr->AddSpacer(space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
SetSizerAndFit(main_szr);
|
|
|
|
|
|
|
|
ResetValues();
|
|
|
|
FinishLayout();
|
2011-06-27 13:44:27 -06:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
TASInputDlg::Control TASInputDlg::CreateControl(long style, int width, int height, bool reverse,
|
|
|
|
u32 range, u32 default_value)
|
2011-06-27 13:44:27 -06:00
|
|
|
{
|
2016-08-02 00:22:53 -06:00
|
|
|
Control control;
|
|
|
|
control.range = range;
|
|
|
|
control.default_value = default_value;
|
|
|
|
control.slider_id = m_eleID++;
|
|
|
|
control.slider = new DolphinSlider(this, control.slider_id, default_value, 0, range,
|
|
|
|
wxDefaultPosition, FromDIP(wxSize(width, height)), style);
|
|
|
|
control.slider->Bind(wxEVT_SLIDER, &TASInputDlg::UpdateFromSliders, this);
|
|
|
|
control.text_id = m_eleID++;
|
|
|
|
control.text = new wxTextCtrl(this, control.text_id, std::to_string(default_value));
|
|
|
|
control.text->SetMaxLength(range > 999 ? 4 : 3);
|
|
|
|
control.text->SetMinSize(WxUtils::GetTextWidgetMinSize(control.text, range));
|
|
|
|
control.text->Bind(wxEVT_TEXT, &TASInputDlg::UpdateFromText, this);
|
|
|
|
control.reverse = reverse;
|
|
|
|
return control;
|
2011-06-27 13:44:27 -06:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
TASInputDlg::Stick TASInputDlg::CreateStick(int id_stick, int xRange, int yRange, u32 defaultX,
|
|
|
|
u32 defaultY, bool reverseX, bool reverseY)
|
2012-01-21 17:39:17 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
Stick tempStick;
|
|
|
|
tempStick.bitmap = new wxStaticBitmap(this, id_stick, CreateStickBitmap(128, 128));
|
|
|
|
tempStick.bitmap->Bind(wxEVT_MOTION, &TASInputDlg::OnMouseDownL, this);
|
|
|
|
tempStick.bitmap->Bind(wxEVT_LEFT_DOWN, &TASInputDlg::OnMouseDownL, this);
|
|
|
|
tempStick.bitmap->Bind(wxEVT_RIGHT_UP, &TASInputDlg::OnMouseUpR, this);
|
|
|
|
tempStick.x_cont = CreateControl(wxSL_HORIZONTAL | (reverseX ? wxSL_INVERSE : 0), 120, -1,
|
|
|
|
reverseX, xRange, defaultX);
|
2016-06-25 23:25:29 -06:00
|
|
|
tempStick.y_cont = CreateControl(wxSL_VERTICAL | wxSL_LEFT | (reverseY ? wxSL_INVERSE : 0), -1,
|
|
|
|
120, reverseY, yRange, defaultY);
|
2016-06-24 02:43:46 -06:00
|
|
|
return tempStick;
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
wxStaticBoxSizer* TASInputDlg::CreateStickLayout(Stick* stick, const wxString& title)
|
2014-09-14 21:42:32 -06:00
|
|
|
{
|
2016-08-02 00:22:53 -06:00
|
|
|
const int space3 = FromDIP(3);
|
|
|
|
|
|
|
|
wxStaticBoxSizer* const temp_box = new wxStaticBoxSizer(wxVERTICAL, this, title);
|
|
|
|
wxFlexGridSizer* const layout = new wxFlexGridSizer(2, space3, space3);
|
|
|
|
|
|
|
|
layout->Add(stick->x_cont.slider, 0, wxEXPAND);
|
|
|
|
layout->Add(stick->x_cont.text, 0, wxALIGN_CENTER);
|
|
|
|
layout->Add(stick->bitmap, 0, wxALIGN_RIGHT);
|
|
|
|
layout->Add(stick->y_cont.slider, 0, wxEXPAND);
|
|
|
|
layout->AddSpacer(1); // Placeholder for unused cell
|
|
|
|
layout->Add(stick->y_cont.text, 0, wxALIGN_CENTER);
|
|
|
|
|
|
|
|
temp_box->AddSpacer(space3);
|
|
|
|
temp_box->Add(layout, 0, wxLEFT | wxRIGHT, space3);
|
|
|
|
temp_box->AddSpacer(space3);
|
2016-06-24 02:43:46 -06:00
|
|
|
return temp_box;
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
2012-01-22 12:45:55 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
wxStaticBoxSizer* TASInputDlg::CreateAccelLayout(Control* x, Control* y, Control* z,
|
|
|
|
const wxString& title)
|
2014-10-31 02:34:30 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
wxStaticBoxSizer* const temp_box = new wxStaticBoxSizer(wxHORIZONTAL, this, title);
|
|
|
|
wxStaticBoxSizer* const xBox = new wxStaticBoxSizer(wxVERTICAL, this, _("X"));
|
|
|
|
wxStaticBoxSizer* const yBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Y"));
|
|
|
|
wxStaticBoxSizer* const zBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Z"));
|
2016-08-02 00:22:53 -06:00
|
|
|
const int space5 = FromDIP(5);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-06-25 23:25:29 -06:00
|
|
|
xBox->Add(x->slider, 0, wxALIGN_CENTER_HORIZONTAL);
|
|
|
|
xBox->Add(x->text, 0, wxALIGN_CENTER_HORIZONTAL);
|
|
|
|
yBox->Add(y->slider, 0, wxALIGN_CENTER_HORIZONTAL);
|
|
|
|
yBox->Add(y->text, 0, wxALIGN_CENTER_HORIZONTAL);
|
|
|
|
zBox->Add(z->slider, 0, wxALIGN_CENTER_HORIZONTAL);
|
|
|
|
zBox->Add(z->text, 0, wxALIGN_CENTER_HORIZONTAL);
|
2016-08-02 00:22:53 -06:00
|
|
|
temp_box->AddSpacer(space5);
|
|
|
|
temp_box->Add(xBox, 0, wxBOTTOM, space5);
|
|
|
|
temp_box->AddSpacer(space5);
|
|
|
|
temp_box->Add(yBox, 0, wxBOTTOM, space5);
|
|
|
|
temp_box->AddSpacer(space5);
|
|
|
|
temp_box->Add(zBox, 0, wxBOTTOM, space5);
|
|
|
|
temp_box->AddSpacer(space5);
|
2016-06-24 02:43:46 -06:00
|
|
|
return temp_box;
|
2014-10-31 02:34:30 -06:00
|
|
|
}
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
TASInputDlg::Button TASInputDlg::CreateButton(const wxString& name)
|
2014-09-14 21:42:32 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
Button temp;
|
2016-08-02 00:22:53 -06:00
|
|
|
temp.id = m_eleID++;
|
|
|
|
wxCheckBox* checkbox = new wxCheckBox(this, temp.id, name);
|
2016-06-24 02:43:46 -06:00
|
|
|
checkbox->Bind(wxEVT_RIGHT_DOWN, &TASInputDlg::SetTurbo, this);
|
|
|
|
checkbox->Bind(wxEVT_LEFT_DOWN, &TASInputDlg::SetTurbo, this);
|
|
|
|
checkbox->Bind(wxEVT_CHECKBOX, &TASInputDlg::OnCheckboxToggle, this);
|
|
|
|
temp.checkbox = checkbox;
|
|
|
|
return temp;
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
2012-01-22 12:45:55 -07:00
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
void TASInputDlg::OnCheckboxToggle(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
auto cbox = static_cast<wxCheckBox*>(event.GetEventObject());
|
|
|
|
static_cast<Button*>(cbox->GetClientData())->is_checked = event.IsChecked();
|
2016-05-01 06:09:58 -06:00
|
|
|
}
|
|
|
|
|
2014-09-14 21:42:32 -06:00
|
|
|
void TASInputDlg::ResetValues()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
for (Button* const button : m_buttons)
|
|
|
|
{
|
|
|
|
if (button != nullptr)
|
|
|
|
{
|
|
|
|
button->value = false;
|
2016-08-13 13:13:33 -06:00
|
|
|
button->is_checked = false;
|
2016-06-24 02:43:46 -06:00
|
|
|
button->checkbox->SetValue(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Control* const control : m_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr)
|
|
|
|
{
|
|
|
|
control->value = control->default_value;
|
|
|
|
control->slider->SetValue(control->default_value);
|
|
|
|
control->text->SetValue(std::to_string(control->default_value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_ext == 2)
|
|
|
|
{
|
|
|
|
for (Button& button : m_cc_buttons)
|
|
|
|
{
|
|
|
|
button.value = false;
|
2016-08-13 13:13:33 -06:00
|
|
|
button.is_checked = false;
|
2016-06-24 02:43:46 -06:00
|
|
|
button.checkbox->SetValue(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Control* control : m_cc_controls)
|
|
|
|
{
|
|
|
|
control->value = control->default_value;
|
|
|
|
control->slider->SetValue(control->default_value);
|
|
|
|
control->text->SetValue(std::to_string(control->default_value));
|
|
|
|
}
|
|
|
|
}
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
2012-01-21 17:39:17 -07:00
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
// NOTE: Host / CPU Thread
|
2015-09-07 03:15:23 -06:00
|
|
|
void TASInputDlg::SetStickValue(Control* control, int CurrentValue, int center)
|
2014-09-14 21:42:32 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (CurrentValue != center)
|
|
|
|
{
|
|
|
|
control->value = CurrentValue;
|
|
|
|
control->set_by_keyboard = true;
|
|
|
|
}
|
|
|
|
else if (control->set_by_keyboard)
|
|
|
|
{
|
|
|
|
control->value = center;
|
|
|
|
control->set_by_keyboard = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateControl(control);
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
2012-01-21 17:39:17 -07:00
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
// NOTE: Host / CPU Thread
|
2015-04-10 20:14:21 -06:00
|
|
|
void TASInputDlg::SetSliderValue(Control* control, int CurrentValue)
|
2014-09-14 21:42:32 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (CurrentValue != (int)control->default_value)
|
|
|
|
{
|
|
|
|
control->value = CurrentValue;
|
|
|
|
control->set_by_keyboard = true;
|
|
|
|
}
|
|
|
|
else if (control->set_by_keyboard)
|
|
|
|
{
|
|
|
|
control->value = control->default_value;
|
|
|
|
control->set_by_keyboard = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateControl(control);
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
// NOTE: Host / CPU Thread
|
2014-09-14 21:42:32 -06:00
|
|
|
void TASInputDlg::SetButtonValue(Button* button, bool CurrentState)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (CurrentState)
|
|
|
|
{
|
|
|
|
button->set_by_keyboard = true;
|
|
|
|
}
|
|
|
|
else if (button->set_by_keyboard)
|
|
|
|
{
|
|
|
|
button->set_by_keyboard = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
button->value = CurrentState;
|
|
|
|
InvalidateButton(button);
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
2012-01-21 17:39:17 -07:00
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
// NOTE: Host / CPU Thread
|
2014-10-24 19:59:16 -06:00
|
|
|
void TASInputDlg::SetWiiButtons(u16* butt)
|
2014-09-14 21:42:32 -06:00
|
|
|
{
|
2017-04-02 04:43:57 -06:00
|
|
|
for (size_t i = 0; i < s_wii_buttons_bitmask.size(); ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
if (m_buttons[i] != nullptr)
|
2016-08-02 00:22:53 -06:00
|
|
|
*butt |= (m_buttons[i]->is_checked) ? s_wii_buttons_bitmask[i] : 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
ButtonTurbo();
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
2012-01-21 17:39:17 -07:00
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
// NOTE: Host / CPU Thread
|
2014-09-14 21:42:32 -06:00
|
|
|
void TASInputDlg::GetKeyBoardInput(GCPadStatus* PadStatus)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
SetStickValue(&m_main_stick.x_cont, PadStatus->stickX);
|
|
|
|
SetStickValue(&m_main_stick.y_cont, PadStatus->stickY);
|
|
|
|
|
|
|
|
SetStickValue(&m_c_stick.x_cont, PadStatus->substickX);
|
|
|
|
SetStickValue(&m_c_stick.y_cont, PadStatus->substickY);
|
|
|
|
SetSliderValue(&m_l_cont, PadStatus->triggerLeft);
|
|
|
|
SetSliderValue(&m_r_cont, PadStatus->triggerRight);
|
|
|
|
|
2017-04-02 04:43:57 -06:00
|
|
|
for (size_t i = 0; i < m_buttons.size(); ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
if (m_buttons[i] != nullptr)
|
2016-08-02 00:22:53 -06:00
|
|
|
SetButtonValue(m_buttons[i], ((PadStatus->button & s_gc_pad_buttons_bitmask[i]) != 0));
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
SetButtonValue(&m_l,
|
|
|
|
((PadStatus->triggerLeft) == 255) || ((PadStatus->button & PAD_TRIGGER_L) != 0));
|
|
|
|
SetButtonValue(&m_r,
|
|
|
|
((PadStatus->triggerRight) == 255) || ((PadStatus->button & PAD_TRIGGER_R) != 0));
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
// NOTE: Host / CPU Thread
|
2016-06-24 02:43:46 -06:00
|
|
|
void TASInputDlg::GetKeyBoardInput(u8* data, WiimoteEmu::ReportFeatures rptf, int ext,
|
|
|
|
const wiimote_key key)
|
2014-09-14 21:42:32 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
u8* const coreData = rptf.core ? (data + rptf.core) : nullptr;
|
|
|
|
u8* const accelData = rptf.accel ? (data + rptf.accel) : nullptr;
|
|
|
|
// u8* const irData = rptf.ir ? (data + rptf.ir) : nullptr;
|
|
|
|
u8* const extData = rptf.ext ? (data + rptf.ext) : nullptr;
|
|
|
|
|
|
|
|
if (coreData)
|
|
|
|
{
|
2017-04-02 04:43:57 -06:00
|
|
|
for (size_t i = 0; i < s_wii_buttons_bitmask.size(); ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
if (m_buttons[i] != nullptr)
|
|
|
|
SetButtonValue(m_buttons[i],
|
2016-08-02 00:22:53 -06:00
|
|
|
(((wm_buttons*)coreData)->hex & s_wii_buttons_bitmask[i]) != 0);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (accelData)
|
|
|
|
{
|
|
|
|
wm_accel* dt = (wm_accel*)accelData;
|
|
|
|
|
|
|
|
SetSliderValue(&m_x_cont, dt->x << 2 | ((wm_buttons*)coreData)->acc_x_lsb);
|
|
|
|
SetSliderValue(&m_y_cont, dt->y << 2 | ((wm_buttons*)coreData)->acc_y_lsb << 1);
|
|
|
|
SetSliderValue(&m_z_cont, dt->z << 2 | ((wm_buttons*)coreData)->acc_z_lsb << 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// I don't think this can be made to work in a sane manner.
|
|
|
|
// if (irData)
|
|
|
|
//{
|
|
|
|
// u16 x = 1023 - (irData[0] | ((irData[2] >> 4 & 0x3) << 8));
|
|
|
|
// u16 y = irData[1] | ((irData[2] >> 6 & 0x3) << 8);
|
|
|
|
|
|
|
|
// SetStickValue(&m_main_stick.x_cont.set_by_keyboard, &m_main_stick.x_cont.value,
|
2016-06-24 04:16:10 -06:00
|
|
|
// m_main_stick.x_cont.text, x, 561);
|
2016-06-24 02:43:46 -06:00
|
|
|
// SetStickValue(&m_main_stick.y_cont.set_by_keyboard, &m_main_stick.y_cont.value,
|
2016-06-24 04:16:10 -06:00
|
|
|
// m_main_stick.y_cont.text, y, 486);
|
2016-06-24 02:43:46 -06:00
|
|
|
//}
|
|
|
|
|
|
|
|
if (extData && ext == 1)
|
|
|
|
{
|
|
|
|
wm_nc& nunchuk = *(wm_nc*)extData;
|
|
|
|
WiimoteDecrypt(&key, (u8*)&nunchuk, 0, sizeof(wm_nc));
|
|
|
|
nunchuk.bt.hex = nunchuk.bt.hex ^ 0x3;
|
|
|
|
SetButtonValue(m_buttons[11], nunchuk.bt.c != 0);
|
|
|
|
SetButtonValue(m_buttons[12], nunchuk.bt.z != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extData && ext == 2)
|
|
|
|
{
|
|
|
|
wm_classic_extension& cc = *(wm_classic_extension*)extData;
|
|
|
|
WiimoteDecrypt(&key, (u8*)&cc, 0, sizeof(wm_classic_extension));
|
|
|
|
cc.bt.hex = cc.bt.hex ^ 0xFFFF;
|
2017-04-02 04:43:57 -06:00
|
|
|
for (size_t i = 0; i < m_cc_buttons.size(); ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-02 00:22:53 -06:00
|
|
|
SetButtonValue(&m_cc_buttons[i], ((cc.bt.hex & s_cc_buttons_bitmask[i]) != 0));
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_cc_l.value == 31)
|
|
|
|
{
|
|
|
|
m_cc_buttons[10].value = true;
|
|
|
|
InvalidateButton(&m_cc_buttons[10]);
|
|
|
|
}
|
|
|
|
if (m_cc_r.value == 31)
|
|
|
|
{
|
|
|
|
m_cc_buttons[11].value = true;
|
|
|
|
InvalidateButton(&m_cc_buttons[11]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetSliderValue(&m_cc_l_stick.x_cont, cc.regular_data.lx);
|
|
|
|
SetSliderValue(&m_cc_l_stick.y_cont, cc.regular_data.ly);
|
|
|
|
|
|
|
|
SetSliderValue(&m_cc_r_stick.x_cont, cc.rx1 | (cc.rx2 << 1) | (cc.rx3 << 3));
|
|
|
|
SetSliderValue(&m_cc_r_stick.y_cont, cc.ry);
|
|
|
|
}
|
2014-09-14 21:42:32 -06:00
|
|
|
}
|
2012-01-21 17:39:17 -07:00
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
// NOTE: Host / CPU Thread
|
|
|
|
// Do not touch the GUI. Requires wxMutexGuiEnter which will deadlock against
|
|
|
|
// the GUI when pausing/stopping.
|
2016-06-24 02:43:46 -06:00
|
|
|
void TASInputDlg::GetValues(u8* data, WiimoteEmu::ReportFeatures rptf, int ext,
|
|
|
|
const wiimote_key key)
|
2014-09-14 21:42:32 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (!IsShown() || !m_has_layout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GetKeyBoardInput(data, rptf, ext, key);
|
|
|
|
|
|
|
|
u8* const coreData = rptf.core ? (data + rptf.core) : nullptr;
|
|
|
|
u8* const accelData = rptf.accel ? (data + rptf.accel) : nullptr;
|
|
|
|
u8* const irData = rptf.ir ? (data + rptf.ir) : nullptr;
|
|
|
|
u8* const extData = rptf.ext ? (data + rptf.ext) : nullptr;
|
|
|
|
if (ext != 2)
|
|
|
|
{
|
|
|
|
if (coreData)
|
|
|
|
SetWiiButtons(&((wm_buttons*)coreData)->hex);
|
|
|
|
|
|
|
|
if (accelData)
|
|
|
|
{
|
|
|
|
wm_accel& dt = *(wm_accel*)accelData;
|
|
|
|
wm_buttons& but = *(wm_buttons*)coreData;
|
|
|
|
dt.x = m_x_cont.value >> 2;
|
|
|
|
dt.y = m_y_cont.value >> 2;
|
|
|
|
dt.z = m_z_cont.value >> 2;
|
|
|
|
but.acc_x_lsb = m_x_cont.value & 0x3;
|
|
|
|
but.acc_y_lsb = m_y_cont.value >> 1 & 0x1;
|
|
|
|
but.acc_z_lsb = m_z_cont.value >> 1 & 0x1;
|
|
|
|
}
|
|
|
|
if (irData)
|
|
|
|
{
|
2017-04-02 04:43:57 -06:00
|
|
|
std::array<u16, 4> x;
|
|
|
|
u16 y = m_main_stick.y_cont.value;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
x[0] = m_main_stick.x_cont.value;
|
|
|
|
x[1] = x[0] + 100;
|
|
|
|
x[2] = x[0] - 10;
|
|
|
|
x[3] = x[1] + 10;
|
|
|
|
|
|
|
|
u8 mode;
|
|
|
|
// Mode 5 not supported in core anyway.
|
|
|
|
if (rptf.ext)
|
|
|
|
mode = (rptf.ext - rptf.ir) == 10 ? 1 : 3;
|
|
|
|
else
|
|
|
|
mode = (rptf.size - rptf.ir) == 10 ? 1 : 3;
|
|
|
|
|
|
|
|
if (mode == 1)
|
|
|
|
{
|
|
|
|
memset(irData, 0xFF, sizeof(wm_ir_basic) * 2);
|
|
|
|
wm_ir_basic* ir_data = (wm_ir_basic*)irData;
|
|
|
|
for (unsigned int i = 0; i < 2; ++i)
|
|
|
|
{
|
|
|
|
if (x[i * 2] < 1024 && y < 768)
|
|
|
|
{
|
|
|
|
ir_data[i].x1 = static_cast<u8>(x[i * 2]);
|
|
|
|
ir_data[i].x1hi = x[i * 2] >> 8;
|
|
|
|
|
|
|
|
ir_data[i].y1 = static_cast<u8>(y);
|
|
|
|
ir_data[i].y1hi = y >> 8;
|
|
|
|
}
|
|
|
|
if (x[i * 2 + 1] < 1024 && y < 768)
|
|
|
|
{
|
|
|
|
ir_data[i].x2 = static_cast<u8>(x[i * 2 + 1]);
|
|
|
|
ir_data[i].x2hi = x[i * 2 + 1] >> 8;
|
|
|
|
|
|
|
|
ir_data[i].y2 = static_cast<u8>(y);
|
|
|
|
ir_data[i].y2hi = y >> 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(data, 0xFF, sizeof(wm_ir_extended) * 4);
|
|
|
|
wm_ir_extended* const ir_data = (wm_ir_extended*)irData;
|
2017-04-02 04:43:57 -06:00
|
|
|
for (size_t i = 0; i < x.size(); ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
if (x[i] < 1024 && y < 768)
|
|
|
|
{
|
|
|
|
ir_data[i].x = static_cast<u8>(x[i]);
|
|
|
|
ir_data[i].xhi = x[i] >> 8;
|
|
|
|
|
|
|
|
ir_data[i].y = static_cast<u8>(y);
|
|
|
|
ir_data[i].yhi = y >> 8;
|
|
|
|
|
|
|
|
ir_data[i].size = 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ext != m_ext)
|
|
|
|
{
|
|
|
|
m_ext = ext;
|
|
|
|
InvalidateExtension();
|
|
|
|
}
|
|
|
|
else if (extData && ext == 1)
|
|
|
|
{
|
|
|
|
wm_nc& nunchuk = *(wm_nc*)extData;
|
|
|
|
|
|
|
|
nunchuk.jx = m_c_stick.x_cont.value;
|
|
|
|
nunchuk.jy = m_c_stick.y_cont.value;
|
|
|
|
|
|
|
|
nunchuk.ax = m_nx_cont.value >> 2;
|
|
|
|
nunchuk.bt.acc_x_lsb = m_nx_cont.value & 0x3;
|
|
|
|
nunchuk.ay = m_ny_cont.value >> 2;
|
|
|
|
nunchuk.bt.acc_y_lsb = m_ny_cont.value & 0x3;
|
|
|
|
nunchuk.az = m_nz_cont.value >> 2;
|
|
|
|
nunchuk.bt.acc_z_lsb = m_nz_cont.value & 0x3;
|
|
|
|
|
|
|
|
nunchuk.bt.hex |= (m_buttons[11]->is_checked) ? WiimoteEmu::Nunchuk::BUTTON_C : 0;
|
|
|
|
nunchuk.bt.hex |= (m_buttons[12]->is_checked) ? WiimoteEmu::Nunchuk::BUTTON_Z : 0;
|
|
|
|
nunchuk.bt.hex = nunchuk.bt.hex ^ 0x3;
|
|
|
|
WiimoteEncrypt(&key, (u8*)&nunchuk, 0, sizeof(wm_nc));
|
|
|
|
}
|
|
|
|
else if (extData && ext == 2)
|
|
|
|
{
|
|
|
|
wm_classic_extension& cc = *(wm_classic_extension*)extData;
|
|
|
|
WiimoteDecrypt(&key, (u8*)&cc, 0, sizeof(wm_classic_extension));
|
|
|
|
cc.bt.hex = 0;
|
|
|
|
|
2017-04-02 04:43:57 -06:00
|
|
|
for (size_t i = 0; i < m_cc_buttons.size(); ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-02 00:22:53 -06:00
|
|
|
cc.bt.hex |= (m_cc_buttons[i].is_checked) ? s_cc_buttons_bitmask[i] : 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
cc.bt.hex ^= 0xFFFF;
|
|
|
|
|
|
|
|
u16 rx = m_cc_r_stick.x_cont.value;
|
|
|
|
cc.rx1 = rx & 0x1;
|
|
|
|
cc.rx2 = (rx >> 1) & 0x3;
|
|
|
|
cc.rx3 = (rx >> 3) & 0x3;
|
|
|
|
cc.ry = m_cc_r_stick.y_cont.value;
|
|
|
|
|
|
|
|
cc.regular_data.lx = m_cc_l_stick.x_cont.value;
|
|
|
|
cc.regular_data.ly = m_cc_l_stick.y_cont.value;
|
|
|
|
|
|
|
|
cc.rt = m_cc_r.value;
|
|
|
|
cc.lt1 = m_cc_l.value & 0x7;
|
|
|
|
cc.lt2 = (m_cc_l.value >> 3) & 0x3;
|
|
|
|
|
|
|
|
WiimoteEncrypt(&key, (u8*)&cc, 0, sizeof(wm_classic_extension));
|
|
|
|
}
|
2013-07-23 17:24:05 -06:00
|
|
|
}
|
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
// NOTE: Host / CPU Thread
|
2014-09-14 21:42:32 -06:00
|
|
|
void TASInputDlg::GetValues(GCPadStatus* PadStatus)
|
2011-06-27 13:44:27 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (!IsShown() || !m_has_layout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// TODO:: Make this instant not when polled.
|
|
|
|
GetKeyBoardInput(PadStatus);
|
|
|
|
|
|
|
|
PadStatus->stickX = m_main_stick.x_cont.value;
|
|
|
|
PadStatus->stickY = m_main_stick.y_cont.value;
|
|
|
|
PadStatus->substickX = m_c_stick.x_cont.value;
|
|
|
|
PadStatus->substickY = m_c_stick.y_cont.value;
|
|
|
|
PadStatus->triggerLeft = m_l.is_checked ? 255 : m_l_cont.value;
|
|
|
|
PadStatus->triggerRight = m_r.is_checked ? 255 : m_r_cont.value;
|
|
|
|
|
2017-04-02 04:43:57 -06:00
|
|
|
for (size_t i = 0; i < m_buttons.size(); ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
if (m_buttons[i] != nullptr)
|
|
|
|
{
|
|
|
|
if (m_buttons[i]->is_checked)
|
2016-08-02 00:22:53 -06:00
|
|
|
PadStatus->button |= s_gc_pad_buttons_bitmask[i];
|
2016-06-24 02:43:46 -06:00
|
|
|
else
|
2016-08-02 00:22:53 -06:00
|
|
|
PadStatus->button &= ~s_gc_pad_buttons_bitmask[i];
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_a.is_checked)
|
|
|
|
PadStatus->analogA = 0xFF;
|
|
|
|
else
|
|
|
|
PadStatus->analogA = 0x00;
|
|
|
|
|
|
|
|
if (m_b.is_checked)
|
|
|
|
PadStatus->analogB = 0xFF;
|
|
|
|
else
|
|
|
|
PadStatus->analogB = 0x00;
|
|
|
|
|
|
|
|
ButtonTurbo();
|
2011-06-27 13:44:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::UpdateFromSliders(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
wxTextCtrl* text = nullptr;
|
|
|
|
|
|
|
|
for (Control* const control : m_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr && event.GetId() == control->slider_id)
|
|
|
|
text = control->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Control* const control : m_cc_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr && event.GetId() == control->slider_id)
|
|
|
|
text = control->text;
|
|
|
|
}
|
|
|
|
int value = ((wxSlider*)event.GetEventObject())->GetValue();
|
|
|
|
if (text)
|
|
|
|
text->SetValue(std::to_string(value));
|
2011-06-27 13:44:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::UpdateFromText(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
if (!((wxTextCtrl*)event.GetEventObject())->GetValue().ToULong(&value))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (Control* const control : m_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr && event.GetId() == control->text_id)
|
|
|
|
{
|
|
|
|
int v = (value > control->range) ? control->range : value;
|
|
|
|
control->slider->SetValue(v);
|
|
|
|
control->text->ChangeValue(std::to_string(v));
|
|
|
|
control->value = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Control* const control : m_cc_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr && event.GetId() == control->text_id)
|
|
|
|
{
|
|
|
|
int v = (value > control->range) ? control->range : value;
|
|
|
|
control->slider->SetValue(v);
|
|
|
|
control->text->ChangeValue(std::to_string(v));
|
|
|
|
control->value = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_controls[0] != nullptr)
|
|
|
|
UpdateStickBitmap(m_main_stick);
|
|
|
|
if (m_controls[2] != nullptr)
|
|
|
|
UpdateStickBitmap(m_c_stick);
|
|
|
|
if (m_cc_controls[CC_L_STICK_X] != nullptr)
|
|
|
|
UpdateStickBitmap(m_cc_l_stick);
|
|
|
|
if (m_cc_controls[CC_R_STICK_X] != nullptr)
|
|
|
|
UpdateStickBitmap(m_cc_r_stick);
|
2015-04-10 20:14:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::UpdateStickBitmap(Stick stick)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
int x = (u8)(
|
|
|
|
std::floor(((double)stick.x_cont.value / (double)(stick.x_cont.range + 1) * 255.0) + .5));
|
|
|
|
int y = (u8)(
|
|
|
|
std::floor(((double)stick.y_cont.value / (double)(stick.y_cont.range + 1) * 255.0) + .5));
|
|
|
|
if (stick.x_cont.reverse)
|
|
|
|
x = 256 - (u8)x;
|
|
|
|
if (stick.y_cont.reverse)
|
|
|
|
y = 256 - (u8)y;
|
|
|
|
stick.bitmap->SetBitmap(CreateStickBitmap(x, y));
|
2011-06-27 13:44:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::OnCloseWindow(wxCloseEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (event.CanVeto())
|
|
|
|
{
|
|
|
|
event.Skip(false);
|
|
|
|
Show(false);
|
|
|
|
ResetValues();
|
|
|
|
}
|
2011-06-27 13:44:27 -06:00
|
|
|
}
|
2011-07-12 23:53:56 -06:00
|
|
|
|
2015-04-10 20:14:21 -06:00
|
|
|
TASInputDlg::Stick* TASInputDlg::FindStickByID(int id)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (id == ID_MAIN_STICK)
|
|
|
|
return &m_main_stick;
|
|
|
|
else if (id == ID_C_STICK)
|
|
|
|
return &m_c_stick;
|
|
|
|
else if (id == ID_CC_L_STICK)
|
|
|
|
return &m_cc_l_stick;
|
|
|
|
else if (id == ID_CC_R_STICK)
|
|
|
|
return &m_cc_r_stick;
|
|
|
|
else
|
|
|
|
return nullptr;
|
2015-04-10 20:14:21 -06:00
|
|
|
}
|
2014-09-14 21:42:32 -06:00
|
|
|
void TASInputDlg::OnMouseUpR(wxMouseEvent& event)
|
2012-01-21 17:39:17 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
Stick* stick = FindStickByID(event.GetId());
|
|
|
|
if (stick == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
stick->x_cont.value = stick->x_cont.default_value;
|
|
|
|
stick->y_cont.value = stick->y_cont.default_value;
|
|
|
|
stick->bitmap->SetBitmap(CreateStickBitmap(128, 128));
|
|
|
|
stick->x_cont.text->SetValue(std::to_string(stick->x_cont.default_value));
|
|
|
|
stick->y_cont.text->SetValue(std::to_string(stick->y_cont.default_value));
|
|
|
|
stick->x_cont.slider->SetValue(stick->x_cont.default_value);
|
|
|
|
stick->y_cont.slider->SetValue(stick->y_cont.default_value);
|
|
|
|
|
|
|
|
event.Skip();
|
2012-01-21 17:39:17 -07:00
|
|
|
}
|
|
|
|
|
2014-09-14 21:42:32 -06:00
|
|
|
void TASInputDlg::OnRightClickSlider(wxMouseEvent& event)
|
2012-01-21 17:39:17 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
for (Control* const control : m_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr && event.GetId() == control->slider_id)
|
|
|
|
{
|
|
|
|
control->value = control->default_value;
|
|
|
|
control->slider->SetValue(control->default_value);
|
|
|
|
control->text->SetValue(std::to_string(control->default_value));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Control* const control : m_cc_controls)
|
|
|
|
{
|
|
|
|
if (control != nullptr && event.GetId() == control->slider_id)
|
|
|
|
{
|
|
|
|
control->value = control->default_value;
|
|
|
|
control->slider->SetValue(control->default_value);
|
|
|
|
control->text->SetValue(std::to_string(control->default_value));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-01-21 17:39:17 -07:00
|
|
|
}
|
|
|
|
|
2013-06-25 09:04:28 -06:00
|
|
|
void TASInputDlg::OnMouseDownL(wxMouseEvent& event)
|
2012-01-21 17:39:17 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (!event.LeftIsDown())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Stick* stick = FindStickByID(event.GetId());
|
|
|
|
if (stick == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxPoint ptM(event.GetPosition());
|
2016-08-02 00:22:53 -06:00
|
|
|
wxSize bitmap_size = FromDIP(wxSize(127, 127));
|
|
|
|
stick->x_cont.value = ptM.x * stick->x_cont.range / bitmap_size.GetWidth();
|
|
|
|
stick->y_cont.value = ptM.y * stick->y_cont.range / bitmap_size.GetHeight();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
if ((unsigned)stick->y_cont.value > stick->y_cont.range)
|
|
|
|
stick->y_cont.value = stick->y_cont.range;
|
|
|
|
if ((unsigned)stick->x_cont.value > stick->x_cont.range)
|
|
|
|
stick->x_cont.value = stick->x_cont.range;
|
|
|
|
|
|
|
|
if (stick->y_cont.reverse)
|
|
|
|
stick->y_cont.value = stick->y_cont.range - (u16)stick->y_cont.value;
|
|
|
|
if (stick->x_cont.reverse)
|
|
|
|
stick->x_cont.value = stick->x_cont.range - (u16)stick->x_cont.value;
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
stick->x_cont.value = std::min<u32>(stick->x_cont.value, stick->x_cont.range);
|
|
|
|
stick->y_cont.value = std::min<u32>(stick->y_cont.value, stick->y_cont.range);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// This updates sliders and the bitmap too.
|
|
|
|
stick->x_cont.text->SetValue(std::to_string(stick->x_cont.value));
|
|
|
|
stick->y_cont.text->SetValue(std::to_string(stick->y_cont.value));
|
|
|
|
|
|
|
|
event.Skip();
|
2012-01-21 17:39:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::SetTurbo(wxMouseEvent& event)
|
|
|
|
{
|
2016-08-13 13:13:33 -06:00
|
|
|
auto cbox = static_cast<wxCheckBox*>(event.GetEventObject());
|
|
|
|
auto button = static_cast<Button*>(cbox->GetClientData());
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
if (event.LeftDown())
|
|
|
|
{
|
|
|
|
if (button)
|
|
|
|
button->turbo_on = false;
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (button)
|
|
|
|
{
|
|
|
|
button->checkbox->SetValue(true);
|
2016-08-13 13:13:33 -06:00
|
|
|
button->is_checked = true;
|
2016-06-24 02:43:46 -06:00
|
|
|
button->turbo_on = !button->turbo_on;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
2012-01-21 17:39:17 -07:00
|
|
|
}
|
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
// NOTE: Host / CPU Thread
|
2012-01-21 17:39:17 -07:00
|
|
|
void TASInputDlg::ButtonTurbo()
|
|
|
|
{
|
2016-08-04 10:54:45 -06:00
|
|
|
static u64 frame = Movie::GetCurrentFrame();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-04 10:54:45 -06:00
|
|
|
if (frame != Movie::GetCurrentFrame())
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-08-04 10:54:45 -06:00
|
|
|
frame = Movie::GetCurrentFrame();
|
2016-06-24 02:43:46 -06:00
|
|
|
for (Button* const button : m_buttons)
|
|
|
|
{
|
|
|
|
if (button != nullptr && button->turbo_on)
|
|
|
|
{
|
|
|
|
button->value = !button->is_checked;
|
|
|
|
InvalidateButton(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_ext == 2)
|
|
|
|
{
|
|
|
|
for (Button& button : m_cc_buttons)
|
|
|
|
{
|
|
|
|
if (button.turbo_on)
|
|
|
|
{
|
|
|
|
button.value = !button.is_checked;
|
|
|
|
InvalidateButton(&button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-21 17:39:17 -07:00
|
|
|
}
|
|
|
|
|
2015-09-07 03:15:23 -06:00
|
|
|
void TASInputDlg::InvalidateButton(Button* button)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (!wxIsMainThread())
|
|
|
|
{
|
|
|
|
wxCommandEvent* evt = new wxCommandEvent(INVALIDATE_BUTTON_EVENT, button->id);
|
|
|
|
evt->SetClientData(button);
|
|
|
|
wxQueueEvent(this, evt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
button->checkbox->SetValue(button->value);
|
|
|
|
button->is_checked = button->value;
|
2015-09-07 03:15:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::InvalidateControl(Control* control)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (!wxIsMainThread())
|
|
|
|
{
|
|
|
|
wxCommandEvent* evt = new wxCommandEvent(INVALIDATE_CONTROL_EVENT, control->text_id);
|
|
|
|
evt->SetClientData(control);
|
|
|
|
wxQueueEvent(this, evt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
control->text->SetValue(std::to_string(control->value));
|
2015-09-07 03:15:23 -06:00
|
|
|
}
|
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
void TASInputDlg::InvalidateExtension()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (!wxIsMainThread())
|
|
|
|
{
|
|
|
|
GetEventHandler()->QueueEvent(new wxThreadEvent(INVALIDATE_EXTENSION_EVENT));
|
|
|
|
return;
|
|
|
|
}
|
2016-05-01 06:09:58 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
HandleExtensionChange();
|
2016-05-01 06:09:58 -06:00
|
|
|
}
|
|
|
|
|
2015-09-07 03:15:23 -06:00
|
|
|
void TASInputDlg::UpdateFromInvalidatedButton(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
Button* button = static_cast<Button*>(event.GetClientData());
|
|
|
|
_assert_msg_(PAD, button->id == button->checkbox->GetId(), "Button ids do not match: %i != %i",
|
|
|
|
button->id, button->checkbox->GetId());
|
|
|
|
button->checkbox->SetValue(button->value);
|
|
|
|
button->is_checked = button->value;
|
2015-09-07 03:15:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TASInputDlg::UpdateFromInvalidatedControl(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
Control* control = static_cast<Control*>(event.GetClientData());
|
|
|
|
_assert_msg_(PAD, control->text_id == control->text->GetId(),
|
|
|
|
"Control ids do not match: %i != %i", control->text_id, control->text->GetId());
|
|
|
|
control->text->SetValue(std::to_string(control->value));
|
2015-09-07 03:15:23 -06:00
|
|
|
}
|
|
|
|
|
2016-05-01 06:09:58 -06:00
|
|
|
void TASInputDlg::UpdateFromInvalidatedExtension(wxThreadEvent&)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
HandleExtensionChange();
|
2016-05-01 06:09:58 -06:00
|
|
|
}
|
|
|
|
|
2012-01-21 17:39:17 -07:00
|
|
|
wxBitmap TASInputDlg::CreateStickBitmap(int x, int y)
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
x = x / 2;
|
|
|
|
y = y / 2;
|
|
|
|
|
2016-08-02 00:22:53 -06:00
|
|
|
// Scale for screen DPI
|
|
|
|
static constexpr int WIDTH = 129;
|
|
|
|
static constexpr int HEIGHT = 129;
|
|
|
|
wxSize bitmap_size = FromDIP(wxSize(WIDTH, HEIGHT));
|
|
|
|
double scale_x = bitmap_size.GetWidth() / static_cast<double>(WIDTH);
|
|
|
|
double scale_y = bitmap_size.GetHeight() / static_cast<double>(HEIGHT);
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
wxMemoryDC memDC;
|
2016-08-02 00:22:53 -06:00
|
|
|
wxBitmap bitmap;
|
|
|
|
bitmap.CreateScaled(bitmap_size.GetWidth(), bitmap_size.GetHeight(), wxBITMAP_SCREEN_DEPTH,
|
|
|
|
GetContentScaleFactor());
|
2016-06-24 02:43:46 -06:00
|
|
|
memDC.SelectObject(bitmap);
|
2016-08-02 00:22:53 -06:00
|
|
|
memDC.SetUserScale(scale_x, scale_y);
|
2016-06-24 02:43:46 -06:00
|
|
|
memDC.SetBackground(*wxLIGHT_GREY_BRUSH);
|
|
|
|
memDC.Clear();
|
|
|
|
memDC.SetBrush(*wxWHITE_BRUSH);
|
2016-06-25 23:25:29 -06:00
|
|
|
memDC.DrawCircle(64, 64, 64);
|
|
|
|
memDC.SetPen(wxPen(*wxBLACK, 3, wxPENSTYLE_SOLID));
|
2016-06-24 02:43:46 -06:00
|
|
|
memDC.DrawLine(64, 64, x, y);
|
|
|
|
memDC.SetPen(*wxBLACK_PEN);
|
2016-08-02 00:22:53 -06:00
|
|
|
memDC.DrawLine(64, 0, 64, HEIGHT); // CrossHair doesn't work @96DPI on Windows for some reason
|
|
|
|
memDC.DrawLine(0, 64, WIDTH, 64);
|
2016-06-24 02:43:46 -06:00
|
|
|
memDC.SetBrush(*wxBLUE_BRUSH);
|
|
|
|
memDC.DrawCircle(x, y, 5);
|
|
|
|
memDC.SelectObject(wxNullBitmap);
|
|
|
|
return bitmap;
|
2012-05-26 07:24:18 -06:00
|
|
|
}
|