From 7578fed39afcc518a6d6f44a71258372f35fd1aa Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 15 Apr 2005 12:25:59 +0000 Subject: [PATCH] add SetMaxHeight --- stepmania/src/BitmapText.cpp | 45 ++++++++++++++++++++++++++---------- stepmania/src/BitmapText.h | 6 ++++- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index 64a21e8b41..42d6545c8a 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -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 diff --git a/stepmania/src/BitmapText.h b/stepmania/src/BitmapText.h index b059ef3ebe..e7a0c2f56a 100644 --- a/stepmania/src/BitmapText.h +++ b/stepmania/src/BitmapText.h @@ -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::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 m_iLineWidths; // in source pixels int m_iWrapWidthPixels; // -1 = no wrap float m_fMaxWidth; + float m_fMaxHeight; bool m_bRainbow;