📄 cbsdialog.cpp
字号:
#include "CBSDialog.h"
CBSDialog::CBSDialog( int _id, float x, float y, float w, float h,
float bx, float by, float bw, float bh, hgeSprite *sp )
{
id = _id;
bStatic = false;
bVisible = true;
bEnabled = true;
rect.Set(x, y, x+w, y+h);
m_buttonRect.Set( bx, by, bx + bw, by + bh );
m_sp = sp;
m_bEnterAnim= true;
m_alpha = 0;
m_bURL = false;
}
CBSDialog::~CBSDialog()
{
}
void CBSDialog::Render()
{
m_sp->SetColor( ARGB( (int)m_alpha, 255, 255, 255 ) );
m_sp->Render( rect.x1, rect.y1 );
}
void CBSDialog::Update( float dt )
{
if( m_bEnterAnim &&
bVisible )
{
//enter animation, fade in effect
m_alpha += dt * 200;
if( m_alpha > 255 )
{
m_alpha = 255;
m_bEnterAnim = false;//the animation is end
}
}
hgeGUIObject::Update( dt );
}
bool CBSDialog::MouseLButton( bool bDown )
{
if( bDown )
{
float mx,my;
hge->Input_GetMousePos( &mx, &my );
if( mx >= m_buttonRect.x1 + rect.x1 &&
mx <= rect.x1 + m_buttonRect.x2 &&
my >= m_buttonRect.y1 + rect.y1 &&
my <= m_buttonRect.y2 + rect.y1 )
{
//the button on the dialog was pressed
m_alpha = 0;
m_bEnterAnim = true;
return true;
}
//open an url
if( m_bURL &&
mx >= rect.x1 + 10 &&
mx <= rect.x1 + 250 &&
my >= rect.y1 + 320 &&
my <= rect.y1 + 340 )
{
hge->System_Launch( "http://blog.csdn.net/kevinlynx" );
}
}
return false;
}
//============================================================================================
// CBSOptionDlg class
//
//============================================================================================
CBSOptionDlg::CBSOptionDlg( int _id, float x, float y, float w, float h,
float bx, float by, float bw, float bh, //the button position ,releative position
hgeSprite *sp, hgeSprite *okSign ) :
CBSDialog( _id, x, y, w, h, bx, by, bw, bh, sp )
{
m_okSign = okSign;
m_optionData= NULL;
m_sound = NULL;
//init these radio button's rect
//absolute coordinate
m_rMusic.Set( x + 45, y + 75, x + 45 + 30, y + 75 + 30 );
m_rSound.Set( x + 45, y + 112, x + 45 + 30, y + 112 + 30 );
m_rFullscreen.Set( x + 45, y + 149, x + 45 + 30, y + 149 + 30 );
m_rBomb.Set( x + 45, y + 235, x + 45 + 30, y + 235 + 30 );
m_rArrowChanger.Set( x + 182, y + 235, x + 182 + 30, y + 235 + 30 );
m_rUniversal.Set( x + 45, y + 330, x + 45 + 30, y + 330 + 30 );
m_buttonRect.Set( x + bx, y + by, x + bx + bw, y + by + bh );
}
CBSOptionDlg::~CBSOptionDlg()
{
}
void CBSOptionDlg::Init( CSound *sound, COptionData *option )
{
m_sound = sound;
m_optionData = option;
}
void CBSOptionDlg::Render()
{
CBSDialog::Render();
m_okSign->SetColor( ARGB( (int)m_alpha, 255, 255, 255 ) );
//draw these ok sign
if( m_optionData->m_bMusic )
{
m_okSign->Render( m_rMusic.x1, m_rMusic.y1 );
}
if( m_optionData->m_bSound )
{
m_okSign->Render( m_rSound.x1, m_rSound.y1 );
}
if( m_optionData->m_bFullscreen )
{
m_okSign->Render( m_rFullscreen.x1, m_rFullscreen.y1 );
}
if( m_optionData->m_bBomb )
{
m_okSign->Render( m_rBomb.x1, m_rBomb.y1 );
}
if( m_optionData->m_bArrowChanger )
{
m_okSign->Render( m_rArrowChanger.x1, m_rArrowChanger.y1 );
}
if( m_optionData->m_bUniversal )
{
m_okSign->Render( m_rUniversal.x1, m_rUniversal.y1 );
}
if( m_alpha > 250 )
hge->Gfx_RenderLine( 45 + rect.x1, 302 + rect.y1,
279 + rect.x1, 302 + rect.y1, ARGB( 255, 0, 255, 255) ); //not support now
}
bool CBSOptionDlg::MouseLButton( bool bDown )
{
if( bDown )
{
float mx,my;
hge->Input_GetMousePos( &mx, &my );
if( m_rMusic.TestPoint( mx, my ) )
{
m_optionData->m_bMusic = 1 - m_optionData->m_bMusic ;
//m_sndMgr->Sound_Background( (bool)m_optionData->m_bMusic );
}
if( m_rSound.TestPoint( mx, my ) )
{
m_optionData->m_bSound = 1 - m_optionData->m_bSound ;
//m_sndMgr->EnableSoundEffect( (bool)m_optionData->m_bSound );
}
if( m_rFullscreen.TestPoint( mx, my ) )
{
m_optionData->m_bFullscreen = 1 - m_optionData->m_bFullscreen ;
}
if( m_rBomb.TestPoint( mx, my ) )
{
m_optionData->m_bBomb = 1 - m_optionData->m_bBomb ;
}
if( m_rArrowChanger.TestPoint( mx, my ) )
{
m_optionData->m_bArrowChanger = 1 - m_optionData->m_bArrowChanger ;
}
if( m_rUniversal.TestPoint( mx, my ) )
{
m_optionData->m_bUniversal = 1 - m_optionData->m_bUniversal ;
}
if( m_buttonRect.TestPoint( mx, my ) )
{
//end the dialog
m_alpha = 0;
m_bEnterAnim = true;
return true;
}
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -