Added some more convenience operators for wx interface construction. These are intended as a substitute for wxSizerFlags(), like so:

*target += control | wxSizerFlags().Expand().Centre()
// becomes:
*target += control | pxExpand | pxCentre;

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2227 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-11-20 03:26:10 +00:00
parent 08f67ebdee
commit d6f9462ffa
8 changed files with 260 additions and 78 deletions

View File

@ -24,10 +24,88 @@
#include <wx/wx.h>
class pxStaticText;
class pxStaticHeading;
class pxCheckBox;
#define wxSF wxSizerFlags()
// --------------------------------------------------------------------------------------
// pxAlignment / pxStretchType
// --------------------------------------------------------------------------------------
// These are full blown class types instead of enumerations because wxSizerFlags has an
// implicit conversion from integer (silly design flaw creating more work for me!)
//
struct pxAlignmentType
{
enum
{
Centre,
Center = Centre,
Middle,
Left,
Right,
Top,
Bottom
};
int intval;
wxSizerFlags Apply( wxSizerFlags flags=wxSizerFlags() ) const;
operator wxSizerFlags() const
{
return Apply();
}
wxSizerFlags operator | ( const wxSizerFlags& _flgs )
{
return Apply( _flgs );
}
};
struct pxStretchType
{
enum
{
Shrink,
Expand,
Shaped,
ReserveHidden,
FixedMinimum
};
int intval;
wxSizerFlags Apply( wxSizerFlags flags=wxSizerFlags() ) const;
operator wxSizerFlags() const
{
return Apply();
}
wxSizerFlags operator | ( const wxSizerFlags& _flgs )
{
return Apply( _flgs );
}
};
extern const pxAlignmentType
pxCentre, // Horizontal centered alignment
pxCenter,
pxMiddle, // vertical centered alignment
pxAlignLeft,
pxAlignRight,
pxAlignTop,
pxAlignBottom;
extern const pxStretchType
pxShrink,
pxExpand,
pxShaped,
pxReserveHidden,
pxFixedMinimum;
// --------------------------------------------------------------------------------------
// pxWindowAndFlags
// --------------------------------------------------------------------------------------
@ -49,29 +127,40 @@ struct pxWindowAndFlags
wxSizerFlags flags;
};
__forceinline wxSizerFlags operator | ( const wxSizerFlags& _flgs, pxAlignmentType align )
{
return align.Apply( _flgs );
}
__forceinline wxSizerFlags operator | ( const wxSizerFlags& _flgs, pxStretchType stretch )
{
return stretch.Apply( _flgs );
}
template< typename WinType >
static pxWindowAndFlags<WinType> operator | ( WinType* _win, const wxSizerFlags& _flgs )
pxWindowAndFlags<WinType> operator | ( WinType* _win, const wxSizerFlags& _flgs )
{
pxWindowAndFlags<WinType> result = { _win, _flgs };
return result;
}
template< typename WinType >
static pxWindowAndFlags<WinType> operator | ( WinType& _win, const wxSizerFlags& _flgs )
pxWindowAndFlags<WinType> operator | ( WinType& _win, const wxSizerFlags& _flgs )
{
pxWindowAndFlags<WinType> result = { &_win, _flgs };
return result;
}
template< typename WinType >
static pxWindowAndFlags<WinType> operator | ( const wxSizerFlags& _flgs, WinType* _win )
pxWindowAndFlags<WinType> operator | ( const wxSizerFlags& _flgs, WinType* _win )
{
pxWindowAndFlags<WinType> result = { _win, _flgs };
return result;
}
template< typename WinType >
static pxWindowAndFlags<WinType> operator | ( const wxSizerFlags& _flgs, WinType& _win )
pxWindowAndFlags<WinType> operator | ( const wxSizerFlags& _flgs, WinType& _win )
{
pxWindowAndFlags<WinType> result = { &_win, _flgs };
return result;
@ -91,10 +180,11 @@ static pxWindowAndFlags<WinType> operator | ( const wxSizerFlags& _flgs, WinType
extern void operator+=( wxSizer& target, wxWindow* src );
extern void operator+=( wxSizer& target, wxSizer* src );
extern void operator+=( wxSizer& target, int spacer );
extern void operator+=( wxPanel& target, int spacer );
extern void operator+=( wxDialog& target, int spacer );
extern void operator+=( wxWindow& target, wxWindow* src );
extern void operator+=( wxWindow& target, wxSizer* src );
extern void operator+=( wxWindow& target, int spacer );
template< typename WinType >
void operator+=( wxSizer& target, const pxWindowAndFlags<WinType>& src )
@ -103,34 +193,12 @@ void operator+=( wxSizer& target, const pxWindowAndFlags<WinType>& src )
}
template< typename WinType >
void operator+=( wxPanel& target, const pxWindowAndFlags<WinType>& src )
void operator+=( wxWindow& target, const pxWindowAndFlags<WinType>& src )
{
if( !pxAssert( target.GetSizer() != NULL ) ) return;
*target.GetSizer() += src;
}
template< typename WinType >
void operator+=( wxPanel& target, WinType* src )
{
if( !pxAssert( target.GetSizer() != NULL ) ) return;
*target.GetSizer() += src;
}
template< typename WinType >
void operator+=( wxDialog& target, const pxWindowAndFlags<WinType>& src )
{
if( !pxAssert( target.GetSizer() != NULL ) ) return;
*target.GetSizer() += src;
}
template< typename WinType >
void operator+=( wxDialog& target, WinType* src )
{
if( !pxAssert( target.GetSizer() != NULL ) ) return;
*target.GetSizer() += src;
}
// ----------------------------------------------------------------------------
// wxGuiTools.h
//
@ -170,6 +238,8 @@ public:
virtual ~wxDialogWithHelpers() throw();
void AddOkCancel( wxSizer& sizer, bool hasApply=false );
pxStaticText* StaticText( const wxString& label );
pxStaticHeading* StaticHeading( const wxString& label );
wxDialogWithHelpers& SetIdealWidth( int newWidth ) { m_idealWidth = newWidth; return *this; }
int GetIdealWidth() const { return m_idealWidth; }
@ -211,6 +281,9 @@ public:
wxPanelWithHelpers* AddStaticBox( const wxString& label, wxOrientation orient=wxVERTICAL );
pxStaticText* StaticText( const wxString& label );
pxStaticHeading* StaticHeading( const wxString& label );
// TODO : Propagate to children?
wxPanelWithHelpers& SetIdealWidth( int width ) { m_idealWidth = width; return *this; }
int GetIdealWidth() const { return m_idealWidth; }

View File

@ -126,3 +126,4 @@ void operator+=( wxSizer& target, pxStaticText* src )
if( !pxAssert( src != NULL ) ) return;
src->AddTo( target );
}

View File

@ -15,10 +15,124 @@
#include "PrecompiledHeader.h"
#include "wxGuiTools.h"
#include "pxStaticText.h"
#include <wx/app.h>
#include <wx/window.h>
const pxAlignmentType
pxCentre = { pxAlignmentType::Center }, // Horizontal centered alignment
pxCenter = pxCentre,
pxMiddle = { pxAlignmentType::Middle }, // vertical centered alignment
pxAlignLeft = { pxAlignmentType::Left },
pxAlignRight = { pxAlignmentType::Right },
pxAlignTop = { pxAlignmentType::Top },
pxAlignBottom = { pxAlignmentType::Bottom };
const pxStretchType
pxShrink = { pxStretchType::Shrink },
pxExpand = { pxStretchType::Expand },
pxShaped = { pxStretchType::Shaped },
pxReserveHidden = { pxStretchType::ReserveHidden },
pxFixedMinimum = { pxStretchType::FixedMinimum };
wxSizerFlags pxAlignmentType::Apply( wxSizerFlags flags ) const
{
switch( intval )
{
case Centre:
flags.Align( flags.GetFlags() | wxALIGN_CENTRE_HORIZONTAL );
break;
case Middle:
flags.Align( flags.GetFlags() | wxALIGN_CENTRE_VERTICAL );
break;
case Left:
flags.Left();
break;
case Right:
flags.Right();
break;
case Top:
flags.Top();
break;
case Bottom:
flags.Bottom();
break;
}
return flags;
}
wxSizerFlags pxStretchType::Apply( wxSizerFlags flags ) const
{
switch( intval )
{
case Shrink:
//pxFail( "wxSHRINK is an ignored stretch flag." );
break;
case Expand:
flags.Expand();
break;
case Shaped:
flags.Shaped();
break;
case ReserveHidden:
flags.ReserveSpaceEvenIfHidden();
break;
case FixedMinimum:
flags.FixedMinSize();
break;
//case Tile:
// pxAssert( "pxTile is an unsupported stretch tag (ignored)." );
//break;
}
return flags;
}
void operator+=( wxSizer& target, wxWindow* src )
{
target.Add( src );
}
void operator+=( wxSizer& target, wxSizer* src )
{
target.Add( src );
}
void operator+=( wxSizer& target, int spacer )
{
target.AddSpacer( spacer );
}
void operator+=( wxWindow& target, wxWindow* src )
{
if( !pxAssert( target.GetSizer() != NULL ) ) return;
*target.GetSizer() += src;
}
void operator+=( wxWindow& target, wxSizer* src )
{
if( !pxAssert( target.GetSizer() != NULL ) ) return;
*target.GetSizer() += src;
}
void operator+=( wxWindow& target, int spacer )
{
if( !pxAssert( target.GetSizer() != NULL ) ) return;
target.GetSizer()->AddSpacer( spacer );
}
// Returns FALSE if the window position is considered invalid, which means that it's title
// bar is most likely not easily grabble. Such a window should be moved to a valid or
// default position.
@ -98,33 +212,6 @@ wxSizerFlags pxSizerFlags::Checkbox()
return StdExpand();
}
void operator+=( wxSizer& target, wxWindow* src )
{
target.Add( src );
}
void operator+=( wxSizer& target, wxSizer* src )
{
target.Add( src );
}
void operator+=( wxSizer& target, int spacer )
{
target.AddSpacer( spacer );
}
void operator+=( wxPanel& target, int spacer )
{
if( !pxAssert( target.GetSizer() != NULL ) ) return;
target.GetSizer()->AddSpacer( spacer );
}
void operator+=( wxDialog& target, int spacer )
{
if( !pxAssert( target.GetSizer() != NULL ) ) return;
target.GetSizer()->AddSpacer( spacer );
}
// --------------------------------------------------------------------------------------
// pxTextWrapper / pxTextWrapperBase Implementations
// --------------------------------------------------------------------------------------

View File

@ -78,6 +78,16 @@ wxDialogWithHelpers::~wxDialogWithHelpers() throw()
pxAssert( m_DialogIdents[GetId()] >= 0 );
}
pxStaticText* wxDialogWithHelpers::StaticText( const wxString& label )
{
return new pxStaticText( this, label );
}
pxStaticHeading* wxDialogWithHelpers::StaticHeading( const wxString& label )
{
return new pxStaticHeading( this, label );
}
void wxDialogWithHelpers::OnActivate(wxActivateEvent& evt)
{
//evt.Skip();
@ -172,6 +182,17 @@ wxPanelWithHelpers* wxPanelWithHelpers::AddStaticBox( const wxString& label, wxO
return this;
}
pxStaticText* wxPanelWithHelpers::StaticText( const wxString& label )
{
return new pxStaticText( this, label );
}
pxStaticHeading* wxPanelWithHelpers::StaticHeading( const wxString& label )
{
return new pxStaticHeading( this, label );
}
wxPanelWithHelpers::wxPanelWithHelpers( wxWindow* parent, wxOrientation orient, const wxString& staticBoxLabel )
: wxPanel( parent )
{

View File

@ -84,7 +84,7 @@ Dialogs::AboutBoxDialog::AboutBoxDialog( wxWindow* parent, int id ):
SetSizer( new wxBoxSizer( wxVERTICAL ) );
*this += new pxStaticText( this, _("PCSX2 - Playstation 2 Emulator") );
*this += StaticText(_("PCSX2 - Playstation 2 Emulator"));
// This sizer holds text of the authors and a logo!
wxBoxSizer& AuthLogoSizer = *new wxBoxSizer( wxHORIZONTAL );

View File

@ -86,7 +86,7 @@ Panels::BiosSelectorPanel::BiosSelectorPanel( wxWindow* parent, int idealWidth )
m_FolderPicker.SetStaticDesc( _("Click the Browse button to select a different folder where PCSX2 will look for PS2 BIOS roms.") );
*this += new pxStaticText( this, _("Select a BIOS rom:") );
*this += StaticText(_("Select a BIOS rom:"));
*this += m_ComboBox | pxSizerFlags::StdExpand();
*this += 6;
*this += m_FolderPicker | pxSizerFlags::StdExpand();

View File

@ -167,7 +167,7 @@ Panels::UsermodeSelectionPanel::UsermodeSelectionPanel( wxWindow* parent, bool i
m_radio_UserMode->SetPaddingHoriz( m_radio_UserMode->GetPaddingHoriz() + 4 );
m_radio_UserMode->Realize();
*this += new pxStaticText( this, isFirstTime ? usermodeExplained : usermodeWarning );
*this += StaticText( (isFirstTime ? usermodeExplained : usermodeWarning) );
*this += m_radio_UserMode | pxSizerFlags::StdExpand();
*this += 4;
}
@ -201,7 +201,7 @@ Panels::LanguageSelectionPanel::LanguageSelectionPanel( wxWindow* parent )
size, compiled.GetPtr(), wxCB_READONLY | wxCB_SORT );
m_picker->SetSelection( cursel );
*this += new pxStaticText( this, _("Select a language: "), wxALIGN_CENTRE_VERTICAL );
*this += StaticText(_("Select a language: ")) | pxMiddle;
*this += 5;
*this += m_picker | pxSizerFlags::StdSpace();
}

View File

@ -89,22 +89,22 @@ Panels::FramelimiterPanel::FramelimiterPanel( wxWindow* parent )
wxFlexGridSizer& s_spins( *new wxFlexGridSizer( 5 ) );
s_spins.AddGrowableCol( 0 );
s_spins += new pxStaticText( this, _("Base Framerate Adjust:") );
s_spins += StaticText(_("Base Framerate Adjust:"));
s_spins += 5;
s_spins += m_spin_NominalPct | wxSF.Border(wxTOP, 3);
s_spins += new pxStaticText( this, L"%" );
s_spins += StaticText(L"%" );
s_spins += 5;
s_spins += new pxStaticText( this, _("Slow Motion Adjust:") );
s_spins += StaticText(_("Slow Motion Adjust:"));
s_spins += 5;
s_spins += m_spin_SlomoPct | wxSF.Border(wxTOP, 3);
s_spins += new pxStaticText( this, L"%" );
s_spins += StaticText(L"%" );
s_spins += 5;
s_spins += new pxStaticText( this, _("Turbo Adjust:") );
s_spins += StaticText(_("Turbo Adjust:"));
s_spins += 5;
s_spins += m_spin_TurboPct | wxSF.Border(wxTOP, 3);
s_spins += new pxStaticText( this, L"%" );
s_spins += StaticText(L"%" );
s_spins += 5;
s_spins += 15;
@ -116,20 +116,20 @@ Panels::FramelimiterPanel::FramelimiterPanel( wxWindow* parent )
wxFlexGridSizer& s_fps( *new wxFlexGridSizer( 5 ) );
s_fps.AddGrowableCol( 0 );
s_fps += new pxStaticText( this, _("NTSC Framerate:") );
s_fps += StaticText(_("NTSC Framerate:"));
s_fps += 5;
s_fps += m_text_BaseNtsc | wxSF.Align(wxALIGN_RIGHT).Border(wxTOP, 3);
s_fps += new pxStaticText( this, _("FPS") );
s_fps += m_text_BaseNtsc | wxSF.Right().Border(wxTOP, 3);
s_fps += StaticText(_("FPS"));
s_fps += 5;
s_fps += new pxStaticText( this, _("PAL Framerate:") );
s_fps += StaticText(_("PAL Framerate:"));
s_fps += 5;
s_fps += m_text_BasePal | wxSF.Align(wxALIGN_RIGHT).Border(wxTOP, 3);
s_fps += new pxStaticText( this, _("FPS") );
s_fps += m_text_BasePal | wxSF.Right().Border(wxTOP, 3);
s_fps += StaticText(_("FPS"));
s_fps += 5;
*this += s_spins | wxSizerFlags().Expand();
*this += s_fps | wxSizerFlags().Expand();
*this += s_spins | pxExpand;
*this += s_fps | pxExpand;
m_spin_NominalPct ->SetValue( 100 );
m_spin_SlomoPct ->SetValue( 50 );
@ -183,7 +183,7 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent )
wxBoxSizer& s_customsize( *new wxBoxSizer( wxHORIZONTAL ) );
s_customsize += m_text_WindowWidth;
s_customsize += new pxStaticText( this, L"x" );
s_customsize += StaticText(L"x" );
s_customsize += m_text_WindowHeight;
//wxFlexGridSizer& s_winsize( *new wxFlexGridSizer( 2 ) );
@ -226,8 +226,8 @@ Panels::VideoPanel::VideoPanel( wxWindow* parent ) :
wxFlexGridSizer* s_table = new wxFlexGridSizer( 2 );
*left += winpan | wxSizerFlags().Expand();
*right += fpan | wxSizerFlags().Expand();
*left += winpan | pxExpand;
*right += fpan | pxExpand;
*s_table += left | StdExpand();
*s_table += right | StdExpand();