Code:
"cSilentFont" is a C++ class coded by silentchris. All credits goes to silentchris and the MSDN (Microsoft). Please credit silentchris if you use this class. "cSilentFont" got made to make LPD3DXFONT-using easier and let it render faster. It`s recommend to use the PreloadText function to get the highest performance out of your LPD3DXFONT. Make sure that you only call it once for each static string. ################################################ ## The 3 different drawfunctions: ################################################ 1. [DrawText()] - Is basically left aligned without any extras. - Flags - 1. "T_CENTER" will make the font center aligned. - 2. "T_RIGHT" will make the font right aligned. - 3. "T_SHADOW" will add a shadow around the font. - Examples - Left : pFont->DrawText( 10, 10, 0xFFFFFFFF, NULL , "Text" ); - Left (Shadow) : pFont->DrawText( 10, 10, 0xFFFFFFFF, T_SHADOW , "Text" ); - Center : pFont->DrawText( 10, 10, 0xFFFFFFFF, T_CENTER , "Text" ); - Center (Shadow): pFont->DrawText( 10, 10, 0xFFFFFFFF, T_CENTER|T_SHADOW, "Text" ); - Right : pFont->DrawText( 10, 10, 0xFFFFFFFF, T_RIGHT , "Text" ); - Right (Shadow) : pFont->DrawText( 10, 10, 0xFFFFFFFF, T_RIGHT|T_SHADOW , "Text" ); 2. [DrawTextMaxLen()] - Will draw a left aligned text with choosable MAX-LEN. - Can be shadowed or non-shadowed. - Examples - Normal: pFont->DrawTextMaxLen( 10, 10, 5, 0xFFFFFFFF, FALSE, "Text" ); - Shadow: pFont->DrawTextMaxLen( 10, 10, 5, 0xFFFFFFFF, TRUE , "Text" ); 3. [DrawTextAutoScrolling()] - Will draw text which will scroll from the right to the left over and over again inside the selected field. - You can set the speed. - You`ll need to add a buffer as we want it to be different for each call. - Examples - Normal: pFont->DrawTextAutoScrolling( 10, 10, 100, 1, &buf, 0xFFFFFFFF, FALSE, "Text" ); - Shadow: pFont->DrawTextAutoScrolling( 10, 10, 100, 1, &buf, 0xFFFFFFFF, TRUE , "Text" ); ################################################ ## How to use: ################################################ 1. Add this on the top of any file: C_SilentFont *pFont; 2. Call this once inside your Present/Endscene: pFont = new C_SilentFont( pDevice, "Arial", 14, FW_SEMIBOLD, FALSE ); Parameter 1: Your D3D Device Parameter 2: The name of your font Parameter 3: The size of your font Parameter 4: The Weight of your font Parameter 5: You want your font Italic?! 3. Before your drawing call this every frame: pFont->InitVolatileResources( ); 4. DRAW! 5. After your drawing call this every frame: pFont->FreeVolatileResources( ); 6. Thats it :) ################################################ ## All Functions listed: ################################################ C_SilentFont( LPDIRECT3DDEVICE9 pd3dDevice, TCHAR* strFontName, INT dwFontSize, UINT dwFontFlags, BOOL Italic ); ~C_SilentFont( ); LPDIRECT3DDEVICE9 GetDevice( ); LPD3DXSPRITE GetSprite( ); LPD3DXFONT GetFont( ); CHAR *GetName( ); INT GetTextLenght( CHAR *str ); INT GetTextHeight( ); UINT GetFlags( ); BOOL GetItalic( ); HRESULT PreloadText( CHAR *dwText ); HRESULT InitVolatileResources( ); HRESULT FreeVolatileResources( ); HRESULT DrawText( INT x, INT y, DWORD dwColor, DWORD dwFlags, const char *fmt, ... ); HRESULT DrawTextMaxLen( INT x, INT y, INT w, DWORD dwColor, BOOL shadowed, const char *fmt, ... ); HRESULT DrawTextAutoScrolling( INT x, INT y, INT w, INT speed, INT *pos_buf, DWORD dwColor, BOOL shadowed, const char *fmt, ... ); ################################################ ## Changelog: ################################################ [ v1.1 ] - Code is alot smaller now. Added Multi-Flags. [ v1.0 ] - First Version
Sharing is caring
Download: