From 14e1ecbbf6e0fd50d8a3f41f03b2a8f8cc8d52d4 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sat, 19 Sep 2020 20:44:19 -0400 Subject: [PATCH] recording: Store VirtualPad window position in .ini file --- pcsx2/Recording/InputRecording.cpp | 4 +++- pcsx2/Recording/VirtualPad/VirtualPad.cpp | 22 +++++++++++++++++----- pcsx2/Recording/VirtualPad/VirtualPad.h | 8 ++++++-- pcsx2/gui/AppConfig.cpp | 17 +++++++++++++++++ pcsx2/gui/AppConfig.h | 13 +++++++++++++ pcsx2/gui/AppInit.cpp | 10 +++++----- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/pcsx2/Recording/InputRecording.cpp b/pcsx2/Recording/InputRecording.cpp index cb42058d91..d580afa7b9 100644 --- a/pcsx2/Recording/InputRecording.cpp +++ b/pcsx2/Recording/InputRecording.cpp @@ -15,11 +15,12 @@ #include "PrecompiledHeader.h" +#include "AppSaveStates.h" + #ifndef DISABLE_RECORDING #include -#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() { diff --git a/pcsx2/Recording/VirtualPad/VirtualPad.cpp b/pcsx2/Recording/VirtualPad/VirtualPad.cpp index 0b110170eb..b3ad162347 100644 --- a/pcsx2/Recording/VirtualPad/VirtualPad.cpp +++ b/pcsx2/Recording/VirtualPad/VirtualPad.cpp @@ -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 diff --git a/pcsx2/Recording/VirtualPad/VirtualPad.h b/pcsx2/Recording/VirtualPad/VirtualPad.h index 2e25b932dc..e154bc675a 100644 --- a/pcsx2/Recording/VirtualPad/VirtualPad.h +++ b/pcsx2/Recording/VirtualPad/VirtualPad.h @@ -20,7 +20,9 @@ #include #include +#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 analogElements; /// Event Listeners + void OnMoveAround(wxMoveEvent& event); void OnClose(wxCloseEvent& event); void OnIconize(wxIconizeEvent& event); void OnEraseBackground(wxEraseEvent& event); diff --git a/pcsx2/gui/AppConfig.cpp b/pcsx2/gui/AppConfig.cpp index e6648fd450..4322a6cb4a 100644 --- a/pcsx2/gui/AppConfig.cpp +++ b/pcsx2/gui/AppConfig.cpp @@ -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() { diff --git a/pcsx2/gui/AppConfig.h b/pcsx2/gui/AppConfig.h index d70df3d984..872b6d9d45 100644 --- a/pcsx2/gui/AppConfig.h +++ b/pcsx2/gui/AppConfig.h @@ -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 diff --git a/pcsx2/gui/AppInit.cpp b/pcsx2/gui/AppInit.cpp index 9132efa1c7..9f23c232ce 100644 --- a/pcsx2/gui/AppInit.cpp +++ b/pcsx2/gui/AppInit.cpp @@ -78,18 +78,18 @@ 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); - g_InputRecording.setVirtualPadPtr(virtualPad1, 1); + + VirtualPad* virtualPad1 = new VirtualPad(mainFrame, 1, g_Conf->inputRecording); + g_InputRecording.setVirtualPadPtr(virtualPad1, 1); m_id_VirtualPad[1] = virtualPad1->GetId(); NewRecordingFrame* newRecordingFrame = new NewRecordingFrame(mainFrame); m_id_NewRecordingFrame = newRecordingFrame->GetId(); #endif - + if (g_Conf->EmuOptions.Debugger.ShowDebuggerOnStart) disassembly->Show();