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 )
|
|
|
|
: _parent( parent )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
: _parent( parent )
|
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;
|
|
|
|
|
|
|
|
//SetHeight( 1 );
|
|
|
|
SetLabel( label );
|
|
|
|
Connect( wxEVT_PAINT, wxPaintEventHandler(pxStaticText::paintEvent) );
|
2009-11-18 07:53:02 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
pxStaticText& pxStaticText::SetHeight( int lines )
|
|
|
|
{
|
|
|
|
if( !pxAssert(lines > 0) ) lines = 2;
|
|
|
|
m_heightInLines = lines;
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
GetTextExtent( _("MyjS 23"), &width, &height );
|
|
|
|
const int newHeight = ((height+1)*m_heightInLines) + (m_paddingPix_vert*2);
|
|
|
|
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-04 08:00:19 +00:00
|
|
|
wxString label(GetLabel());
|
|
|
|
return dc.GetMultiLineTextExtent(pxTextWrapper().Wrap( this, label, idealWidth - calcPaddingWidth(idealWidth) ).GetResult());
|
|
|
|
}
|
|
|
|
|
|
|
|
pxStaticText& pxStaticText::WrapAt( int width )
|
|
|
|
{
|
|
|
|
m_autowrap = false;
|
|
|
|
|
|
|
|
if( (width <= 1) || (width == m_wrappedWidth) ) return *this;
|
|
|
|
|
|
|
|
wxString wrappedLabel;
|
|
|
|
m_wrappedWidth = width;
|
|
|
|
|
|
|
|
if( width > 1 )
|
|
|
|
{
|
|
|
|
wxString label( GetLabel() );
|
|
|
|
wrappedLabel = pxTextWrapper().Wrap( this, 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 )
|
|
|
|
{
|
|
|
|
wxString label( GetLabel() );
|
|
|
|
wrappedLabel = pxTextWrapper().Wrap( this, label, m_wrappedWidth ).GetResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04 08:00:19 +00:00
|
|
|
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 );
|
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 );
|
|
|
|
|
|
|
|
wxString label;
|
|
|
|
|
|
|
|
if( m_autowrap )
|
|
|
|
{
|
|
|
|
_updateWrapping( false );
|
|
|
|
label = m_wrappedLabel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
label = GetLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
best.x = wxDefaultCoord;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|