#include "StdAfx.h" #include "TabButton.h" #include "UIContainer.h" #include "FontAgent.h" #include "PlaneObject.h" #include "SoundSystem.h" cTabButton::cTabButton( eUINodeType type ) : cPushButton( type ) , mpTabButtonImage(0) , mScreenX(0) , mScreenY(0) , mUpSize(0, 0) , mDownSize(0, 0) { mPressed = false; mHovered = false; mUpColor = mDefaultColor; mDownColor = mDefaultColor; mProcessEnable = false; } cTabButton::~cTabButton() { SAFE_DELETE( mpTabButtonImage ); } bool cTabButton::SetSkin( const cUINodeSkin* pskin ) { if( pskin->IsKindof( eUINODE_TABBUTTON ) == false ) { assert( 0 && "not button skin type" ); return false; } /// À̹ÌÁö ¼³Á¤ if( pskin->mpTexture ) { mScreenX = (short)pskin->mSkinInfo->mX; mScreenY = (short)pskin->mSkinInfo->mY; /// ÅØ½ºÃ³ ¿µ¿ª ¼³Á¤ mUpPos.mX = pskin->mSkinInfo->mTexX; mUpPos.mY = pskin->mSkinInfo->mTexY; mOriginalTexWidth = pskin->mSkinInfo->mTexWidth; mOriginalTexHeight = pskin->mSkinInfo->mTexHeight; if( mpTabButtonImage == 0 ) { mpTabButtonImage = new cPlaneObject; if( mpTabButtonImage->Create( pskin->mpTexture, mScreenX, mScreenY, (unsigned short)mOriginalTexWidth, (unsigned short)mOriginalTexHeight, (unsigned short)mUpPos.mX, (unsigned short)mUpPos.mY, (unsigned short)mUpPos.mX + (unsigned short)mOriginalTexWidth, (unsigned short)mUpPos.mY + (unsigned short)mOriginalTexHeight ) == false ) { assert( 0 && "failed to create gauge image"); return false; } } else { mpTabButtonImage->SetTextureRect( (unsigned short)mUpPos.mX, (unsigned short)mUpPos.mY, (unsigned short)mUpPos.mX + (unsigned short)mOriginalTexWidth, (unsigned short)mUpPos.mY + (unsigned short)mOriginalTexHeight ); } } cUINode::SetRelativeRect( cUIRect( mScreenX, mScreenY, mScreenX + mOriginalTexWidth, mScreenY + mOriginalTexHeight) ); cButtonSkin* p = (cButtonSkin*)pskin; if( p->mText.IsEmpty() == false ) mText = p->mText; /// ¹öưÀÇ À̹ÌÁö º¯È¯ÁÂÇ¥ ÀúÀå mUpPos = p->mUpPos; mDownPos = p->mDownPos; if( p->mUpOverPos.mX == 0 && p->mUpOverPos.mY == 0 ) mUpOverPos = p->mUpPos; else mUpOverPos = p->mUpOverPos; /// ¹öư »óÅÂ ÅØ½ºÆ® Ä÷¯ mUpColor = p->mUpColor; mDownColor = p->mDownColor; /// ÅǹöưÀº À̹ÌÁö¿¡ µû¸¥ »çÀÌÁîÀÚü°¡ ´Ù¸£¹Ç·Î µû·ÎÀúÀå. mUpSize = p->mUpSize; mDownSize = p->mDownSize; mDownSoundIdx = p->mDownSoundIdx; mHoverTipIndex = p->mSkinInfo->mHoverTipIndex; if( mUpSize.mWidth == 0 || mUpSize.mHeight == 0 ) { mUpSize.mWidth = mOriginalTexWidth; mUpSize.mHeight = mOriginalTexHeight; } if( mDownSize.mWidth == 0 || mDownSize.mHeight == 0 ) { mDownSize.mWidth = mOriginalTexWidth; mDownSize.mHeight = mOriginalTexHeight; } /// ÅØ½ºÆ® ÁÂÇ¥ ¾÷µ¥ÀÌÆ® UpdateText(); /// SetPress( false ); return true; } void cTabButton::UpdateRect() { cUINode::UpdateRect(); if( mpTabButtonImage ) { mpTabButtonImage->SetScreenXY( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); } UpdateText(); } /// void cTabButton::UpdateSkin() { /// ºÎ¸ð¿¡ ´ëÇÑ »ó´ëÀûÀÎ À§Ä¡À̹ǷÎ, º¯°æÇÏÁö ¾Ê´Â´Ù. } /// ÁÖÀÇ»çÇ× : void cTabButton::OnRender( cUIFontItemKeeper* pKeeper ) { /// À̹ÌÁö ·»´õ¸µ if( mpTabButtonImage ) mpTabButtonImage->Draw(); /// ÅØ½ºÆ® ·»´õ¸µ pKeeper->AddFontItem( cFontAgent::eFont_UI, const_cast(mText.Cstr()), mTextPosX, mTextPosY, mUpColor, mOutLine ); } /// ÁÖÀÇ»çÇ× : void cTabButton::OnMouseHovered( const cUIPos& pos ) { cUINode::OnMouseHovered( pos ); /// ¶óµð¿À ¹öưÀÌ ¾È ´­·Á ÀÖÀ»¶§¸¸ ¾÷ ¿À¹ö À̹ÌÁö·Î °»½Å if( mPressed == false ) { mpTabButtonImage->SetTextureRect( (unsigned short)mUpOverPos.mX, (unsigned short)mUpOverPos.mY, (unsigned short)(mUpOverPos.mX + mUpSize.mWidth ), (unsigned short)(mUpOverPos.mY + mUpSize.mHeight ) ); } } /// ÁÖÀÇ»çÇ× : È£¹ö ³ëµå À̺¥Æ® ¹ÞÀ½ void cTabButton::OnMouseLeft( const cUIPos& pos ) { cUINode::OnMouseLeft( pos ); mHovered = false; if( mPressed ) { mpTabButtonImage->SetTextureRect( (unsigned short)mDownPos.mX, (unsigned short)mDownPos.mY, (unsigned short)(mDownPos.mX + mDownSize.mWidth), (unsigned short)(mDownPos.mY + mDownSize.mHeight) ); } else { mpTabButtonImage->SetTextureRect( (unsigned short)mUpPos.mX, (unsigned short)mUpPos.mY, (unsigned short)(mUpPos.mX + mUpSize.mWidth), (unsigned short)(mUpPos.mY + mUpSize.mHeight) ); } } /// ÁÖÀÇ»çÇ× : void cTabButton::OnLButtonDown( const cUIPos& pos, bool ctrl, bool alt, bool shift ) { cUINode::OnLButtonDown( pos, ctrl, alt, shift ); SOUNDSYS->Play2DSound( mDownSoundIdx ); SetPress( true ); cUIEvent event; event.mpCaller = this; event.mID = mID; event.mType = eUIEVENT_TABBUTTON_PRESSED; mpParent->HandleEvent( event ); } /// ÁÖÀÇ»çÇ× : void cTabButton::SetPress( bool press ) { cUINode::SetPress( press ); if( mPressed == true ) { /// ¶óµð¿À ¹öưÀÌ ´­·ÈÀ¸¸é À̹ÌÁö¸¦ °»½ÅÇÑ´Ù mpTabButtonImage->SetScreenWH( (unsigned short)mDownSize.mWidth, (unsigned short)mDownSize.mHeight ); mpTabButtonImage->SetTextureRect( (unsigned short)(mDownPos.mX), (unsigned short)(mDownPos.mY), (unsigned short)(mDownPos.mX + mDownSize.mWidth ), (unsigned short)(mDownPos.mY + mDownSize.mHeight ) ); /// »çÀÌÁî º¯°æ½Ã À§Ä¡ À̵¿ if( mDownSize.mHeight - mUpSize.mHeight > 0 ) { cUIPos pos( mScreenX, mScreenY ); cUINode::SetRelativePos( pos ); mpTabButtonImage->SetScreenXY( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); } } else if( mPressed == false ) { /// ¶óµð¿À ¹öưÀÌ ¾È ´­¸° À̹ÌÁö¸¦ °»½ÅÇÑ´Ù mpTabButtonImage->SetScreenWH( (unsigned short)mUpSize.mWidth, (unsigned short)mUpSize.mHeight ); mpTabButtonImage->SetTextureRect( (unsigned short)(mUpPos.mX), (unsigned short)(mUpPos.mY), (unsigned short)(mUpPos.mX + mUpSize.mWidth ), (unsigned short)(mUpPos.mY + mUpSize.mHeight ) ); /// »çÀÌÁî º¯°æ½Ã À§Ä¡ À̵¿ if( mDownSize.mHeight - mUpSize.mHeight > 0 ) { int height = mDownSize.mHeight - mUpSize.mHeight; cUIPos pos( mScreenX, mScreenY + height ); cUINode::SetRelativePos( pos ); mpTabButtonImage->SetScreenXY( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); } } } void cTabButton::SetRelativeRect( const cUIRect& rect ) { cUINode::SetRelativeRect( rect ); mScreenX = (short)rect.mLeft; mScreenY = (short)rect.mTop; } void cTabButton::SetRelativePos( const cUIPos& pos ) { cUINode::SetRelativePos( pos ); mScreenX = (short)pos.mX; mScreenY = (short)pos.mY; }