2009-11-18 07:53:02 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2009-11-18 07:53:02 +00:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PrecompiledHeader.h"
|
|
|
|
#include "pxStaticText.h"
|
2010-06-04 08:00:19 +00:00
|
|
|
#include <wx/wizard.h>
|
2009-11-18 07:53:02 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
2010-06-04 08:00:19 +00:00
|
|
|
// pxStaticText (implementations)
|
2009-11-18 07:53:02 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2010-06-04 08:00:19 +00:00
|
|
|
pxStaticText::pxStaticText( wxWindow* parent )
|
2010-06-06 23:26:07 +00:00
|
|
|
: _parent( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER )
|
2010-06-04 08:00:19 +00:00
|
|
|
{
|
|
|
|
m_heightInLines = 1;
|
|
|
|
}
|
2009-11-18 07:53:02 +00:00
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
pxStaticText::pxStaticText( wxWindow* parent, const wxString& label, wxAlignment align )
|
2010-06-06 23:26:07 +00:00
|
|
|
: _parent( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
m_heightInLines = 1;
|
|
|
|
m_align = align;
|
|
|
|
|
|
|
|
SetPaddingDefaults();
|
|
|
|
Init( label );
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
void pxStaticText::Init( const wxString& label )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
m_autowrap = true;
|
|
|
|
m_wrappedWidth = -1;
|
2010-06-06 23:26:07 +00:00
|
|
|
m_label = label;
|
2010-06-04 08:00:19 +00:00
|
|
|
Connect( wxEVT_PAINT, wxPaintEventHandler(pxStaticText::paintEvent) );
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
// we need to refresh the window after changing its size as the standard
|
|
|
|
// control doesn't always update itself properly (fials typically on window resizes where
|
|
|
|
// the control is expanded to fit -- ie the control's size changes but the position does not)
|
|
|
|
void pxStaticText::DoSetSize(int x, int y, int w, int h, int sizeFlags)
|
|
|
|
{
|
|
|
|
_parent::DoSetSize(x, y, w, h, sizeFlags);
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
void pxStaticText::SetPaddingDefaults()
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
m_paddingPix_horiz = 7;
|
|
|
|
m_paddingPix_vert = 1;
|
|
|
|
|
|
|
|
m_paddingPct_horiz = 0.0f;
|
|
|
|
m_paddingPct_vert = 0.0f;
|
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
pxStaticText& pxStaticText::SetMinWidth( int width )
|
|
|
|
{
|
|
|
|
SetMinSize( wxSize( width, GetMinHeight() ) );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
pxStaticText& pxStaticText::SetMinHeight( int height )
|
|
|
|
{
|
|
|
|
SetMinSize( wxSize( GetMinWidth(), height) );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
pxStaticText& pxStaticText::SetHeight( int lines )
|
|
|
|
{
|
|
|
|
if( !pxAssert(lines > 0) ) lines = 2;
|
|
|
|
m_heightInLines = lines;
|
|
|
|
|
2010-06-09 17:37:11 +00:00
|
|
|
const int newHeight = (pxGetCharHeight(this)*m_heightInLines) + (m_paddingPix_vert*2);
|
2010-06-04 08:00:19 +00:00
|
|
|
SetMinSize( wxSize(GetMinWidth(), newHeight) );
|
|
|
|
|
2009-11-18 07:53:02 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
pxStaticText& pxStaticText::Bold()
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
wxFont bold( GetFont() );
|
|
|
|
bold.SetWeight(wxBOLD);
|
|
|
|
SetFont( bold );
|
|
|
|
return *this;
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
pxStaticText& pxStaticText::PaddingPixH( int pixels )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
m_paddingPix_horiz = pixels;
|
|
|
|
UpdateWrapping( false );
|
|
|
|
Refresh();
|
|
|
|
return *this;
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
pxStaticText& pxStaticText::PaddingPixV( int pixels )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
m_paddingPix_vert = pixels;
|
|
|
|
Refresh();
|
2009-11-18 07:53:02 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
pxStaticText& pxStaticText::PaddingPctH( float pct )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
pxAssume( pct < 0.5 );
|
|
|
|
|
|
|
|
m_paddingPct_horiz = pct;
|
|
|
|
UpdateWrapping( false );
|
|
|
|
Refresh();
|
|
|
|
return *this;
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
pxStaticText& pxStaticText::PaddingPctV( float pct )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
pxAssume( pct < 0.5 );
|
|
|
|
|
|
|
|
m_paddingPct_vert = pct;
|
|
|
|
Refresh();
|
|
|
|
return *this;
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
pxStaticText& pxStaticText::Unwrapped()
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
m_autowrap = false;
|
|
|
|
UpdateWrapping( false );
|
|
|
|
return *this;
|
|
|
|
}
|
2009-11-18 07:53:02 +00:00
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
int pxStaticText::calcPaddingWidth( int newWidth ) const
|
|
|
|
{
|
|
|
|
return (int)(newWidth*m_paddingPct_horiz*2) + (m_paddingPix_horiz*2);
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
int pxStaticText::calcPaddingHeight( int newHeight ) const
|
|
|
|
{
|
|
|
|
return (int)(newHeight*m_paddingPct_vert*2) + (m_paddingPix_vert*2);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSize pxStaticText::GetBestWrappedSize( const wxClientDC& dc ) const
|
|
|
|
{
|
|
|
|
pxAssume( m_autowrap );
|
|
|
|
|
|
|
|
// Find an ideal(-ish) width, based on a search of all parent controls and their
|
|
|
|
// valid Minimum sizes.
|
|
|
|
|
|
|
|
int idealWidth = wxDefaultCoord;
|
|
|
|
int parentalAdjust = 0;
|
2010-06-05 14:25:41 +00:00
|
|
|
double parentalFactor = 1.0;
|
2010-06-04 08:00:19 +00:00
|
|
|
const wxWindow* millrun = this;
|
|
|
|
|
|
|
|
while( millrun )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
// IMPORTANT : wxWizard changes its min size and then expects everything else
|
|
|
|
// to play nice and NOT resize according to the new min size. (wtf stupid)
|
|
|
|
// Anyway, this fixes it -- ignore min size specifier on wxWizard!
|
|
|
|
if( wxIsKindOf( millrun, wxWizard ) ) break;
|
2009-11-18 07:53:02 +00:00
|
|
|
|
2010-06-05 14:25:41 +00:00
|
|
|
int min = (int)((millrun->GetMinWidth() - parentalAdjust) * parentalFactor);
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
if( min > 0 && ((idealWidth < 0 ) || (min < idealWidth)) )
|
|
|
|
{
|
|
|
|
idealWidth = min;
|
|
|
|
}
|
2009-11-18 07:53:02 +00:00
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
parentalAdjust += pxSizerFlags::StdPadding*2;
|
2009-11-18 07:53:02 +00:00
|
|
|
millrun = millrun->GetParent();
|
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
if( idealWidth <= 0 )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-06 04:17:43 +00:00
|
|
|
// FIXME: The minimum size of this control is unknown, so let's just pick a guess based on
|
|
|
|
// the size of the user's display area.
|
|
|
|
|
|
|
|
idealWidth = (int)(wxGetDisplaySize().GetWidth() * 0.66) - (parentalAdjust*2);
|
2010-06-04 08:00:19 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
return dc.GetMultiLineTextExtent(pxTextWrapper().Wrap( this, m_label, idealWidth - calcPaddingWidth(idealWidth) ).GetResult());
|
2010-06-04 08:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pxStaticText& pxStaticText::WrapAt( int width )
|
|
|
|
{
|
|
|
|
m_autowrap = false;
|
|
|
|
|
|
|
|
if( (width <= 1) || (width == m_wrappedWidth) ) return *this;
|
|
|
|
|
|
|
|
wxString wrappedLabel;
|
|
|
|
m_wrappedWidth = width;
|
|
|
|
|
|
|
|
if( width > 1 )
|
2010-06-06 23:26:07 +00:00
|
|
|
wrappedLabel = pxTextWrapper().Wrap( this, m_label, width ).GetResult();
|
2009-11-18 07:53:02 +00:00
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
if(m_wrappedLabel != wrappedLabel )
|
|
|
|
{
|
|
|
|
m_wrappedLabel = wrappedLabel;
|
|
|
|
wxSize area = wxClientDC( this ).GetMultiLineTextExtent(m_wrappedLabel);
|
|
|
|
SetMinSize( wxSize(
|
|
|
|
area.GetWidth() + calcPaddingWidth(area.GetWidth()),
|
|
|
|
area.GetHeight() + calcPaddingHeight(area.GetHeight())
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
return *this;
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
bool pxStaticText::_updateWrapping( bool textChanged )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
if( !m_autowrap )
|
|
|
|
{
|
|
|
|
//m_wrappedLabel = wxEmptyString;
|
|
|
|
//m_wrappedWidth = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString wrappedLabel;
|
|
|
|
int newWidth = GetSize().GetWidth();
|
|
|
|
newWidth -= (int)(newWidth*m_paddingPct_horiz*2) + (m_paddingPix_horiz*2);
|
|
|
|
|
|
|
|
if( !textChanged && (newWidth == m_wrappedWidth) ) return false;
|
|
|
|
|
|
|
|
// 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 )
|
2010-06-06 23:26:07 +00:00
|
|
|
wrappedLabel = pxTextWrapper().Wrap( this, m_label, m_wrappedWidth ).GetResult();
|
2010-06-04 08:00:19 +00:00
|
|
|
|
|
|
|
if( m_wrappedLabel == wrappedLabel ) return false;
|
|
|
|
m_wrappedLabel = wrappedLabel;
|
|
|
|
|
|
|
|
return true;
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
void pxStaticText::UpdateWrapping( bool textChanged )
|
2009-11-18 07:53:02 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
if( _updateWrapping( textChanged ) ) Refresh();
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
2009-11-19 13:44:44 +00:00
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
void pxStaticText::SetLabel(const wxString& label)
|
2009-11-19 13:44:44 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
const bool labelChanged( label != m_label );
|
2010-06-04 08:00:19 +00:00
|
|
|
if( labelChanged )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
m_label = label;
|
2010-06-04 08:00:19 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always update wrapping, in case window width or something else also changed.
|
|
|
|
UpdateWrapping( labelChanged );
|
2010-06-08 12:09:28 +00:00
|
|
|
InvalidateBestSize();
|
2009-11-19 13:44:44 +00:00
|
|
|
}
|
2009-11-20 03:26:10 +00:00
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
wxFont pxStaticText::GetFontOk() const
|
2009-11-25 03:54:57 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
wxFont font( GetFont() );
|
|
|
|
if( !font.Ok() ) return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
|
|
|
return font;
|
2009-11-25 03:54:57 +00:00
|
|
|
}
|
2009-12-14 12:18:55 +00:00
|
|
|
|
2010-06-05 14:25:41 +00:00
|
|
|
bool pxStaticText::Enable( bool enabled )
|
|
|
|
{
|
|
|
|
if( _parent::Enable(enabled))
|
|
|
|
{
|
|
|
|
Refresh();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-04 08:00:19 +00:00
|
|
|
void pxStaticText::paintEvent(wxPaintEvent& evt)
|
2009-12-14 12:18:55 +00:00
|
|
|
{
|
2010-06-04 08:00:19 +00:00
|
|
|
wxPaintDC dc( this );
|
|
|
|
const int dcWidth = dc.GetSize().GetWidth();
|
|
|
|
const int dcHeight = dc.GetSize().GetHeight();
|
|
|
|
if( dcWidth < 1 ) return;
|
|
|
|
dc.SetFont( GetFontOk() );
|
|
|
|
|
2010-06-05 14:25:41 +00:00
|
|
|
if( IsEnabled() )
|
|
|
|
dc.SetTextForeground(GetForegroundColour());
|
|
|
|
else
|
|
|
|
dc.SetTextForeground(*wxLIGHT_GREY);
|
2010-06-04 08:00:19 +00:00
|
|
|
|
|
|
|
pxWindowTextWriter writer( dc );
|
|
|
|
writer.Align( m_align );
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
const wxString& label( m_autowrap ? m_wrappedLabel : m_label );
|
|
|
|
if( m_autowrap ) _updateWrapping( false );
|
2010-06-04 08:00:19 +00:00
|
|
|
|
|
|
|
int tWidth, tHeight;
|
|
|
|
dc.GetMultiLineTextExtent( label, &tWidth, &tHeight );
|
|
|
|
|
|
|
|
writer.Align( m_align );
|
|
|
|
if( m_align & wxALIGN_CENTER_VERTICAL )
|
|
|
|
writer.SetY( (dcHeight - tHeight) / 2 );
|
|
|
|
else
|
|
|
|
writer.SetY( (int)(dcHeight*m_paddingPct_vert) + m_paddingPix_vert );
|
|
|
|
|
|
|
|
writer.WriteLn( label ); // without formatting please.
|
|
|
|
|
|
|
|
//dc.SetBrush( *wxTRANSPARENT_BRUSH );
|
|
|
|
//dc.DrawRectangle(wxPoint(), dc.GetSize());
|
2009-12-14 12:18:55 +00:00
|
|
|
}
|
2010-06-04 08:00:19 +00:00
|
|
|
|
|
|
|
// Overloaded form wxPanel and friends.
|
|
|
|
wxSize pxStaticText::DoGetBestSize() const
|
|
|
|
{
|
|
|
|
wxClientDC dc( const_cast<pxStaticText*>(this) );
|
|
|
|
dc.SetFont( GetFontOk() );
|
|
|
|
|
|
|
|
wxSize best;
|
|
|
|
|
|
|
|
if( m_autowrap )
|
|
|
|
{
|
|
|
|
best = GetBestWrappedSize(dc);
|
2010-06-08 12:09:28 +00:00
|
|
|
//best.x = wxDefaultCoord;
|
2010-06-04 08:00:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No autowrapping, so we can force a specific size here!
|
|
|
|
best = dc.GetMultiLineTextExtent( GetLabel() );
|
|
|
|
best.x += calcPaddingWidth( best.x );
|
|
|
|
}
|
|
|
|
|
|
|
|
best.y += calcPaddingHeight( best.y );
|
|
|
|
|
|
|
|
CacheBestSize(best);
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// pxStaticHeading (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
pxStaticHeading::pxStaticHeading( wxWindow* parent, const wxString& label )
|
|
|
|
: _parent( parent )
|
|
|
|
{
|
|
|
|
m_align = wxALIGN_CENTER;
|
|
|
|
|
|
|
|
SetPaddingDefaults();
|
|
|
|
Init( label );
|
|
|
|
}
|
|
|
|
|
|
|
|
void pxStaticHeading::SetPaddingDefaults()
|
|
|
|
{
|
|
|
|
m_paddingPix_horiz = 4;
|
|
|
|
m_paddingPix_vert = 1;
|
|
|
|
|
|
|
|
m_paddingPct_horiz = 0.08f;
|
|
|
|
m_paddingPct_vert = 0.0f;
|
|
|
|
}
|
|
|
|
|
2010-06-08 12:09:28 +00:00
|
|
|
void operator+=( wxSizer& target, pxStaticText* src )
|
|
|
|
{
|
|
|
|
if( src ) target.Add( src, pxExpand );
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator+=( wxSizer& target, pxStaticText& src )
|
|
|
|
{
|
|
|
|
target.Add( &src, pxExpand );
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator+=( wxSizer* target, pxStaticText& src )
|
|
|
|
{
|
|
|
|
target->Add( &src, pxExpand );
|
|
|
|
}
|