dolphin/Source/Core/DolphinWX/TASInputDlg.cpp

787 lines
23 KiB
C++
Raw Normal View History

// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
2014-02-22 22:36:30 +00:00
#include <cstddef>
#include <wx/bitmap.h>
#include <wx/chartype.h>
#include <wx/checkbox.h>
#include <wx/dcmemory.h>
#include <wx/defs.h>
#include <wx/dialog.h>
#include <wx/event.h>
#include <wx/gdicmn.h>
#include <wx/layout.h>
#include <wx/sizer.h>
#include <wx/slider.h>
#include <wx/statbmp.h>
#include <wx/string.h>
#include <wx/textctrl.h>
#include <wx/translation.h>
#include <wx/validate.h>
#include <wx/window.h>
#include <wx/windowid.h>
#include "Common/CommonTypes.h"
#include "Core/Movie.h"
2014-09-15 03:42:32 +00:00
#include "Core/HW/WiimoteEmu/MatrixMath.h"
#include "DolphinWX/TASInputDlg.h"
2014-02-22 22:36:30 +00:00
#include "InputCommon/GCPadStatus.h"
2014-09-15 03:42:32 +00:00
BEGIN_EVENT_TABLE(TASInputDlg, wxDialog)
EVT_CLOSE(TASInputDlg::OnCloseWindow)
END_EVENT_TABLE()
TASInputDlg::TASInputDlg(wxWindow* parent, wxWindowID id, const wxString& title,
2014-09-15 03:42:32 +00:00
const wxPoint& position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
{
m_buttons[0] = &m_a;
m_buttons[1] = &m_b;
m_buttons[2] = &m_dpad_down;
m_buttons[3] = &m_dpad_up;
m_buttons[4] = &m_dpad_left;
m_buttons[5] = &m_dpad_right;
m_buttons[13] = nullptr;
m_controls[0] = &m_main_stick.x_cont;
m_controls[1] = &m_main_stick.y_cont;
m_controls[9] = nullptr;
m_a = CreateButton("A");
m_b = CreateButton("B");
m_dpad_up = CreateButton("Up");
m_dpad_right = CreateButton("Right");
m_dpad_down = CreateButton("Down");
m_dpad_left = CreateButton("Left");
m_buttons_dpad->AddSpacer(20);
m_buttons_dpad->Add(m_dpad_up.checkbox, false);
m_buttons_dpad->AddSpacer(20);
m_buttons_dpad->Add(m_dpad_left.checkbox, false);
m_buttons_dpad->AddSpacer(20);
m_buttons_dpad->Add(m_dpad_right.checkbox, false);
m_buttons_dpad->AddSpacer(20);
m_buttons_dpad->Add(m_dpad_down.checkbox, false);
m_buttons_dpad->AddSpacer(20);
2014-09-15 03:42:32 +00:00
}
const int TASInputDlg::m_gc_pad_buttons_bitmask[12] = {
2014-09-15 03:42:32 +00:00
PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_DOWN, PAD_BUTTON_UP, PAD_BUTTON_LEFT,PAD_BUTTON_RIGHT,
PAD_BUTTON_X, PAD_BUTTON_Y, PAD_TRIGGER_Z, PAD_TRIGGER_L, PAD_TRIGGER_R, PAD_BUTTON_START
};
const int TASInputDlg::m_wii_buttons_bitmask[13] = {
2014-09-15 03:42:32 +00:00
WiimoteEmu::Wiimote::BUTTON_A, WiimoteEmu::Wiimote::BUTTON_B, WiimoteEmu::Wiimote::PAD_DOWN,
WiimoteEmu::Wiimote::PAD_UP, WiimoteEmu::Wiimote::PAD_LEFT, WiimoteEmu::Wiimote::PAD_RIGHT,
WiimoteEmu::Wiimote::BUTTON_ONE, WiimoteEmu::Wiimote::BUTTON_TWO, WiimoteEmu::Wiimote::BUTTON_PLUS,
WiimoteEmu::Wiimote::BUTTON_MINUS, WiimoteEmu::Wiimote::BUTTON_HOME
};
void TASInputDlg::CreateWiiLayout()
{
if (m_has_layout)
2014-09-15 03:42:32 +00:00
return;
m_is_wii = true;
m_has_layout = true;
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_buttons[11] = nullptr; //&C;
m_buttons[12] = nullptr; //&Z;
m_controls[2] = nullptr;
m_controls[3] = nullptr;
m_controls[4] = nullptr;
m_controls[5] = nullptr;
m_controls[6] = &m_x_cont;
m_controls[7] = &m_y_cont;
m_controls[8] = &m_z_cont;
m_main_stick = CreateStick(ID_MAIN_STICK);
wxStaticBoxSizer* const main_stick = CreateStickLayout(&m_main_stick, _("IR"));
m_main_stick.x_cont.default_value = 512;
m_main_stick.y_cont.default_value = 384;
2014-09-15 03:42:32 +00:00
wxStaticBoxSizer* const axisBox = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Orientation"));
wxStaticBoxSizer* const xBox = new wxStaticBoxSizer(wxVERTICAL, this, _("X"));
wxStaticBoxSizer* const yBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Y"));
wxStaticBoxSizer* const zBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Z"));
m_x_cont = CreateControl(wxSL_VERTICAL, -1, 100);
m_y_cont = CreateControl(wxSL_VERTICAL, -1, 100);
m_z_cont = CreateControl(wxSL_VERTICAL, -1, 100);
m_z_cont.default_value = 154;
xBox->Add(m_x_cont.slider, 0, wxALIGN_CENTER_VERTICAL);
xBox->Add(m_x_cont.text, 0, wxALIGN_CENTER_VERTICAL);
yBox->Add(m_y_cont.slider, 0, wxALIGN_CENTER_VERTICAL);
yBox->Add(m_y_cont.text, 0, wxALIGN_CENTER_VERTICAL);
zBox->Add(m_z_cont.slider, 0, wxALIGN_CENTER_VERTICAL);
zBox->Add(m_z_cont.text, 0, wxALIGN_CENTER_VERTICAL);
2014-09-15 03:42:32 +00:00
axisBox->Add(xBox);
axisBox->Add(yBox);
axisBox->Add(zBox);
for (unsigned int i = 0; i < 10; ++i)
{
if (m_controls[i] != nullptr)
m_controls[i]->slider->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(TASInputDlg::OnRightClickSlider), nullptr, this);
2014-09-15 03:42:32 +00:00
}
wxStaticBoxSizer* const buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
wxGridSizer* const buttons_grid = new wxGridSizer(4);
//m_c = CreateButton("C");
//m_z = CreateButton("Z");
m_plus = CreateButton("+");
m_minus = CreateButton("-");
m_one = CreateButton("1");
m_two = CreateButton("2");
m_home = CreateButton("HOME");
buttons_grid->Add(m_a.checkbox, false);
buttons_grid->Add(m_b.checkbox, false);
//buttons_grid->Add(C.checkbox, false);
//buttons_grid->Add(Z.checkbox, false);
buttons_grid->Add(m_plus.checkbox, false);
buttons_grid->Add(m_minus.checkbox, false);
buttons_grid->Add(m_one.checkbox, false);
buttons_grid->Add(m_two.checkbox, false);
buttons_grid->Add(m_home.checkbox, false);
2014-09-15 03:42:32 +00:00
buttons_grid->AddSpacer(5);
buttons_box->Add(buttons_grid);
buttons_box->Add(m_buttons_dpad);
2014-09-15 03:42:32 +00:00
wxBoxSizer* const main_szr = new wxBoxSizer(wxHORIZONTAL);
main_szr->Add(main_stick);
main_szr->Add(axisBox);
main_szr->Add(buttons_box);
SetSizerAndFit(main_szr);
ResetValues();
}
void TASInputDlg::CreateGCLayout()
{
if (m_has_layout)
2014-09-15 03:42:32 +00:00
return;
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_buttons[12] = nullptr;
m_controls[2] = &m_l_cont;
m_controls[3] = &m_r_cont;
m_controls[4] = &m_c_stick.x_cont;
m_controls[5] = &m_c_stick.y_cont;
m_controls[6] = nullptr;
m_controls[7] = nullptr;
m_controls[8] = nullptr;
wxBoxSizer* const top_box = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* const bottom_box = new wxBoxSizer(wxHORIZONTAL);
m_main_stick = CreateStick(ID_MAIN_STICK);
wxStaticBoxSizer* const main_box = CreateStickLayout(&m_main_stick, _("Main Stick"));
m_c_stick = CreateStick(ID_C_STICK);
wxStaticBoxSizer* const c_box = CreateStickLayout(&m_c_stick, _("C Stick"));
2014-09-15 03:42:32 +00:00
wxStaticBoxSizer* const shoulder_box = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Shoulder Buttons"));
m_l_cont = CreateControl(wxSL_VERTICAL | wxSL_INVERSE, -1, 100);
m_l_cont.default_value = 0;
m_r_cont = CreateControl(wxSL_VERTICAL | wxSL_INVERSE, -1, 100);
m_r_cont.default_value = 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);
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 10; ++i)
{
if (m_controls[i] != nullptr)
m_controls[i]->slider->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(TASInputDlg::OnRightClickSlider), nullptr, this);
2014-09-15 03:42:32 +00:00
}
wxStaticBoxSizer* const buttons_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Buttons"));
wxGridSizer* const buttons_grid = new wxGridSizer(4);
m_x = CreateButton("X");
m_y = CreateButton("Y");
m_l = CreateButton("L");
m_r = CreateButton("R");
m_z = CreateButton("Z");
m_start = CreateButton("Start");
buttons_grid->Add(m_a.checkbox, false);
buttons_grid->Add(m_b.checkbox, false);
buttons_grid->Add(m_x.checkbox, false);
buttons_grid->Add(m_y.checkbox, false);
buttons_grid->Add(m_l.checkbox, false);
buttons_grid->Add(m_r.checkbox, false);
buttons_grid->Add(m_z.checkbox, false);
buttons_grid->Add(m_start.checkbox, false);
buttons_grid->AddSpacer(5);
buttons_box->Add(buttons_grid);
buttons_box->Add(m_buttons_dpad);
wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL);
2012-01-22 00:39:17 +00:00
top_box->AddSpacer(5);
top_box->Add(main_box);
top_box->AddSpacer(5);
top_box->Add(c_box);
top_box->AddSpacer(5);
bottom_box->AddSpacer(5);
bottom_box->Add(shoulder_box);
bottom_box->AddSpacer(5);
bottom_box->Add(buttons_box);
bottom_box->AddSpacer(5);
main_szr->Add(top_box);
main_szr->Add(bottom_box);
SetSizerAndFit(main_szr);
ResetValues();
2014-10-08 13:46:28 +00:00
m_has_layout = true;
}
2014-09-15 03:42:32 +00:00
TASInputDlg::Control TASInputDlg::CreateControl(long style, int width, int height, u32 range)
{
2014-09-15 03:42:32 +00:00
Control tempCont;
tempCont.range = range;
tempCont.slider = new wxSlider(this, m_eleID++, range/2+1, 0, range, wxDefaultPosition, wxDefaultSize, style);
tempCont.slider->SetMinSize(wxSize(width, height));
tempCont.slider->Connect(wxEVT_SLIDER, wxCommandEventHandler(TASInputDlg::UpdateFromSliders), nullptr, this);
tempCont.text = new wxTextCtrl(this, m_eleID++, std::to_string(range/2+1), wxDefaultPosition, wxSize(40, 20));
tempCont.text->SetMaxLength(range > 999 ? 4 : 3);
tempCont.text_id = m_eleID - 1;
tempCont.text->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(TASInputDlg::UpdateFromText), nullptr, this);
tempCont.slider_id = m_eleID - 2;
2014-09-15 03:42:32 +00:00
return tempCont;
}
2014-09-15 03:42:32 +00:00
TASInputDlg::Stick TASInputDlg::CreateStick(int id_stick)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
Stick tempStick;
tempStick.bitmap = new wxStaticBitmap(this, id_stick, CreateStickBitmap(128,128), wxDefaultPosition, wxDefaultSize);
tempStick.bitmap->Connect(wxEVT_MOTION, wxMouseEventHandler(TASInputDlg::OnMouseDownL), nullptr, this);
tempStick.bitmap->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(TASInputDlg::OnMouseDownL), nullptr, this);
tempStick.bitmap->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(TASInputDlg::OnMouseUpR), nullptr, this);
tempStick.x_cont = CreateControl(wxSL_HORIZONTAL | (m_is_wii ? wxSL_INVERSE : 0), 120, -1, m_is_wii ? 1024 : 255);
tempStick.y_cont = CreateControl(wxSL_VERTICAL | (m_is_wii ? 0 : wxSL_INVERSE), -1, 120, m_is_wii ? 768 : 255);
2014-09-15 03:42:32 +00:00
return tempStick;
}
wxStaticBoxSizer* TASInputDlg::CreateStickLayout(Stick* tempStick, const wxString& title)
2014-09-15 03:42:32 +00:00
{
wxStaticBoxSizer* const temp_box = new wxStaticBoxSizer(wxHORIZONTAL, this, title);
2014-09-15 03:42:32 +00:00
wxBoxSizer* const temp_xslider_box = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* const temp_yslider_box = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* const temp_stick_box = new wxBoxSizer(wxVERTICAL);
temp_xslider_box->Add(tempStick->x_cont.slider, 0, wxALIGN_TOP);
temp_xslider_box->Add(tempStick->x_cont.text, 0, wxALIGN_TOP);
2014-09-15 03:42:32 +00:00
temp_stick_box->Add(temp_xslider_box);
temp_stick_box->Add(tempStick->bitmap,0, wxALL|wxCenter,3);
temp_box->Add(temp_stick_box);
temp_yslider_box->Add(tempStick->y_cont.slider, 0, wxALIGN_CENTER_VERTICAL);
temp_yslider_box->Add(tempStick->y_cont.text, 0, wxALIGN_CENTER_VERTICAL);
2014-09-15 03:42:32 +00:00
temp_box->Add(temp_yslider_box);
return temp_box;
}
2014-09-15 03:42:32 +00:00
TASInputDlg::Button TASInputDlg::CreateButton(const std::string& name)
{
Button temp;
wxCheckBox* checkbox = new wxCheckBox(this, m_eleID++, name, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxCheckBoxNameStr);
2014-09-15 03:42:32 +00:00
checkbox->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(TASInputDlg::SetTurbo), nullptr, this);
checkbox->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(TASInputDlg::SetTurbo), nullptr, this);
temp.checkbox = checkbox;
temp.id = m_eleID - 1;
2014-09-15 03:42:32 +00:00
return temp;
}
2014-09-15 03:42:32 +00:00
void TASInputDlg::ResetValues()
{
if (!m_has_layout)
2014-09-15 03:42:32 +00:00
return;
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 14; ++i)
{
if (m_buttons[i] != nullptr)
m_buttons[i]->checkbox->SetValue(false);
}
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 10; ++i)
2012-01-22 00:39:17 +00:00
{
if (m_controls[i] != nullptr)
2014-09-15 03:42:32 +00:00
{
m_controls[i]->value = m_controls[i]->default_value;
m_controls[i]->slider->SetValue(m_controls[i]->default_value);
m_controls[i]->text->SetValue(std::to_string(m_controls[i]->default_value));
2014-09-15 03:42:32 +00:00
}
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
}
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
void TASInputDlg::SetStickValue(bool* ActivatedByKeyboard, int* AmountPressed, wxTextCtrl* Textbox, int CurrentValue, int center)
{
if (CurrentValue != center)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
*AmountPressed = CurrentValue;
*ActivatedByKeyboard = true;
Textbox->SetValue(std::to_string(*AmountPressed));
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
else if (*ActivatedByKeyboard)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
*AmountPressed = center;
*ActivatedByKeyboard = false;
Textbox->SetValue(std::to_string(*AmountPressed));
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
}
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
void TASInputDlg::SetSliderValue(Control* control, int CurrentValue, int defaultValue)
{
if (CurrentValue != defaultValue)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
control->value = CurrentValue;
control->set_by_keyboard = true;
control->text->SetValue(std::to_string(CurrentValue));
2012-01-22 00:39:17 +00:00
}
else if (control->set_by_keyboard)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
control->value = defaultValue;
control->set_by_keyboard = false;
control->text->SetValue(std::to_string(defaultValue));
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
}
2014-09-15 03:42:32 +00:00
void TASInputDlg::SetButtonValue(Button* button, bool CurrentState)
{
if (CurrentState)
2012-01-22 00:39:17 +00:00
{
button->set_by_keyboard = true;
button->checkbox->SetValue(CurrentState);
2012-01-22 00:39:17 +00:00
}
else if (button->set_by_keyboard)
2012-01-22 00:39:17 +00:00
{
button->set_by_keyboard = false;
button->checkbox->SetValue(CurrentState);
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
}
2012-01-22 00:39:17 +00:00
void TASInputDlg::SetWiiButtons(u16* butt)
2014-09-15 03:42:32 +00:00
{
for (unsigned int i = 0; i < 14; ++i)
2012-01-22 00:39:17 +00:00
{
if (m_buttons[i] != nullptr)
*butt |= (m_buttons[i]->checkbox->IsChecked()) ? m_wii_buttons_bitmask[i] : 0;
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
ButtonTurbo();
}
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
void TASInputDlg::GetKeyBoardInput(GCPadStatus* PadStatus)
{
SetStickValue(&m_main_stick.x_cont.set_by_keyboard, &m_main_stick.x_cont.value, m_main_stick.x_cont.text, PadStatus->stickX);
SetStickValue(&m_main_stick.y_cont.set_by_keyboard, &m_main_stick.y_cont.value, m_main_stick.y_cont.text, PadStatus->stickY);
2012-01-22 00:39:17 +00:00
SetStickValue(&m_c_stick.x_cont.set_by_keyboard, &m_c_stick.x_cont.value, m_c_stick.x_cont.text, PadStatus->substickX);
SetStickValue(&m_c_stick.y_cont.set_by_keyboard, &m_c_stick.y_cont.value, m_c_stick.y_cont.text, PadStatus->substickY);
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 14; ++i)
2012-01-22 00:39:17 +00:00
{
if (m_buttons[i] != nullptr)
SetButtonValue(m_buttons[i], ((PadStatus->button & m_gc_pad_buttons_bitmask[i]) != 0));
2012-01-22 00:39:17 +00:00
}
SetButtonValue(&m_l, ((PadStatus->triggerLeft) != 0) || ((PadStatus->button & PAD_TRIGGER_L) != 0));
SetButtonValue(&m_r, ((PadStatus->triggerRight) != 0) || ((PadStatus->button & PAD_TRIGGER_R) != 0));
2014-09-15 03:42:32 +00:00
}
void TASInputDlg::GetKeyBoardInput(u8* data, WiimoteEmu::ReportFeatures rptf)
{
u8* const coreData = rptf.core ? (data + rptf.core) : nullptr;
u8* const accelData = rptf.accel ? (data + rptf.accel) : nullptr;
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
if (coreData)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 14; ++i)
{
if (m_buttons[i] != nullptr)
SetButtonValue(m_buttons[i], (((wm_buttons*)coreData)->hex & m_wii_buttons_bitmask[i]) != 0);
}
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
if (accelData)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
wm_accel* dt = (wm_accel*)accelData;
SetSliderValue(&m_x_cont, dt->x);
SetSliderValue(&m_y_cont, dt->y);
SetSliderValue(&m_z_cont, dt->z, 154);
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
// 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);
2014-09-15 03:42:32 +00:00
// SetStickValue(&MainStick.xCont.SetByKeyboard, &MainStick.xCont.value, MainStick.xCont.Text, x, 561);
// SetStickValue(&MainStick.yCont.SetByKeyboard, &MainStick.yCont.value, MainStick.yCont.Text, y, 486);
//}
}
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
void TASInputDlg::GetValues(u8* data, WiimoteEmu::ReportFeatures rptf)
{
if (!IsShown() || !m_is_wii)
2014-09-15 03:42:32 +00:00
return;
GetKeyBoardInput(data, rptf);
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;
if (coreData)
SetWiiButtons(&((wm_buttons*)coreData)->hex);
2014-09-15 03:42:32 +00:00
if (accelData)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
wm_accel* dt = (wm_accel*)accelData;
dt->x = m_x_cont.value;
dt->y = m_y_cont.value;
dt->z = m_z_cont.value;
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
if (irData)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
u16 x[4];
u16 y;
2012-01-22 00:39:17 +00:00
x[0] = m_main_stick.x_cont.value;
y = m_main_stick.y_cont.value;
2014-09-15 03:42:32 +00:00
x[1] = x[0] + 100;
x[2] = x[0] - 10;
x[3] = x[1] + 10;
2014-09-15 03:42:32 +00:00
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* irBasic = (wm_ir_basic*)irData;
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 2; ++i)
{
if (x[i*2] < 1024 && y < 768)
{
irBasic[i].x1 = static_cast<u8>(x[i*2]);
irBasic[i].x1hi = x[i*2] >> 8;
2014-09-15 03:42:32 +00:00
irBasic[i].y1 = static_cast<u8>(y);
irBasic[i].y1hi = y >> 8;
2014-09-15 03:42:32 +00:00
}
if (x[i*2+1] < 1024 && y < 768)
{
irBasic[i].x2 = static_cast<u8>(x[i*2+1]);
irBasic[i].x2hi = x[i*2+1] >> 8;
2014-09-15 03:42:32 +00:00
irBasic[i].y2 = static_cast<u8>(y);
irBasic[i].y2hi = y >> 8;
2014-09-15 03:42:32 +00:00
}
}
}
else
{
memset(data, 0xFF, sizeof(wm_ir_extended) * 4);
wm_ir_extended* const irExtended = (wm_ir_extended*)irData;
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 4; ++i)
{
if (x[i] < 1024 && y < 768)
{
irExtended[i].x = static_cast<u8>(x[i]);
irExtended[i].xhi = x[i] >> 8;
2014-09-15 03:42:32 +00:00
irExtended[i].y = static_cast<u8>(y);
irExtended[i].yhi = y >> 8;
2014-09-15 03:42:32 +00:00
irExtended[i].size = 10;
2014-09-15 03:42:32 +00:00
}
}
}
}
}
2014-09-15 03:42:32 +00:00
void TASInputDlg::GetValues(GCPadStatus* PadStatus)
{
if (!IsShown() || m_is_wii)
2014-09-15 03:42:32 +00:00
return;
//TODO:: Make this instant not when polled.
2012-01-22 00:39:17 +00:00
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.checkbox->GetValue() ? 255 : m_l_cont.slider->GetValue();
PadStatus->triggerRight = m_r.checkbox->GetValue() ? 255 : m_r_cont.slider->GetValue();
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 14; ++i)
{
if (m_buttons[i] != nullptr)
2014-09-15 03:42:32 +00:00
{
if (m_buttons[i]->checkbox->IsChecked())
PadStatus->button |= m_gc_pad_buttons_bitmask[i];
2014-09-15 03:42:32 +00:00
else
PadStatus->button &= ~m_gc_pad_buttons_bitmask[i];
2014-09-15 03:42:32 +00:00
}
}
2014-09-15 03:42:32 +00:00
if (m_a.checkbox->IsChecked())
2014-09-15 03:42:32 +00:00
PadStatus->analogA = 0xFF;
else
PadStatus->analogA = 0x00;
if (m_b.checkbox->IsChecked())
PadStatus->analogB = 0xFF;
else
PadStatus->analogB = 0x00;
2012-01-22 00:39:17 +00:00
ButtonTurbo();
}
void TASInputDlg::UpdateFromSliders(wxCommandEvent& event)
{
wxTextCtrl* text = nullptr;
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 10; ++i)
{
if (m_controls[i] != nullptr && event.GetId() == m_controls[i]->slider_id)
text = m_controls[i]->text;
}
int value = ((wxSlider*) event.GetEventObject())->GetValue();
if (text)
text->SetValue(std::to_string(value));
}
void TASInputDlg::UpdateFromText(wxCommandEvent& event)
{
2014-09-15 03:42:32 +00:00
int v;
unsigned long value;
2014-09-15 03:42:32 +00:00
if (!((wxTextCtrl*) event.GetEventObject())->GetValue().ToULong(&value))
return;
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 10; ++i)
{
if (m_controls[i] != nullptr && event.GetId() == m_controls[i]->text_id)
2012-01-22 00:39:17 +00:00
{
v = value > m_controls[i]->range ? m_controls[i]->range : value;
m_controls[i]->slider->SetValue(v);
m_controls[i]->value = v;
2012-01-22 00:39:17 +00:00
}
2012-03-02 00:00:41 +00:00
}
if (!m_is_wii)
m_c_stick.bitmap->SetBitmap(CreateStickBitmap(m_c_stick.x_cont.value, 255 - m_c_stick.y_cont.value));
2014-09-15 03:42:32 +00:00
int x = (u8)((double)m_main_stick.x_cont.value / (double)m_main_stick.x_cont.range * 255.0);
int y = (u8)((double)m_main_stick.y_cont.value / (double)m_main_stick.y_cont.range * 255.0);
if (!m_is_wii)
2014-09-15 03:42:32 +00:00
y = 255 - (u8)y;
else
x = 255 - (u8)x;
m_main_stick.bitmap->SetBitmap(CreateStickBitmap(x, y));
}
void TASInputDlg::OnCloseWindow(wxCloseEvent& event)
{
if (event.CanVeto())
{
event.Skip(false);
this->Show(false);
ResetValues();
}
}
bool TASInputDlg::TASHasFocus()
{
if (!m_has_layout)
2014-10-08 13:46:28 +00:00
return false;
2012-01-22 00:39:17 +00:00
//allows numbers to be used as hotkeys
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 10; ++i)
{
if (m_controls[i] != nullptr && wxWindow::FindFocus() == m_controls[i]->text)
2014-09-15 03:42:32 +00:00
return false;
}
2012-01-22 00:39:17 +00:00
if (wxWindow::FindFocus() == this)
return true;
2014-09-15 03:42:32 +00:00
else if (wxWindow::FindFocus() != nullptr && wxWindow::FindFocus()->GetParent() == this)
return true;
else
return false;
}
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
void TASInputDlg::OnMouseUpR(wxMouseEvent& event)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
Stick* stick = nullptr;
if (event.GetId() == ID_MAIN_STICK)
stick = &m_main_stick;
2014-09-15 03:42:32 +00:00
else if (event.GetId() == ID_C_STICK)
stick = &m_c_stick;
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
if (stick == nullptr)
return;
2012-01-22 00:39:17 +00:00
u32 xCenter = stick->x_cont.range / 2 + (stick->x_cont.range % 2 == 0 ? 0 : 1);
u32 yCenter = stick->y_cont.range / 2 + (stick->y_cont.range % 2 == 0 ? 0 : 1);
2012-01-22 00:39:17 +00:00
stick->x_cont.value = xCenter;
stick->y_cont.value = yCenter;
2014-09-15 03:42:32 +00:00
stick->bitmap->SetBitmap(CreateStickBitmap(128,128));
stick->x_cont.text->SetValue(std::to_string(xCenter));
stick->y_cont.text->SetValue(std::to_string(yCenter));
stick->x_cont.slider->SetValue(xCenter);
stick->y_cont.slider->SetValue(yCenter);
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
event.Skip(true);
2012-01-22 00:39:17 +00:00
}
2014-09-15 03:42:32 +00:00
void TASInputDlg::OnRightClickSlider(wxMouseEvent& event)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 10; ++i)
2012-01-22 00:39:17 +00:00
{
if (m_controls[i] != nullptr && event.GetId() == m_controls[i]->slider_id)
2014-09-15 03:42:32 +00:00
{
m_controls[i]->value = m_controls[i]->default_value;
m_controls[i]->slider->SetValue(m_controls[i]->default_value);
m_controls[i]->text->SetValue(std::to_string(m_controls[i]->default_value));
2014-09-15 03:42:32 +00:00
}
2012-01-22 00:39:17 +00:00
}
}
void TASInputDlg::OnMouseDownL(wxMouseEvent& event)
2012-01-22 00:39:17 +00:00
{
2014-09-15 03:42:32 +00:00
if (!event.LeftIsDown())
return;
2014-09-15 03:42:32 +00:00
Stick* stick;
if (event.GetId() == ID_MAIN_STICK)
stick = &m_main_stick;
2014-09-15 03:42:32 +00:00
else if (event.GetId() == ID_C_STICK)
stick = &m_c_stick;
2014-09-15 03:42:32 +00:00
else
return;
2012-01-22 00:39:17 +00:00
wxPoint ptM(event.GetPosition());
stick->x_cont.value = ptM.x * stick->x_cont.range / 127;
stick->y_cont.value = ptM.y * stick->y_cont.range / 127;
2012-01-22 00:39:17 +00:00
if ((unsigned int)stick->y_cont.value > stick->y_cont.range)
stick->y_cont.value = stick->y_cont.range;
if ((unsigned int)stick->x_cont.value > stick->x_cont.range)
stick->x_cont.value = stick->x_cont.range;
2012-01-22 00:39:17 +00:00
if (!m_is_wii)
stick->y_cont.value = 255 - (u8)stick->y_cont.value;
2014-09-15 03:42:32 +00:00
else
stick->x_cont.value = stick->x_cont.range - (u16)stick->x_cont.value;
2012-01-22 00:39:17 +00:00
stick->x_cont.value = (unsigned int)stick->x_cont.value > stick->x_cont.range ? stick->x_cont.range : stick->x_cont.value;
stick->y_cont.value = (unsigned int)stick->y_cont.value > stick->y_cont.range ? stick->y_cont.range : stick->y_cont.value;
stick->x_cont.value = stick->x_cont.value < 0 ? 0 : stick->x_cont.value;
stick->y_cont.value = stick->y_cont.value < 0 ? 0 : stick->y_cont.value;
2012-01-22 00:39:17 +00:00
2014-09-15 03:42:32 +00:00
stick->bitmap->SetBitmap(CreateStickBitmap(ptM.x*2, ptM.y*2));
2012-01-22 00:39:17 +00:00
stick->x_cont.text->SetValue(std::to_string(stick->x_cont.value));
stick->y_cont.text->SetValue(std::to_string(stick->y_cont.value));
stick->x_cont.slider->SetValue(stick->x_cont.value);
stick->y_cont.slider->SetValue(stick->y_cont.value);
2014-09-15 03:42:32 +00:00
event.Skip(true);
2012-01-22 00:39:17 +00:00
}
void TASInputDlg::SetTurbo(wxMouseEvent& event)
{
Button* button = nullptr;
2014-09-15 03:42:32 +00:00
for (unsigned int i = 0; i < 14; ++i)
{
if (m_buttons[i] != nullptr && event.GetId() == m_buttons[i]->id)
button = m_buttons[i];
2014-09-15 03:42:32 +00:00
}
2014-09-15 03:42:32 +00:00
if (event.LeftDown())
2012-01-22 00:39:17 +00:00
{
if (button)
button->turbo_on = false;
2014-09-15 03:42:32 +00:00
event.Skip(true);
return;
2012-01-22 00:39:17 +00:00
}
if (button)
{
button->checkbox->SetValue(true);
button->turbo_on = !button->turbo_on;
}
2014-09-15 03:42:32 +00:00
event.Skip(true);
2012-01-22 00:39:17 +00:00
}
void TASInputDlg::ButtonTurbo()
{
static u64 frame = Movie::g_currentFrame;
if (frame != Movie::g_currentFrame)
2012-01-22 00:39:17 +00:00
{
frame = Movie::g_currentFrame;
for (unsigned int i = 0; i < 14; ++i)
{
if (m_buttons[i] != nullptr && m_buttons[i]->turbo_on)
m_buttons[i]->checkbox->SetValue(!m_buttons[i]->checkbox->GetValue());
}
2012-01-22 00:39:17 +00:00
}
}
wxBitmap TASInputDlg::CreateStickBitmap(int x, int y)
{
2014-09-15 03:42:32 +00:00
x = x / 2;
y = y / 2;
2012-01-22 00:39:17 +00:00
wxMemoryDC memDC;
2014-09-15 03:42:32 +00:00
wxBitmap bitmap(129, 129);
memDC.SelectObject(bitmap);
memDC.SetBackground(*wxLIGHT_GREY_BRUSH);
memDC.Clear();
memDC.SetBrush(*wxWHITE_BRUSH);
2014-09-15 03:42:32 +00:00
memDC.DrawCircle(65, 65, 64);
2012-01-22 00:39:17 +00:00
memDC.SetBrush(*wxRED_BRUSH);
2014-09-15 03:42:32 +00:00
memDC.DrawLine(64, 64, x, y);
memDC.DrawLine(63, 64, x - 1, y);
memDC.DrawLine(65, 64, x + 1 , y);
memDC.DrawLine(64, 63, x, y - 1);
memDC.DrawLine(64, 65, x, y + 1);
2012-01-22 00:39:17 +00:00
memDC.SetPen(*wxBLACK_PEN);
2014-09-15 03:42:32 +00:00
memDC.CrossHair(64, 64);
2012-01-22 00:39:17 +00:00
memDC.SetBrush(*wxBLUE_BRUSH);
2014-09-15 03:42:32 +00:00
memDC.DrawCircle(x, y, 5);
memDC.SelectObject(wxNullBitmap);
2014-09-15 03:42:32 +00:00
return bitmap;
}