#include "Stdafx.h" #include "ScrollBar.h" #include "Token.h" #include "UISkinLexer.h" #include "Parser.h" #include "UIImage.h" #include "UIContainer.h" #include "PlaneObject.h" #include "SoundSystem.h" #include "Button.h" #include "BarButton.h" cScrollBar::cScrollBar( eUINodeType type ) : cUIWindow( type ) , mpScrollImage(0) , mpUpButton(0) , mpDownButton(0) , mpBarButton(0) { } cScrollBar::~cScrollBar() { SAFE_DELETE( mpScrollImage ); mpBarButton = 0; mpDownButton = 0; mpUpButton = 0; } void cScrollBar::OnShow() { mpBarButton->Show(); mpDownButton->Show(); mpUpButton->Show(); cUIWindow::OnShow(); } void cScrollBar::OnHide() { cUIWindow::OnHide(); mpBarButton->Hide(); mpDownButton->Hide(); mpUpButton->Hide(); } void cScrollBar::Show( bool onsound ) { if( mVisible ) return; if( onsound && mOpenSoundIdx != ULONG_MAX ) SOUNDSYS->Play2DSound( mOpenSoundIdx ); SetVisible( true ); OnShow(); } /// ÁÖÀÇ»çÇ× : bool cScrollBar::OnCreate( cUINodeProperty* ) { mpBarButton = new cBarButton; if( mpBarButton->CreateBySkinName( mBarButtonSkin, this, eSCROOLBAR_BARBUTTON ) == false ) { return false; } mpUpButton = new cButton; if( mpUpButton->CreateBySkinName( mUpButtonSkin, this, eSCROOLBAR_UP ) == false ) { return false; } mpDownButton = new cButton; if( mpDownButton->CreateBySkinName( mDownButtonSkin, this, eSCROOLBAR_DOWN ) == false ) { return false; } /// BAR ¹öưÀÇ À§Ä¡´Â ½ºÅ©·Ñ¹Ù¸¦ ±âÁØÀ¸·Î ÀçÁ¶Á¤ cUIPos pos; pos.mX = 0; pos.mY = mpUpButton->GetRelativeRect().mBottom; mpBarButton->SetRelativePos( pos ); return true; } /// ÁÖÀÇ»çÇ× : bool cScrollBar::SetSkin( const cUINodeSkin* pskin ) { if( pskin->IsKindof( eUINODE_SCROLLBAR ) == false ) { assert( 0 && "not editbox skin type" ); return false; } if( cUINode::SetSkin( pskin ) == false ) { return false; } cScrollBarSkin* p = (cScrollBarSkin*)pskin; mBarButtonSkin = p->mBarButtonSkin; mUpButtonSkin = p->mUpButtonSkin; mDownButtonSkin = p->mDownButtonSkin; cUISkin* pUISkin = UIMAN->GetSkin(); if( !pskin ) { assert(0); return false; } /// ½ºÅ² ³×ÀÓ À¯È¿¼º °Ë»ç if( mBarButtonSkin && pUISkin->GetNodeSkin( mBarButtonSkin ) == 0 ) { assert( 0 && "error skin name" ); return false; } if( mUpButtonSkin && pUISkin->GetNodeSkin( mUpButtonSkin ) == 0 ) { assert( 0 && "error skin name" ); return false; } if( mDownButtonSkin && pUISkin->GetNodeSkin( mDownButtonSkin ) == 0 ) { assert( 0 && "error skin name" ); return false; } if( pskin->mpTexture ) { /// ÅØ½ºÃ³ ¿µ¿ª ¼³Á¤ unsigned short w = (unsigned short)pskin->mSkinInfo->mWidth; unsigned short h = (unsigned short)pskin->mSkinInfo->mHeight; unsigned short tx = (unsigned short)pskin->mSkinInfo->mTexX; unsigned short ty = (unsigned short)pskin->mSkinInfo->mTexY; mpScrollImage = new cPlaneObject; if( mpScrollImage->Create( pskin->mpTexture, 0, 0, w, h, tx, ty, tx + w, ty + h ) == false ) { assert( 0 && "failed to create scroll back image"); return false; } } /// ÀÚüÀ̹ÌÁö¸¦ µû·Î »ý¼ºÇؼ­ »ç¿ëÇϹǷΠÇÊ¿ä¾øÀ½ SAFE_DELETE( mpImage ); return true; } /// ÁÖÀÇ»çÇ× : bool cScrollBar::HandleEvent( const cUIEvent& event ) { if( mEnabled == false || mVisible == false ) { return true; } if( event.mType == eUIEVENT_SCROLLBAR_MOVE ) { UpdateBarButtonPos( event.mPos ); } if( event.mType == eUIEVENT_LBUTTON_DBLCLK ) return true; if( event.mType == eUIEVENT_LBUTTON_DOWN || event.mType == eUIEVENT_MOUSE_MOVE ) return true; return mpParent->HandleEvent( event ); } /// ÁÖÀÇ»çÇ× : void cScrollBar::UpdateSkin() { cUIWindow::UpdateSkin(); /// BAR ¹öưÀÇ À§Ä¡´Â ½ºÅ©·Ñ¹Ù¸¦ ±âÁØÀ¸·Î ÀçÁ¶Á¤ if( mpUpButton && mpBarButton ) { cUIPos pos; pos.mX = 0; pos.mY = mpUpButton->GetRelativeRect().mBottom; mpBarButton->SetRelativePos( pos ); } } /// void cScrollBar::UpdateRect() { cUIWindow::UpdateRect(); if( mpScrollImage ) { mpScrollImage->SetScreenXY( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); } } /// ÁÖÀÇ»çÇ× : void cScrollBar::OnRender( cUIFontItemKeeper* pKeeper ) { /// À̹ÌÁö ·»´õ¸µ if( mpScrollImage ) { mpScrollImage->Draw(); } /// ÀÚ½Ä ·»´õ¸µ cUIWindow::OnRender(pKeeper); } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹ÙÀÇ ¹Ù¹öưÀÌ ¿òÁ÷Àϰæ¿ì, void cScrollBar::UpdateBarButtonPos( const cUIPos& pos ) { /// ½ºÅ©·Ñ¹Ù°¡ ±×·ÁÁöÁö ¾Ê´Â »óÅÂ¸é ¸®ÅÏ if( mpBarButton->IsVisible() == false ) return; cUIRect child = mpBarButton->GetAbsoluteRect(); cUIPos& oldPos = mpBarButton->GetOldMousePos(); int uppos = mpUpButton->GetAbsoluteRect().mBottom; int downpos = mpDownButton->GetAbsoluteRect().mTop; int value = 0; /// À§ÂÊ À̵¿À̸é cUIRect parentRc = mpParent->GetAbsoluteRect(); if( parentRc.ContainPoint( pos ) == false ) return; if( pos.mY - oldPos.mY < 0 ) { if( child.mTop > uppos ) { if( child.mTop + pos.mY - oldPos.mY < uppos) { /// ÃÖ¼Ò À§Ä¡±îÁö º¸Á¤ value = uppos - child.mTop; } else { /// ¸¶¿ì½º À̵¿·® ¸¸Å­ À̵¿ value = pos.mY - oldPos.mY; } } mpBarButton->MoveY( value , pos ); } /// ¾Æ·¡ÂÊ À̵¿À̸é else if( pos.mY - oldPos.mY > 0 ) { if( child.mBottom < downpos ) { /// if( child.mBottom + pos.mY - oldPos.mY >= downpos ) { /// ÃÖ´ë À§Ä¡±îÁö º¸Á¤ value = downpos - child.mBottom; } else { /// ¸¶¿ì½º À̵¿·® ¸¸Å­ À̵¿ value = pos.mY - oldPos.mY; } } mpBarButton->MoveY( value , pos ); } } /// ÁÖÀÇ»çÇ× : void cScrollBar::OnLButtonDown( const cUIPos& pos, bool ctrl, bool alt, bool shift ) { cUIWindow::OnLButtonDown( pos, ctrl, alt, shift ); if( GetCapture() != this ) { SetCapture(); } } /// ÁÖÀÇ»çÇ× : void cScrollBar::OnLButtonUp( const cUIPos& pos ) { /// ¿µ¿ª ¹Û¿¡¼­ ¸¶¿ì½º¸¦ ³ö¹ö¸®¸é if( mAbsoluteRect.ContainPoint( pos ) == false ) { ReleaseCapture(); } } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹ÙÀÇ Ãʱâ X À§Ä¡ ¼¼ÆÃ void cScrollBar::SetPosX( unsigned int x ) { if( mpScrollImage ) { cUIPos pos; pos.mX = x; pos.mY = GetRelativeRect().mTop; SetRelativePos( pos ); mpScrollImage->SetScreenXY( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); } } void cScrollBar::SetPosY( unsigned int y ) { if( mpScrollImage ) { cUIPos pos; pos.mX = GetRelativeRect().mLeft; pos.mY = y; SetRelativePos( pos ); mpScrollImage->SetScreenXY( (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop ); } } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹ÙÀÇ ³ôÀ̰ª ¼¼ÆÃ void cScrollBar::SetHeight( unsigned int h ) { if( mpScrollImage && mpDownButton ) { cUISize size; size.mWidth = GetRelativeRect().GetWidth(); size.mHeight = h; SetRelativeSize( size ); mpScrollImage->SetScreenWH( (short)GetAbsoluteRect().GetWidth(), (short)GetAbsoluteRect().GetHeight() ); /// DOWN ¹öưÀÇ À§Ä¡´Â ½ºÅ©·Ñ¹Ù¸¦ ±âÁØÀ¸·Î ÀçÁ¶Á¤ cUIPos pos; pos.mX = 0; pos.mY = h - mpDownButton->GetRelativeRect().GetHeight(); mpDownButton->SetRelativePos( pos ); } } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹Ù Àüü ±æÀ̰¡ ÀûÀ»¶§´Â ¹Ù¹öư¸¸ ¾Èº¸¿©ÁØ´Ù. void cScrollBar::SetVisibleBarButton( bool visible ) { if( !mpBarButton ) return; if( visible ) mpBarButton->Show(); else mpBarButton->Hide(); } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹Ù ³ôÀÌ °ª ¾ò±â ( ¹Ù ¹öưÀÌ ½ºÅ©·Ñ °¡´ÉÇÑ ¿µ¿ª¸¸ °è»ê ) unsigned int cScrollBar::GetScrollBarHeight() { return ( GetAbsoluteRect().GetHeight() - (2 * mpUpButton->GetAbsoluteRect().GetHeight()) ); } unsigned int cScrollBar::GetScrollButtonHeight() { return (mpUpButton) ? mpUpButton->GetAbsoluteRect().GetHeight() : 0; } /// ÁÖÀÇ»çÇ× : ¹Ù ¹öưÀÇ À§Ä¡ ¾ò±â unsigned int cScrollBar::GetBarButtonPosY() { return (mpBarButton->GetRelativeRect().mTop - mpUpButton->GetRelativeRect().GetHeight() ); } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ [°¡´ÉÇÑ] ¿µ¿ª »çÀÌÁî ¸®ÅÏ unsigned int cScrollBar::GetScrollMarginHeight() { /// ½ºÅ©·Ñ¹Ù ±æÀÌ - ¹Ù ¹öư ±æÀÌ - ¾÷, ´Ù¿î ¹öư ±æÀÌ return ( GetAbsoluteRect().GetHeight() - mpBarButton->GetAbsoluteRect().GetHeight() - (2 * mpUpButton->GetAbsoluteRect().GetHeight()) ); } /// ÁÖÀÇ»çÇ× : ¹Ù ¹öưÀÌ ÀÛ¾ÆÁú¼ö ÀÖ´Â ÃÖ¼Ò »çÀÌÁî unsigned int cScrollBar::GetMinimumHeight() { return mpUpButton->GetAbsoluteRect().GetHeight(); } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹ÙÀÇ À­ ¹öưÀÌ ´­·ÈÀ»°æ¿ìÀÇ Ã³¸® void cScrollBar::MoveScrollUp( int h ) { /// ¹Ù ¹öưÀÇ top À§Ä¡ int toplimit = mpBarButton->GetAbsoluteRect().mTop; /// up ¹öưÀÇ bottom À§Ä¡ int bottomlimit = mpUpButton->GetAbsoluteRect().mBottom; /// top À§Ä¡°¡ bottom ÀÛÀ¸¸é ¹Ù ¹öưÀÌ up¹öưÀ» ¶Õ°í Áö³ª°¡´Â Çö»ó ¹ß»ý if( toplimit >= bottomlimit ) { int value = toplimit - bottomlimit; /// ³²Àº ¿µ¿ªÀÌ h º¸´Ù ÀûÀ¸¸é, if( h > value ) { mpBarButton->Move( cUIPos( 0, -value ) ); } else { mpBarButton->Move( cUIPos( 0, -h ) ); } } } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹ÙÀÇ ¾Æ·¡ ¹öưÀÌ ´­·ÈÀ» °æ¿ìÀÇ Ã³¸® void cScrollBar::MoveScrollDown( int h ) { /// ¹Ù ¹öưÀÇ bottom À§Ä¡ int bottomlimit = mpBarButton->GetAbsoluteRect().mBottom; /// down ¹öưÀÇ top À§Ä¡ int toplimit = mpDownButton->GetAbsoluteRect().mTop; /// bottom À§Ä¡°¡ top ÀÛÀ¸¸é ¹Ù ¹öưÀÌ down¹öưÀ» ¶Õ°í Áö³ª°¡´Â Çö»ó ¹ß»ý if( bottomlimit <= toplimit ) { int value = toplimit - bottomlimit; /// ³²Àº ¿µ¿ªÀÌ h º¸´Ù ÀûÀ¸¸é, if( h > value ) { mpBarButton->Move( cUIPos( 0, value ) ); } else { mpBarButton->Move( cUIPos( 0, h ) ); } } } ///////////////////////////////////////////////////////////////////////// cScrollBarSkin::cScrollBarSkin( eUINodeType type ) : cUINodeSkin( type ) { } cScrollBarSkin::~cScrollBarSkin() { } /// ÁÖÀÇ»çÇ× : bool cScrollBarSkin::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_BARBUTTONSKIN: { mBarButtonSkin = parser.ParseString(); } break; case eTOKEN_UPBUTTONSKIN: { mUpButtonSkin = parser.ParseString(); } break; case eTOKEN_DOWNBUTTONSKIN: { mDownButtonSkin = parser.ParseString(); } break; default: if( cUINodeSkin::ParseLine( parser, token ) == false ) { return false; } break; } } return true; }