recording: Store VirtualPad window position in .ini file

This commit is contained in:
Tyler Wilding 2020-09-19 20:44:19 -04:00 committed by refractionpcsx2
parent 4519e32586
commit 14e1ecbbf6
6 changed files with 61 additions and 13 deletions

View File

@ -15,11 +15,12 @@
#include "PrecompiledHeader.h"
#include "AppSaveStates.h"
#ifndef DISABLE_RECORDING
#include <vector>
#include "AppSaveStates.h"
#include "AppGameDatabase.h"
#include "DebugTools/Debug.h"
#include "Counters.h"
@ -27,6 +28,7 @@
#include "InputRecording.h"
#include "InputRecordingControls.h"
#endif
void SaveStateBase::InputRecordingFreeze()
{

View File

@ -46,9 +46,9 @@
#include "Recording/VirtualPad/img/trianglePressed.h"
#include "Recording/VirtualPad/img/upPressed.h"
// 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)
VirtualPad::VirtualPad(wxWindow* parent, int controllerPort, AppConfig::InputRecordingOptions& options)
: wxFrame(parent, wxID_ANY, wxEmptyString)
, options(options)
{
// Images at 1.00 scale are designed to work well on HiDPI (4k) at 150% scaling (default recommended setting on windows)
// Therefore, on a 1080p monitor we halve the scaling, on 1440p we reduce it by 25%, which from some quick tests looks comparable
@ -99,9 +99,10 @@ VirtualPad::VirtualPad(wxWindow* parent, wxWindowID id, const wxString& title, i
Bind(wxEVT_CHECKBOX, &VirtualPad::OnIgnoreRealController, this, ignoreRealControllerBox->GetId());
// Bind Window Events
Bind(wxEVT_ERASE_BACKGROUND, &VirtualPad::OnEraseBackground, this);
Bind(wxEVT_MOVE, &VirtualPad::OnMoveAround, this);
Bind(wxEVT_CLOSE_WINDOW, &VirtualPad::OnClose, this);
Bind(wxEVT_ICONIZE, &VirtualPad::OnIconize, this);
Bind(wxEVT_ERASE_BACKGROUND, &VirtualPad::OnEraseBackground, this);
// Temporary Paint event handler so the window displays properly before the controller-interrupt routine takes over with manual drawing.
// The reason for this is in order to minimize the performance impact, we need total control over when render is called
// Windows redraws the window _alot_ otherwise which leads to major performance problems (when GS is using the software renderer)
@ -111,13 +112,24 @@ VirtualPad::VirtualPad(wxWindow* parent, wxWindowID id, const wxString& title, i
// Finalize layout
SetIcons(wxGetApp().GetIconBundle());
SetTitle(wxString::Format("Virtual Pad - Port %d", controllerPort + 1));
SetPosition(options.VirtualPadPosition);
SetBackgroundColour(*wxWHITE);
SetBackgroundStyle(wxBG_STYLE_PAINT);
// This window does not allow for resizing for sake of simplicity: all images are scaled initially and stored, ready to be rendered
SetWindowStyle(style & ~wxRESIZE_BORDER);
SetWindowStyle(wxDEFAULT_FRAME_STYLE & ~wxRESIZE_BORDER);
SetDoubleBuffered(true);
}
void VirtualPad::OnMoveAround(wxMoveEvent& event)
{
if (IsBeingDeleted() || !IsVisible() || IsIconized())
return;
if (!IsMaximized())
options.VirtualPadPosition = GetPosition();
event.Skip();
}
void VirtualPad::OnClose(wxCloseEvent& event)
{
// Re-bind the Paint event in case this is due to a game being opened/closed

View File

@ -20,7 +20,9 @@
#include <map>
#include <queue>
#include "AppConfig.h"
#include "Pcsx2Types.h"
#include "wx/checkbox.h"
#include "wx/dc.h"
#include "wx/event.h"
@ -36,8 +38,7 @@
class VirtualPad : public wxFrame
{
public:
VirtualPad(wxWindow* parent, wxWindowID id, const wxString& title, int controllerPort,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE);
VirtualPad(wxWindow* parent, int controllerPort, AppConfig::InputRecordingOptions& options);
// Updates the VirtualPad's data if necessary, as well as updates the provided PadData if the VirtualPad overrides it
// - PadData will not be updated if ReadOnly mode is set
// - returns a bool to indicate if the PadData has been updated
@ -50,6 +51,8 @@ public:
void Redraw();
private:
AppConfig::InputRecordingOptions& options;
bool clearScreenRequired = false;
bool ignoreRealController = false;
// When enabled, forces the VirtualPad to be re-rendered even if no updates are made.
@ -72,6 +75,7 @@ private:
std::map<wxWindowID, AnalogVector*> analogElements;
/// Event Listeners
void OnMoveAround(wxMoveEvent& event);
void OnClose(wxCloseEvent& event);
void OnIconize(wxIconizeEvent& event);
void OnEraseBackground(wxEraseEvent& event);

View File

@ -673,6 +673,9 @@ void AppConfig::LoadSave( IniInterface& ini )
BaseFilenames .LoadSave( ini );
GSWindow .LoadSave( ini );
Framerate .LoadSave( ini );
#ifndef DISABLE_RECORDING
inputRecording.loadSave(ini);
#endif
Templates .LoadSave( ini );
ini.Flush();
@ -900,6 +903,20 @@ void AppConfig::GSWindowOptions::LoadSave( IniInterface& ini )
if( ini.IsLoading() ) SanityCheck();
}
#ifndef DISABLE_RECORDING
AppConfig::InputRecordingOptions::InputRecordingOptions()
: VirtualPadPosition(wxDefaultPosition)
{
}
void AppConfig::InputRecordingOptions::loadSave(IniInterface& ini)
{
ScopedIniGroup path(ini, L"InputRecording");
IniEntry(VirtualPadPosition);
}
#endif
// ----------------------------------------------------------------------------
AppConfig::FramerateOptions::FramerateOptions()
{

View File

@ -250,6 +250,16 @@ public:
void SanityCheck();
};
#ifndef DISABLE_RECORDING
struct InputRecordingOptions
{
wxPoint VirtualPadPosition;
InputRecordingOptions();
void loadSave( IniInterface& conf );
};
#endif
struct UiTemplateOptions {
UiTemplateOptions();
void LoadSave(IniInterface& conf);
@ -341,6 +351,9 @@ public:
FilenameOptions BaseFilenames;
GSWindowOptions GSWindow;
FramerateOptions Framerate;
#ifndef DISABLE_RECORDING
InputRecordingOptions inputRecording;
#endif
UiTemplateOptions Templates;
// PCSX2-core emulation options, which are passed to the emu core prior to initiating

View File

@ -78,11 +78,11 @@ void Pcsx2App::OpenMainFrame()
m_id_Disassembler = disassembly->GetId();
#ifndef DISABLE_RECORDING
VirtualPad* virtualPad0 = new VirtualPad(mainFrame, wxID_ANY, wxEmptyString, 0);
VirtualPad* virtualPad0 = new VirtualPad(mainFrame, 0, g_Conf->inputRecording);
g_InputRecording.setVirtualPadPtr(virtualPad0, 0);
m_id_VirtualPad[0] = virtualPad0->GetId();
VirtualPad *virtualPad1 = new VirtualPad(mainFrame, wxID_ANY, wxEmptyString, 1);
VirtualPad* virtualPad1 = new VirtualPad(mainFrame, 1, g_Conf->inputRecording);
g_InputRecording.setVirtualPadPtr(virtualPad1, 1);
m_id_VirtualPad[1] = virtualPad1->GetId();