2001-11-03 10:52:42 +00:00
|
|
|
#include "stdafx.h"
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
File: BitmapText.h
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-04 19:34:28 +00:00
|
|
|
Desc: A font class that draws characters from a bitmap.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001 Chris Danford. All rights reserved.
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
#include "BitmapText.h"
|
|
|
|
|
#include "IniFile.h"
|
2001-11-27 22:47:30 +00:00
|
|
|
#include <stdio.h>
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BitmapText::BitmapText()
|
|
|
|
|
{
|
2001-11-27 22:47:30 +00:00
|
|
|
// m_colorTop = D3DXCOLOR(1,1,1,1);
|
|
|
|
|
// m_colorBottom = D3DXCOLOR(1,1,1,1);
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-27 22:47:30 +00:00
|
|
|
for( int i=0; i<NUM_CHARS; i++ )
|
|
|
|
|
m_fCharWidthsInSourcePixels[i] = 16;
|
2001-12-19 01:50:57 +00:00
|
|
|
|
|
|
|
|
// m_bHasShadow = false;
|
2001-11-25 04:31:44 +00:00
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-25 04:31:44 +00:00
|
|
|
bool BitmapText::LoadFromFontName( CString sFontName )
|
|
|
|
|
{
|
|
|
|
|
RageLog( "BitmapText::LoadFromFontName(%s)", sFontName );
|
|
|
|
|
|
|
|
|
|
m_sFontName = sFontName; // save font name
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-27 22:47:30 +00:00
|
|
|
Sprite::LoadFromTexture( ssprintf("Fonts/%s 16x16.png",sFontName) );
|
|
|
|
|
LoadCharWidths( ssprintf("Fonts/%s.widths",sFontName) );
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-27 22:47:30 +00:00
|
|
|
// returns the font height in the case of a bitmap load. note does not use the real bitmap height but rather
|
|
|
|
|
// the height of the bitmap / 16. generally returns > 0 for success.
|
|
|
|
|
bool BitmapText::LoadCharWidths( CString sWidthFilePath )
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2001-11-27 22:47:30 +00:00
|
|
|
FILE *file;
|
|
|
|
|
file = fopen( sWidthFilePath, "rb" );
|
|
|
|
|
for( int i=0; i<256; i++ ) {
|
|
|
|
|
BYTE widthSourcePixels;
|
|
|
|
|
if( fread(&widthSourcePixels, 1, 1, file) != 1 )
|
|
|
|
|
return false;
|
|
|
|
|
m_fCharWidthsInSourcePixels[i] = widthSourcePixels;
|
|
|
|
|
}
|
|
|
|
|
fclose(file);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-27 22:47:30 +00:00
|
|
|
|
|
|
|
|
// get a rectangle for the text, considering a possible text scaling.
|
|
|
|
|
// useful to know if some text is visible or not
|
2001-12-19 01:50:57 +00:00
|
|
|
float BitmapText::GetWidthInSourcePixels()
|
2001-11-27 22:47:30 +00:00
|
|
|
{
|
|
|
|
|
float fTextWidth = 0;
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<m_sText.GetLength(); i++ )
|
|
|
|
|
fTextWidth += m_fCharWidthsInSourcePixels[ m_sText[i] ];
|
|
|
|
|
|
|
|
|
|
return fTextWidth;
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
2001-11-25 04:31:44 +00:00
|
|
|
|
2001-11-27 22:47:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// draw text at x, y using colorTop blended down to colorBottom, with size multiplied by scale
|
|
|
|
|
void BitmapText::Draw()
|
|
|
|
|
{
|
2001-12-19 01:50:57 +00:00
|
|
|
// some basic properties of the text
|
|
|
|
|
float fTextWidthInSourcePixels = GetWidthInSourcePixels();
|
2001-11-27 22:47:30 +00:00
|
|
|
float fTextWidth = fTextWidthInSourcePixels* GetZoom();
|
|
|
|
|
float fFrameWidth = GetZoomedWidth();
|
2001-12-19 01:50:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if( m_bHasShadow )
|
|
|
|
|
{
|
|
|
|
|
// do a pass for the shadow
|
|
|
|
|
|
|
|
|
|
float fOriginalX = GetX();
|
|
|
|
|
float fOriginalY = GetY();
|
|
|
|
|
D3DXCOLOR colorOriginalDiffuse[4];
|
|
|
|
|
for( int i=0; i<4; i++ )
|
|
|
|
|
colorOriginalDiffuse[i] = GetDiffuseColors(i);
|
|
|
|
|
D3DXCOLOR colorOriginalAdd = GetAddColor();
|
|
|
|
|
|
|
|
|
|
float fX = fOriginalX - (fTextWidth/2) + 10;
|
|
|
|
|
float fY = fOriginalY + 10;
|
|
|
|
|
|
|
|
|
|
SetY( fY );
|
|
|
|
|
SetDiffuseColor( D3DXCOLOR(0,0,0,0) ); // transparent
|
|
|
|
|
SetAddColor( D3DXCOLOR(0,0,0,0.5f) ); // semi-transparent black
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( i=0; i<m_sText.GetLength(); i++ ) {
|
|
|
|
|
char c = m_sText[i];
|
|
|
|
|
float fCharWidthZoomed = m_fCharWidthsInSourcePixels[c] * GetZoom();
|
|
|
|
|
SetState( c );
|
|
|
|
|
fX += fCharWidthZoomed/2;
|
|
|
|
|
SetX( fX );
|
|
|
|
|
Sprite::Draw();
|
|
|
|
|
fX += fCharWidthZoomed/2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set properties back to original
|
|
|
|
|
SetX( fOriginalX );
|
|
|
|
|
SetY( fOriginalY );
|
|
|
|
|
for( i=0; i<4; i++ )
|
|
|
|
|
SetDiffuseColors( i, colorOriginalDiffuse[i] );
|
|
|
|
|
SetAddColor( colorOriginalAdd );
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// draw the text
|
|
|
|
|
|
|
|
|
|
float fCenterX = GetX();
|
2001-11-27 22:47:30 +00:00
|
|
|
float fX = fCenterX - (fTextWidth/2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<m_sText.GetLength(); i++ ) {
|
|
|
|
|
char c = m_sText[i];
|
2001-11-30 06:32:52 +00:00
|
|
|
float fCharWidthZoomed = m_fCharWidthsInSourcePixels[c] * GetZoom();
|
2001-11-27 22:47:30 +00:00
|
|
|
SetState( c );
|
2001-11-30 06:32:52 +00:00
|
|
|
fX += fCharWidthZoomed/2;
|
2001-12-19 01:50:57 +00:00
|
|
|
SetX( fX );
|
2001-11-27 22:47:30 +00:00
|
|
|
Sprite::Draw();
|
2001-11-30 06:32:52 +00:00
|
|
|
fX += fCharWidthZoomed/2;
|
2001-11-27 22:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set properties back to original
|
|
|
|
|
SetX( fCenterX );
|
|
|
|
|
}
|