#include "StdAfx.h" #include "BaseIcon.h" #include "Token.h" #include "Parser.h" #include "UIContainer.h" #include "PlaneObject.h" #include "Lexer.h" cBaseIcon::cBaseIcon( eUINodeType type ) : cUINode( type ) , mParam( 0 ) , mShiftDown( false ) , mEnableUse( true ) , mIconType( eICON_NORMAL ) , mColor( NiColorA::WHITE ) { mProcessEnable = true; } cBaseIcon::~cBaseIcon() { } void cBaseIcon::SetUsedFlag( bool enable, bool colorchange ) { mEnableUse = enable; if( enable == false ) { if( colorchange ) SetColor( 0.5f, 0.5f, 0.5f, 1.0f ); } else { SetColor( mColor ); } } void cBaseIcon::ChangeImage( cIconParam* param, unsigned int texW, unsigned int texH ) { mParam = param; if( param == 0 ) return; assert( param->mpTexture ); // /// ÅØ½ºÃ³ ¼³Á¤ if( mpImage == 0 ) mpImage = new cUIImage( param->mpTexture ); else mpImage->SetTexture( param->mpTexture ); /// mpImage->SetColor( mColor ); /// ÅØ½ºÃ³ ¿µ¿ª ¼³Á¤ unsigned int tx = param->mTexPos.mX; unsigned int ty = param->mTexPos.mY; unsigned int tw = texW; unsigned int th = texH; if( texW == 0 || texH == 0 ) { tw = mRelativeRect.GetWidth(); th = mRelativeRect.GetHeight(); } mpImage->SetTextureRect( tx, ty, tx + tw, ty + th ); /// À̹ÌÁö ¿µ¿ªÀ» °»½Å mpImage->SetScreenRect( mAbsoluteRect ); } void cBaseIcon::ClearImage() { mParam = NULL; /// ÅØ½ºÃ³ ¼³Á¤ if( mpImage ) delete mpImage; mpImage = NULL; } void cBaseIcon::UpdateRect() { cUINode::UpdateRect(); /// À̹ÌÁö ¿µ¿ªÀ» °»½Å if( mParam && mpImage ) mpImage->SetScreenRect( mAbsoluteRect ); } bool cBaseIcon::SetSkin( const cUINodeSkin* skin ) { if( skin->IsKindof( eUINODE_ICON ) == false ) { assert( 0 && "not icon skin type" ); return false; } /// ³ëµå ½ºÅ²ÀÇ ÀûÇÕ¼º °Ë»ç if( skin->IsValid() == false ) { assert( 0 && "invalid skin" ); return false; } /// À̹ÌÁö ¼³Á¤ if( skin->mpTexture ) { if( mpImage == 0 ) { mpImage = new cUIImage(skin->mpTexture); } else { assert(0); } /// Ä÷¯¸¦ ÁöÁ¤ SetColor( skin->mColor ); /// ÅØ½ºÃ³ ¿µ¿ª ¼³Á¤ unsigned int tx = skin->mSkinInfo->mTexX; unsigned int ty = skin->mSkinInfo->mTexY; unsigned int tw = skin->mSkinInfo->mTexWidth; unsigned int th = skin->mSkinInfo->mTexHeight; mpImage->SetTextureRect( tx, ty, tx + tw, ty + th ); } else { delete mpImage; mpImage = 0; } /// ·çÆ®ÀÇ ¹Ù·Î ÀÚ½ÄÀÎ À©µµ¿ìµéÀº ±âÁ¸ÁÂÇ¥¸¦ ÀúÀåÇÑä ÇØ»óµµ¸¦ º¯°æ if( mpParent == 0 ) { assert(0); return false; } unsigned int x = skin->mSkinInfo->mX; unsigned int y = skin->mSkinInfo->mY; unsigned int w = skin->mSkinInfo->mWidth; unsigned int h = skin->mSkinInfo->mHeight; /// ºÎ¸ð°¡ ·çÆ® ŸÀÔÀÌ¸é ¸ðµÎ °»½Å if( mpParent->GetType() == eUINODE_ROOT ) { x = ( GetScreenWidth() * skin->mSkinInfo->mX ) / mDefaultWidth; y = ( GetScreenHeight() * skin->mSkinInfo->mY ) / mDefaultHeight; /// ¿À¸¥ÂÊÀ̳ª ¾Æ·§ÂÊ¿¡ À©µµ¿ì°¡ ºÙ¾îÀÖÀ¸¸é ÇØ»óµµ º¯°æ½Ã¿¡µµ /// ºÙ¾îÀÖµµ·Ï ÇÑ´Ù if( (skin->mSkinInfo->mX + skin->mSkinInfo->mWidth) >= (int)mDefaultWidth ) { x = GetScreenWidth() - w; } if( (skin->mSkinInfo->mY + skin->mSkinInfo->mHeight) >= (int)mDefaultHeight ) { y = GetScreenHeight() - h; } } /// Àû¿ë SetRelativeRect( cUIRect( x, y, x + w, y + h) ); /// mHoverTipIndex = skin->mSkinInfo->mHoverTipIndex; return true; } bool cBaseIcon::HandleEvent( const cUIEvent& event ) { if( mParam == 0 ) { if( !(mHoverTipIndex > 0 && (event.mType == eUIEVENT_MOUSE_HOVERED || event.mType == eUIEVENT_MOUSE_LEFT)) ) return mpParent->HandleEvent( event ); } return cUINode::HandleEvent( event ); } void cBaseIcon::OnRender( cUIFontItemKeeper* pKeeper ) { if( mParam && mpImage ) mpImage->Draw(); } void cBaseIcon::OnMouseHovered( const cUIPos& pos ) { if( mHoverTipIndex > 0 ) UIMAN->ShowUITip( pos, mHoverTipIndex ); SendEvent( mpParent, eUIEVENT_ICON_HOVERED, this, mID, mShiftDown ); } void cBaseIcon::OnMouseLeft( const cUIPos& ) { ReleaseCapture(); mPressed = false; UIMAN->HideTip(); } void cBaseIcon::OnMouseMove( const cUIPos& ) { if( mPressed && mEnableUse ) { ReleaseCapture(); mPressed = false; SendEvent( mpParent, eUIEVENT_ICON_DRAGGED, this, mID, mShiftDown ); UIMAN->HideTip(); } } void cBaseIcon::OnLButtonDown( const cUIPos& pos, bool ctrl, bool alt, bool shift ) { if( mEnableUse ) { cUINode::OnLButtonDown( pos, ctrl, alt, shift ); if( GetCapture() != this ) { SetCapture(); } mPressed = true; mShiftDown = shift; SendEvent( mpParent, eUIEVENT_ICON_CLICKED, this, mID ); } } void cBaseIcon::OnLButtonUp( const cUIPos& /*pos*/ ) { ReleaseCapture(); mPressed = false; } void cBaseIcon::OnLButtonDoubleClick( const cUIPos& /*pos*/ ) { if( mEnableUse ) SendEvent( mpParent, eUIEVENT_ICON_DOUBLECLICKED, this, mID ); } void cBaseIcon::OnRButtonDown( const cUIPos& pos, bool ctrl, bool alt, bool shift ) { cUINode::OnRButtonDown( pos, ctrl, alt, shift ); if( mEnableUse ) SendEvent( mpParent, eUIEVENT_ICON_RIGHTCLICKED, this, mID, shift ); } //////////////////////////////////////////////////////////////////////////////////////// cIconSkin::cIconSkin( eUINodeType type ) : cUINodeSkin( type ) { } cIconSkin::~cIconSkin() { } bool cIconSkin::Load( cParser& parser ) { if( parser.ExpectTokenString( "{" ) == false ) { return false; } cToken token; cLexer* lexer = parser.GetLexer(); while( lexer->GetNextToken( &token ) ) { if( token == "}" ) break; if( cUINodeSkin::ParseLine( parser, token ) == false ) { return false; } } return true; }