#include "StdAfx.h" #include "TextBox.h" #include "Token.h" #include "UISkinLexer.h" #include "Parser.h" #include "UIContainer.h" #include "UIImage.h" #include "UIFuncText.h" #include "FontAgent.h" #include "ScrollBar.h" cTextBox::cTextBox( eUINodeType type ) : cTextCtrl( type ) , mTextPosX(0) , mTextPosY(0) , mNextPosY(0) , mTopRowIdx(0) , mMaxRowInPage(0) , mRowHeight(0) , mpScrollBar(0) , mFixScrollH(0) , mDrawTextBottom( true ) , mScrollBottom( false ) , mIncreseTopRowIdx( true ) , mChatMode( false ) { mFontType = cFontAgent::eFont_Chat; mScrollbarPosType = eRIGHT_SCROLLBAR; mTextColor = mDefaultColor; } cTextBox::~cTextBox() { /// ½ºÅ©·Ñ¹Ù ¼Ò¸ê( ºÎ¸ð´Ü¿¡¼­ ÇØÁÜ ) mpScrollBar = 0; } /// void cTextBox::Clear() { cTextCtrl::Clear(); /// ¸ðµç °ª ÃʱâÈ­ mTopRowIdx = 0; mIncreseTopRowIdx = true; /// ½ºÅ©·Ñ¹Ù ÃʱâÈ­ UpdateScrollBarButton(); /// ½ºÅ©·Ñ¹Ù À§Ä¡ ÃʱâÈ­ UpdateScrollBarPos(); } /// ÁÖÀÇ»çÇ× : bool cTextBox::OnCreate( cUINodeProperty* property ) { /// Ãß°¡ÀûÀÎ °ÍÀº À̰ÍÀ¸·Î »ý¼º if( cUIWindow::OnCreate( property ) == false ) return false; /// ¸®½ºÆ® ÇÑÆäÀÌÁö¿¡ ÃÖ´ë µé¾î°¥¼ö ÀÖ´Â °¹¼ö ¼¼ÆÃ mMaxRowInPage = GetAbsoluteRect().GetHeight() / mRowHeight; mIncreseTopRowIdx = true; /// ½ºÅ©·Ñ¹Ù »ý¼º if( mScrollSkin ) { mpScrollBar = new cScrollBar; if( mpScrollBar->CreateBySkinName( mScrollSkin, this, eTEXTBOX_SCROLL ) == false ) return false; /// ½ºÅ©·Ñ¹Ù ±æÀÌ ¼¼ÆÃ mpScrollBar->SetHeight( GetAbsoluteRect().GetHeight() - mFixScrollH ); /// ¹Ù ¹öư »çÀÌÁî ¼¼ÆÃ UpdateScrollBarButton(); /// UpdateScrollBarPos(); /// ½ºÅ©·Ñ¹ÙÀÇ À§Ä¡¿É¼ÇÀ» º¸°í À§Ä¡¸¦ ¼³Á¤ if( mScrollbarPosType == eRIGHT_SCROLLBAR ) { mpScrollBar->SetPosX( GetRelativeRect().mRight - GetRelativeRect().mLeft - mpScrollBar->GetAbsoluteRect().GetWidth()); } else { mpScrollBar->SetPosX( GetRelativeRect().mLeft - mpScrollBar->GetAbsoluteRect().GetWidth()); } mpScrollBar->Hide(); } /// ³Êºñ ¼³Á¤ if( mpScrollBar ) { mMaxTextWidth = GetAbsoluteRect().GetWidth() - mpScrollBar->GetAbsoluteRect().GetWidth(); } else { mMaxTextWidth = GetAbsoluteRect().GetWidth(); } return true; } /// ÁÖÀÇ»çÇ× : bool cTextBox::SetSkin( const cUINodeSkin* pskin ) { if( pskin->IsKindof( eUINODE_TEXTBOX ) == false ) { assert( 0 && "not list skin type" ); return false; } if( cUINode::SetSkin( pskin ) == false ) { return false; } /// ½ºÅ©¸³Æ® ÀÇ ¼Ó¼º ÀúÀå cTextBoxSkin* p = (cTextBoxSkin*)pskin; cUISkin* pUISkin = UIMAN->GetSkin(); if( !pUISkin ) { assert(0); return false; } /// ÀÚ½Ä ½ºÅ² ³×ÀÓ ÀúÀå mScrollSkin = p->mScrollSkin; /// ½ºÅ² ³×ÀÓ À¯È¿¼º °Ë»ç if( mScrollSkin && pUISkin->GetNodeSkin( p->mScrollSkin ) == 0 ) { assert( 0 && "error skin name" ); return false; } /// ¸®½ºÆ®¿¡ ÃÖ´ë µé¾î°¥¼ö ÀÖ´Â °¹¼ö ¼¼ÆÃ mTotalMaxNum = p->mTotalMaxNum; /// ¾ÆÀÌÅÛ ³ôÀÌ ¼¼ÆÃ mRowHeight = p->mRowHeight; if( mRowHeight < 0 ) { assert(0); return false; } /// ½ºÅ©·Ñ¹ÙÀÇ À§Ä¡ ¼¼ÆÃ ¿É¼Ç mScrollbarPosType = ( p->mScrollBarRightPos ) ? eRIGHT_SCROLLBAR : eLEFT_SCROLLBAR; return true; } /// void cTextBox::UpdateRect() { cUIWindow::UpdateRect(); UpdateText(); } /// ÁÖÀÇ»çÇ× : ÇØ»óµµ º¯°æ¿¡ µû¸¥ ÀçÁ¶Á¤ void cTextBox::UpdateSkin() { cUISkin* pskin = UIMAN->GetSkin(); if( pskin == 0 ) { assert(0); } /// ³ëµå ½ºÅ² °Ë»ö cUINodeSkin* pnodeSkin = pskin->GetNodeSkin( mSkinName ); if( pnodeSkin == 0 ) { assert(0); } /// ·çÆ®ÀÇ ¹Ù·Î ÀÚ½ÄÀÎ À©µµ¿ìµéÀº ±âÁ¸ÁÂÇ¥¸¦ ÀúÀåÇÑä ÇØ»óµµ¸¦ º¯°æ if( mpParent == 0 ) { assert(0); return; } /// ±âÁ¸ ÇØ»óµµ ÀúÀå mOldScreenWidth = GetScreenWidth(); mOldScreenHeight = GetScreenHeight(); /// ÀÚ½Ä ½ºÅ² Àû¿ë cChildList::cIterator i = mChildList.Begin(); cChildList::cIterator end = mChildList.End(); for( ; i != end; ++i ) { cUINode* n = (cUINode*)(*i); if( n ) n->UpdateSkin(); } /// ¸®½ºÆ® ÇÑÆäÀÌÁö¿¡ ÃÖ´ë µé¾î°¥¼ö ÀÖ´Â °¹¼ö ¼¼ÆÃ mMaxRowInPage = GetAbsoluteRect().GetHeight() / mRowHeight; /// ½ºÅ©·Ñ¹Ù°¡ ÀÖÀ¸¸é ½ºÅ©·Ñ¹Ùµµ Àç¼¼ÆÃ if( mpScrollBar ) { /// ½ºÅ©·Ñ¹Ù ±æÀÌ ¼¼ÆÃ mpScrollBar->SetHeight( GetAbsoluteRect().GetHeight() - mFixScrollH ); /// ¹Ù ¹öư »çÀÌÁî ¼¼ÆÃ UpdateScrollBarButton(); /// žÀ妽º Á¶Àý if( mScrollBottom && GetRowCount() >= mMaxRowInPage ) { mTopRowIdx = GetRowCount() - mMaxRowInPage; } /// ½ºÅ©·Ñ¹Ù y À§Ä¡ ¼¼ÆÃ UpdateScrollBarPos(); /// ½ºÅ©·Ñ¹ÙÀÇ À§Ä¡¿É¼ÇÀ» º¸°í À§Ä¡¸¦ ¼³Á¤ if( mScrollbarPosType == eRIGHT_SCROLLBAR ) { mpScrollBar->SetPosX( GetRelativeRect().mRight - GetRelativeRect().mLeft - mpScrollBar->GetAbsoluteRect().GetWidth()); } else { mpScrollBar->SetPosX( GetRelativeRect().mLeft - mpScrollBar->GetAbsoluteRect().GetWidth()); } UpdateText(); } } /// ÁÖÀÇ»çÇ× : bool cTextBox::HandleEvent( const cUIEvent& event ) { if( mEnabled == false || mVisible == false ) { return mpParent->HandleEvent( event ); } switch( event.mType ) { case eUIEVENT_COMMAND: case eUIEVENT_BUTTON_DOWNED: { if( event.mID == eSCROOLBAR_UP || event.mID == eSCROOLBAR_DOWN ) CheckButtonEvent( event.mID ); else mpParent->HandleEvent( event ); } break; case eUIEVENT_SCROLLBAR_MOVE: OnScrollbarMoved( event.mPos ); break; case eUIEVENT_MOUSE_WHEEL: OnMouseWheel( event.mPos, event.mWheel ); break; case eUIEVENT_LBUTTON_DOWN: case eUIEVENT_LBUTTON_UP: mpParent->HandleEvent( event ); OnLButtonDown( event.mPos, false, false, false ); break; default: return cUINode::HandleEvent( event ); } return true; } /// ÁÖÀÇ»çÇ×: ÅØ½ºÆ® ÁÂÇ¥ ¾÷µ¥ÀÌÆ® void cTextBox::UpdateText() { /// ¸®½ºÆ® ¹Ú½ºÀÇ ÁÂÇ¥ ¹Þ¾Æ¿À±â cUIRect rc = GetAbsoluteRect(); mTextPosX = rc.mLeft + 2; mTextPosY = rc.mTop + 1; /// ÅØ½ºÆ®¹Ú½ºÀÇ ÅØ½ºÆ®¸¦ »Ñ¸± À§Ä¡ ÁöÁ¤ if( mpScrollBar && mScrollbarPosType == eLEFT_SCROLLBAR ) { /// ½ºÅ©·Ñ¹Ù¸¦ ÅØ½ºÆ®¹Ú½º ±âÁØÀ¸·Î ¿ÞÂÊ¿¡ µÎ·ÁÇÑ´Ù¸é /// ½ºÅ©·Ñ¹Ù ³ÐÀ̸¸Å­À» ´õÇÑ À§Ä¡ºÎÅÍ Ãâ·ÂÇÑ´Ù unsigned int width = mpScrollBar->GetAbsoluteRect().GetWidth(); mTextPosX = rc.mLeft + width + 2; } /// ÆäÀÌÁö¿¡ µé¾î°¥¼ö ÀÖ´Â ÁÙ¼ö¸¦ ÃʰúÇϸé ÅØ½ºÆ®Ã¢ óÀ½ À§Ä¡ºÎÅÍ Çϳª¾¿ »Ñ¸°´Ù. mNextPosY = mTextPosY; /// ÅØ½ºÆ® Ãâ·Â À§Ä¡ ¼³Á¤ if( mDrawTextBottom && GetRowCount() <= mMaxRowInPage ) { mNextPosY = rc.mBottom - (GetRowCount() * mRowHeight); } } /// ÁÖÀÇ»çÇ× : void cTextBox::OnRender( cUIFontItemKeeper* pKeeper ) { if( mVisible == false ) return; /// À̹ÌÁö ·»´õ¸µ if( mpImage ) mpImage->Draw(); /// ÀÚ½Ä ·»´õ¸µ cChildList::cIterator i = mChildList.Begin(); cChildList::cIterator end = mChildList.End(); for( ; i != end; ++i ) { if( ((cUINode*)(*i))->IsVisible() == true ) { ((cUINode*)(*i))->OnRender(pKeeper); } } if( GetRowCount() > 0 ) { unsigned int rowCount = ( mMaxRowInPage > GetRowCount() )? GetRowCount() : mMaxRowInPage; for( unsigned int row = mTopRowIdx; row < mTopRowIdx + rowCount; ++row ) { sRowTextData* rowData = GetRowData( row ); if( !rowData ) continue; int addX = 0; unsigned int colCount = rowData->mColumes.GetSize(); /// °°Àº ¿­, Áï Ä÷³µéÀ» ¿·¿¡ ºÙ¿©°¡¸é¼­ Ãâ·ÂÇÑ´Ù. for( unsigned int col = 0; col < colCount; ++col ) { sTextData* colData = rowData->mColumes[col]; if( colData ) { int addY = ( row - mTopRowIdx ) * mRowHeight; pKeeper->AddFontItem( mFontType, (LPTSTR)(colData->mText).Cstr(), mTextPosX + addX, mNextPosY + addY, (unsigned long)(colData->mColor), mOutLine ); addX += FONTAGENT->GetTextExtent( mFontType, (LPTSTR)(colData->mText).Cstr(), colData->mText.GetLength() ); } } } } pKeeper->DrawAll(); } /// Å×½ºÆ®¿ë - ¶óÀÎ µÎ°³¿¡ °ÉÄ£ ÅØ½ºÆ®´Â ¸øÃ£´Â´Ù. void cTextBox::OnLButtonDown( const cUIPos& pos, bool /*ctrl*/, bool /*alt*/, bool ) { /// ³»¿ëÀÌ ¾øÀ¸¸é ¸®ÅÏ if( GetRowCount() <= 0 ) return; /// ÅØ½ºÆ®¹Ú½º¾È¿¡¼­ÀÇ ¸¶¿ì½º ÁÂÇ¥ unsigned int mouseX = pos.mX - mTextPosX; unsigned int mouseY = pos.mY - mTextPosY; /// ¶óÀÎ ±¸Çϱâ int row = 0; unsigned int lineNum = mouseY / mRowHeight; if( GetRowCount() >= mMaxRowInPage ) { /// ²ËÂ÷ÀÖÀ¸¸é row = mTopRowIdx + lineNum; } else { /// ºó ÁÙÀÌ ÀÖÀ¸¸é °è»ê row = lineNum - ( mMaxRowInPage - GetRowCount() ); } if( row < 0 ) return; /// ÇØ´ç¶óÀο¡ x À§Ä¡¸¸ ºñ±³Çؼ­ ÅØ½ºÆ® µ¥ÀÌÅÍ Ã£±â sRowTextData* rowData = GetRowData( row ); if( !rowData ) return; /// °°Àº ¿­, Áï Ä÷³µéÀ» °Ë»ç unsigned int addX = 0; unsigned int colWidth = 0; unsigned int colCount = rowData->mColumes.GetSize(); bool search = false; for( unsigned int col = 0; col < colCount; ++col ) { sTextData* colData = rowData->mColumes[col]; if( !colData ) { assert(0); continue; } colWidth = FONTAGENT->GetTextExtent( cFontAgent::eFont_Chat, (LPTSTR)(colData->mText).Cstr(), colData->mText.GetSize() ); /// ³Êºñ¾È¿¡ Æ÷ÇÔÇÏ´Â µ¥ÀÌÅÍ Ã£±â if( mouseX >= addX && mouseX < addX + colWidth ) { if( colData->mUseInven ) { sInvenData* inven = (sInvenData*)colData; if( inven ) { UIMAN->ShowChatItemTip( pos, inven->mInventory ); search = true; break; } else { assert(0); } } } /// ´ÙÀ½ ³Êºñ ±¸Çϱâ addX += colWidth; } if( search == false ) UIMAN->HideTip(); } /// void cTextBox::OnMouseWheel( const cUIPos&, int wheel ) { if( !mpScrollBar || mpScrollBar->IsVisible() == false ) return; assert( GetRowCount() >= mMaxRowInPage); /// ½ºÅ©·Ñ¹Ù À§·Î ÈÙ Àû¿ë if( wheel > 0 ) { if( mTopRowIdx > 0 ) { mTopRowIdx--; } } /// ¾Æ·¡·Î ÈÙ Àû¿ë else if ( wheel < 0 ) { /// ³²´Â ¿µ¿ªÀÌ ¾ø°Ô²û ½ºÅ©·Ñ if( GetRowCount() - mTopRowIdx > mMaxRowInPage ) { mTopRowIdx++; } } else { assert( 0 && "error mouse wheel message" ); return; } /// ½ºÅ©·Ñ¹Ù ¾÷µ¥ÀÌÆ® UpdateScrollBarPos(); } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹Ù°¡ ¿òÁ÷À̸é, ÅØ½ºÆ® ¹Ú½º ¾ÆÀÌÅÛ Ãâ·Â ¼øÀ§ °»½Å void cTextBox::OnScrollbarMoved( const cUIPos& ) { if( mpScrollBar ) { assert( GetRowCount() > mMaxRowInPage ); /// ¹Ù ¹öư À§Ä¡¸¦ ¾ò¾î¿È. unsigned int barbuttonPos = mpScrollBar->GetBarButtonPosY(); double h = mpScrollBar->GetScrollMarginHeight() / (double)( GetRowCount() - mMaxRowInPage ); /// ÇöÀç ¹Ù ¹öư À§Ä¡¿¡ ÇØ´çÇÏ´Â ¾ÆÀÌÅÛ À妽º ±¸Çϱâ double x = ((double)barbuttonPos / h); mTopRowIdx = (int)x; } } /// ½ºÅ©·Ñ¹ÙÀÇ À§Ä¡¿Í, ³ôÀ̸¦ Á¶Á¤ÇÑ´Ù void cTextBox::SetScrollbar( unsigned int addh ) { /// º¸Á¤°ª ¼¼ÆÃ mFixScrollH = addh; if( mpScrollBar ) { mpScrollBar->SetPosY( mFixScrollH ); /// ½ºÅ©·Ñ¹Ù ±æÀÌ ¼¼ÆÃ mpScrollBar->SetHeight( GetAbsoluteRect().GetHeight() - mFixScrollH ); //// ¹Ù ¹öư »çÀÌÁî ¼¼ÆÃ UpdateScrollBarButton(); /// ½ºÅ©·Ñ "¹Ù" y À§Ä¡ ¼¼ÆÃ UpdateScrollBarPos(); } } /// µ¿ÀÏ ¶óÀΠã¾Æ¼­ ÅØ½ºÆ® °»½Å void cTextBox::UpdateRowText( int line, LPCTSTR text ) { if( GetRowCount() <= 0 ) return; unsigned int rowCount = GetRowCount(); for( unsigned int row = 0; row < rowCount; ++row ) { sRowTextData* rowData = GetRowData( row ); if( !rowData ) continue; unsigned int colCount = rowData->mColumes.GetSize(); for( unsigned int col = 0; col < colCount; ++col ) { sTextData* colData = rowData->mColumes[col]; if( colData && line == (int)row ) { colData->mText = text; break; } } } } /// ÁÖÀÇ»çÇ× : ºó °ø¹é ¶óÀÎ Ãß°¡ ( ¿£ÅÍ ÀÔ·Â È¿°ú ) void cTextBox::AddEmptyRow( unsigned int line ) { int nOldTextCount = GetRowCount(); cTextCtrl::AddEmptyRow( line ); if( GetRowCount() > mMaxRowInPage ) { /// ½ºÅ©·Ñ¹Ù ¹öư »çÀÌÁî ¾÷µ¥ÀÌÆ® UpdateScrollBarButton(); /// ¸Ç ¹ØÀ» ±âÁØÀ¸·Î Çϰí½ÍÀ¸¸é, if( mScrollBottom ) { /// ¸Ç¸¶Áö¸·À§Ä¡·Î °è»ê mTopRowIdx = ( GetRowCount() - mMaxRowInPage ); /// ½ºÅ©·Ñ "¹Ù" y À§Ä¡ ¼¼ÆÃ UpdateScrollBarPos(); } else { if( mChatMode == true ) { if( mIncreseTopRowIdx == true ) { int nAddCnt = GetRowCount() - nOldTextCount; if( mTopRowIdx == 0 && nAddCnt >= 2) { mTopRowIdx += 1; } else { mTopRowIdx += nAddCnt; } UpdateScrollBarPos(); if( GetRowCount() >= (mTotalMaxNum - 1) ) mIncreseTopRowIdx = false; } } else { UpdateScrollBarPos(); } } } UpdateText(); } /// ÁÖÀÇ»çÇ× : »õ·Î¿î ¿­¿¡ ÅØ½ºÆ® ÀÔ·Â int cTextBox::AddNewRow( LPCTSTR text, unsigned long textcolor, sInventory* inventory ) { int nOldTextCount = GetRowCount(); /// »ðÀÔ cTextCtrl::AddNewRow( text, textcolor, inventory ); /// if( GetRowCount() > mMaxRowInPage ) { /// ½ºÅ©·Ñ¹Ù ¹öư »çÀÌÁî ¾÷µ¥ÀÌÆ® UpdateScrollBarButton(); /// ¸Ç ¹ØÀ» ±âÁØÀ¸·Î Çϰí½ÍÀ¸¸é, if( mScrollBottom ) { /// ¸Ç¸¶Áö¸·À§Ä¡·Î °è»ê mTopRowIdx = GetRowCount() - mMaxRowInPage; UpdateScrollBarPos(); } else { if( mChatMode == true ) { if( mIncreseTopRowIdx == true ) { int nAddCnt = GetRowCount() - nOldTextCount; if( mTopRowIdx == 0 && nAddCnt >= 2) { mTopRowIdx += 1; } else { mTopRowIdx += nAddCnt; } UpdateScrollBarPos(); if( GetRowCount() >= (mTotalMaxNum - 1) ) mIncreseTopRowIdx = false; } } else { UpdateScrollBarPos(); } } } UpdateText(); return ( GetRowCount() > 1 ) ? GetRowCount() - 1 : 0 ; } void cTextBox::AddPasteRow( LPCTSTR text, unsigned long textcolor, sInventory* inventory ) { int nOldTextCount = GetRowCount(); cTextCtrl::AddPasteRow( text, textcolor, inventory ); if( GetRowCount() > mMaxRowInPage ) { /// ½ºÅ©·Ñ¹Ù ¹öư »çÀÌÁî ¾÷µ¥ÀÌÆ® UpdateScrollBarButton(); /// ¸Ç ¹ØÀ» ±âÁØÀ¸·Î Çϰí½ÍÀ¸¸é, if( mScrollBottom ) { /// ¸Ç¸¶Áö¸·À§Ä¡·Î °è»ê mTopRowIdx = ( GetRowCount() - mMaxRowInPage ); /// ½ºÅ©·Ñ "¹Ù" y À§Ä¡ ¼¼ÆÃ UpdateScrollBarPos(); } else { if( mChatMode == true ) { if( mIncreseTopRowIdx == true ) { int nAddCnt = GetRowCount() - nOldTextCount; if( mTopRowIdx == 0 && nAddCnt >= 2) { mTopRowIdx += 1; } else { mTopRowIdx += nAddCnt; } UpdateScrollBarPos(); if( GetRowCount() >= (mTotalMaxNum - 1) ) mIncreseTopRowIdx = false; } } else { UpdateScrollBarPos(); } } } UpdateText(); } /// bool cTextBox::AddFucnText( cUIFuncTextNode* node, cUIFuncTextParam* param ) { if( !node ) { assert(0); return false; } bool newLine = true; mTextColor = mDefaultColor; for( ; node; node = node->GetNext() ) { switch( node->mType ) { case eTEXTNODE_STRING: { if( newLine == true ) AddNewRow( node->mpString, mTextColor ); else AddPasteRow( node->mpString, mTextColor ); newLine = false; } break; case eTEXTNODE_COLOR: { mTextColor = node->mColor; } break; case eTEXTNODE_VARNAME: { if( param ) { if( newLine == true ) AddNewRow( param->mName.Cstr(), mTextColor ); else AddPasteRow( param->mName.Cstr(), mTextColor ); } else assert(0); newLine = false; } break; case eTEXTNODE_NEWLINE: { AddEmptyRow( 1 ); } break; default: { assert( 0 && "invalid npc text node type" ); } return false; } } return true; } /// ÁÖÀÇ»çÇ× : ÅØ½ºÆ®¹Ú½ºÀÇ »çÀÌÁî º¯È­¿¡ µû¸¥ ¸ðµç Á¤º¸ °»½Å void cTextBox::UpdateTextBox( bool add ) { /// ¸®½ºÆ® ÇÑÆäÀÌÁö¿¡ ÃÖ´ë µé¾î°¥¼ö ÀÖ´Â °¹¼ö ¼¼ÆÃ mMaxRowInPage = GetAbsoluteRect().GetHeight() / mRowHeight; /// ÅØ½ºÆ®¹Ú½º È®Àå if( add == true ) { /// Ãâ·Â °¹¼ö ±¸Çϱâ if( mMaxRowInPage <= GetRowCount() ) { /// tapIdx °¡ ÇѰè¹üÀ§¸¦ ³Ñ¾î°¡Áö ¾Êµµ·Ï ÇÑ´Ù if( mTopRowIdx > 0 ) { mTopRowIdx--; } } } /// ÅØ½ºÆ®¹Ú½º Ãà¼Ò else { /// Ãâ·Â °¹¼ö ±¸Çϱâ if( mMaxRowInPage < GetRowCount() ) { /// tapIdx °¡ ÇѰè¹üÀ§¸¦ ³Ñ¾î°¡Áö ¾Êµµ·Ï ÇÑ´Ù if( GetRowCount() - mTopRowIdx > mMaxRowInPage ) { mTopRowIdx++; } } } if( mpScrollBar ) { /// ½ºÅ©·Ñ¹Ù ±æÀÌ ¼¼ÆÃ mpScrollBar->SetHeight( GetAbsoluteRect().GetHeight() - mFixScrollH ); /// ¹Ù ¹öư »çÀÌÁî ¼¼ÆÃ UpdateScrollBarButton(); /// ½ºÅ©·Ñ "¹Ù" y À§Ä¡ ¼¼ÆÃ UpdateScrollBarPos(); } UpdateText(); } /// ÁÖÀÇ»çÇ× : ¹öưÀÇ »óÅ üũ void cTextBox::CheckButtonEvent( unsigned int id ) { if( !mpScrollBar ) { /// ¿©±â µé¾î¿Â´Ù¸é À߸øµÈ ºÎºÐÀδÙ. assert(0); return; } /// ½ºÅ©·Ñ¹Ù°¡ ±×·ÁÁöÁö ¾Ê´Â »óÅÂ¸é ¸®ÅÏ if( mpScrollBar->IsVisible() == false ) { /// ¿©±â µé¾î¿Â´Ù¸é À߸øµÈ ºÎºÐÀδÙ. assert(0); return; } assert( GetRowCount() >= mMaxRowInPage ); switch( id ) { case eSCROOLBAR_UP: if( mTopRowIdx > 0 ) { mTopRowIdx--; } break; case eSCROOLBAR_DOWN: /// ³²´Â GetRowCount() ¾ø°Ô²û ½ºÅ©·Ñ if( GetRowCount() - mTopRowIdx > mMaxRowInPage ) { mTopRowIdx++; } break; } /// ½ºÅ©·Ñ "¹Ù" y À§Ä¡ ¼¼ÆÃ UpdateScrollBarPos(); } /// ½ºÅ©·Ñ¹Ù À§Ä¡ ¾÷µ¥ÀÌÆ® void cTextBox::UpdateScrollBarPos() { if( !mpScrollBar ) return; /// ½ºÅ©·Ñ¹Ù°¡ ±×·ÁÁöÁö ¾Ê´Â »óÅÂ¸é ¸®ÅÏ if( mpScrollBar->IsVisible() == false ) return; /// ÇÑ ¾ÆÀÌÅÛ´ç ½ºÅ©·Ñ¹Ù°¡ ¿òÁ÷ÀÌ´Â °Å¸® ±¸Çϱâ double h = mpScrollBar->GetScrollMarginHeight() / (double)( GetRowCount() - mMaxRowInPage ); /// ÇöÀç žÀ妽º * ÇѰ³¿µ¿ª = »õ·Î¿î ½ºÅ©·Ñ¹Ù À§Ä¡ double newposY = h * mTopRowIdx; double oldY = mpScrollBar->GetBarButtonPosY(); /// ±âÁ¸ À§Ä¡¶û ºñ±³Çؼ­ ½ºÅ©·Ñ¹ÙÀÇ À§Ä¡¸¦ ÀçÁ¶Á¤ÇÑ´Ù. int value = (int)(newposY-oldY); if( newposY > oldY ) { mpScrollBar->MoveScrollDown( value ); } else { mpScrollBar->MoveScrollUp( -value ); } } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹ÙÀÇ »çÀÌÁî °è»ê void cTextBox::UpdateScrollBarButton() { if( !mpScrollBar ) return; /// ÅØ½ºÆ®¹Ú½º°¡ ³Ê¹«ÀÛÀ¸¸é ½ºÅ©·Ñ¹ÙÀÇ ¹öưÀ» ±×¸®Áö ¾Ê´Â´Ù. unsigned int scrollHeight = mpScrollBar->GetAbsoluteRect().GetHeight(); unsigned int buttonHeight = mpScrollBar->GetScrollButtonHeight() * 2; bool isHideBarButton = false; if( scrollHeight > buttonHeight ) { scrollHeight -= buttonHeight; } else isHideBarButton = true; /// ÇÑ¿µ¿ª¿¡ µé¾î°¥ ¼ö ÀÖ´Â °¹¼öº¸´Ù ¸¹Àº ¾ÆÀÌÅÛ¼ö°¡ ÀÖÀ¸¸é, if( GetRowCount() > mMaxRowInPage ) { /// ½ºÅ©·Ñ¹Ù Àüü¸¦ ±×¸°´Ù mpScrollBar->Show(); /// ½ºÅ©·Ñ¹ÙÀÇ Å©±â¸¦ ºñ±³ÇÏ¿© ¹Ù ¹öưÀ» ±×¸®Áö ¾Ê´Â´Ù. if( scrollHeight < mpScrollBar->GetMinimumHeight() || isHideBarButton ) mpScrollBar->SetVisibleBarButton( false ); else mpScrollBar->SetVisibleBarButton( true ); } else { /// ½ºÅ©·Ñ¹ÙÀÇ ¹Ù ¹öưÀ» ±×¸®Áö ¾Ê´Â´Ù. mpScrollBar->Hide(); } } ////////////////////////////////////////////////////////////////////////////// cTextBoxSkin::cTextBoxSkin( eUINodeType type ) : cUINodeSkin( type ) , mRowHeight( 0 ) , mTotalMaxNum( 0 ) , mScrollBarRightPos(true) { } cTextBoxSkin::~cTextBoxSkin() { } /// ÁÖÀÇ»çÇ× : ½ºÅ©¸³Æ® ÆÄÀÏÀ» Àоîµé¿©¼­ °ªÀ» ¼¼ÆÃÇÑ´Ù bool cTextBoxSkin::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_ROWHEIGHT: { mRowHeight = parser.ParseInt(); } break; case eTOKEN_SCROLLBAR_RIGHTPOS: { lexer->GetNextToken( &token ); if( token.mType == eTOKEN_TRUE ) { mScrollBarRightPos = true; } else if( token.mType == eTOKEN_FALSE ) { mScrollBarRightPos = false; } else { assert( 0 && "invalid token" ); return false; } } break; case eTOKEN_SCROLLSKIN: { mScrollSkin = parser.ParseString(); } break; case eTOKEN_MAXITEMNUM: { mTotalMaxNum = parser.ParseInt(); } break; default: if( cUINodeSkin::ParseLine( parser, token ) == false ) { return false; } break; } } return true; }