recording: Linting pass on files involved in this change

This commit is contained in:
Tyler Wilding 2020-04-29 00:09:36 -04:00 committed by refractionpcsx2
parent c89e9134f6
commit bbc305d2b9
9 changed files with 199 additions and 218 deletions

View File

@ -131,7 +131,7 @@ void InputRecording::ControllerInterrupt(u8 &data, u8 &port, u16 &bufCount, u8 b
bufVal = tmp;
// Update controller data state for future VirtualPad / logging usage.
padData[port]->UpdateControllerData(bufIndex, bufVal);
if (virtualPads[port] != NULL && virtualPads[port]->IsShown())
if (virtualPads[port] && virtualPads[port]->IsShown())
{
virtualPads[port]->UpdateControllerData(bufIndex, padData[port]);
}
@ -143,7 +143,7 @@ void InputRecording::ControllerInterrupt(u8 &data, u8 &port, u16 &bufCount, u8 b
// Update controller data state for future VirtualPad / logging usage.
padData[port]->UpdateControllerData(bufIndex, bufVal);
if (virtualPads[port] != NULL && virtualPads[port]->IsShown())
if (virtualPads[port] && virtualPads[port]->IsShown())
{
// If the VirtualPad updated the PadData, we have to update the buffer
// before committing it to the recording / sending it to the game
@ -154,9 +154,9 @@ void InputRecording::ControllerInterrupt(u8 &data, u8 &port, u16 &bufCount, u8 b
}
// If we have reached the end of the pad data, log it out
if (bufIndex == 17) { // TODO constant for end
padData[port]->LogPadData();
if (virtualPads[port] != NULL && virtualPads[port]->IsShown())
if (bufIndex == PadData::END_INDEX_CONTROLLER_BUFFER) {
padData[port]->LogPadData(port);
if (virtualPads[port] && virtualPads[port]->IsShown())
{
virtualPads[port]->Redraw();
}

View File

@ -108,7 +108,7 @@ private:
// Controller Data
PadData *padData[2];
// VirtualPad
// VirtualPads
VirtualPad *virtualPads[2];
// Resolve the name and region of the game currently loaded using the GameDB

View File

@ -165,7 +165,7 @@ u8 PadData::PollControllerData(u16 bufIndex)
bool PadData::IsButtonPressed(ButtonResolver buttonResolver, u8 const &bufVal)
{
// Rather than the flags being SET if the button is pressed, it is the opposite
// For example: 0111 1111 with left being the first bit indicates left is pressed.
// For example: 0111 1111 with `left` being the first bit indicates `left` is pressed.
// So, we are forced to flip the pressed bits with a NOT first
return (~bufVal & buttonResolver.buttonBitmask) > 0;
}
@ -187,11 +187,15 @@ wxString PadData::RawPadBytesToString(int start, int end)
return str;
}
void PadData::LogPadData() {
void PadData::LogPadData(u8 const &port) {
wxString pressedBytes = RawPadBytesToString(0, 2);
wxString rightAnalogBytes = RawPadBytesToString(2, 4);
wxString leftAnalogBytes = RawPadBytesToString(4, 6);
wxString pressureBytes = RawPadBytesToString(6, 17);
controlLog(wxString::Format("[PAD] Raw Bytes: Pressed = [%s], Right Analog = [%s], Left Analog = [%s]\n", pressedBytes, rightAnalogBytes, leftAnalogBytes));
controlLog(wxString::Format("[PAD] Raw Bytes: Pressure = [%s]\n", pressureBytes));
wxString fullLog =
wxString::Format("[PAD %d] Raw Bytes: Pressed = [%s]\n", port + 1, pressedBytes) +
wxString::Format("[PAD %d] Raw Bytes: Right Analog = [%s]\n", port + 1, rightAnalogBytes) +
wxString::Format("[PAD %d] Raw Bytes: Left Analog = [%s]\n", port + 1, leftAnalogBytes) +
wxString::Format("[PAD %d] Raw Bytes: Pressure = [%s]\n", port + 1, pressureBytes);
controlLog(fullLog);
}

View File

@ -19,10 +19,8 @@ class PadData
{
public:
/// Constants
const u8 PRESSURE_BUTTON_UNPRESSED = 0;
const bool BUTTON_PRESSED = true;
const bool BUTTON_UNPRESSED = false;
const u8 ANALOG_VECTOR_CENTER_POS = 127;
static const u8 ANALOG_VECTOR_NEUTRAL = 127;
static const u16 END_INDEX_CONTROLLER_BUFFER = 17;
enum class BufferIndex
{
@ -47,54 +45,53 @@ public:
};
/// Pressure Buttons - 0-255
u8 circlePressure = PRESSURE_BUTTON_UNPRESSED;
u8 crossPressure = PRESSURE_BUTTON_UNPRESSED;
u8 squarePressure = PRESSURE_BUTTON_UNPRESSED;
u8 trianglePressure = PRESSURE_BUTTON_UNPRESSED;
u8 downPressure = PRESSURE_BUTTON_UNPRESSED;
u8 leftPressure = PRESSURE_BUTTON_UNPRESSED;
u8 rightPressure = PRESSURE_BUTTON_UNPRESSED;
u8 upPressure = PRESSURE_BUTTON_UNPRESSED;
u8 l1Pressure = PRESSURE_BUTTON_UNPRESSED;
u8 l2Pressure = PRESSURE_BUTTON_UNPRESSED;
u8 r1Pressure = PRESSURE_BUTTON_UNPRESSED;
u8 r2Pressure = PRESSURE_BUTTON_UNPRESSED;
u8 circlePressure = 0;
u8 crossPressure = 0;
u8 squarePressure = 0;
u8 trianglePressure = 0;
u8 downPressure = 0;
u8 leftPressure = 0;
u8 rightPressure = 0;
u8 upPressure = 0;
u8 l1Pressure = 0;
u8 l2Pressure = 0;
u8 r1Pressure = 0;
u8 r2Pressure = 0;
/// Pressure Button Flags
/// NOTE - It shouldn't be possible to depress a button
/// while also having no pressure (PAD plugin should default to max pressure).
/// NOTE - It shouldn't be possible to depress a button while also having no pressure
/// But for the sake of completeness, it should be tracked.
bool circlePressed = BUTTON_UNPRESSED;
bool crossPressed = BUTTON_UNPRESSED;
bool squarePressed = BUTTON_UNPRESSED;
bool trianglePressed = BUTTON_UNPRESSED;
bool downPressed = BUTTON_UNPRESSED;
bool leftPressed = BUTTON_UNPRESSED;
bool rightPressed = BUTTON_UNPRESSED;
bool upPressed = BUTTON_UNPRESSED;
bool l1Pressed = BUTTON_UNPRESSED;
bool l2Pressed = BUTTON_UNPRESSED;
bool r1Pressed = BUTTON_UNPRESSED;
bool r2Pressed = BUTTON_UNPRESSED;
bool circlePressed = false;
bool crossPressed = false;
bool squarePressed = false;
bool trianglePressed = false;
bool downPressed = false;
bool leftPressed = false;
bool rightPressed = false;
bool upPressed = false;
bool l1Pressed = false;
bool l2Pressed = false;
bool r1Pressed = false;
bool r2Pressed = false;
/// Normal (un)pressed buttons
bool select = BUTTON_UNPRESSED;
bool start = BUTTON_UNPRESSED;
bool l3 = BUTTON_UNPRESSED;
bool r3 = BUTTON_UNPRESSED;
bool select = false;
bool start = false;
bool l3 = false;
bool r3 = false;
/// Analog Sticks - 0-255 (127 center)
u8 leftAnalogX = ANALOG_VECTOR_CENTER_POS;
u8 leftAnalogY = ANALOG_VECTOR_CENTER_POS;
u8 rightAnalogX = ANALOG_VECTOR_CENTER_POS;
u8 rightAnalogY = ANALOG_VECTOR_CENTER_POS;
u8 leftAnalogX = ANALOG_VECTOR_NEUTRAL;
u8 leftAnalogY = ANALOG_VECTOR_NEUTRAL;
u8 rightAnalogX = ANALOG_VECTOR_NEUTRAL;
u8 rightAnalogY = ANALOG_VECTOR_NEUTRAL;
// Given the input buffer and the current index, updates the correct field(s)
void UpdateControllerData(u16 bufIndex, u8 const &bufVal);
u8 PollControllerData(u16 bufIndex);
// Prints current PadData to the Controller Log filter which disabled by default
void LogPadData();
void LogPadData(u8 const &port);
private:
struct ButtonResolver

View File

@ -19,8 +19,8 @@
#include "App.h"
#include "Utilities/EmbeddedImage.h"
#include "wx/display.h"
#include "wx/dcbuffer.h"
#include "wx/display.h"
#include "wx/spinctrl.h"
#include "Recording/VirtualPad/VirtualPad.h"
@ -44,7 +44,7 @@
#include "Recording/VirtualPad/img/trianglePressed.h"
#include "Recording/VirtualPad/img/upPressed.h"
// TODO - store position of frame in ini file?
// TODO - Store position of frame in an (possibly the main) .ini file
VirtualPad::VirtualPad(wxWindow* parent, wxWindowID id, const wxString& title, int controllerPort, const wxPoint& pos, const wxSize& size, long style) :
wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
@ -56,7 +56,7 @@ VirtualPad::VirtualPad(wxWindow* parent, wxWindowID id, const wxString& title, i
// Slight multi-monitor support, will use whatever window pcsx2 is opened with, but won't currently re-init if
// windows are dragged between differing monitors!
wxDisplay display(wxDisplay::GetFromWindow(this));
wxRect screen = display.GetClientArea();
const wxRect screen = display.GetClientArea();
if (screen.height > 1080 && screen.height <= 1440) // 1440p display
{
scalingFactor = 0.75;
@ -71,29 +71,28 @@ VirtualPad::VirtualPad(wxWindow* parent, wxWindowID id, const wxString& title, i
// Use the background image's size to define the window size
SetClientSize(virtualPadData.background.width, virtualPadData.background.height);
// TODO - rename to Gui
InitPressureButtonGUIElements(virtualPadData.cross, NewBitmap(EmbeddedImage<res_crossPressed>().Get(), wxPoint(968, 498)), this, wxPoint(1062, 660));
InitPressureButtonGUIElements(virtualPadData.circle, NewBitmap(EmbeddedImage<res_circlePressed>().Get(), wxPoint(1057, 413)), this, wxPoint(1062, 700));
InitPressureButtonGUIElements(virtualPadData.triangle, NewBitmap(EmbeddedImage<res_trianglePressed>().Get(), wxPoint(968, 325)), this, wxPoint(1062, 740));
InitPressureButtonGUIElements(virtualPadData.square, NewBitmap(EmbeddedImage<res_squarePressed>().Get(), wxPoint(879, 413)), this, wxPoint(1062, 780));
InitPressureButtonGUIElements(virtualPadData.down, NewBitmap(EmbeddedImage<res_downPressed>().Get(), wxPoint(191, 488)), this, wxPoint(199, 660), true);
InitPressureButtonGUIElements(virtualPadData.right, NewBitmap(EmbeddedImage<res_rightPressed>().Get(), wxPoint(255, 429)), this, wxPoint(199, 700), true);
InitPressureButtonGUIElements(virtualPadData.up, NewBitmap(EmbeddedImage<res_upPressed>().Get(), wxPoint(191, 354)), this, wxPoint(199, 740), true);
InitPressureButtonGUIElements(virtualPadData.left, NewBitmap(EmbeddedImage<res_leftPressed>().Get(), wxPoint(115, 429)), this, wxPoint(199, 780), true);
InitPressureButtonGUIElements(virtualPadData.l1, NewBitmap(EmbeddedImage<res_l1Pressed>().Get(), wxPoint(166, 8)), this, wxPoint(294, 20));
InitPressureButtonGUIElements(virtualPadData.l2, NewBitmap(EmbeddedImage<res_l2Pressed>().Get(), wxPoint(166, 81)), this, wxPoint(294, 100));
InitPressureButtonGUIElements(virtualPadData.r1, NewBitmap(EmbeddedImage<res_r1Pressed>().Get(), wxPoint(958, 7)), this, wxPoint(940, 20), true);
InitPressureButtonGUIElements(virtualPadData.r2, NewBitmap(EmbeddedImage<res_r2Pressed>().Get(), wxPoint(958, 81)), this, wxPoint(940, 100), true);
InitPressureButtonGuiElements(virtualPadData.cross, NewBitmap(EmbeddedImage<res_crossPressed>().Get(), wxPoint(968, 498)), this, wxPoint(1062, 660));
InitPressureButtonGuiElements(virtualPadData.circle, NewBitmap(EmbeddedImage<res_circlePressed>().Get(), wxPoint(1057, 413)), this, wxPoint(1062, 700));
InitPressureButtonGuiElements(virtualPadData.triangle, NewBitmap(EmbeddedImage<res_trianglePressed>().Get(), wxPoint(968, 325)), this, wxPoint(1062, 740));
InitPressureButtonGuiElements(virtualPadData.square, NewBitmap(EmbeddedImage<res_squarePressed>().Get(), wxPoint(879, 413)), this, wxPoint(1062, 780));
InitPressureButtonGuiElements(virtualPadData.down, NewBitmap(EmbeddedImage<res_downPressed>().Get(), wxPoint(191, 488)), this, wxPoint(199, 660), true);
InitPressureButtonGuiElements(virtualPadData.right, NewBitmap(EmbeddedImage<res_rightPressed>().Get(), wxPoint(255, 429)), this, wxPoint(199, 700), true);
InitPressureButtonGuiElements(virtualPadData.up, NewBitmap(EmbeddedImage<res_upPressed>().Get(), wxPoint(191, 354)), this, wxPoint(199, 740), true);
InitPressureButtonGuiElements(virtualPadData.left, NewBitmap(EmbeddedImage<res_leftPressed>().Get(), wxPoint(115, 429)), this, wxPoint(199, 780), true);
InitPressureButtonGuiElements(virtualPadData.l1, NewBitmap(EmbeddedImage<res_l1Pressed>().Get(), wxPoint(166, 8)), this, wxPoint(294, 20));
InitPressureButtonGuiElements(virtualPadData.l2, NewBitmap(EmbeddedImage<res_l2Pressed>().Get(), wxPoint(166, 81)), this, wxPoint(294, 100));
InitPressureButtonGuiElements(virtualPadData.r1, NewBitmap(EmbeddedImage<res_r1Pressed>().Get(), wxPoint(958, 7)), this, wxPoint(940, 20), true);
InitPressureButtonGuiElements(virtualPadData.r2, NewBitmap(EmbeddedImage<res_r2Pressed>().Get(), wxPoint(958, 81)), this, wxPoint(940, 100), true);
InitNormalButtonGUIElements(virtualPadData.select, NewBitmap(EmbeddedImage<res_selectPressed>().Get(), wxPoint(473, 441)), this, wxPoint(545, 448));
InitNormalButtonGUIElements(virtualPadData.start, NewBitmap(EmbeddedImage<res_startPressed>().Get(), wxPoint(710, 440)), this, wxPoint(675, 448));
InitNormalButtonGUIElements(virtualPadData.l3, NewBitmap(EmbeddedImage<res_r3Pressed>().Get(), wxPoint(347, 585)), this, wxPoint(440, 835));
InitNormalButtonGUIElements(virtualPadData.r3, NewBitmap(EmbeddedImage<res_l3Pressed>().Get(), wxPoint(750, 585)), this, wxPoint(844, 835));
InitNormalButtonGuiElements(virtualPadData.select, NewBitmap(EmbeddedImage<res_selectPressed>().Get(), wxPoint(473, 441)), this, wxPoint(545, 448));
InitNormalButtonGuiElements(virtualPadData.start, NewBitmap(EmbeddedImage<res_startPressed>().Get(), wxPoint(710, 440)), this, wxPoint(675, 448));
InitNormalButtonGuiElements(virtualPadData.l3, NewBitmap(EmbeddedImage<res_r3Pressed>().Get(), wxPoint(347, 585)), this, wxPoint(440, 835));
InitNormalButtonGuiElements(virtualPadData.r3, NewBitmap(EmbeddedImage<res_l3Pressed>().Get(), wxPoint(750, 585)), this, wxPoint(844, 835));
InitAnalogStickGuiElements(virtualPadData.leftAnalog, this, wxPoint(418, 656), 105, wxPoint(326, 782), wxPoint(545, 568), false, wxPoint(522, 800), wxPoint(522, 760));
InitAnalogStickGuiElements(virtualPadData.rightAnalog, this, wxPoint(821, 656), 105, wxPoint(730, 782), wxPoint(672, 568), true, wxPoint(720, 800), wxPoint(720, 760), true);
ignoreRealControllerBox = new wxCheckBox(this, wxID_ANY, wxEmptyString, NewScaledPoint(605, 256), wxDefaultSize);
ignoreRealControllerBox = new wxCheckBox(this, wxID_ANY, wxEmptyString, ScaledPoint(605, 256), wxDefaultSize);
Bind(wxEVT_CHECKBOX, &VirtualPad::OnIgnoreRealController, this, ignoreRealControllerBox->GetId());
// Bind Window Events
@ -117,14 +116,12 @@ VirtualPad::VirtualPad(wxWindow* parent, wxWindowID id, const wxString& title, i
SetDoubleBuffered(true);
}
// TODO - test open/close routine
void VirtualPad::OnClose(wxCloseEvent & event)
{
// Re-bind the Paint event in case this is due to a game being opened/closed
manualRedrawMode = false;
Bind(wxEVT_PAINT, &VirtualPad::OnPaint, this);
Hide(); // TODO - hide vs closed?
Hide();
}
void VirtualPad::OnMouseEvent(wxMouseEvent &evt)
@ -209,7 +206,10 @@ void VirtualPad::Render(wxDC &dc)
// After some tests, the performance impact is well within reason, and on the hardware renderer modes, is almost non-existant.
while (!renderQueue.empty()) {
VirtualPadElement *element = renderQueue.front();
if (element)
{
element->Render(bdc);
}
renderQueue.pop();
}
}
@ -220,34 +220,42 @@ bool VirtualPad::UpdateControllerData(u16 const bufIndex, PadData *padData, bool
return virtualPadData.UpdateVirtualPadData(bufIndex, padData, ignoreRealController && !readOnly, readOnly);
}
void VirtualPad::OnIgnoreRealController(wxCommandEvent &event)
void VirtualPad::OnIgnoreRealController(wxCommandEvent const &event)
{
const wxCheckBox* ignoreButton = (wxCheckBox*) event.GetEventObject();
if (ignoreButton)
{
wxCheckBox* ignoreButton = (wxCheckBox*) event.GetEventObject();
ignoreRealController = ignoreButton->GetValue();
}
}
void VirtualPad::OnNormalButtonPress(wxCommandEvent &event)
{
wxCheckBox* pressedButton = (wxCheckBox*) event.GetEventObject();
const wxCheckBox* pressedButton = (wxCheckBox*) event.GetEventObject();
ControllerNormalButton *eventBtn = buttonElements[pressedButton->GetId()];
if (pressedButton)
{
eventBtn->pressed = pressedButton->GetValue();
}
// If the real controller is being bypassed, we move on, otherwise we begin bypassing the controller
if (!eventBtn->isControllerBypassed) {
eventBtn->isControllerBypassed = true;
if (!eventBtn->isControllerPressBypassed) {
eventBtn->isControllerPressBypassed = true;
}
}
void VirtualPad::OnPressureButtonPressureChange(wxCommandEvent &event)
{
wxSpinCtrl* pressureSpinner = (wxSpinCtrl*) event.GetEventObject();
const wxSpinCtrl* pressureSpinner = (wxSpinCtrl*) event.GetEventObject();
ControllerPressureButton *eventBtn = pressureElements[pressureSpinner->GetId()];
if (pressureSpinner)
{
eventBtn->pressure = pressureSpinner->GetValue();
}
eventBtn->pressed = eventBtn->pressure > 0;
// If the real controller is being bypassed, we move on, otherwise we begin bypassing the controller
if (!eventBtn->isControllerPressureBypassed || !eventBtn->isControllerPressBypassed) {
eventBtn->isControllerPressureBypassed = true;
eventBtn->isControllerPressBypassed = true;
@ -256,13 +264,15 @@ void VirtualPad::OnPressureButtonPressureChange(wxCommandEvent &event)
void VirtualPad::OnAnalogSpinnerChange(wxCommandEvent &event)
{
wxSpinCtrl* analogSpinner = (wxSpinCtrl*) event.GetEventObject();
const wxSpinCtrl* analogSpinner = (wxSpinCtrl*) event.GetEventObject();
AnalogVector *eventVector = analogElements[analogSpinner->GetId()];
if (analogSpinner)
{
eventVector->val = analogSpinner->GetValue();
}
eventVector->slider->SetValue(eventVector->val);
// If the real controller is being bypassed, we move on, otherwise we begin bypassing the controller
if (!eventVector->isControllerBypassed) {
eventVector->isControllerBypassed = true;
}
@ -270,13 +280,15 @@ void VirtualPad::OnAnalogSpinnerChange(wxCommandEvent &event)
void VirtualPad::OnAnalogSliderChange(wxCommandEvent &event)
{
wxSlider* analogSlider = (wxSlider*) event.GetEventObject();
const wxSlider* analogSlider = (wxSlider*) event.GetEventObject();
AnalogVector *eventVector = analogElements[analogSlider->GetId()];
if (analogSlider)
{
eventVector->val = analogSlider->GetValue();
}
eventVector->spinner->SetValue(eventVector->val);
// If the real controller is being bypassed, we move on, otherwise we begin bypassing the controller
if (!eventVector->isControllerBypassed) {
eventVector->isControllerBypassed = true;
}
@ -284,14 +296,27 @@ void VirtualPad::OnAnalogSliderChange(wxCommandEvent &event)
/// GUI Element Utility Functions
wxPoint VirtualPad::NewScaledPoint(wxPoint point)
wxPoint VirtualPad::ScaledPoint(wxPoint point, int widgetWidth, bool rightAligned)
{
return wxPoint(point.x * scalingFactor, point.y * scalingFactor);
return ScaledPoint(point.x, point.y, widgetWidth, rightAligned);
}
wxPoint VirtualPad::NewScaledPoint(int x, int y)
wxPoint VirtualPad::ScaledPoint(int x, int y, int widgetWidth, bool rightAligned)
{
return wxPoint(x * scalingFactor, y * scalingFactor);
wxPoint scaledPoint = wxPoint(x * scalingFactor, y * scalingFactor);
if (rightAligned) {
scaledPoint.x -= widgetWidth * scalingFactor;
if (scaledPoint.x < 0)
{
scaledPoint.x = 0;
}
}
return scaledPoint;
}
wxSize VirtualPad::ScaledSize(int x, int y)
{
return wxSize(x * scalingFactor, y * scalingFactor);
}
ImageFile VirtualPad::NewBitmap(wxImage resource, wxPoint point)
@ -307,40 +332,26 @@ ImageFile VirtualPad::NewBitmap(float scalingFactor, wxImage resource, wxPoint p
image.image = bitmap;
image.width = bitmap.GetWidth();
image.height = bitmap.GetHeight();
image.coords = NewScaledPoint(point);
image.coords = ScaledPoint(point);
return image;
}
void VirtualPad::InitNormalButtonGUIElements(ControllerNormalButton &button, ImageFile image, wxWindow *parentWindow, wxPoint point)
void VirtualPad::InitNormalButtonGuiElements(ControllerNormalButton &button, ImageFile image, wxWindow *parentWindow, wxPoint point)
{
button.icon = image;
button.pressedBox = new wxCheckBox(parentWindow, wxID_ANY, wxEmptyString, NewScaledPoint(point), wxDefaultSize);
button.isControllerBypassed = false;
button.prevPressedVal = false;
button.pressedBox = new wxCheckBox(parentWindow, wxID_ANY, wxEmptyString, ScaledPoint(point), wxDefaultSize);
Bind(wxEVT_CHECKBOX, &VirtualPad::OnNormalButtonPress, this, button.pressedBox->GetId());
buttonElements[button.pressedBox->GetId()] = &button;
}
void VirtualPad::InitPressureButtonGUIElements(ControllerPressureButton &button, ImageFile image, wxWindow *parentWindow, wxPoint point, bool rightAlignedPoint)
void VirtualPad::InitPressureButtonGuiElements(ControllerPressureButton &button, ImageFile image, wxWindow *parentWindow, wxPoint point, bool rightAlignedPoint)
{
wxPoint scaledPoint = wxPoint(point.x * scalingFactor, point.y * scalingFactor);
if (rightAlignedPoint) {
scaledPoint.x -= 100 * scalingFactor;
if (scaledPoint.x < 0) {
scaledPoint.x = 0;
}
}
wxSpinCtrl *spinner = new wxSpinCtrl(parentWindow, wxID_ANY, wxEmptyString, scaledPoint, wxSize(100 * scalingFactor, wxDefaultSize.GetHeight()), wxSP_ARROW_KEYS, 0, 255, 0);
const int spinnerWidth = 100;
const wxPoint scaledPoint = ScaledPoint(point.x, point.y, spinnerWidth, rightAlignedPoint);
wxSpinCtrl *spinner = new wxSpinCtrl(parentWindow, wxID_ANY, wxEmptyString, scaledPoint, ScaledSize(spinnerWidth, wxDefaultSize.GetHeight()), wxSP_ARROW_KEYS, 0, 255, 0);
// TODO - defaults on the classes' constructor would clean this up
button.icon = image;
button.prevPressedVal = 0;
button.pressureSpinner = spinner;
button.isControllerPressBypassed = false;
button.isControllerPressureBypassed = false;
button.prevPressedVal = false;
button.prevPressureVal = 0;
Bind(wxEVT_SPINCTRL, &VirtualPad::OnPressureButtonPressureChange, this, button.pressureSpinner->GetId());
pressureElements[button.pressureSpinner->GetId()] = &button;
}
@ -348,46 +359,31 @@ void VirtualPad::InitPressureButtonGUIElements(ControllerPressureButton &button,
void VirtualPad::InitAnalogStickGuiElements(AnalogStick &analog, wxWindow *parentWindow, wxPoint centerPoint, int radius, wxPoint xSliderPoint, wxPoint ySliderPoint, bool flipYSlider, wxPoint xSpinnerPoint, wxPoint ySpinnerPoint, bool rightAlignedSpinners)
{
AnalogPosition analogPos = AnalogPosition();
analogPos.centerCoords = NewScaledPoint(centerPoint);
analogPos.endCoords = NewScaledPoint(centerPoint);
analogPos.centerCoords = ScaledPoint(centerPoint);
analogPos.endCoords = ScaledPoint(centerPoint);
analogPos.radius = radius * scalingFactor;
analogPos.lineThickness = 6 * scalingFactor;
// TODO - make a function to scale wxSize values easier
const int spinnerWidth = 90;
const wxPoint xSpinnerScaledPoint = ScaledPoint(xSpinnerPoint, spinnerWidth, rightAlignedSpinners);
const wxPoint ySpinnerScaledPoint = ScaledPoint(ySpinnerPoint, spinnerWidth, rightAlignedSpinners);
wxSlider *xSlider = new wxSlider(parentWindow, wxID_ANY, 127, 0, 255, NewScaledPoint(xSliderPoint), wxSize(185 * scalingFactor, 30 * scalingFactor));
wxSlider *ySlider = new wxSlider(parentWindow, wxID_ANY, 127, 0, 255, NewScaledPoint(ySliderPoint), wxSize(30 * scalingFactor, 185 * scalingFactor), flipYSlider ? wxSL_LEFT : wxSL_RIGHT);
// TODO - function to right-align spinners easier
wxPoint xSpinnerScaledPoint = NewScaledPoint(xSpinnerPoint);
wxPoint ySpinnerScaledPoint = NewScaledPoint(ySpinnerPoint);
if (rightAlignedSpinners) {
xSpinnerScaledPoint.x -= 90 * scalingFactor;
if (xSpinnerScaledPoint.x < 0) {
xSpinnerScaledPoint.x = 0;
}
ySpinnerScaledPoint.x -= 90 * scalingFactor;
if (ySpinnerScaledPoint.x < 0) {
ySpinnerScaledPoint.x = 0;
}
}
wxSpinCtrl *xSpinner = new wxSpinCtrl(parentWindow, wxID_ANY, wxEmptyString, xSpinnerScaledPoint, wxSize(90 * scalingFactor, wxDefaultSize.GetHeight()), wxSP_ARROW_KEYS, 0, 255, 127);
wxSpinCtrl *ySpinner = new wxSpinCtrl(parentWindow, wxID_ANY, wxEmptyString, ySpinnerScaledPoint, wxSize(90 * scalingFactor, wxDefaultSize.GetHeight()), wxSP_ARROW_KEYS, 0, 255, 127);
wxSlider *xSlider = new wxSlider(parentWindow, wxID_ANY, 127, 0, 255, ScaledPoint(xSliderPoint), ScaledSize(185, 30));
wxSlider *ySlider = new wxSlider(parentWindow, wxID_ANY, 127, 0, 255, ScaledPoint(ySliderPoint), ScaledSize(30, 185), flipYSlider ? wxSL_LEFT : wxSL_RIGHT);
wxSpinCtrl *xSpinner = new wxSpinCtrl(parentWindow, wxID_ANY, wxEmptyString, xSpinnerScaledPoint, ScaledSize(90, wxDefaultSize.GetHeight()), wxSP_ARROW_KEYS, 0, 255, 127);
wxSpinCtrl *ySpinner = new wxSpinCtrl(parentWindow, wxID_ANY, wxEmptyString, ySpinnerScaledPoint, ScaledSize(90, wxDefaultSize.GetHeight()), wxSP_ARROW_KEYS, 0, 255, 127);
analog.xVector.slider = xSlider;
analog.yVector.slider = ySlider;
analog.xVector.spinner = xSpinner;
analog.yVector.spinner = ySpinner;
analog.positionGraphic = analogPos;
Bind(wxEVT_SPINCTRL, &VirtualPad::OnAnalogSpinnerChange, this, analog.xVector.spinner->GetId());
Bind(wxEVT_SPINCTRL, &VirtualPad::OnAnalogSpinnerChange, this, analog.yVector.spinner->GetId());
Bind(wxEVT_SLIDER, &VirtualPad::OnAnalogSliderChange, this, analog.xVector.slider->GetId());
Bind(wxEVT_SLIDER, &VirtualPad::OnAnalogSliderChange, this, analog.yVector.slider->GetId());
analogElements[analog.xVector.spinner->GetId()] = &analog.xVector;
analogElements[analog.yVector.spinner->GetId()] = &analog.yVector;
analogElements[analog.xVector.slider->GetId()] = &analog.xVector;
analogElements[analog.yVector.slider->GetId()] = &analog.yVector;
Bind(wxEVT_SLIDER, &VirtualPad::OnAnalogSliderChange, this, xSlider->GetId());
Bind(wxEVT_SLIDER, &VirtualPad::OnAnalogSliderChange, this, ySlider->GetId());
Bind(wxEVT_SPINCTRL, &VirtualPad::OnAnalogSpinnerChange, this, xSpinner->GetId());
Bind(wxEVT_SPINCTRL, &VirtualPad::OnAnalogSpinnerChange, this, ySpinner->GetId());
analogElements[xSlider->GetId()] = &analog.xVector;
analogElements[ySlider->GetId()] = &analog.yVector;
analogElements[xSpinner->GetId()] = &analog.xVector;
analogElements[ySpinner->GetId()] = &analog.yVector;
}

View File

@ -18,10 +18,10 @@
#include <map>
#include <queue>
#include "wx/window.h"
#include "wx/frame.h"
#include "wx/checkbox.h"
#include "Pcsx2Types.h"
#include "wx/checkbox.h"
#include "wx/frame.h"
#include "wx/window.h"
#include "Recording/PadData.h"
#include "Recording/VirtualPad/VirtualPadData.h"
@ -37,21 +37,21 @@ public:
private:
bool manualRedrawMode = false;
bool clearScreenRequired = false;
void RedrawBackground(wxDC &dc, ImageFile &img);
std::queue<VirtualPadElement*> renderQueue;
/// GUI Creation Utility Functions
float scalingFactor = 1.0;
wxPoint NewScaledPoint(wxPoint point);
wxPoint NewScaledPoint(int x, int y);
wxSize ScaledSize(int x, int y);
wxPoint ScaledPoint(wxPoint point, int widgetWidth = 0, bool rightAligned = false);
wxPoint ScaledPoint(int x, int y, int widgetWidth = 0, bool rightAligned = false);
ImageFile NewBitmap(wxImage resource, wxPoint point);
ImageFile NewBitmap(float scalingFactor, wxImage resource, wxPoint point);
void InitPressureButtonGUIElements(ControllerPressureButton &button, ImageFile image, wxWindow *parentWindow, wxPoint point, bool rightAlignedPoint = false);
void InitNormalButtonGUIElements(ControllerNormalButton &btn, ImageFile image, wxWindow *parentWindow, wxPoint point);
void InitPressureButtonGuiElements(ControllerPressureButton &button, ImageFile image, wxWindow *parentWindow, wxPoint point, bool rightAlignedPoint = false);
void InitNormalButtonGuiElements(ControllerNormalButton &btn, ImageFile image, wxWindow *parentWindow, wxPoint point);
void InitAnalogStickGuiElements(AnalogStick &analog, wxWindow *parentWindow, wxPoint centerPoint, int radius, wxPoint xSliderPoint, wxPoint ySliderPoint, bool flipYSlider, wxPoint xSpinnerPoint, wxPoint ySpinnerPoint, bool rightAlignedSpinners = false);
/// GUI Elements
@ -61,7 +61,6 @@ private:
std::map<wxWindowID, ControllerNormalButton*> buttonElements;
std::map<wxWindowID, ControllerPressureButton*> pressureElements;
std::map<wxWindowID, AnalogVector*> analogElements;
// TODO - analog stick resolver might need to be a tuple of the slider/spinctrl
bool ignoreRealController = false;
VirtualPadData virtualPadData;
@ -75,18 +74,12 @@ private:
void OnPaint(wxPaintEvent & evt);
void Render(wxDC& dc);
void OnClose(wxCloseEvent &event);
void OnShow(wxShowEvent &event);
void OnMouseEvent(wxMouseEvent &event);
void OnFocusEvent(wxFocusEvent &event);
void UpdateVirtualPadComponent(wxDC &dc, ControllerNormalButton &btn);
void UpdateVirtualPadComponent(wxDC &dc, ControllerPressureButton &btn);
void DrawImageFile(wxDC &dc, ImageFile &imgFile);
void UpdateVirtualPadComponent(wxDC &dc, AnalogStick &analogStick);
void OnNormalButtonPress(wxCommandEvent &event);
void OnPressureButtonPressureChange(wxCommandEvent &event);
void OnAnalogSliderChange(wxCommandEvent &event);
void OnAnalogSpinnerChange(wxCommandEvent &event);
void OnIgnoreRealController(wxCommandEvent &event);
void OnIgnoreRealController(wxCommandEvent const &event);
};

View File

@ -27,22 +27,22 @@ public:
/// Pressure Buttons
ControllerPressureButton circle;
ControllerPressureButton cross;
ControllerPressureButton square;
ControllerPressureButton triangle;
ControllerPressureButton down;
ControllerPressureButton left;
ControllerPressureButton right;
ControllerPressureButton up;
ControllerPressureButton l1;
ControllerPressureButton l2;
ControllerPressureButton left;
ControllerPressureButton r1;
ControllerPressureButton r2;
ControllerPressureButton right;
ControllerPressureButton square;
ControllerPressureButton triangle;
ControllerPressureButton up;
/// Normal (un)pressed buttons
ControllerNormalButton select;
ControllerNormalButton start;
ControllerNormalButton l3;
ControllerNormalButton r3;
ControllerNormalButton select;
ControllerNormalButton start;
/// Analog Sticks
AnalogStick leftAnalog;

View File

@ -124,20 +124,19 @@ void AnalogStick::Render(wxDC &dc)
analogStick.currentlyRendered = true;
}
// TODO - duplicate code between this and the pressure button, inheritance should be able to remove it
bool ControllerNormalButton::UpdateData(bool &padDataVal, bool ignoreRealController, bool readOnly)
bool ControllerButton::UpdateButtonData(bool &padDataVal, bool ignoreRealController, bool readOnly)
{
ControllerNormalButton &button = *this;
ControllerButton &button = *this;
if (!ignoreRealController) {
// If controller is being bypassed and controller's state has changed
bool bypassedWithChangedState = button.isControllerBypassed && padDataVal != button.prevPressedVal;
bool bypassedWithChangedState = button.isControllerPressBypassed && padDataVal != button.prevPressedVal;
if (bypassedWithChangedState) {
button.prevPressedVal = padDataVal;
button.isControllerBypassed = false;
button.isControllerPressBypassed = false;
}
// If we aren't bypassing the controller OR the previous condition was met
if (bypassedWithChangedState || !button.isControllerBypassed) {
button.renderRequired = button.pressed != padDataVal;
if (bypassedWithChangedState || !button.isControllerPressBypassed) {
button.widgetUpdateRequired = button.pressed != padDataVal;
button.pressed = padDataVal;
return false;
}
@ -147,24 +146,14 @@ bool ControllerNormalButton::UpdateData(bool &padDataVal, bool ignoreRealControl
return button.prevPressedVal != button.pressed;
}
bool ControllerNormalButton::UpdateData(bool &padDataVal, bool ignoreRealController, bool readOnly)
{
return this->UpdateButtonData(padDataVal, ignoreRealController, readOnly);
}
bool ControllerPressureButton::UpdateData(bool &padDataVal, bool ignoreRealController, bool readOnly)
{
ControllerPressureButton &button = *this;
if (!ignoreRealController) {
bool bypassedWithChangedState = button.isControllerPressBypassed && padDataVal != button.prevPressedVal;
if (bypassedWithChangedState) {
button.prevPressedVal = padDataVal;
button.isControllerPressBypassed = false;
}
if (bypassedWithChangedState || !button.isControllerPressBypassed) {
button.renderRequired = button.pressed != padDataVal;
button.pressed = padDataVal;
return false;
}
}
button.prevPressedVal = padDataVal;
padDataVal = button.pressed;
return button.prevPressedVal != button.pressed;
return this->UpdateButtonData(padDataVal, ignoreRealController, readOnly);
}
bool ControllerPressureButton::UpdateData(u8 &padDataVal, bool ignoreRealController, bool readOnly)
@ -177,7 +166,7 @@ bool ControllerPressureButton::UpdateData(u8 &padDataVal, bool ignoreRealControl
button.isControllerPressureBypassed = false;
}
if (bypassedWithChangedState || !button.isControllerPressureBypassed) {
button.renderRequired = button.pressure != padDataVal;
button.widgetUpdateRequired = button.pressure != padDataVal;
button.pressure = padDataVal;
return false;
}
@ -197,7 +186,7 @@ bool AnalogVector::UpdateData(u8 &padDataVal, bool ignoreRealController, bool re
vector.isControllerBypassed = false;
}
if (bypassedWithChangedState || !vector.isControllerBypassed) {
vector.renderRequired = vector.val != padDataVal;
vector.widgetUpdateRequired = vector.val != padDataVal;
vector.val = padDataVal;
return false;
}

View File

@ -21,15 +21,15 @@ struct ImageFile
{
wxBitmap image;
wxPoint coords;
u32 width;
u32 height;
u32 width = 0;
u32 height = 0;
};
struct AnalogVector
{
// GUI
wxSlider *slider;
wxSpinCtrl *spinner;
wxSlider *slider = 0;
wxSpinCtrl *spinner = 0;
u8 val = 127;
@ -46,8 +46,8 @@ struct AnalogPosition
wxPoint centerCoords;
wxPoint endCoords;
int lineThickness;
int radius;
int lineThickness = 0;
int radius = 0;
};
class VirtualPadElement
@ -59,41 +59,43 @@ public:
virtual void Render(wxDC &dc) = 0;
};
class ControllerNormalButton : VirtualPadElement
class ControllerButton
{
public:
bool pressed = false;
bool widgetUpdateRequired = false;
bool isControllerPressBypassed = false;
bool prevPressedVal = false;
bool UpdateButtonData(bool &padDataVal, bool ignoreRealController, bool readOnly);
};
class ControllerNormalButton : public ControllerButton, VirtualPadElement
{
public:
/// GUI
ImageFile icon;
wxCheckBox *pressedBox;
bool pressed = false;
wxCheckBox *pressedBox = 0;
/// State
bool renderRequired = false;
bool isControllerBypassed;
bool prevPressedVal;
void UpdateGuiElement(std::queue<VirtualPadElement *> *renderQueue, bool &clearScreenRequired) override;
void Render(wxDC &dc) override;
bool UpdateData(bool &padDataVal, bool ignoreRealController, bool readOnly);
};
class ControllerPressureButton : VirtualPadElement
class ControllerPressureButton : public ControllerButton, VirtualPadElement
{
public:
/// GUI
ImageFile icon;
wxSpinCtrl *pressureSpinner;
wxSpinCtrl *pressureSpinner = 0;
bool pressed = false;
u8 pressure;
u8 pressure = 0;
/// State Management
bool renderRequired = false;
bool isControllerPressBypassed;
bool isControllerPressureBypassed;
bool prevPressedVal;
u8 prevPressureVal;
bool isControllerPressureBypassed = false;
u8 prevPressureVal = 0;
void UpdateGuiElement(std::queue<VirtualPadElement *> *renderQueue, bool &clearScreenRequired) override;
void Render(wxDC &dc) override;