#include "StdAfx.h" #include "SpinBox.h" #include "UIManager.h" #include "UISkinLexer.h" #include "Token.h" #include "Parser.h" #include "UIContainer.h" #include "Button.h" #include "Label.h" cSpinBox::cSpinBox( eUINodeType type ) : cSpinCtrl( type ) , mpLabel(0) , mpLeftButton(0) , mpRightButton(0) , mRotation(true) { mSelectedIdx = 0; } cSpinBox::~cSpinBox() { mpLabel = 0; mpLeftButton = 0; mpRightButton = 0; mSelectedIdx = 0; } /// ÁÖÀÇ»çÇ× : bool cSpinBox::OnCreate( cUINodeProperty* ) { mpLeftButton = new cButton; if( mpLeftButton->CreateBySkinName( mLeftButtonSkin, this, eSPINBOX_LEFTBTN ) == false ) { return false; } mpRightButton = new cButton; if( mpRightButton->CreateBySkinName( mRightButtonSkin, this, eSPINBOX_RIGNTBTN ) == false ) { return false; } mpLabel = new cLabel; if( mpLabel->CreateBySkinName( mLabelSkin, this, eSPINBOX_LABEL ) == false ) { return false; } if( !mpLabel || !mpLeftButton || !mpRightButton ) { assert( 0 && "failed to create spinbox child" ); return false; } /// ¶óº§°ú ¶óº§ ¹è°æÀ̹ÌÁö¸¦ Áß¾ÓÀ¸·Î Á¤·Ä½ÃŲ´Ù mpLabel->SetAlign( this, eALIGN_CENTER ); /// left ¹öư À§Ä¡ ¼¼ÆÃ cUIPos leftpos; leftpos.mX = 0; leftpos.mY = ( GetRelativeRect().GetHeight() - mpLeftButton->GetRelativeRect().GetHeight() ) / 2; mpLeftButton->SetRelativePos( leftpos ); /// right ¹öư À§Ä¡ ¼¼ÆÃ cUIPos rightpos; rightpos.mX = GetRelativeRect().GetWidth() - mpRightButton->GetRelativeRect().GetWidth(); rightpos.mY = ( GetRelativeRect().GetHeight() - mpRightButton->GetRelativeRect().GetHeight() ) / 2; mpRightButton->SetRelativePos( rightpos ); return true; } /// ÁÖÀÇ»çÇ× : bool cSpinBox::SetSkin( const cUINodeSkin* pskin ) { if( pskin->IsKindof( eUINODE_SPINBOX ) == false ) { assert( 0 && "not spinbox skin type" ); return false; } if( cUINode::SetSkin( pskin ) == false ) { return false; } cSpinBoxSkin* p = (cSpinBoxSkin*)pskin; /// ÀÚ½Ä ½ºÅ² ³×ÀÓ Àû¿ë mLeftButtonSkin = p->mLeftButtonSkin; mRightButtonSkin = p->mRightButtonSkin; mLabelSkin = p->mLabelSkin; /// ½ºÇɹڽº ŸÀÔ Àû¿ë mRotation = p->mRotation; cUISkin* pUISkin = UIMAN->GetSkin(); if( !pskin ) { assert(0); return false; } /// ½ºÅ² ³×ÀÓ À¯È¿¼º °Ë»ç if( mLeftButtonSkin && pUISkin->GetNodeSkin( mLeftButtonSkin ) == 0 ) { assert( 0 && "error skin name" ); return false; } if( mRightButtonSkin && pUISkin->GetNodeSkin( mRightButtonSkin ) == 0 ) { assert( 0 && "error skin name" ); return false; } if( mLabelSkin && pUISkin->GetNodeSkin( mLabelSkin ) == 0 ) { assert( 0 && "error skin name" ); return false; } return true; } /// ÁÖÀÇ»çÇ× : bool cSpinBox::HandleEvent( const cUIEvent& event ) { if( mEnabled == false || mVisible == false ) { return mpParent->HandleEvent( event ); } if( event.mType == eUIEVENT_COMMAND ) { CheckButtonEvent( event.mID ); cUIEvent ev = event; ev.mpCaller = (cUINode*)this; mpParent->HandleEvent( ev ); } return true; } void cSpinBox::UpdateSkin() { cUIWindow::UpdateSkin(); if( mpLeftButton ) { /// left ¹öư À§Ä¡ ¼¼ÆÃ cUIPos leftpos; leftpos.mX = 0; leftpos.mY = ( GetRelativeRect().GetHeight() - mpLeftButton->GetRelativeRect().GetHeight() ) / 2; mpLeftButton->SetRelativePos( leftpos ); } if( mpRightButton ) { /// right ¹öư À§Ä¡ ¼¼ÆÃ cUIPos rightpos; rightpos.mX = GetRelativeRect().GetWidth() - mpRightButton->GetRelativeRect().GetWidth(); rightpos.mY = ( GetRelativeRect().GetHeight() - mpRightButton->GetRelativeRect().GetHeight() ) / 2; mpRightButton->SetRelativePos( rightpos ); } if( mpLabel ) { mpLabel->SetAlign( this, eALIGN_CENTER ); } } /// ÁÖÀÇ»çÇ× : void cSpinBox::OnLButtonDown( const cUIPos& pos, bool ctrl, bool alt, bool shift ) { cUIWindow::OnLButtonDown( pos, ctrl, alt, shift ); } /// ÁÖÀÇ»çÇ× : void cSpinBox::OnLButtonUp( const cUIPos& ) { } /// ÁÖÀÇ»çÇ× : ¾î´À ¹öưÀÌ ´­·È´ÂÁö üũ void cSpinBox::CheckButtonEvent( unsigned int id ) { cString str; switch( id ) { case eSPINBOX_LEFTBTN: { mSelectedIdx--; /// °è¼Ó µµ´Â ÇüÅÂÀÇ ½ºÇɹڽº if( mRotation == true ) { if( mSelectedIdx < 0 ) { mSelectedIdx = GetSize() - 1; } } /// ÇÑ“‡ÇâÀÇ ³¡±îÁö¹Û¿¡ ¸ø°¡´Â ½ºÇɹڽº else { if( mpRightButton->IsVisible() == false ) mpRightButton->Show(); /// óÀ½±îÁö °¡¸é ¿ÞÂÊ ¹öưÀ» º¸ÀÌÁö ¾Ê´Â´Ù if( mSelectedIdx <= 0 ) { mpLeftButton->Hide(); } } } break; case eSPINBOX_RIGNTBTN: { mSelectedIdx++; if( mRotation == true ) { if( mSelectedIdx > GetSize()-1 ) { mSelectedIdx = 0; } } else { if( mpLeftButton->IsVisible() == false ) mpLeftButton->Show(); /// ³¡±îÁö°¡¸é ¿À¸¥ÂÊ ¹öưÀ» º¸ÀÌÁö ¾Ê´Â´Ù if( mSelectedIdx == GetSize() - 1 ) { mpRightButton->Hide(); } } } break; } /// ÃÖÁ¾ º¸Á¤ if( mSelectedIdx < 0 ) mSelectedIdx = 0; /// ¶óº§°ª °»½Å UpdateLabel(); } void cSpinBox::AddData( LPCTSTR str, void* pExData ) { cSpinCtrl::AddData( str, pExData ); UpdateLabel(); if( mRotation == false ) { /// ÇöÀç ¼±ÅÃµÈ °ÍÀÌ ¸Ç¸¶Áö¸· À̾úÀ¸¸é, /// »õ·ÎÃß°¡ÇÒ°ÍÀ» °í·ÁÇØ¼­ rightbutton À» º¸¿©ÁØ´Ù. if( GetSize() < 2 ) { mpLeftButton->Hide(); mpRightButton->Hide(); } else if( mSelectedIdx <= 0 ) { mpLeftButton->Hide(); mpRightButton->Show(); } else { mpLeftButton->Show(); mpRightButton->Show(); } } else { mpLeftButton->Show(); mpRightButton->Show(); } } void cSpinBox::Clear() { cSpinCtrl::Clear(); mSelectedIdx = 0; mpLeftButton->Hide(); mpRightButton->Hide(); } void cSpinBox::UpdateLabel() { if( mpLabel ) { mpLabel->SetTextColor( mDefaultColor ); mpLabel->SetAlign( this, eALIGN_CENTER ); mpLabel->SetText( GetLabelData(mSelectedIdx) ); } } void cSpinBox::SetSelectIdx( int idx ) { if( idx < 0 || idx > GetSize()-1 ) return; mSelectedIdx = idx; UpdateLabel(); } ///////////////////////////////////////////////////////////////////////////////// cSpinBoxSkin::cSpinBoxSkin( eUINodeType type ) : cUINodeSkin( type ) , mTextAlign( eALIGN_LEFT ) , mRotation( true ) { } cSpinBoxSkin::~cSpinBoxSkin() { } /// ÁÖÀÇ»çÇ× : ½ºÅ©¸³Æ® ÆÄÀÏÀ» Àоîµé¿©¼­ °ªÀ» ¼¼ÆÃÇÑ´Ù bool cSpinBoxSkin::Load( cParser& parser ) { if( parser.ExpectTokenString( "{" ) == false ) { return false; } cToken token; cLexer* lexer = parser.GetLexer(); /// ±×´ÙÀ½ÅäÅ«À» °è¼Ó °Ë»ç while( lexer->GetNextToken( &token ) ) { if( token == "}" ) { break; } switch( token.mType ) { case eTOKEN_ROTATION: { /// Rotation ´ÙÀ½¿¡ ¿À´Â °ªÀ» ÀоîµéÀ̱â À§ÇÔ lexer->GetNextToken( &token ); if( token.mType == eTOKEN_TRUE ) { mRotation = true; } else if( token.mType == eTOKEN_FALSE ) { mRotation = false; } else { assert( 0 && "invalid token" ); return false; } } break; case eTOKEN_LEFTBUTTON: { mLeftButtonSkin = parser.ParseString(); } break; case eTOKEN_RIGHTBUTTON: { mRightButtonSkin = parser.ParseString(); } break; case eTOKEN_LABELSKIN: { mLabelSkin = parser.ParseString(); } break; default: if( cUINodeSkin::ParseLine( parser, token ) == false ) { return false; } break; } } return true; }