CbuttonFont.cpp
上传用户:jalin138
上传日期:2022-02-12
资源大小:5720k
文件大小:1k
- #include "CbuttonFont.h"
- CbuttonFont::CbuttonFont(wchar_t *_Name, int size)
- {
- m_pFont = new GfxFont( "黑体", size);
- m_pFont->SetColor( 0xffbf14fe );
- m_sName = _Name;
- m_pSprite = new hgeSprite(NULL, 0, 0, 0 ,0 );
- m_fWidth = (float)(m_pFont->GetTextSize(_Name).cx);
- m_fHeight = (float)(m_pFont->GetTextSize(_Name).cy);
- }
- CbuttonFont::~CbuttonFont(void)
- {
- m_sName = NULL;
- SAFE_DELETE( m_pFont );
- SAFE_DELETE( m_pSprite );
- }
- bool CbuttonFont::Logic(float _x, float _y)
- {
- m_fX = _x;
- m_fY = _y;
- m_Rect.x1 = _x;
- m_Rect.y1 = _y;
- m_Rect.x2 = _x + m_fWidth;
- m_Rect.y2 = _y + m_fHeight;
- if ( g_Hge->Input_IsMouseOver() )
- {
- float mt_mouseX = 0.0f, mt_mouseY = 0.0f;
- g_Hge->Input_GetMousePos( &mt_mouseX, &mt_mouseY );
- if ( m_Rect.TestPoint(mt_mouseX, mt_mouseY) )
- {
- m_bIn = true;
- if ( g_Hge->Input_KeyUp(HGEK_LBUTTON) )
- return true;
- return false;
- }
- m_bIn = false;
- }
- return false;
- }
- void CbuttonFont::Render(void)
- {
- if ( m_bIn )
- {
- m_pSprite->SetColor( 0xff4cdff0 );
- m_pSprite->RenderStretch(m_Rect.x1, m_Rect.y1,
- m_Rect.x2, m_Rect.y2 );
- }
- m_pFont->Render( m_fX, m_fY, m_sName );
- }