Skip to content

Commit

Permalink
recording: Store VirtualPad window position in .ini file
Browse files Browse the repository at this point in the history
  • Loading branch information
xTVaser authored and refractionpcsx2 committed Oct 1, 2020
1 parent 4519e32 commit 14e1ecb
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 13 deletions.
4 changes: 3 additions & 1 deletion pcsx2/Recording/InputRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@

#include "PrecompiledHeader.h"

#include "AppSaveStates.h"

#ifndef DISABLE_RECORDING

#include <vector>

#include "AppSaveStates.h"
#include "AppGameDatabase.h"
#include "DebugTools/Debug.h"
#include "Counters.h"

#include "InputRecording.h"
#include "InputRecordingControls.h"

#endif

void SaveStateBase::InputRecordingFreeze()
{
Expand Down
22 changes: 17 additions & 5 deletions pcsx2/Recording/VirtualPad/VirtualPad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions pcsx2/Recording/VirtualPad/VirtualPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -50,6 +51,8 @@ class VirtualPad : public wxFrame
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.
Expand All @@ -72,6 +75,7 @@ class VirtualPad : public wxFrame
std::map<wxWindowID, AnalogVector*> analogElements;

/// Event Listeners
void OnMoveAround(wxMoveEvent& event);
void OnClose(wxCloseEvent& event);
void OnIconize(wxIconizeEvent& event);
void OnEraseBackground(wxEraseEvent& event);
Expand Down
17 changes: 17 additions & 0 deletions pcsx2/gui/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
{
Expand Down
13 changes: 13 additions & 0 deletions pcsx2/gui/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ class AppConfig
void SanityCheck();
};

#ifndef DISABLE_RECORDING
struct InputRecordingOptions
{
wxPoint VirtualPadPosition;

InputRecordingOptions();
void loadSave( IniInterface& conf );
};
#endif

struct UiTemplateOptions {
UiTemplateOptions();
void LoadSave(IniInterface& conf);
Expand Down Expand Up @@ -341,6 +351,9 @@ class AppConfig
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
Expand Down
10 changes: 5 additions & 5 deletions pcsx2/gui/AppInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 14e1ecb

Please sign in to comment.