diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index a6e905a525..e134263ece 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -241,6 +241,19 @@ void BitmapText::SetText( CString sText, CString sAlternateText ) BuildChars(); } +void BitmapText::SetTextMaxWidth( float MaxWidth, const CString &text, const CString &alttext ) +{ + this->SetText(text, alttext); + + /* Avoid division by zero. */ + const int Width = GetWidestLineWidthInSourcePixels()+1; + + /* Never decrease the zoom. Important: make sure you reset zoom before + * changing text with this function. */ + const float Zoom = min( GetZoom(), MaxWidth/Width ); + this->SetZoomX( Zoom ); +} + bool BitmapText::StringWillUseAlternate(CString sText, CString sAlternateText) const { ASSERT( m_pFont ); diff --git a/stepmania/src/BitmapText.h b/stepmania/src/BitmapText.h index da66a3359a..e0026c9be3 100644 --- a/stepmania/src/BitmapText.h +++ b/stepmania/src/BitmapText.h @@ -27,6 +27,7 @@ public: bool LoadFromNumbers( CString sTexturePath ) { return LoadFromTextureAndChars(sTexturePath,"0123456789%. :x"); }; bool LoadFromTextureAndChars( CString sTexturePath, CString sChars ); void SetText( CString sText, CString sAlternateText = "" ); + void SetTextMaxWidth( float MaxWidth, const CString &text, const CString &alttext = "" ); int GetWidestLineWidthInSourcePixels() { return m_iWidestLineWidth; }; void CropToWidth( int iWidthInSourcePixels );