www.pudn.com > GameEngine_src.rar > CProgressBar.cpp


// CProgressBar.cpp: implementation of the CProgressBar class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "CProgressBar.h" 
#include "normal.h" 
 
extern PEASYDRAW	g_pEasyDraw; 
 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
CProgressBar::CProgressBar() 
{ 
	m_BackSurface = NULL; 
	m_FrontSurface= NULL; 
 
	m_FrontOffset.x = 0; 
	m_FrontOffset.y = 0; 
} 
 
 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
CProgressBar::~CProgressBar() 
{ 
 
} 
 
 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
bool CProgressBar::Init( PSURFACE BackSurf, PSURFACE FrontSurf, int x, int y ) 
{ 
	m_BackSurface = BackSurf; 
	m_FrontSurface= FrontSurf; 
	m_FrontOffset.x = x; 
	m_FrontOffset.y = y; 
	return true; 
} 
 
 
 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
void CProgressBar::Free() 
{ 
	g_pEasyDraw->DeleteSurface( m_BackSurface ); 
	g_pEasyDraw->DeleteSurface( m_FrontSurface ); 
} 
 
 
////////////////////////////////////////////////////////////////////// 
// 
////////////////////////////////////////////////////////////////////// 
void CProgressBar::Draw( int x, int y, int cur_value, int max_value ) 
{ 
	debug_assert( m_BackSurface != NULL && m_FrontSurface != NULL ); 
 
	float w = float(cur_value) / float(max_value) * float(m_FrontSurface->GetWidth()); 
 
 
	m_BackSurface->DrawSurface( x, y, 0 );				//进度条通常都在窗口内,所以不用裁剪 
 
	x += m_FrontOffset.x; 
	y += m_FrontOffset.y; 
 
	RECT rc = { 0, 0, (int)w, m_FrontSurface->GetHeight() }; 
	m_FrontSurface->DrawSurface( x, y, &rc ); 
}