コード例 #1
0
ファイル: RendererDX.cpp プロジェクト: DArtagan/electricsheep
void	CRendererDX::Text( spCBaseFont _spFont, const std::string &_text, const Base::Math::CVector4 &_color, const Base::Math::CRect &_rect, uint32 _flags )
{
    ASSERT( _text != "" );

	if( _spFont == NULL )
		return;

	const fp4 w05 = (fp4)m_spDisplay->Width() * 0.5f;
	const fp4 h05 = (fp4)m_spDisplay->Height() * 0.5f;
	Base::Math::CRect _r( lerpMacro( -w05, w05, _rect.m_X0 ), lerpMacro( -h05, h05, _rect.m_Y0 ), lerpMacro( -w05, w05, _rect.m_X1 ), lerpMacro( -h05, h05, _rect.m_Y1 ) );

	RECT r = { (LONG)_r.m_X0, (LONG)_r.m_Y0, (LONG)_r.m_X1, (LONG)_r.m_Y1, };

    DWORD d3dFlags = DT_NOCLIP;

	if( _flags & CBaseFont::Bottom )		d3dFlags |= DT_BOTTOM; // bug if CBaseFont::Bottom == 0 because of check _flag & 0 != 0
    if( _flags & CBaseFont::Top )			d3dFlags |= DT_TOP;
    if( _flags & CBaseFont::Center )		d3dFlags |= DT_CENTER;
    if( _flags & CBaseFont::Left )			d3dFlags |= DT_LEFT;
    if( _flags & CBaseFont::Right )			d3dFlags |= DT_RIGHT;
    if( _flags & CBaseFont::VCenter )		d3dFlags |= DT_VCENTER;
    if( _flags & CBaseFont::NoClip )		d3dFlags |= DT_NOCLIP;
    if( _flags & CBaseFont::ExpandTabs )	d3dFlags |= DT_EXPANDTABS;
    if( _flags & CBaseFont::WordBreak )		d3dFlags |= DT_WORDBREAK;

	DWORD d3dColor = D3DCOLOR_COLORVALUE( _color.m_X, _color.m_Y, _color.m_Z, _color.m_W );

	spCFontDX	spDXFont = _spFont;
	ID3DXFont	*pDXFont = spDXFont->GetDXFont();
    ASSERT( pDXFont );

    m_pSprite->Begin( D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_DO_NOT_ADDREF_TEXTURE );
    pDXFont->DrawTextA( m_pSprite, (const char *)_text.c_str(), -1, &r, d3dFlags, d3dColor );
    m_pSprite->End();
}
コード例 #2
0
void D9Draw::DrawTextA(const char* text, unsigned long font, util::Color color, util::Vector2 pos) {
	RECT tpos;
	tpos.left = (long)pos.x;
	tpos.top = (long)pos.y;

	ID3DXFont* nativeFont = reinterpret_cast<ID3DXFont*>(font);
	nativeFont->DrawTextA(0, text, strlen(text), &tpos, DT_NOCLIP, color.GetD3DColor());
}
コード例 #3
0
ファイル: RendererDX.cpp プロジェクト: DArtagan/electricsheep
Base::Math::CVector2	CRendererDX::GetTextExtent( spCBaseFont _spFont, const std::string &_text )
{
    ASSERT( _text != "" );

	Base::Math::CVector2 result;

	if( _spFont == NULL )
		return result;

	uint32 width = 0;
    uint32 height = 0;

	fp4	dispWidth  = (fp4)m_spDisplay->Width();
    fp4	dispHeight = (fp4)m_spDisplay->Height();

	spCFontDX	spDXFont = _spFont;
	ID3DXFont	*pDXFont = spDXFont->GetDXFont();
    ASSERT( pDXFont );

    //	Make a copy of `text' and extend it by `.'.
	size_t textLength = _text.length();
	ASSERT( textLength < 2048 );

	static char	pTmp[ 2048 ];
    strcpy( pTmp, (const char *)_text.c_str() );
    pTmp[ textLength ] = '.';
    pTmp[ textLength + 1 ] = '\0';

    //	Determine extents of `.'.
    RECT dotRect = { 0, 0, 0, 0 };
    int32 h = pDXFont->DrawTextA( NULL, ".", -1, &dotRect, DT_LEFT | DT_NOCLIP | DT_CALCRECT, 0 );
    int32 dotWidth = dotRect.right - dotRect.left;

    RECT rect = { 0, 0, 0, 0 };
    h = pDXFont->DrawTextA( NULL, pTmp, -1, &rect, DT_LEFT | DT_NOCLIP | DT_CALCRECT, 0 );

    width = rect.right - rect.left - dotWidth;
    height = rect.bottom - rect.top;

	result = Base::Math::CVector2( (fp4(width) / dispWidth), (fp4(height) / dispHeight) );

	return( result );
}