remove arbitrary caps; simplify

This commit is contained in:
Glenn Maynard
2002-12-29 22:55:26 +00:00
parent 3f9b031c3f
commit b7f3768ba9
4 changed files with 49 additions and 108 deletions
+39 -89
View File
@@ -20,15 +20,10 @@
#include "PrefsManager.h" #include "PrefsManager.h"
#include "ThemeManager.h" #include "ThemeManager.h"
#include "GameConstantsAndTypes.h" #include "GameConstantsAndTypes.h"
#include "Font.h"
#define RAINBOW_COLOR_1 THEME->GetMetricC("BitmapText","RainbowColor1") #define RAINBOW_COLOR(n) THEME->GetMetricC("BitmapText",ssprintf("RainbowColor%i", n+1))
#define RAINBOW_COLOR_2 THEME->GetMetricC("BitmapText","RainbowColor2")
#define RAINBOW_COLOR_3 THEME->GetMetricC("BitmapText","RainbowColor3")
#define RAINBOW_COLOR_4 THEME->GetMetricC("BitmapText","RainbowColor4")
#define RAINBOW_COLOR_5 THEME->GetMetricC("BitmapText","RainbowColor5")
#define RAINBOW_COLOR_6 THEME->GetMetricC("BitmapText","RainbowColor6")
#define RAINBOW_COLOR_7 THEME->GetMetricC("BitmapText","RainbowColor7")
const int NUM_RAINBOW_COLORS = 7; const int NUM_RAINBOW_COLORS = 7;
RageColor RAINBOW_COLORS[NUM_RAINBOW_COLORS]; RageColor RAINBOW_COLORS[NUM_RAINBOW_COLORS];
@@ -40,13 +35,8 @@ BitmapText::BitmapText()
static int iReloadCounter = 0; static int iReloadCounter = 0;
if( iReloadCounter%20==0 ) if( iReloadCounter%20==0 )
{ {
RAINBOW_COLORS[0] = RAINBOW_COLOR_1; for(int i = 0; i < NUM_RAINBOW_COLORS; ++i)
RAINBOW_COLORS[1] = RAINBOW_COLOR_2; RAINBOW_COLORS[i] = RAINBOW_COLOR(i);
RAINBOW_COLORS[2] = RAINBOW_COLOR_3;
RAINBOW_COLORS[3] = RAINBOW_COLOR_4;
RAINBOW_COLORS[4] = RAINBOW_COLOR_5;
RAINBOW_COLORS[5] = RAINBOW_COLOR_6;
RAINBOW_COLORS[6] = RAINBOW_COLOR_7;
} }
iReloadCounter++; iReloadCounter++;
@@ -55,16 +45,8 @@ BitmapText::BitmapText()
m_pFont = NULL; m_pFont = NULL;
m_iNumLines = 0;
m_iWidestLineWidth = 0; m_iWidestLineWidth = 0;
for( int i=0; i<MAX_TEXT_LINES; i++ )
{
m_szTextLines[i] = '\0';
m_iLineLengths[i] = -1;
m_iLineWidths[i] = 1;
}
m_bShadow = true; m_bShadow = true;
m_bRainbow = false; m_bRainbow = false;
@@ -112,96 +94,70 @@ bool BitmapText::LoadFromTextureAndChars( CString sTexturePath, CString sChars )
void BitmapText::SetText( CString sText ) void BitmapText::SetText( CString sText )
{ {
//LOG->Trace( "BitmapText::SetText()" );
ASSERT( m_pFont ); ASSERT( m_pFont );
if( m_pFont->m_bCapitalsOnly ) if( m_pFont->m_bCapitalsOnly )
sText.MakeUpper(); sText.MakeUpper();
// m_szText = sText;
// save the string and crop if necessary
//
ASSERT( sText.GetLength() < MAX_TEXT_CHARS/2 );
strncpy( m_szText, sText, MAX_TEXT_CHARS ); /* Break the string into lines. */
m_szText[MAX_TEXT_CHARS-1] = '\0'; m_szTextLines.clear();
m_iLineWidths.clear();
/* split(m_szText, "\n", m_szTextLines, false);
Do NOT stop out all extended ASCII chars. Why was this here? -Chris
int iLength = strlen( m_szText ); /* calculate line lengths and widths */
//
// strip out non-low ASCII chars
//
for( int i=0; i<iLength; i++ ) // for each character
{
if( m_szText[i] < 0 || m_szText[i] > MAX_FONT_CHARS-1 )
m_szText[i] = ' ';
}
*/
//
// break the string into lines
//
m_iNumLines = 0;
LPSTR token;
/* Establish string and get the first token: */
token = strtok( m_szText, "\n" );
while( token != NULL )
{
m_szTextLines[m_iNumLines++] = token;
token = strtok( NULL, "\n" );
}
//
// calculate line lengths and widths
//
m_iWidestLineWidth = 0; m_iWidestLineWidth = 0;
for( int l=0; l<m_iNumLines; l++ ) // for each line for( unsigned l=0; l<m_szTextLines.size(); l++ ) // for each line
{ {
m_iLineLengths[l] = strlen( m_szTextLines[l] ); m_iLineWidths.push_back(m_pFont->GetLineWidthInSourcePixels( m_szTextLines[l] ));
m_iLineWidths[l] = m_pFont->GetLineWidthInSourcePixels( m_szTextLines[l], m_iLineLengths[l] ); m_iWidestLineWidth = max(m_iWidestLineWidth, m_iLineWidths.back());
if( m_iLineWidths[l] > m_iWidestLineWidth )
m_iWidestLineWidth = m_iLineWidths[l];
} }
// fill the RageScreen's vertex buffer with what we're going to draw
//RebuildVertexBuffer();
} }
void BitmapText::CropToWidth( int iMaxWidthInSourcePixels ) void BitmapText::CropToWidth( int iMaxWidthInSourcePixels )
{ {
iMaxWidthInSourcePixels = max( 0, iMaxWidthInSourcePixels ); iMaxWidthInSourcePixels = max( 0, iMaxWidthInSourcePixels );
for( int l=0; l<m_iNumLines; l++ ) // for each line for( unsigned l=0; l<m_szTextLines.size(); l++ ) // for each line
{ {
while( m_iLineWidths[l] > iMaxWidthInSourcePixels ) while( m_iLineWidths[l] > iMaxWidthInSourcePixels )
{ {
m_iLineLengths[l]--; m_szTextLines[l].erase(m_szTextLines[l].end()-1, m_szTextLines[l].end());
m_iLineWidths[l] = m_pFont->GetLineWidthInSourcePixels( m_szTextLines[l], m_iLineLengths[l] ); m_iLineWidths[l] = m_pFont->GetLineWidthInSourcePixels( m_szTextLines[l] );
} }
} }
} }
// draw text at x, y using colorTop blended down to colorBottom, with size multiplied by scale // draw text at x, y using colorTop blended down to colorBottom, with size multiplied by scale
void BitmapText::DrawPrimitives() void BitmapText::DrawPrimitives()
{ {
if( m_iNumLines == 0 ) if( m_szTextLines.empty() )
return; return;
RageTexture* pTexture = m_pFont->m_pTexture; RageTexture* pTexture = m_pFont->m_pTexture;
static RageVertex *v = NULL;
static int vcnt = 0;
{
int charcnt = 0;
for( unsigned i=0; i<m_szTextLines.size(); i++ )
charcnt += m_szTextLines[i].size();
charcnt *= 4; /* 4 vertices per char */
if(charcnt > vcnt)
{
vcnt = charcnt;
delete [] v;
v = new RageVertex[vcnt];
}
}
// make the object in logical units centered at the origin
static RageVertex v[4000];
int iNumV = 0; // the current vertex number int iNumV = 0; // the current vertex number
// make the object in logical units centered at the origin
const int iHeight = pTexture->GetSourceFrameHeight(); // height of a character const int iHeight = pTexture->GetSourceFrameHeight(); // height of a character
const int iLineSpacing = m_pFont->m_iLineSpacing; // spacing between lines const int iLineSpacing = m_pFont->m_iLineSpacing; // spacing between lines
const int iFrameWidth = pTexture->GetSourceFrameWidth(); // width of a character frame in logical units const int iFrameWidth = pTexture->GetSourceFrameWidth(); // width of a character frame in logical units
@@ -209,17 +165,15 @@ void BitmapText::DrawPrimitives()
int iY; // the center position of the first row of characters int iY; // the center position of the first row of characters
switch( m_VertAlign ) switch( m_VertAlign )
{ {
case align_bottom: iY = -(m_iNumLines) * iLineSpacing + iLineSpacing/2; break; case align_bottom: iY = -(int(m_szTextLines.size())) * iLineSpacing + iLineSpacing/2; break;
case align_middle: iY = -(m_iNumLines-1) * iLineSpacing/2; break; case align_middle: iY = -(int(m_szTextLines.size())-1) * iLineSpacing/2; break;
case align_top: iY = + iLineSpacing/2; break; case align_top: iY = + iLineSpacing/2; break;
default: ASSERT( false ); return; default: ASSERT( false ); return;
} }
for( unsigned i=0; i<m_szTextLines.size(); i++ ) // foreach line
for( int i=0; i<m_iNumLines; i++ ) // foreach line
{ {
const char *szLine = m_szTextLines[i]; const CString &szLine = m_szTextLines[i];
const int iLineLength = m_iLineLengths[i];
const int iLineWidth = m_iLineWidths[i]; const int iLineWidth = m_iLineWidths[i];
int iX; int iX;
@@ -231,7 +185,7 @@ void BitmapText::DrawPrimitives()
default: ASSERT( false ); return; default: ASSERT( false ); return;
} }
for( int j=0; j<iLineLength; j++ ) // for each character in the line for( unsigned j=0; j<szLine.size(); j++ ) // for each character in the line
{ {
const char c = szLine[j]; const char c = szLine[j];
const int iFrameNo = m_pFont->m_iCharToFrameNo[ (unsigned char)c ]; const int iFrameNo = m_pFont->m_iCharToFrameNo[ (unsigned char)c ];
@@ -288,7 +242,6 @@ void BitmapText::DrawPrimitives()
else else
DISPLAY->SetBlendModeNormal(); DISPLAY->SetBlendModeNormal();
/* Draw if we're not fully transparent or the zbuffer is enabled (which ignores /* Draw if we're not fully transparent or the zbuffer is enabled (which ignores
* alpha). */ * alpha). */
if( m_temp.diffuse[0].a != 0 || DISPLAY->ZBufferEnabled()) if( m_temp.diffuse[0].a != 0 || DISPLAY->ZBufferEnabled())
@@ -339,9 +292,7 @@ void BitmapText::DrawPrimitives()
DISPLAY->DrawQuads( v, iNumV ); DISPLAY->DrawQuads( v, iNumV );
} }
////////////////////// /* render the glow pass */
// render the glow pass
//////////////////////
if( m_temp.glow.a != 0 ) if( m_temp.glow.a != 0 )
{ {
DISPLAY->SetTextureModeGlow(); DISPLAY->SetTextureModeGlow();
@@ -351,5 +302,4 @@ void BitmapText::DrawPrimitives()
v[i].c = m_temp.glow; v[i].c = m_temp.glow;
DISPLAY->DrawQuads( v, iNumV ); DISPLAY->DrawQuads( v, iNumV );
} }
} }
+4 -11
View File
@@ -13,16 +13,11 @@
#include "Sprite.h" #include "Sprite.h"
#include "Font.h"
class Font;
const int MAX_TEXT_LINES = 40;
const int MAX_TEXT_CHARS = 2000;
class BitmapText : public Actor class BitmapText : public Actor
{ {
protected:
public: public:
BitmapText(); BitmapText();
virtual ~BitmapText(); virtual ~BitmapText();
@@ -48,11 +43,9 @@ public:
protected: protected:
// recalculate the items below on SetText() // recalculate the items below on SetText()
char m_szText[MAX_TEXT_CHARS]; CString m_szText;
char* m_szTextLines[MAX_TEXT_LINES]; // pointers into m_szText vector<CString> m_szTextLines;
int m_iLineLengths[MAX_TEXT_LINES]; // in characters vector<int> m_iLineWidths; // in source pixels
int m_iNumLines;
int m_iLineWidths[MAX_TEXT_LINES]; // in source pixels
int m_iWidestLineWidth; // in source pixels int m_iWidestLineWidth; // in source pixels
bool m_bRainbow; bool m_bRainbow;
+2 -2
View File
@@ -150,11 +150,11 @@ Font::~Font()
} }
int Font::GetLineWidthInSourcePixels( const char *szLine, int iLength ) int Font::GetLineWidthInSourcePixels( const CString &szLine )
{ {
int iLineWidth = 0; int iLineWidth = 0;
for( int i=0; i<iLength; i++ ) for( unsigned i=0; i<szLine.size(); i++ )
{ {
const char c = szLine[i]; const char c = szLine[i];
const int iFrameNo = m_iCharToFrameNo[ (unsigned char)c ]; const int iFrameNo = m_iCharToFrameNo[ (unsigned char)c ];
+1 -3
View File
@@ -18,14 +18,12 @@ const int MAX_FONT_CHARS = 256; // only low ASCII chars are supported
class Font class Font
{ {
protected:
public: public:
Font( const CString &sASCIITexturePath ); Font( const CString &sASCIITexturePath );
Font( const CString &sTexturePath, const CString& sChars ); Font( const CString &sTexturePath, const CString& sChars );
~Font(); ~Font();
int GetLineWidthInSourcePixels( const char *szLine, int iLength ); int GetLineWidthInSourcePixels( const CString &szLine );
int m_iRefCount; int m_iRefCount;