From 35c78ae6603ebeabd3a4e3200675108c38b5f57a Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Wed, 25 Nov 2009 15:38:24 +0000 Subject: [PATCH] Added a "Screenshot" button to the Settings window; it saves a screenshot of the settings to png file. :) It's just preliminary for now. I'll replace it with an artsy icon later, hopefully. :) Cleaned up the operator overloads some more, and added operator, (yes, comma) to solve some ambiguity problems when trying to apply multiple attributes to a single window. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2252 96395faa-99c1-11dd-bbfe-3dabce05a288 --- common/include/Utilities/wxGuiTools.h | 23 +++-------- common/src/Utilities/wxGuiTools.cpp | 22 +++++++++-- common/src/Utilities/wxHelpers.cpp | 48 +++++++++++++---------- pcsx2/gui/Dialogs/ConfigurationDialog.cpp | 40 +++++++++++++++---- pcsx2/gui/Dialogs/ConfigurationDialog.h | 1 + pcsx2/gui/Dialogs/ConfirmationDialogs.cpp | 14 ++++--- pcsx2/gui/Dialogs/ModalPopups.h | 26 +++++++----- pcsx2/gui/IsoDropTarget.cpp | 10 +++-- pcsx2/gui/MainMenuClicks.cpp | 6 ++- pcsx2/gui/Panels/PluginSelectorPanel.cpp | 4 +- 10 files changed, 123 insertions(+), 71 deletions(-) diff --git a/common/include/Utilities/wxGuiTools.h b/common/include/Utilities/wxGuiTools.h index b0bb36ed95..7317bf8656 100644 --- a/common/include/Utilities/wxGuiTools.h +++ b/common/include/Utilities/wxGuiTools.h @@ -128,8 +128,8 @@ struct pxWindowAndFlags }; -extern wxSizerFlags operator | ( const wxSizerFlags& _flgs, pxAlignmentType align ); -extern wxSizerFlags operator | ( const wxSizerFlags& _flgs, pxStretchType stretch ); +extern wxSizerFlags operator , ( const wxSizerFlags& _flgs, const wxSizerFlags& _flgs2 ); //pxAlignmentType align ); +//extern wxSizerFlags operator , ( const wxSizerFlags& _flgs, pxStretchType stretch ); template< typename WinType > pxWindowAndFlags operator | ( WinType* _win, const wxSizerFlags& _flgs ) @@ -145,20 +145,6 @@ pxWindowAndFlags operator | ( WinType& _win, const wxSizerFlags& _flgs return result; } -template< typename WinType > -pxWindowAndFlags operator | ( const wxSizerFlags& _flgs, WinType* _win ) -{ - pxWindowAndFlags result = { _win, _flgs }; - return result; -} - -template< typename WinType > -pxWindowAndFlags operator | ( const wxSizerFlags& _flgs, WinType& _win ) -{ - pxWindowAndFlags result = { &_win, _flgs }; - return result; -} - // -------------------------------------------------------------------------------------- // wxSizer Operator += .. a wxSizer.Add() Substitute // -------------------------------------------------------------------------------------- @@ -238,8 +224,9 @@ class wxDialogWithHelpers : public wxDialog DECLARE_DYNAMIC_CLASS_NO_COPY(wxDialogWithHelpers) protected: - bool m_hasContextHelp; - int m_idealWidth; + bool m_hasContextHelp; + int m_idealWidth; + wxBoxSizer* m_extraButtonSizer; public: wxDialogWithHelpers(); diff --git a/common/src/Utilities/wxGuiTools.cpp b/common/src/Utilities/wxGuiTools.cpp index 94e5dd9651..37e53f2ea2 100644 --- a/common/src/Utilities/wxGuiTools.cpp +++ b/common/src/Utilities/wxGuiTools.cpp @@ -99,15 +99,29 @@ wxSizerFlags pxStretchType::Apply( wxSizerFlags flags ) const return flags; } -wxSizerFlags operator | ( const wxSizerFlags& _flgs, pxAlignmentType align ) +wxSizerFlags operator , ( const wxSizerFlags& _flgs, const wxSizerFlags& _flgs2 ) { - return align.Apply( _flgs ); + //return align.Apply( _flgs ); + wxSizerFlags retval; + + uint allflags = (_flgs.GetFlags() | _flgs2.GetFlags()); + + retval.Align( allflags & wxALIGN_MASK ); + if( allflags & wxEXPAND ) retval.Expand(); + if( allflags & wxSHAPED ) retval.Shaped(); + if( allflags & wxFIXED_MINSIZE ) retval.FixedMinSize(); + if( allflags & wxRESERVE_SPACE_EVEN_IF_HIDDEN ) retval.ReserveSpaceEvenIfHidden(); + + // Compounding borders is probably a fair approach: + retval.Border( allflags & wxALL, _flgs.GetBorderInPixels() + _flgs2.GetBorderInPixels() ); + + return retval; } -wxSizerFlags operator | ( const wxSizerFlags& _flgs, pxStretchType stretch ) +/*wxSizerFlags operator | ( const wxSizerFlags& _flgs, pxStretchType stretch ) { return stretch.Apply( _flgs ); -} +}*/ void operator+=( wxSizer& target, wxWindow* src ) diff --git a/common/src/Utilities/wxHelpers.cpp b/common/src/Utilities/wxHelpers.cpp index ae7883ebdd..09600e7f3a 100644 --- a/common/src/Utilities/wxHelpers.cpp +++ b/common/src/Utilities/wxHelpers.cpp @@ -21,6 +21,8 @@ #include #include +using namespace pxSizerFlags; + // ===================================================================================================== // wxDialogWithHelpers Class Implementations @@ -44,6 +46,7 @@ wxDialogWithHelpers::wxDialogWithHelpers() { m_idealWidth = wxDefaultCoord; m_hasContextHelp = false; + m_extraButtonSizer = NULL; } wxDialogWithHelpers::wxDialogWithHelpers( wxWindow* parent, int id, const wxString& title, bool hasContextHelp, const wxPoint& pos, const wxSize& size ) @@ -51,7 +54,8 @@ wxDialogWithHelpers::wxDialogWithHelpers( wxWindow* parent, int id, const wxStr { ++m_DialogIdents[GetId()]; - m_idealWidth = wxDefaultCoord; + m_idealWidth = wxDefaultCoord; + m_extraButtonSizer = NULL; m_hasContextHelp = hasContextHelp; if( m_hasContextHelp ) @@ -88,34 +92,38 @@ void wxDialogWithHelpers::OnActivate(wxActivateEvent& evt) void wxDialogWithHelpers::AddOkCancel( wxSizer &sizer, bool hasApply ) { - wxSizer* buttonSizer = &sizer; - if( m_hasContextHelp ) - { - // Add the context-sensitive help button on the caption for the platforms - // which support it (currently MSW only) - SetExtraStyle( wxDIALOG_EX_CONTEXTHELP ); - -#ifndef __WXMSW__ - // create a sizer to hold the help and ok/cancel buttons, for platforms - // that need a custom help icon. [fixme: help icon prolly better off somewhere else] - buttonSizer = new wxBoxSizer( wxHORIZONTAL ); - buttonSizer->Add( new wxContextHelpButton(this), pxSizerFlags::StdButton().Align( wxALIGN_LEFT ) ); - sizer.Add( buttonSizer, wxSizerFlags().Center() ); -#endif - } - - wxStdDialogButtonSizer& s_buttons = *new wxStdDialogButtonSizer(); + wxStdDialogButtonSizer& s_buttons( *new wxStdDialogButtonSizer() ); s_buttons.AddButton( new wxButton( this, wxID_OK ) ); s_buttons.AddButton( new wxButton( this, wxID_CANCEL ) ); if( hasApply ) - { s_buttons.AddButton( new wxButton( this, wxID_APPLY ) ); + + m_extraButtonSizer = new wxBoxSizer( wxHORIZONTAL ); + + // Add the context-sensitive help button on the caption for the platforms + // which support it (currently MSW only) + if( m_hasContextHelp ) + { + SetExtraStyle( wxDIALOG_EX_CONTEXTHELP ); +#ifndef __WXMSW__ + s_littles += new wxContextHelpButton(this) | StdButton(); +#endif } + + // create a sizer to hold the help and ok/cancel buttons, for platforms + // that need a custom help icon. [fixme: help icon prolly better off somewhere else] + wxFlexGridSizer& flex( *new wxFlexGridSizer( 2 ) ); + flex.AddGrowableCol( 0, 1 ); + flex.AddGrowableCol( 1, 15 ); + + flex += m_extraButtonSizer | pxAlignLeft; + flex += s_buttons | pxExpand, pxCenter; + + sizer += flex | StdExpand(); s_buttons.Realize(); - buttonSizer->Add( &s_buttons, pxSizerFlags::StdButton() ); } // -------------------------------------------------------------------------------------- diff --git a/pcsx2/gui/Dialogs/ConfigurationDialog.cpp b/pcsx2/gui/Dialogs/ConfigurationDialog.cpp index 3d6020a1d4..19fd255d3a 100644 --- a/pcsx2/gui/Dialogs/ConfigurationDialog.cpp +++ b/pcsx2/gui/Dialogs/ConfigurationDialog.cpp @@ -18,12 +18,14 @@ #include "App.h" #include "ConfigurationDialog.h" +#include "ModalPopups.h" #include "Panels/ConfigurationPanels.h" #include #include #include #include +//#include "wx/clipbrd.h" #ifdef __WXMSW__ # include // needed for Vista icon spacing fix. @@ -56,7 +58,7 @@ Dialogs::ConfigurationDialog::ConfigurationDialog( wxWindow* parent, int id ) : { m_idealWidth = 600; - wxBoxSizer& mainSizer = *new wxBoxSizer( wxVERTICAL ); + SetSizer( new wxBoxSizer( wxVERTICAL ) ); m_listbook.SetImageList( &wxGetApp().GetImgList_Config() ); const AppImageIds::ConfigIds& cfgid( wxGetApp().GetImgId().Config ); @@ -71,12 +73,13 @@ Dialogs::ConfigurationDialog::ConfigurationDialog( wxWindow* parent, int id ) : AddPage( wxLt("Plugins"), cfgid.Plugins ); AddPage ( wxLt("Folders"), cfgid.Paths ); - mainSizer.Add( &m_listbook ); - AddOkCancel( mainSizer, true ); - + *this += m_listbook; + AddOkCancel( *GetSizer(), true ); + *m_extraButtonSizer += new wxButton( this, wxID_SAVE, _("Screenshot!") ); + FindWindow( wxID_APPLY )->Disable(); - SetSizerAndFit( &mainSizer ); + Fit(); CenterOnScreen(); #ifdef __WXMSW__ @@ -92,6 +95,7 @@ Dialogs::ConfigurationDialog::ConfigurationDialog( wxWindow* parent, int id ) : Connect( wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( ConfigurationDialog::OnOk_Click ) ); Connect( wxID_CANCEL, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( ConfigurationDialog::OnCancel_Click ) ); Connect( wxID_APPLY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( ConfigurationDialog::OnApply_Click ) ); + Connect( wxID_SAVE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( ConfigurationDialog::OnScreenshot_Click ) ); // ---------------------------------------------------------------------------- // Bind a variety of standard "something probably changed" events. If the user invokes @@ -145,9 +149,31 @@ void Dialogs::ConfigurationDialog::OnApply_Click( wxCommandEvent& evt ) } +void Dialogs::ConfigurationDialog::OnScreenshot_Click( wxCommandEvent& evt ) +{ + wxBitmap memBmp; + + { + wxWindowDC dc( this ); + wxSize dcsize( dc.GetSize() ); + wxMemoryDC memDC( memBmp = wxBitmap( dcsize.x, dcsize.y ) ); + memDC.Blit( wxPoint(), dcsize, &dc, wxPoint() ); + } + + wxString filenameDefault; + filenameDefault.Printf( L"pcsx2_settings_%s.png", m_listbook.GetPageText( m_listbook.GetSelection() ).c_str() ); + filenameDefault.Replace( L"/", L"-" ); + + wxString filename( wxFileSelector( _("Save dialog screenshots to..."), g_Conf->Folders.Snapshots.ToString(), + filenameDefault, L"png", NULL, wxFD_SAVE | wxFD_OVERWRITE_PROMPT, this ) ); + + if( !filename.IsEmpty() ) + memBmp.SaveFile( filename, wxBITMAP_TYPE_PNG ); +} + // ---------------------------------------------------------------------------- -Dialogs::BiosSelectorDialog::BiosSelectorDialog( wxWindow* parent, int id ) : - wxDialogWithHelpers( parent, id, _("BIOS Selector"), false ) +Dialogs::BiosSelectorDialog::BiosSelectorDialog( wxWindow* parent, int id ) + : wxDialogWithHelpers( parent, id, _("BIOS Selector"), false ) { m_idealWidth = 500; diff --git a/pcsx2/gui/Dialogs/ConfigurationDialog.h b/pcsx2/gui/Dialogs/ConfigurationDialog.h index 62d10962ff..82b21fe6d2 100644 --- a/pcsx2/gui/Dialogs/ConfigurationDialog.h +++ b/pcsx2/gui/Dialogs/ConfigurationDialog.h @@ -42,6 +42,7 @@ namespace Dialogs void OnOk_Click( wxCommandEvent& evt ); void OnCancel_Click( wxCommandEvent& evt ); void OnApply_Click( wxCommandEvent& evt ); + void OnScreenshot_Click( wxCommandEvent& evt ); virtual void OnSomethingChanged( wxCommandEvent& evt ) { diff --git a/pcsx2/gui/Dialogs/ConfirmationDialogs.cpp b/pcsx2/gui/Dialogs/ConfirmationDialogs.cpp index 7736c56727..1f15bb26ee 100644 --- a/pcsx2/gui/Dialogs/ConfirmationDialogs.cpp +++ b/pcsx2/gui/Dialogs/ConfirmationDialogs.cpp @@ -85,7 +85,7 @@ static wxWindowID ParseThatResult( const wxString& src, const ConfButtons& valid return wxID_ANY; } -wxWindowID Dialogs::IssueConfirmation( wxWindow* parent, const wxString& disablerKey, const ConfButtons& type, const wxString& title, const wxString& msg ) +wxWindowID Dialogs::IssueConfirmation( ExtensibleConfirmation& confirmDlg, const wxString& disablerKey ) { wxConfigBase* cfg = GetAppConfig(); @@ -112,14 +112,12 @@ wxWindowID Dialogs::IssueConfirmation( wxWindow* parent, const wxString& disable result = split[0]; if( result == L"disabled" || result == L"off" || result == L"no" ) { - int result = ParseThatResult( split[1], type ); + int result = ParseThatResult( split[1], confirmDlg.GetButtons() ); if( result != wxID_ANY ) return result; } } } - Dialogs::ExtensibleConfirmation confirmDlg( parent, type, title, msg ); - if( cfg == NULL ) return confirmDlg.ShowModal(); // Add an option that allows the user to disable this popup from showing again. @@ -128,7 +126,7 @@ wxWindowID Dialogs::IssueConfirmation( wxWindow* parent, const wxString& disable pxCheckBox& DisablerCtrl( *new pxCheckBox(&confirmDlg, _("Do not show this dialog again.")) ); confirmDlg.GetExtensibleSizer().Add( &DisablerCtrl, wxSizerFlags().Centre() ); - if( type != ConfButtons().OK() ) + if( confirmDlg.GetButtons() != ConfButtons().OK() ) pxSetToolTip(&DisablerCtrl, _("Disables this popup and whatever response you select here will be automatically used from now on.")); else pxSetToolTip(&DisablerCtrl, _("The popup will not be shown again. This setting can be undone from the settings panels.")); @@ -152,7 +150,8 @@ Dialogs::ExtensibleConfirmation::ExtensibleConfirmation( wxWindow* parent, const , m_ExtensibleSizer( *new wxBoxSizer( wxVERTICAL ) ) , m_ButtonSizer( *new wxBoxSizer( wxHORIZONTAL ) ) { - m_idealWidth = 500; + m_Buttons = type; + m_idealWidth = 500; SetSizer( new wxBoxSizer(wxVERTICAL) ); @@ -194,6 +193,9 @@ Dialogs::ExtensibleConfirmation::ExtensibleConfirmation( wxWindow* parent, const if( type.HasReset() ) AddCustomButton( wxID_RESET, _("Reset") ); + if( type.HasClose() ) + AddActionButton( wxID_CLOSE ); + #ifndef __WXGTK__ if( type.HasNo() || type.HasCancel() ) // Extra space between Affirm and Cancel Actions m_ButtonSizer.Add(0, 0, 1, wxEXPAND, 0); diff --git a/pcsx2/gui/Dialogs/ModalPopups.h b/pcsx2/gui/Dialogs/ModalPopups.h index 16b0631518..18e01251a5 100644 --- a/pcsx2/gui/Dialogs/ModalPopups.h +++ b/pcsx2/gui/Dialogs/ModalPopups.h @@ -71,16 +71,17 @@ class ConfButtons protected: BITFIELD32() bool - m_OK:1, - m_Cancel:1, - m_Yes:1, - m_No:1, + m_OK :1, + m_Cancel :1, + m_Yes :1, + m_No :1, m_AllowToAll:1, - m_Apply:1, - m_Abort:1, - m_Retry:1, - m_Ignore:1, - m_Reset:1; + m_Apply :1, + m_Abort :1, + m_Retry :1, + m_Ignore :1, + m_Reset :1, + m_Close :1; BITFIELD_END wxString m_CustomLabel; @@ -99,6 +100,7 @@ public: ConfButtons& Retry() { m_Retry = true; return *this; } ConfButtons& Ignore() { m_Ignore = true; return *this; } ConfButtons& Reset() { m_Reset = true; return *this; } + ConfButtons& Close() { m_Close = true; return *this; } ConfButtons& Custom( const wxString& label) { @@ -120,6 +122,7 @@ public: bool HasRetry() const { return m_Retry; } bool HasIgnore() const { return m_Ignore; } bool HasReset() const { return m_Reset; } + bool HasClose() const { return m_Close; } bool HasCustom() const { return !m_CustomLabel.IsEmpty(); } const wxString& GetCustomLabel() const { return m_CustomLabel; } @@ -198,10 +201,13 @@ namespace Dialogs wxBoxSizer& m_ExtensibleSizer; wxBoxSizer& m_ButtonSizer; + ConfButtons m_Buttons; + public: ExtensibleConfirmation( wxWindow* parent, const ConfButtons& type, const wxString& title, const wxString& msg ); virtual ~ExtensibleConfirmation() throw() {} + const ConfButtons& GetButtons() const { return m_Buttons; } virtual wxBoxSizer& GetExtensibleSizer() const { return m_ExtensibleSizer; } protected: @@ -210,6 +216,6 @@ namespace Dialogs virtual void OnActionButtonClicked( wxCommandEvent& evt ); }; - wxWindowID IssueConfirmation( wxWindow* parent, const wxString& disablerKey, const ConfButtons& type, const wxString& title, const wxString& msg ); + wxWindowID IssueConfirmation( ExtensibleConfirmation& confirmDlg, const wxString& disablerKey ); } diff --git a/pcsx2/gui/IsoDropTarget.cpp b/pcsx2/gui/IsoDropTarget.cpp index 854fdb7c65..9e68b7a4a1 100644 --- a/pcsx2/gui/IsoDropTarget.cpp +++ b/pcsx2/gui/IsoDropTarget.cpp @@ -69,11 +69,13 @@ bool IsoDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filen bool confirmed = true; if( SysHasValidState() ) { - confirmed = Dialogs::IssueConfirmation( m_WindowBound, L"DragDrop:BootELF", ConfButtons().Reset().Cancel(), + Dialogs::ExtensibleConfirmation dialog( m_WindowBound, ConfButtons().Reset().Cancel(), _("Confirm PS2 Reset"), _("You have dropped the following ELF binary into PCSX2:\n\n") + filenames[0] + L"\n\n" + GetMsg_ConfirmSysReset() - ) != wxID_CANCEL; + ); + + confirmed = (Dialogs::IssueConfirmation( dialog, L"DragDrop:BootELF" ) != wxID_CANCEL); } if( confirmed ) @@ -109,12 +111,14 @@ bool IsoDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filen if( SysHasValidState() ) { - result = Dialogs::IssueConfirmation( m_WindowBound, L"DragDrop:BootIso", ConfButtons().Reset().Cancel().Custom(_("Swap Disc")), + Dialogs::ExtensibleConfirmation dialog( m_WindowBound, ConfButtons().Reset().Cancel().Custom(_("Swap Disc")), _("Confirm PS2 Reset"), _("You have dropped the following ISO image into PCSX2:\n\n") + filenames[0] + L"\n\n" + _("Do you want to swap discs or boot the new image (via system reset)?") ); + + result = Dialogs::IssueConfirmation( dialog, L"DragDrop:BootIso" ); } if( result != wxID_CANCEL ) diff --git a/pcsx2/gui/MainMenuClicks.cpp b/pcsx2/gui/MainMenuClicks.cpp index f21de7a1a6..964938791c 100644 --- a/pcsx2/gui/MainMenuClicks.cpp +++ b/pcsx2/gui/MainMenuClicks.cpp @@ -123,9 +123,11 @@ void MainEmuFrame::Menu_BootCdvd_Click( wxCommandEvent &event ) if( SysHasValidState() ) { - bool confirmed = IssueConfirmation( this, L"BootCdvd:ConfirmReset", ConfButtons().Yes().Cancel(), + ExtensibleConfirmation dialog( this, ConfButtons().Yes().Cancel(), _("Confirm PS2 Reset"), GetMsg_ConfirmSysReset() - ) != wxID_CANCEL; + ); + + bool confirmed = (IssueConfirmation( dialog, L"BootCdvd:ConfirmReset" ) != wxID_CANCEL); if( !confirmed ) { diff --git a/pcsx2/gui/Panels/PluginSelectorPanel.cpp b/pcsx2/gui/Panels/PluginSelectorPanel.cpp index b52f09faca..8e88cce18b 100644 --- a/pcsx2/gui/Panels/PluginSelectorPanel.cpp +++ b/pcsx2/gui/Panels/PluginSelectorPanel.cpp @@ -312,7 +312,7 @@ void Panels::PluginSelectorPanel::Apply() if( CoreThread.IsRunning() ) { // [TODO] : Post notice that this shuts down existing emulation, and may not safely recover. - int result = Dialogs::IssueConfirmation( this, L"PluginSelector:ConfirmShutdown", ConfButtons().OK().Cancel(), + Dialogs::ExtensibleConfirmation dialog( this, ConfButtons().OK().Cancel(), _("Shutdown PS2 virtual machine?"), @@ -324,6 +324,8 @@ void Panels::PluginSelectorPanel::Apply() L"Are you sure you want to apply settings now?" ) ); + + int result = Dialogs::IssueConfirmation( dialog, L"PluginSelector:ConfirmShutdown" ); if( result == wxID_CANCEL ) throw Exception::CannotApplySettings( this, "Cannot apply settings: canceled by user because plugins changed while the emulation state was active.", false );