Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Renderer.h"
- #include "Vector.h"
- CRenderer* g_pRenderer = new CRenderer( );
- CRenderer::CRenderer( void )
- {
- m_pDevice = NULL;
- m_pFont = NULL;
- m_pLine = NULL;
- }
- CRenderer::~CRenderer( void )
- {
- m_pDevice = NULL;
- m_pFont = NULL;
- m_pLine = NULL;
- }
- void CRenderer::Update( IDirect3DDevice9* pDevice )
- {
- if( !m_pDevice )
- {
- m_pDevice = pDevice;
- }
- if( !m_pFont )
- {
- if( FAILED( D3DXCreateFont( m_pDevice, 14, NULL, NULL, NULL, NULL, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Verdana", &m_pFont ) ) )
- {
- return;
- }
- }
- if( !m_pLine )
- {
- if( FAILED( D3DXCreateLine( m_pDevice, &m_pLine ) ) )
- {
- return;
- }
- }
- }
- void CRenderer::Release( void )
- {
- if( m_pFont )
- {
- m_pFont->OnLostDevice( );
- m_pFont->OnResetDevice( );
- m_pFont = NULL;
- }
- if( m_pLine )
- {
- m_pLine->OnLostDevice( );
- m_pLine->OnResetDevice( );
- m_pLine = NULL;
- }
- }
- void CRenderer::SetFont( ID3DXFont* pFont )
- {
- m_pFont = pFont;
- }
- void CRenderer::SetLine( ID3DXLine* pLine )
- {
- m_pLine = pLine;
- }
- void CRenderer::SetDevice( IDirect3DDevice9* pDevice )
- {
- m_pDevice = pDevice;
- }
- ID3DXFont* CRenderer::GetFont( void )
- {
- return m_pFont;
- }
- ID3DXLine* CRenderer::GetLine( void )
- {
- return m_pLine;
- }
- IDirect3DDevice9* CRenderer::GetDevice( void )
- {
- return m_pDevice;
- }
- void CRenderer::DrawRect( int x, int y, int w, int h, DWORD_PTR color )
- {
- if( !IsReady( ) )
- return;
- D3DXVECTOR2 vecLine[ 2 ];
- m_pLine->SetWidth( w );
- m_pLine->SetAntialias( false );
- m_pLine->SetGLLines( false );
- vecLine[ 0 ].x = x + w / 2;
- vecLine[ 0 ].y = y;
- vecLine[ 1 ].x = x + w / 2;
- vecLine[ 1 ].y = y + h;
- m_pLine->Begin( );
- m_pLine->Draw( vecLine, 2, color );
- m_pLine->End( );
- }
- void CRenderer::DrawRectOutlined( int x, int y, int w, int h, DWORD_PTR color, DWORD_PTR outlined, int thickness )
- {
- if( !IsReady( ) )
- return;
- DrawRect( x, y, w, h, color );
- DrawBorderBox( x - 1, y - 1, w + 1, h + 1, outlined, thickness );
- }
- void CRenderer::DrawBorderBox( int x, int y, int w, int h, DWORD_PTR color, int thickness )
- {
- if( !IsReady( ) )
- return;
- DrawRect( x, y, w, thickness, color );
- DrawRect( x, y, thickness, h, color );
- DrawRect( x + w, y, thickness, h, color );
- DrawRect( x, y + h, w + thickness, thickness, color );
- }
- void CRenderer::DrawBorderBoxOutlined( int x, int y, int w, int h, DWORD_PTR color, DWORD_PTR outlined, int thickness )
- {
- if( !IsReady( ) )
- return;
- DrawBorderBox( x, y, w, h, color, thickness );
- DrawBorderBox( x - 1, y - 1, w + 2, h + 2, outlined, 1 );
- DrawBorderBox( x + 1, y + 1, w - 2, h - 2, outlined, 1 );
- }
- void CRenderer::DrawLine( int x0, int y0, int x1, int y1, DWORD_PTR color )
- {
- if( !IsReady( ) )
- return;
- D3DXVECTOR2 vecLine[ 2 ];
- m_pLine->SetWidth( 1 );
- vecLine[ 0 ].x = x0;
- vecLine[ 0 ].y = y0;
- vecLine[ 1 ].x = x1;
- vecLine[ 1 ].y = y1;
- m_pLine->Draw( vecLine, 2, color );
- }
- void CRenderer::DrawLine( Vector x, Vector y, DWORD_PTR color )
- {
- if( !IsReady( ) )
- return;
- D3DXVECTOR2 vecLine[ 2 ];
- m_pLine->SetWidth( 1 );
- vecLine[ 0 ].x = x.x;
- vecLine[ 0 ].y = x.y;
- vecLine[ 1 ].x = y.x;
- vecLine[ 1 ].y = y.y;
- m_pLine->Draw( vecLine, 2, color );
- }
- void CRenderer::DrawString( int x, int y, DWORD_PTR color, const char* text, ... )
- {
- if( !IsReady( ) )
- return;
- char lpBuffer[ 1024 ];
- va_list va_alist;
- va_start( va_alist, text );
- vsprintf( lpBuffer, text, va_alist );
- va_end( va_alist );
- RECT rect = { x, y, x + 50, y + 50 };
- m_pFont->DrawTextA( NULL, lpBuffer, -1, &rect, DT_NOCLIP, color );
- }
- void CRenderer::DrawStringOutlined( int x, int y, DWORD_PTR color, const char* text, ... )
- {
- if( !IsReady( ) )
- return;
- }
- bool CRenderer::IsReady( void )
- {
- return ( m_pDevice && m_pFont && m_pLine );
- }
Advertisement
Add Comment
Please, Sign In to add comment