From dd021b1ea1625822a7fe27cb4a1dfb2cdb1ecdfd Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Wed, 2 Jun 2010 15:58:34 +0000 Subject: [PATCH] Working on a new replacement for pxStaticText, which should hopefully have more reliable centering and wrapping behavior. Will finish it up later. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3143 96395faa-99c1-11dd-bbfe-3dabce05a288 --- common/build/Utilities/utilities.vcproj | 116 -------------- common/build/x86emitter/x86emitter.vcproj | 32 ---- common/include/Utilities/wxGuiTools.h | 34 +++- common/src/Utilities/pxWindowTextWriter.cpp | 117 ++++++++++++++ common/src/Utilities/wxGuiTools.cpp | 6 + pcsx2/gui/Dialogs/FirstTimeWizard.cpp | 4 +- pcsx2/gui/Dialogs/McdConfigDialog.cpp | 60 ------- pcsx2/gui/Panels/ConfigurationPanels.h | 2 - pcsx2/gui/Panels/MemoryCardPanels.h | 59 ------- pcsx2/gui/Panels/MemoryCardsPanel.cpp | 165 -------------------- pcsx2/gui/Panels/MiscPanelStuff.cpp | 4 +- pcsx2/gui/Panels/VideoPanel.cpp | 3 +- pcsx2/windows/VCprojects/pcsx2_2008.vcproj | 52 ------ 13 files changed, 163 insertions(+), 491 deletions(-) delete mode 100644 pcsx2/gui/Panels/MemoryCardsPanel.cpp diff --git a/common/build/Utilities/utilities.vcproj b/common/build/Utilities/utilities.vcproj index a6cfc2e79b..bf262becb8 100644 --- a/common/build/Utilities/utilities.vcproj +++ b/common/build/Utilities/utilities.vcproj @@ -291,122 +291,6 @@ RelativePath="..\..\src\Utilities\wxHelpers.cpp" > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/common/build/x86emitter/x86emitter.vcproj b/common/build/x86emitter/x86emitter.vcproj index ef3143171c..8ffeef3f14 100644 --- a/common/build/x86emitter/x86emitter.vcproj +++ b/common/build/x86emitter/x86emitter.vcproj @@ -273,38 +273,6 @@ RelativePath="..\..\src\x86emitter\x86emitter.cpp" > - - - - - - - - - - - - - diff --git a/common/include/Utilities/wxGuiTools.h b/common/include/Utilities/wxGuiTools.h index 45aeff35ce..5641f9dfd3 100644 --- a/common/include/Utilities/wxGuiTools.h +++ b/common/include/Utilities/wxGuiTools.h @@ -456,6 +456,7 @@ public: } pxTextWrapper& Wrap( const wxWindow& win, const wxString& text, int widthMax ); + pxTextWrapper& Wrap( const wxWindow* win, const wxString& text, int widthMax ); protected: virtual void OnOutputLine(const wxString& line); @@ -484,8 +485,8 @@ public: m_curpos = wxPoint(); m_align = wxALIGN_CENTER; m_leading = 2; - - OnFontChanged(); + + OnFontChanged(); } virtual ~pxWindowTextWriter() throw() @@ -537,6 +538,35 @@ public: pxWindowTextWriter& MoveY( int ydelta ); }; +// -------------------------------------------------------------------------------------- +// pxStaticTextImproved +// -------------------------------------------------------------------------------------- +class pxStaticTextImproved : public wxPanelWithHelpers +{ + typedef wxPanelWithHelpers _parent; + +protected: + wxAlignment m_align; + wxString m_wrappedLabel; + bool m_autowrap; + int m_wrappedWidth; + int m_padding_horiz; + +public: + pxStaticTextImproved( wxWindow* parent=NULL, const wxString& label=wxEmptyString, wxAlignment align=wxALIGN_CENTER ); + pxStaticTextImproved( wxWindow* parent, int heightInLines, const wxString& label=wxEmptyString, wxAlignment align=wxALIGN_CENTER ); + virtual ~pxStaticTextImproved() throw() {} + + virtual void SetLabel(const wxString& label); + pxStaticTextImproved& Unwrapped(); + +protected: + void Init(); + void paintEvent(wxPaintEvent& evt); + void UpdateWrapping( bool textChanged ); +}; + + // -------------------------------------------------------------------------------------- // MoreStockCursors // -------------------------------------------------------------------------------------- diff --git a/common/src/Utilities/pxWindowTextWriter.cpp b/common/src/Utilities/pxWindowTextWriter.cpp index d8cebfeede..a3d368cc4f 100644 --- a/common/src/Utilities/pxWindowTextWriter.cpp +++ b/common/src/Utilities/pxWindowTextWriter.cpp @@ -134,3 +134,120 @@ pxWindowTextWriter& pxWindowTextWriter::WriteLn( const wxChar* fmt, ... ) va_end(args); return *this; } + +// -------------------------------------------------------------------------------------- +// pxStaticTextImproved (implementations) +// -------------------------------------------------------------------------------------- +pxStaticTextImproved::pxStaticTextImproved( wxWindow* parent, const wxString& label, wxAlignment align ) + : wxPanelWithHelpers( parent ) +{ + Init(); + + m_align = align; + SetLabel( label ); +} + +pxStaticTextImproved::pxStaticTextImproved( wxWindow* parent, int heightInLines, const wxString& label, wxAlignment align ) + : wxPanelWithHelpers( parent ) +{ + SetMinSize( wxSize( wxDefaultCoord, heightInLines*16 ) ); + Init(); + + m_align = align; + SetLabel( label ); +} + +void pxStaticTextImproved::Init() +{ + m_autowrap = true; + m_wrappedWidth = -1; + m_padding_horiz = 8; + + Connect( wxEVT_PAINT, wxPaintEventHandler(pxStaticTextImproved::paintEvent) ); +} + +pxStaticTextImproved& pxStaticTextImproved::Unwrapped() +{ + m_autowrap = false; + UpdateWrapping( false ); + return *this; +} + +void pxStaticTextImproved::UpdateWrapping( bool textChanged ) +{ + if( !m_autowrap ) + { + m_wrappedLabel = wxEmptyString; + m_wrappedWidth = -1; + return; + } + + wxString wrappedLabel; + const int newWidth( GetSize().GetWidth() ); + + if( !textChanged && (newWidth == m_wrappedWidth) ) return; + + // Note: during various stages of sizer-calc, width can be 1, 0, or -1. + // We ignore wrapping in these cases. (the PaintEvent also checks the wrapping + // and updates it if needed, in case the control's size isn't figured out prior + // to being painted). + + m_wrappedWidth = newWidth; + if( m_wrappedWidth > 1 ) + { + wxString label( GetLabel() ); + wrappedLabel = pxTextWrapper().Wrap( this, label, m_wrappedWidth-(m_padding_horiz*2) ).GetResult(); + } + + if( m_wrappedLabel == wrappedLabel ) return; + m_wrappedLabel = wrappedLabel; + Refresh(); +} + +void pxStaticTextImproved::SetLabel(const wxString& label) +{ + const bool labelChanged( label != GetLabel() ); + if( labelChanged ) + { + _parent::SetLabel( label ); + Refresh(); + } + + // Always update wrapping, in case window width or something else also changed. + UpdateWrapping( labelChanged ); +} + +void pxStaticTextImproved::paintEvent(wxPaintEvent& evt) +{ + wxPaintDC dc( this ); + const int dcWidth( dc.GetSize().GetWidth() ); + if( dcWidth < 1 ) return; + + dc.SetFont( GetFont() ); + pxWindowTextWriter writer( dc ); + wxString label; + + if( m_autowrap ) + { + if( m_wrappedLabel.IsEmpty() || m_wrappedWidth != dcWidth ) + { + const wxString original( GetLabel() ); + if( original.IsEmpty() ) return; + m_wrappedLabel = pxTextWrapper().Wrap( this, original, dcWidth-(m_padding_horiz*2) ).GetResult(); + } + label = m_wrappedLabel; + } + else + { + label = GetLabel(); + } + + int tWidth, tHeight; + GetTextExtent( label, &tWidth, &tHeight ); + + writer.Align( m_align ); + if( m_align & wxALIGN_CENTER_VERTICAL ) + writer.SetY( (dc.GetSize().GetHeight() - tHeight) / 2 ); + + writer.WriteLn( label ); +} diff --git a/common/src/Utilities/wxGuiTools.cpp b/common/src/Utilities/wxGuiTools.cpp index e143b70483..789c92fbed 100644 --- a/common/src/Utilities/wxGuiTools.cpp +++ b/common/src/Utilities/wxGuiTools.cpp @@ -349,6 +349,12 @@ pxTextWrapper& pxTextWrapper::Wrap( const wxWindow& win, const wxString& text, i return *this; } +pxTextWrapper& pxTextWrapper::Wrap( const wxWindow* win, const wxString& text, int widthMax ) +{ + if( win ) _parent::Wrap( *win, text, widthMax ); + return *this; +} + void pxTextWrapper::OnOutputLine(const wxString& line) { m_text += line; diff --git a/pcsx2/gui/Dialogs/FirstTimeWizard.cpp b/pcsx2/gui/Dialogs/FirstTimeWizard.cpp index 0e53b246e1..8180efaf1d 100644 --- a/pcsx2/gui/Dialogs/FirstTimeWizard.cpp +++ b/pcsx2/gui/Dialogs/FirstTimeWizard.cpp @@ -74,7 +74,9 @@ FirstTimeWizard::UsermodePage::UsermodePage( wxWizard* parent ) : m_panel_LangSel = new LanguageSelectionPanel( &panel ); m_panel_UserSel = new DocsFolderPickerPanel( &panel ); - panel += panel.Heading(_("PCSX2 is starting from a new or unknown folder and needs to be configured.")); + panel += new pxStaticTextImproved( this, + _("PCSX2 is starting from a new or unknown folder and needs to be configured.") + ) | pxExpand; panel += m_panel_LangSel | StdCenter(); panel += m_panel_UserSel | pxExpand.Border( wxALL, 8 ); diff --git a/pcsx2/gui/Dialogs/McdConfigDialog.cpp b/pcsx2/gui/Dialogs/McdConfigDialog.cpp index d226933ab3..c34673e821 100644 --- a/pcsx2/gui/Dialogs/McdConfigDialog.cpp +++ b/pcsx2/gui/Dialogs/McdConfigDialog.cpp @@ -25,17 +25,6 @@ using namespace pxSizerFlags; -namespace Panels -{ - // Helper class since the 'AddPage' template system needs a single-parameter constructor. - class McdConfigPanel_Multitap2 : public McdConfigPanel_Multitap - { - public: - McdConfigPanel_Multitap2( wxWindow* parent ) : McdConfigPanel_Multitap( parent, 1 ) {} - virtual ~McdConfigPanel_Multitap2() throw() { } - }; -} - wxString GetMsg_McdNtfsCompress() { return pxE( ".Panel:Mcd:NtfsCompress", @@ -109,55 +98,6 @@ void Panels::McdConfigPanel_Toggles::AppStatusEvent_OnSettingsApplied() #endif } -Panels::McdConfigPanel_Standard::McdConfigPanel_Standard(wxWindow *parent) - : _parent( parent ) -{ - m_panel_cardinfo[0] = new MemoryCardInfoPanel( this, 0 ); - m_panel_cardinfo[1] = new MemoryCardInfoPanel( this, 1 ); - - for( uint port=0; port<2; ++port ) - { - wxStaticBoxSizer& portSizer( *new wxStaticBoxSizer( wxVERTICAL, this, wxsFormat(_("Port %u"), port+1) ) ); - portSizer += m_panel_cardinfo[port] | pxExpand; - - *this += portSizer | StdExpand(); - } -} - -void Panels::McdConfigPanel_Standard::Apply() -{ -} - -void Panels::McdConfigPanel_Standard::AppStatusEvent_OnSettingsApplied() -{ -} - -Panels::McdConfigPanel_Multitap::McdConfigPanel_Multitap(wxWindow *parent, int port) : _parent( parent ) -{ - m_port = port; - - m_check_Multitap = new pxCheckBox( this, wxsFormat(_("Enable Multitap on Port %u"), m_port+1) ); - m_check_Multitap->SetFont( wxFont( m_check_Multitap->GetFont().GetPointSize()+1, wxFONTFAMILY_MODERN, wxNORMAL, wxNORMAL, false, L"Lucida Console" ) ); - - *this += m_check_Multitap; - - Connect( m_check_Multitap->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(McdConfigPanel_Multitap::OnMultitapChecked)); -} - -void Panels::McdConfigPanel_Multitap::OnMultitapChecked( wxCommandEvent& evt ) -{ - -} - -void Panels::McdConfigPanel_Multitap::Apply() -{ - -} - -void Panels::McdConfigPanel_Multitap::AppStatusEvent_OnSettingsApplied() -{ - -} using namespace Panels; using namespace pxSizerFlags; diff --git a/pcsx2/gui/Panels/ConfigurationPanels.h b/pcsx2/gui/Panels/ConfigurationPanels.h index 42d1c54089..fb2b68395f 100644 --- a/pcsx2/gui/Panels/ConfigurationPanels.h +++ b/pcsx2/gui/Panels/ConfigurationPanels.h @@ -411,8 +411,6 @@ namespace Panels virtual bool ValidateEnumerationStatus(); }; - class MemoryCardInfoPanel; - // -------------------------------------------------------------------------------------- // PluginSelectorPanel // -------------------------------------------------------------------------------------- diff --git a/pcsx2/gui/Panels/MemoryCardPanels.h b/pcsx2/gui/Panels/MemoryCardPanels.h index 0848f601e8..aa4f57f677 100644 --- a/pcsx2/gui/Panels/MemoryCardPanels.h +++ b/pcsx2/gui/Panels/MemoryCardPanels.h @@ -243,31 +243,6 @@ namespace Panels virtual bool ValidateEnumerationStatus(); }; - // -------------------------------------------------------------------------------------- - // MemoryCardInfoPanel - // -------------------------------------------------------------------------------------- - class MemoryCardInfoPanel : public BaseApplicableConfigPanel - { - protected: - //uint m_port; - uint m_slot; - - wxString m_DisplayName; - wxString m_ErrorMessage; - ScopedPtr m_cardInfo; - - public: - virtual ~MemoryCardInfoPanel() throw() {} - MemoryCardInfoPanel( wxWindow* parent, uint slot ); - void Apply(); - void Eject(); - - protected: - void AppStatusEvent_OnSettingsApplied(); - void paintEvent( wxPaintEvent& evt ); - - }; - // -------------------------------------------------------------------------------------- // McdConfigPanel_Toggles / McdConfigPanel_Standard / McdConfigPanel_Multitap // -------------------------------------------------------------------------------------- @@ -293,40 +268,6 @@ namespace Panels void OnMultitapClicked(); }; - class McdConfigPanel_Standard : public BaseApplicableConfigPanel - { - typedef BaseApplicableConfigPanel _parent; - - protected: - MemoryCardInfoPanel* m_panel_cardinfo[2]; - - public: - McdConfigPanel_Standard( wxWindow* parent ); - virtual ~McdConfigPanel_Standard() throw() { } - void Apply(); - - protected: - void AppStatusEvent_OnSettingsApplied(); - }; - - class McdConfigPanel_Multitap : public BaseApplicableConfigPanel - { - typedef BaseApplicableConfigPanel _parent; - - protected: - int m_port; - pxCheckBox* m_check_Multitap; - - public: - McdConfigPanel_Multitap( wxWindow* parent, int port=0 ); - virtual ~McdConfigPanel_Multitap() throw() { } - void Apply(); - - protected: - void OnMultitapChecked( wxCommandEvent& evt ); - void AppStatusEvent_OnSettingsApplied(); - }; - }; extern bool EnumerateMemoryCard( McdListItem& dest, const wxFileName& filename ); diff --git a/pcsx2/gui/Panels/MemoryCardsPanel.cpp b/pcsx2/gui/Panels/MemoryCardsPanel.cpp deleted file mode 100644 index ecb2fc8d21..0000000000 --- a/pcsx2/gui/Panels/MemoryCardsPanel.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2010 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#include "PrecompiledHeader.h" -#include "ConfigurationPanels.h" -#include "MemoryCardPanels.h" - -#include "Dialogs/ConfigurationDialog.h" - -#include -#include -#include - -using namespace pxSizerFlags; -using namespace Panels; - - -// ===================================================================================================== -// MemoryCardInfoPanel (implementations) -// ===================================================================================================== -MemoryCardInfoPanel::MemoryCardInfoPanel( wxWindow* parent, uint slot ) - : BaseApplicableConfigPanel( parent, wxVERTICAL ) //, wxEmptyString ) -{ - m_slot = slot; - - SetMinSize( wxSize(128, 48) ); - - Connect( wxEVT_PAINT, wxPaintEventHandler(MemoryCardInfoPanel::paintEvent) ); - - // [TODO] Add Unmount button. -} - - -void MemoryCardInfoPanel::paintEvent(wxPaintEvent & evt) -{ - wxPaintDC dc( this ); - pxWindowTextWriter writer( dc ); - - writer.Bold(); - - // Create DC and plot some text (and images!) - writer.WriteLn( m_DisplayName ); - - //dc.DrawCircle( dc.GetSize().GetWidth()/2, 24, dc.GetSize().GetWidth()/4 ); - - if( !m_ErrorMessage.IsEmpty() ) - { - writer.WriteLn(); - writer.WriteLn( m_ErrorMessage ); - } - else if( m_cardInfo ) - { - writer.Normal(); - - writer.WriteLn( wxsFormat( L"%d MB (%s)", - m_cardInfo->SizeInMB, - m_cardInfo->IsFormatted ? _("Formatted") : _("Unformatted") ) - ); - } -} - -void MemoryCardInfoPanel::Eject() -{ - m_cardInfo = NULL; - Refresh(); -} - -void MemoryCardInfoPanel::Apply() -{ - if( m_cardInfo && m_cardInfo->Filename.GetFullName().IsEmpty() ) m_cardInfo = NULL; - - if( m_cardInfo ) - { - wxFileName absfile( Path::Combine( g_Conf->Folders.MemoryCards, m_cardInfo->Filename ) ); - - // The following checks should be theoretically unreachable, unless the user's - // filesystem is changed form under our nose. A little validation goes a - // long way. :p - - if( absfile.IsDir() ) - { - Eject(); - throw Exception::CannotApplySettings( this, - // Diagnostic - wxsFormat( L"Memory card in slot %u conflicts with an existing directory.", m_slot ), - // Translated - wxsFormat( - _("Cannot use or create the memory card in slot %u: the filename conflicts with an existing directory."), - m_slot - ) - ); - } - - if( !absfile.FileExists() ) - { - Eject(); - throw Exception::CannotApplySettings( this, - // Diagnostic - wxsFormat( L"Memory card in slot %u is no longer valid.", m_slot ), - // Translated - wxsFormat( - _("The configured memory card in slot %u no longer exists. Please create a new memory card, or leave the slot unmounted."), - m_slot - ) - ); - } - - g_Conf->Mcd[m_slot].Filename = m_cardInfo->Filename; - g_Conf->Mcd[m_slot].Enabled = true; - } - else - { - // Card is either disabled or in an error state. - - g_Conf->Mcd[m_slot].Enabled = false; - g_Conf->Mcd[m_slot].Filename.Clear(); - } -} - -void MemoryCardInfoPanel::AppStatusEvent_OnSettingsApplied() -{ - m_cardInfo = NULL; - - // Collect Info and Format Strings - - wxString fname( g_Conf->Mcd[m_slot].Filename.GetFullPath() ); - if( fname.IsEmpty() ) - { - m_DisplayName = _("No Card (empty)"); - m_cardInfo = NULL; - } - else - { - wxFileName absfile( Path::Combine( g_Conf->Folders.MemoryCards, fname ) ); - wxFileName relfile( fname ); - - if( !m_cardInfo ) - { - m_cardInfo = new McdListItem(); - if( !EnumerateMemoryCard( *m_cardInfo, absfile.GetFullPath() ) ) - { - m_ErrorMessage = _("Read Error: Card is truncated or corrupted."); - } - } - - absfile.Normalize(); - relfile.Normalize(); - - m_DisplayName = ( absfile == relfile ) ? relfile.GetFullName() : relfile.GetFullPath(); - } - - Refresh(); -} diff --git a/pcsx2/gui/Panels/MiscPanelStuff.cpp b/pcsx2/gui/Panels/MiscPanelStuff.cpp index 01fd2844db..b3cf903df6 100644 --- a/pcsx2/gui/Panels/MiscPanelStuff.cpp +++ b/pcsx2/gui/Panels/MiscPanelStuff.cpp @@ -32,6 +32,8 @@ using namespace pxSizerFlags; Panels::DocsFolderPickerPanel::DocsFolderPickerPanel( wxWindow* parent, bool isFirstTime ) : BaseApplicableConfigPanel( parent, wxVERTICAL, _("Usermode Selection") ) { + SetMinSize( wxSize( GetIdealWidth() - 16, wxDefaultCoord ) ); + const wxString usermodeExplained( pxE( ".Panel:Usermode:Explained", L"Please select your preferred default location for PCSX2 user-level documents below " L"(includes memory cards, screenshots, settings, and savestates). " @@ -64,7 +66,7 @@ Panels::DocsFolderPickerPanel::DocsFolderPickerPanel( wxWindow* parent, bool isF m_dirpicker_custom = new DirPickerPanel( this, FolderId_Documents, _("Select a document root for PCSX2") ); - *this += Text( isFirstTime ? usermodeExplained : usermodeWarning ); + *this += new pxStaticTextImproved( this, 3, isFirstTime ? usermodeExplained : usermodeWarning ) | pxExpand; *this += m_radio_UserMode | StdExpand(); *this += m_dirpicker_custom | pxExpand.Border( wxLEFT, StdPadding + m_radio_UserMode->GetIndentation() ); *this += 4; diff --git a/pcsx2/gui/Panels/VideoPanel.cpp b/pcsx2/gui/Panels/VideoPanel.cpp index 493f6e54a1..aaafa2e379 100644 --- a/pcsx2/gui/Panels/VideoPanel.cpp +++ b/pcsx2/gui/Panels/VideoPanel.cpp @@ -100,7 +100,8 @@ Panels::FramelimiterPanel::FramelimiterPanel( wxWindow* parent ) *this += 5; - *this += Heading( pxE( ".Panel:Framelimiter:Heading", + //*this += Heading( pxE( ".Panel:Framelimiter:Heading", + *this += new pxStaticTextImproved( this, pxE( ".Panel:Framelimiter:Heading", L"The internal framelimiter regulates the speed of the virtual machine. Adjustment values below are in " L"percentages of the default region-based framerate, which can also be configured below." ) ); diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj index e40ca793c4..c821472eec 100644 --- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj +++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj @@ -492,54 +492,6 @@ > - - - - - - - - - - - - - - - - - - - - - @@ -2936,10 +2888,6 @@ RelativePath="..\..\gui\Panels\MemoryCardPanels.h" > - -