add SetMaxHeight

This commit is contained in:
Chris Danford
2005-04-15 12:25:59 +00:00
parent 2f29fef780
commit 7578fed39a
2 changed files with 38 additions and 13 deletions
+33 -12
View File
@@ -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
+5 -1
View File
@@ -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;