add SetMaxHeight
This commit is contained in:
@@ -74,6 +74,7 @@ BitmapText::BitmapText()
|
||||
|
||||
m_iWrapWidthPixels = -1;
|
||||
m_fMaxWidth = 0;
|
||||
m_fMaxHeight = 0;
|
||||
|
||||
SetShadowLength( 4 );
|
||||
}
|
||||
@@ -421,9 +422,15 @@ void BitmapText::SetText( const CString& _sText, const CString& _sAlternateText,
|
||||
UpdateBaseZoom();
|
||||
}
|
||||
|
||||
void BitmapText::SetMaxWidth( float MaxWidth )
|
||||
void BitmapText::SetMaxWidth( float fMaxWidth )
|
||||
{
|
||||
m_fMaxWidth = MaxWidth;
|
||||
m_fMaxWidth = fMaxWidth;
|
||||
UpdateBaseZoom();
|
||||
}
|
||||
|
||||
void BitmapText::SetMaxHeight( float fMaxHeight )
|
||||
{
|
||||
m_fMaxHeight = fMaxHeight;
|
||||
UpdateBaseZoom();
|
||||
}
|
||||
|
||||
@@ -432,18 +439,32 @@ void BitmapText::UpdateBaseZoom()
|
||||
if( m_fMaxWidth == 0 )
|
||||
{
|
||||
this->SetBaseZoomX( 1 );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
const float fWidth = GetUnzoomedWidth();
|
||||
if( fWidth != 0 ) // don't divide by 0
|
||||
{
|
||||
/* Never decrease the zoom. */
|
||||
const float fZoom = min( 1, m_fMaxWidth/fWidth );
|
||||
this->SetBaseZoomX( fZoom );
|
||||
}
|
||||
}
|
||||
|
||||
const float Width = GetUnzoomedWidth();
|
||||
|
||||
/* Avoid division by zero. */
|
||||
if( !Width )
|
||||
return;
|
||||
|
||||
/* Never decrease the zoom. */
|
||||
const float Zoom = min( 1, m_fMaxWidth/Width );
|
||||
this->SetBaseZoomX( Zoom );
|
||||
if( m_fMaxHeight == 0 )
|
||||
{
|
||||
this->SetBaseZoomY( 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
const float fHeight = GetUnzoomedHeight();
|
||||
if( fHeight != 0 ) // don't divide by 0
|
||||
{
|
||||
/* Never decrease the zoom. */
|
||||
const float fZoom = min( 1, m_fMaxHeight/fHeight );
|
||||
this->SetBaseZoomY( fZoom );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool BitmapText::StringWillUseAlternate( const CString& sText, const CString& sAlternateText ) const
|
||||
|
||||
@@ -17,12 +17,14 @@ public:
|
||||
|
||||
static int wrapwidthpixels( T* p, lua_State *L ) { p->SetWrapWidthPixels( IArg(1) ); return 0; }
|
||||
static int maxwidth( T* p, lua_State *L ) { p->SetMaxWidth( FArg(1) ); return 0; }
|
||||
static int maxheight( T* p, lua_State *L ) { p->SetMaxHeight( FArg(1) ); return 0; }
|
||||
static int settext( T* p, lua_State *L ) { p->SetText( SArg(1) ); return 0; }
|
||||
|
||||
static void Register(lua_State *L)
|
||||
{
|
||||
ADD_METHOD( wrapwidthpixels )
|
||||
ADD_METHOD( maxwidth )
|
||||
ADD_METHOD( maxheight )
|
||||
ADD_METHOD( settext )
|
||||
LunaActor<T>::Register( L );
|
||||
}
|
||||
@@ -40,7 +42,8 @@ public:
|
||||
bool LoadFromFont( const CString& sFontName );
|
||||
bool LoadFromTextureAndChars( const CString& sTexturePath, const CString& sChars );
|
||||
void SetText( const CString& sText, const CString& sAlternateText = "", int iWrapWidthPixels = -1 );
|
||||
void SetMaxWidth( float MaxWidth );
|
||||
void SetMaxWidth( float fMaxWidth );
|
||||
void SetMaxHeight( float fMaxHeight );
|
||||
void SetWrapWidthPixels( int iWrapWidthPixels );
|
||||
|
||||
void CropToWidth( int iWidthInSourcePixels );
|
||||
@@ -76,6 +79,7 @@ protected:
|
||||
vector<int> m_iLineWidths; // in source pixels
|
||||
int m_iWrapWidthPixels; // -1 = no wrap
|
||||
float m_fMaxWidth;
|
||||
float m_fMaxHeight;
|
||||
|
||||
bool m_bRainbow;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user