From 3523626462e3b888fe4a9b159b05bd7560e8fa87 Mon Sep 17 00:00:00 2001 From: "avihal@gmail.com" Date: Fri, 6 May 2011 12:46:58 +0000 Subject: [PATCH] GUI: when the config panel is open, and using keyboard shortcuts for frame-limiter (F4) or aspect-ratio (F6), reflect it at the GUI, but ONLY if there are no intermediate changes at the GUI (i.e., only if the "Apply" button is currently disabled). This would prevent re-applying obsolete values when clicking Apply/OK for for these two configs (after they were changed via KB while the GUI was open). This is a very light infrastructure to allow some synchronization between KB shortcuts and the GUI. Currently only used for frame limiter and aspect ratio KB shortcuts. I wanted to also use it with frame-skipping (shift-F4), however, frame skipping GUI seem to have other issues which prevent it from properly reflecting KB modifications, so it's out for now. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4627 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/gui/App.h | 2 ++ pcsx2/gui/AppAccelerators.h | 2 ++ pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp | 5 ++++ pcsx2/gui/Dialogs/ConfigurationDialog.h | 12 +++++++++ pcsx2/gui/Dialogs/SysConfigDialog.cpp | 2 ++ pcsx2/gui/FrameForGS.cpp | 3 +++ pcsx2/gui/GlobalCommands.cpp | 26 +++++++++++-------- 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/pcsx2/gui/App.h b/pcsx2/gui/App.h index 343105ea52..6b4ce59f92 100644 --- a/pcsx2/gui/App.h +++ b/pcsx2/gui/App.h @@ -737,3 +737,5 @@ extern void UI_DisableSysShutdown(); pxAssertMsg( !wxGetApp().SysExecutorThread.IsSelf(), "Thread affinity violation: Call is *not* allowed from SysExecutor thread." ) extern ExecutorThread& GetSysExecutorThread(); + +extern bool g_ConfigPanelChanged; //Indicates that the main config panel is open and holds unapplied changes. \ No newline at end of file diff --git a/pcsx2/gui/AppAccelerators.h b/pcsx2/gui/AppAccelerators.h index f786d7eb66..479fa2122e 100644 --- a/pcsx2/gui/AppAccelerators.h +++ b/pcsx2/gui/AppAccelerators.h @@ -87,6 +87,8 @@ struct GlobalCommandDescriptor const wxChar* Fullname; // Name displayed in pulldown menus const wxChar* Tooltip; // text displayed in toolbar tooltips and menu status bars. + bool AlsoApplyToGui; // Indicates that the GUI should be updated if possible. + int ToolbarIconId; // not implemented yet, leave 0 for now. }; diff --git a/pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp b/pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp index 36dce1e078..69bb9b8509 100644 --- a/pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp +++ b/pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp @@ -187,6 +187,7 @@ void Dialogs::BaseConfigurationDialog::AddOkCancel( wxSizer* sizer ) { _parent::AddOkCancel( sizer, true ); if( wxWindow* apply = FindWindow( wxID_APPLY ) ) apply->Disable(); + SomethingChanged_StateModified_IsChanged(); wxBitmapButton& screenshotButton( *new wxBitmapButton( this, wxID_SAVE, EmbeddedImage().Get() ) ); screenshotButton.SetToolTip( _("Saves a snapshot of this settings panel to a PNG file.") ); @@ -217,6 +218,7 @@ void Dialogs::BaseConfigurationDialog::OnSetSettingsPage( wxCommandEvent& evt ) void Dialogs::BaseConfigurationDialog::SomethingChanged() { if( wxWindow* apply = FindWindow( wxID_APPLY ) ) apply->Enable(); + SomethingChanged_StateModified_IsChanged(); } void Dialogs::BaseConfigurationDialog::OnSomethingChanged( wxCommandEvent& evt ) @@ -250,6 +252,7 @@ void Dialogs::BaseConfigurationDialog::OnOk_Click( wxCommandEvent& evt ) if( m_ApplyState.ApplyAll() ) { if( wxWindow* apply = FindWindow( wxID_APPLY ) ) apply->Disable(); + SomethingChanged_StateModified_IsChanged(); if( m_listbook ) GetConfSettingsTabName() = m_labels[m_listbook->GetSelection()]; AppSaveSettings(); disabler.DetachAll(); @@ -272,6 +275,8 @@ void Dialogs::BaseConfigurationDialog::OnApply_Click( wxCommandEvent& evt ) if( m_listbook ) GetConfSettingsTabName() = m_labels[m_listbook->GetSelection()]; AppSaveSettings(); + + SomethingChanged_StateModified_IsChanged(); } //avih: FIXME: ? for some reason, this OnCancel_Click is called twice when clicking cancel or closing the dialog (Jake's code?). diff --git a/pcsx2/gui/Dialogs/ConfigurationDialog.h b/pcsx2/gui/Dialogs/ConfigurationDialog.h index 48be152eba..60e7c947f3 100644 --- a/pcsx2/gui/Dialogs/ConfigurationDialog.h +++ b/pcsx2/gui/Dialogs/ConfigurationDialog.h @@ -20,6 +20,7 @@ #include "AppCommon.h" #include "ApplyState.h" +#include "App.h" namespace Panels { @@ -62,6 +63,11 @@ namespace Dialogs void AddPage( const wxChar* label, int iconid ); void AllowApplyActivation( bool allow=true ); + virtual bool SomethingChanged_StateModified_IsChanged(){ //returns the state of the apply button. + if( wxWindow* apply = FindWindow( wxID_APPLY ) ) + return apply->IsEnabled(); + return false; + } protected: void OnSettingsApplied( wxCommandEvent& evt ); @@ -94,6 +100,12 @@ namespace Dialogs void Apply(); void Cancel(); + //Stores the state of the apply button in a global var. + //This var will be used by KB shortcuts commands to decide if the gui should be modified (only when no intermediate changes) + virtual bool SomethingChanged_StateModified_IsChanged(){ + return g_ConfigPanelChanged = BaseConfigurationDialog::SomethingChanged_StateModified_IsChanged(); + } + protected: virtual wxString& GetConfSettingsTabName() const { return g_Conf->SysSettingsTabName; } diff --git a/pcsx2/gui/Dialogs/SysConfigDialog.cpp b/pcsx2/gui/Dialogs/SysConfigDialog.cpp index 070ae812e4..8e71c9f48c 100644 --- a/pcsx2/gui/Dialogs/SysConfigDialog.cpp +++ b/pcsx2/gui/Dialogs/SysConfigDialog.cpp @@ -307,3 +307,5 @@ void AppearanceThemesPanel::AppStatusEvent_OnSettingsApplied() { } + +bool g_ConfigPanelChanged = false; \ No newline at end of file diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index 45707c8610..21dcf8b755 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -222,6 +222,9 @@ void GSPanel::DirectKeyCommand( const KeyAcceleratorCode& kac ) DbgCon.WriteLn( "(gsFrame) Invoking command: %s", cmd->Id ); cmd->Invoke(); + + if( cmd->AlsoApplyToGui && !g_ConfigPanelChanged) + AppApplySettings(); } void GSPanel::DirectKeyCommand( wxKeyEvent& evt ) diff --git a/pcsx2/gui/GlobalCommands.cpp b/pcsx2/gui/GlobalCommands.cpp index 2472a62ed6..f99e20d92c 100644 --- a/pcsx2/gui/GlobalCommands.cpp +++ b/pcsx2/gui/GlobalCommands.cpp @@ -16,6 +16,8 @@ #include "PrecompiledHeader.h" #include "MainFrame.h" #include "GSFrame.h" +#include "ApplyState.h" + #include "AppAccelerators.h" #include "AppSaveStates.h" @@ -161,6 +163,16 @@ namespace Implementations pauser.AllowResume(); } + void UpdateImagePosition() + { + //AppApplySettings() would have been nicer, since it also immidiately affects the GUI (if open). + //However, the events sequence it generates also "depresses" Shift/CTRL/etc, so consecutive zoom with CTRL down breaks. + //Since zoom only affects the window viewport anyway, we can live with directly calling it. + if (GSFrame* gsFrame = wxGetApp().GetGsFramePtr()) + if (GSPanel* woot = gsFrame->GetViewport()) + woot->DoResize(); + } + void GSwindow_CycleAspectRatio() { AspectRatioType& art = g_Conf->GSWindow.AspectRatio; @@ -173,17 +185,7 @@ namespace Implementations } Console.WriteLn(L"(GSwindow) Aspect ratio: %s.", arts.c_str()); - AppApplySettings(); - } - - void UpdateImagePosition() - { - //AppApplySettings() would have been nicer, since it also immidiately affects the GUI (if open). - //However, the events sequence it generates also "depresses" Shift/CTRL/etc, so consecutive zoom with CTRL down breaks. - //Since zoom only affects the window viewport anyway, we can live with directly calling it. - if (GSFrame* gsFrame = wxGetApp().GetGsFramePtr()) - if (GSPanel* woot = gsFrame->GetViewport()) - woot->DoResize(); + UpdateImagePosition(); } void SetOffset(float x, float y) @@ -432,12 +434,14 @@ static const GlobalCommandDescriptor CommandDeclarations[] = Implementations::Framelimiter_MasterToggle, NULL, NULL, + true, }, { "GSwindow_CycleAspectRatio", Implementations::GSwindow_CycleAspectRatio, NULL, NULL, + true, }, { "GSwindow_ZoomIn",