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_iWrapWidthPixels = -1;
m_fMaxWidth = 0; m_fMaxWidth = 0;
m_fMaxHeight = 0;
SetShadowLength( 4 ); SetShadowLength( 4 );
} }
@@ -421,9 +422,15 @@ void BitmapText::SetText( const CString& _sText, const CString& _sAlternateText,
UpdateBaseZoom(); 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(); UpdateBaseZoom();
} }
@@ -432,18 +439,32 @@ void BitmapText::UpdateBaseZoom()
if( m_fMaxWidth == 0 ) if( m_fMaxWidth == 0 )
{ {
this->SetBaseZoomX( 1 ); 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(); if( m_fMaxHeight == 0 )
{
/* Avoid division by zero. */ this->SetBaseZoomY( 1 );
if( !Width ) }
return; else
{
/* Never decrease the zoom. */ const float fHeight = GetUnzoomedHeight();
const float Zoom = min( 1, m_fMaxWidth/Width ); if( fHeight != 0 ) // don't divide by 0
this->SetBaseZoomX( Zoom ); {
/* 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 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 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 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 int settext( T* p, lua_State *L ) { p->SetText( SArg(1) ); return 0; }
static void Register(lua_State *L) static void Register(lua_State *L)
{ {
ADD_METHOD( wrapwidthpixels ) ADD_METHOD( wrapwidthpixels )
ADD_METHOD( maxwidth ) ADD_METHOD( maxwidth )
ADD_METHOD( maxheight )
ADD_METHOD( settext ) ADD_METHOD( settext )
LunaActor<T>::Register( L ); LunaActor<T>::Register( L );
} }
@@ -40,7 +42,8 @@ public:
bool LoadFromFont( const CString& sFontName ); bool LoadFromFont( const CString& sFontName );
bool LoadFromTextureAndChars( const CString& sTexturePath, const CString& sChars ); bool LoadFromTextureAndChars( const CString& sTexturePath, const CString& sChars );
void SetText( const CString& sText, const CString& sAlternateText = "", int iWrapWidthPixels = -1 ); 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 SetWrapWidthPixels( int iWrapWidthPixels );
void CropToWidth( int iWidthInSourcePixels ); void CropToWidth( int iWidthInSourcePixels );
@@ -76,6 +79,7 @@ protected:
vector<int> m_iLineWidths; // in source pixels vector<int> m_iLineWidths; // in source pixels
int m_iWrapWidthPixels; // -1 = no wrap int m_iWrapWidthPixels; // -1 = no wrap
float m_fMaxWidth; float m_fMaxWidth;
float m_fMaxHeight;
bool m_bRainbow; bool m_bRainbow;