#include "StdAfx.h" #include "ListBox.h" #include "UIManager.h" #include "UISkinLexer.h" #include "Token.h" #include "Parser.h" #include "UIEvent.h" #include "UIImage.h" #include "PlaneObject.h" #include "UIContainer.h" #include "FontAgent.h" #include "ScrollBar.h" cListBox::cListBox( eUINodeType type ) : cListCtrl( type ) , mpSelectImage(0) , mpScrollBar(0) , mpSkin(0) , mSelectBarWidth(0) , mContinueEvent( false ) , mShowImage( true ) , mPrintPos(0, 0) , mPrintSize(0, 0) { mMaxRowInPage = 0; mTotalMaxNum = 0; mSelectedRowIdx = 0; mHoveredRowIdx = -1; mImageHoveredIdx = -1; mTopRowIdx = 0; mRowHeight = 0; mHoverTextColor = COLOR_WHITE; mOutLine = true; mFontType = cFontAgent::eFont_UI; } cListBox::~cListBox() { mpScrollBar = 0; SAFE_DELETE( mpSelectImage ); } void cListBox::Clear() { mSelectedRowIdx = 0; mHoveredRowIdx = -1; mImageHoveredIdx = -1; mTopRowIdx = 0; UpdateScrollBar(); /// ¼±Åù٠if( mpSelectImage ) UpdateSelectImage(); cListCtrl::Clear(); } /// ÁÖÀÇ»çÇ× : »ý¼ºµÇÀÚ¸¶ÀÚ ÇØ¾ßÇÒ ÀÏ Ã³¸® bool cListBox::OnCreate( cUINodeProperty* pproperty ) { if( cUIWindow::OnCreate( pproperty ) == false ) return false; /// ½ºÅ²À¸·Î »ý¼º if( mScrollSkin ) { mpScrollBar = new cScrollBar; if( mpScrollBar->CreateBySkinName( mScrollSkin, this, eLIST_SCROLL ) == false ) { assert( 0 && "failed to create scroll bar" ); return false; } } if( mpScrollBar ) { /// ½ºÅ©·Ñ¹Ù ³ôÀÌ ¼¼ÆÃ mpScrollBar->SetHeight( GetAbsoluteRect().GetHeight() ); /// ½ºÅ©·Ñ¹Ù x À§Ä¡ ¼¼ÆÃ mpScrollBar->SetPosX( GetRelativeRect().mRight - GetRelativeRect().mLeft - mpScrollBar->GetAbsoluteRect().GetWidth() ); /// ½ºÅ©·Ñ¹Ù °»½Å UpdateScrollBar(); } return true; } /// ÁÖÀÇ»çÇ× : bool cListBox::SetSkin( const cUINodeSkin* pskin ) { if( pskin->IsKindof( eUINODE_LISTBOX ) == false ) { assert( 0 && "not list skin type" ); return false; } if( cUINode::SetSkin( pskin ) == false ) return false; /// ½ºÅ©¸³Æ®·ÎºÎÅÍ ÅØ½ºÃÄ ¹è°æÀ̹ÌÁöÀÇ ¼Ó¼ºÀ» ¹Þ´Â´Ù cListBoxSkin* p = (cListBoxSkin*)pskin; /// ½ºÅ² ÀúÀå mpSkin = p; mScrollSkin = p->mScrollSkin; /// ¸®½ºÆ®ÄÁÆ®·Ñ¿¡ ¾ÆÀÌÅÛ ³ôÀÌ ¼¼ÆÃ mRowHeight = p->mRowHeight; assert( mRowHeight ); /// ¸®½ºÆ®¿¡ ÃÖ´ë µé¾î°¥¼ö ÀÖ´Â °¹¼ö ¼¼ÆÃ mTotalMaxNum = p->mTotalMaxNum; mSelectBarWidth = p->mSelectBarWidth; mPrintPos = p->mPrintPos; mPrintSize = p->mPrintSize; /// ¸®½ºÆ® ÇÑÆäÀÌÁö¿¡ ÃÖ´ë µé¾î°¥¼ö ÀÖ´Â °¹¼ö ¼¼ÆÃ mMaxRowInPage = ( mPrintSize.mHeight > 0 ) ? (mPrintSize.mHeight / mRowHeight) : (pskin->mSkinInfo->mHeight / mRowHeight); if( mMaxRowInPage == 0 ) mMaxRowInPage = p->mTotalMaxNum; assert( mMaxRowInPage ); /// ¾ÆÀÌÅÛ ¼±Åà À̹ÌÁö ÅØ½ºÃÄ ¼³Á¤ if( p->mpSelectBarTexture ) { /// ÅØ½ºÃ³ ¿µ¿ª ¼³Á¤ unsigned short tx = (unsigned short)p->mSelectBarSkin->mTexX; unsigned short ty = (unsigned short)p->mSelectBarSkin->mTexY; unsigned short tw = (unsigned short)p->mSelectBarSkin->mTexWidth; unsigned short th = (unsigned short)p->mSelectBarSkin->mTexHeight; if( mpSelectImage == 0 ) { mpSelectImage = new cPlaneObject; if( mpSelectImage->Create( p->mpSelectBarTexture, (short)GetAbsoluteRect().mLeft, (short)GetAbsoluteRect().mTop, tw, th, tx, ty, tx + tw, ty + th ) == false ) { assert( 0 && "failed to create select image"); return false; } } else { mpSelectImage->SetTextureRect( tx, ty, tx + tw, ty + th ); } } return true; } /// int cListBox::AddRow( LPCTSTR str, unsigned long color, void* pExtraData ) { /// ¼ö¿ë°¹¼ö¸¦ ³Ñ¾î°¡¸é ¸®ÅÏ if( GetRowCount() >= mTotalMaxNum ) return -1; sData* data = new sData; data->mText = str; data->mTextColor = color; unsigned int ret = AddRowData( data, pExtraData ); /// ½ºÅ©·Ñ¹Ù °»½Å UpdateScrollBar(); if( mpSelectImage ) UpdateSelectImage(); return ret; } /// bool cListBox::AddColume( unsigned int rowIdx, LPCTSTR str, unsigned long color ) { /// ¼ö¿ë°¹¼ö¸¦ ³Ñ¾î°¡¸é Ä÷³¼ö °Ë»ç if( GetRowCount() >= mTotalMaxNum ) { unsigned int count = GetColumnCount( rowIdx - 1 ); unsigned int countNow = GetColumnCount( rowIdx ); if( countNow > count ) return 0; } sData* data = new sData; data->mText = str; data->mTextColor = color; return AddColumeData( rowIdx, data ); } /// void cListBox::SetExtraData( unsigned int rowIdx, void* pExtraData ) { if( rowIdx < GetRowCount() ) { sRowData* p = (sRowData*)mRows[rowIdx]; p->mExtraData = pExtraData; } } /// LPCTSTR cListBox::GetText( unsigned int rowIdx, unsigned int colIdx ) { sData* data = GetColumeData( rowIdx, colIdx ); if( data ) return data->mText.Cstr(); else return _T(""); } sData* cListBox::GetColumeData( unsigned int rowIdx, unsigned int columeIdx ) { if( mRows.GetSize() <= 0 ) return 0; if( rowIdx > mRows.GetSize()-1 ) { assert(0); return 0; } sRowData* pRow = (sRowData*)mRows[rowIdx]; return pRow->mColumes[columeIdx]; } /// ÁÖÀÇ»çÇ× : ÇØ»óµµ º¯°æ¿¡ µû¸¥ ÀçÁ¶Á¤ void cListBox::UpdateSkin() { /// ½ºÅ² ÁÂÇ¥ ¾÷µ¥ÀÌÆ® cUIWindow::UpdateSkin(); /// ¼±Åà À̹ÌÁö ÃʱâÈ­ if( mpSelectImage ) UpdateSelectImage(); /// ½ºÅ©·Ñ¹Ù°¡ ÀÖÀ¸¸é ½ºÅ©·Ñ¹Ùµµ Àç¼¼ÆÃ if( mpScrollBar ) { /// ½ºÅ©·Ñ¹Ù ³ôÀÌ ¼¼ÆÃ mpScrollBar->SetHeight( GetAbsoluteRect().GetHeight() ); /// ½ºÅ©·Ñ¹Ù x À§Ä¡ ¼¼ÆÃ mpScrollBar->SetPosX( GetRelativeRect().mRight - GetRelativeRect().mLeft - mpScrollBar->GetAbsoluteRect().GetWidth() ); /// ½ºÅ©·Ñ¹Ù °»½Å UpdateScrollBar(); } mHoveredRowIdx = -1; } /// ÁÖÀÇ»çÇ× : void cListBox::UpdateRect() { cUIWindow::UpdateRect(); if( mpSelectImage ) { /// ¼±Åù٠À̹ÌÁö ¿µ¿ª ¾÷µ¥ÀÌÆ® UpdateSelectImage(); CheckShowImage(); } } /// ÁÖÀÇ»çÇ× : void cListBox::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( mpSelectImage && GetRowCount() && IsEnabled() ) { /// ¼±ÅÃÀ̹ÌÁö ¹Ù°¡, ¸®½ºÆ®¹Ú½º¸¦ ³Ñ¾î°¡Áö ¾Êµµ·Ï ÇÑ´Ù. if( mShowImage == true ) mpSelectImage->Draw(); } /// ¸®½ºÆ® ¹Ú½ºÀÇ ¾ÆÀÌÅÛÀ» ±×·ÁÁÜ. RenderData( pKeeper ); pKeeper->DrawAll(); } /// ÁÖÀÇ»çÇ× : ¸¶¿ì½º°¡ ¿òÁ÷À϶§¸¶´Ù ¼±ÅõȰÍÀ» ¹Ù²Û´Ù void cListBox::OnMouseMove( const cUIPos& pos ) { cUINode::OnMouseMove( pos ); unsigned int row = (pos.mY - GetAbsoluteRect().mTop) / mRowHeight; if( row > mMaxRowInPage - 1 ) { mHoveredRowIdx = -1; return; } if( row >= GetRowCount() ) { mHoveredRowIdx = -1; cUIEvent event; event.mpCaller = this; event.mID = mID; event.mType = eUIEVENT_LISTBOX_ROW_LEFT; mpParent->HandleEvent( event ); return; } /// À̹ÌÁö ¿µ¿ª üũ¿¡ °üÇÑ À̺¥Æ® unsigned int curRow = mTopRowIdx + row; if( curRow >= GetRowCount() ) curRow = GetRowCount() - 1; if( mHoveredRowIdx != (int)row ) { cUIEvent event; event.mpCaller = this; event.mID = mID; event.mPos = pos; event.mType = eUIEVENT_LISTBOX_ROW_HOVERED; event.mExtraData = GetExtraData( curRow ); mpParent->HandleEvent( event ); } mHoveredRowIdx = row; } void cListBox::OnMouseLeft( const cUIPos& pos ) { cListCtrl::OnMouseLeft( pos ); mHoveredRowIdx = -1; cUIEvent event; event.mpCaller = this; event.mID = mID; event.mType = eUIEVENT_LISTBOX_ROW_LEFT; mpParent->HandleEvent( event ); } /// ÁÖÀÇ»çÇ× : void cListBox::OnLButtonDown( const cUIPos& pos, bool ctrl, bool alt, bool shift ) { cUINode::OnLButtonDown( pos, ctrl, alt, shift ); unsigned int row = (pos.mY - GetAbsoluteRect().mTop) / mRowHeight + mTopRowIdx; if( row >= GetRowCount() ) return; mHoveredRowIdx = row - mTopRowIdx; /// »õ·Î¿î ÁÙÀÌ ¼±ÅõǸé À̺¥Æ® º¸³¿ if( mContinueEvent == true || mSelectedRowIdx != row ) { mSelectedRowIdx = row; /// À̺¥Æ® º¸³»±â cUIEvent event; event.mType = eUIEVENT_LISTBOX_CHANGED; event.mpCaller = this; event.mID = mID; mpParent->HandleEvent( event ); /// ¸¶¿ì½º¸¦ ´­·¯ ¼±ÅÃÇÑ ºÎºÐÀº ´Ù¸£°Ô Ä¥ÇÑ´Ù if( mpSelectImage ) { UpdateSelectImage(); CheckShowImage(); } } } void cListBox::OnRButtonDown(const cUIPos& pos, bool, bool, bool shift ) { cUINode::OnLButtonDoubleClick( pos ); unsigned int row = (pos.mY - GetAbsoluteRect().mTop) / mRowHeight + mTopRowIdx; if( row >= GetRowCount() ) return; mSelectedRowIdx = row; mHoveredRowIdx = row - mTopRowIdx; /// À̺¥Æ® º¸³»±â cUIEvent event; event.mType = eUIEVENT_LISTBOX_SELECTEDRBUTTON; event.mpCaller = this; event.mID = mID; event.mShift = shift; mpParent->HandleEvent( event ); /// ¸¶¿ì½º¸¦ ´­·¯ ¼±ÅÃÇÑ ºÎºÐÀº ´Ù¸£°Ô Ä¥ÇÑ´Ù if( mpSelectImage ) { UpdateSelectImage(); CheckShowImage(); } } /// ÁÖÀÇ»çÇ× : void cListBox::OnLButtonDoubleClick( const cUIPos& pos ) { cUINode::OnLButtonDoubleClick( pos ); unsigned int row = (pos.mY - GetAbsoluteRect().mTop) / mRowHeight + mTopRowIdx; if( row >= GetRowCount() ) return; mSelectedRowIdx = row; mHoveredRowIdx = row - mTopRowIdx; /// À̺¥Æ® º¸³»±â cUIEvent event; event.mType = eUIEVENT_LISTBOX_SELECTED; event.mpCaller = this; event.mID = mID; mpParent->HandleEvent( event ); /// ¸¶¿ì½º¸¦ ´­·¯ ¼±ÅÃÇÑ ºÎºÐÀº ´Ù¸£°Ô Ä¥ÇÑ´Ù if( mpSelectImage ) { UpdateSelectImage(); CheckShowImage(); } } /// ÁÖÀÇ»çÇ× : ½ºÅ©·Ñ¹Ù°¡ ¿òÁ÷À̸é, ¸®½ºÆ® ¹Ú½º ¾ÆÀÌÅÛ Ãâ·Â ¼øÀ§ °»½Å void cListBox::OnScrollbarMoved( const cUIPos& ) { if( mpScrollBar == 0) return; assert( GetRowCount() > mMaxRowInPage ); /// ¹Ù ¹öư À§Ä¡¸¦ ¾ò¾î¿È. unsigned int barbuttonPos = mpScrollBar->GetBarButtonPosY(); double h = mpScrollBar->GetScrollMarginHeight() / (double)(GetRowCount()-mMaxRowInPage); /// ÇöÀç ¹Ù ¹öư À§Ä¡¿¡ ÇØ´çÇÏ´Â ¾ÆÀÌÅÛ À妽º ±¸Çϱâ double x = ((double)barbuttonPos / h); mTopRowIdx = (int)x; mHoveredRowIdx = -1; if( mpSelectImage ) { UpdateSelectImage(); CheckShowImage(); } } /// void cListBox::OnMouseWheel( const cUIPos& /*pos*/, int wheel ) { if( !mpScrollBar || mpScrollBar->IsVisible() == false ) { return; } assert(GetRowCount() > mMaxRowInPage); /// ½ºÅ©·Ñ¹Ù À§·Î ÈÙ Àû¿ë if( wheel > 0 ) { if( mTopRowIdx > 0 ) { mTopRowIdx--; if( mpSelectImage ) UpdateSelectImage(); } } /// ¾Æ·¡·Î ÈÙ Àû¿ë else if ( wheel < 0 ) { /// ³²´Â ¿µ¿ªÀÌ ¾ø°Ô²û ½ºÅ©·Ñ if( GetRowCount() - mTopRowIdx > mMaxRowInPage ) { mTopRowIdx++; if( mpSelectImage ) UpdateSelectImage(); } } else { assert( 0 && "error mouse wheel message" ); return; } /// ½ºÅ©·Ñ¹Ù ¾÷µ¥ÀÌÆ® UpdateScrollBar(); CheckShowImage(); } /// ÁÖÀÇ»çÇ× : ¹öưÀÇ »óÅ üũ void cListBox::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--; if( mpSelectImage ) UpdateSelectImage(); } break; case eSCROOLBAR_DOWN: /// ³²´Â ¿µ¿ªÀÌ ¾ø°Ô²û ½ºÅ©·Ñ if( GetRowCount() - mTopRowIdx > mMaxRowInPage ) { mTopRowIdx++; if( mpSelectImage ) UpdateSelectImage(); } break; default: return; } /// ½ºÅ©·Ñ¹Ù ¹öư À§Ä¡ ¾÷µ¥ÀÌÆ® UpdateScrollBar(); CheckShowImage(); } /// bool cListBox::ChangeSelectRow( unsigned int rowIdx, bool changeTop ) { if( rowIdx >= GetRowCount() ) return false; if( mContinueEvent == false && mSelectedRowIdx == rowIdx ) return true; mSelectedRowIdx = rowIdx; if( changeTop ) { /// ÆäÀÌÁö°¡ ³Ñ¾î °£´Ù¸é ¼±Åà °´Ã¼¸¦ ÃÖ»óÀ§·Î ¿Ã¸°´Ù. if( rowIdx >= mMaxRowInPage ) { /// ¿©¹éÀÌ ¾È³²°Ô²û Á¶Àý if( GetRowCount() - rowIdx >= mMaxRowInPage ) mTopRowIdx = mSelectedRowIdx; else mTopRowIdx = GetRowCount() - mMaxRowInPage; /// ½ºÅ©·Ñ¹Ù¸¦ °»½ÅÇÑ´Ù. UpdateScrollBar(); } } /// ¸¶¿ì½º ¿À¹öµÈ À妽ºµµ °»½Å mHoveredRowIdx = -1; /// ¼±Åà À̹ÌÁö °»½Å if( mpSelectImage ) { UpdateSelectImage(); CheckShowImage(); } return true; } /// ÁÖÀÇ»çÇ× : ¸®½ºÆ®ÀÇ Ãâ·Â½ÃÀÛÇÒ Å¾À妽º Á¶Àý bool cListBox::ChangeTopIndex( unsigned int topIdx, bool changeSel ) { if( topIdx >= GetRowCount() ) return false; if( mTopRowIdx == topIdx ) return true; mTopRowIdx = topIdx; if( changeSel == true ) mSelectedRowIdx = mTopRowIdx; else UpdateScrollBar(); /// ¸¶¿ì½º ¿À¹öµÈ À妽ºµµ °»½Å mHoveredRowIdx = -1; /// ¼±Åà À̹ÌÁö °»½Å if( mpSelectImage ) { UpdateSelectImage(); CheckShowImage(); } return true; } /// ÁÖÀÇ»çÇ× : ¸®½ºÆ® ¾ÆÀÌÅÛ ±×·ÁÁÖ±â void cListBox::RenderData( cUIFontItemKeeper* pKeeper ) { /// Àüü ¸®½ºÆ®¸¦ ¾ò¾î¿È if( GetRowCount() <= 0 ) return; /// ½ºÅ² ¹Þ¾Æ¿À±â cListBoxSkin* pListSkin = (cListBoxSkin*)mpSkin; if( !pListSkin ) { assert(0); return; } /// ¸®½ºÆ® ¹Ú½ºÀÇ ÁÂÇ¥ ¹Þ¾Æ¿À±â int textposX = 0; int textPosY = GetAbsoluteRect().mTop + mPrintPos.mY; unsigned int rowCount = ( mMaxRowInPage > GetRowCount() )? GetRowCount() : mMaxRowInPage; for( unsigned int row = mTopRowIdx; row < mTopRowIdx + rowCount; ++row ) { sRowData* rData = GetRowData( row ); if( !rData ) continue; /// ¸®½ºÆ® µ¥ÀÌÅÍ Ãâ·Â unsigned int colCount = rData->mColumes.GetSize(); for( unsigned int col = 0; col< colCount; ++col ) { /// °¢ Ä÷³ µ¥ÀÌÅÍ °¡Á®¿À±â sData* data = rData->mColumes[col]; /// °¢ Ä÷³ÀÇ param data °¡Á®¿À±â ( Ãâ·ÂÀ§Ä¡ µî ) sListCtrlParam* pParam = pListSkin->GetCtrlParam( col ); unsigned int tX = 0; unsigned int tW = 0; eText_Align align = eALIGN_LEFT; if( pParam ) { tX = pParam->mColumnX; tW = pParam->mColumnW; align = pParam->mAlign; } /// ÃÖÁ¾ Ãâ·Â ÁÂÇ¥ °è»ê unsigned int strWidth = FONTAGENT->GetTextExtent( mFontType, (LPTSTR)data->mText.Cstr(), data->mText.GetLength() ); textposX = UpdateTextPos( align, strWidth, tX, tW ); /// Hover µÈ ¾ÆÀÌÅÛÀº ´Ù¸¥ »öÀ¸·Î Ç¥½Ã unsigned color = data->mTextColor; if( mHoveredRowIdx != -1 && row - mTopRowIdx == (unsigned int)mHoveredRowIdx ) color = mHoverTextColor; int addY = 0; if( (long)mRowHeight > FONTAGENT->GetTextHeight(mFontType) ) addY = (int)( (mRowHeight-FONTAGENT->GetTextHeight(mFontType))*0.5f ); pKeeper->AddFontItem( mFontType, (LPTSTR)data->mText.Cstr(), textposX, textPosY + addY, color, mOutLine ); } textPosY += mRowHeight; } } /// ÁÖÀÇ»çÇ× : Á¤·Ä¿¡ µû¸¥ Ãâ·Â ÁÂÇ¥°ª °è»ê unsigned int cListBox::UpdateTextPos( eText_Align align, unsigned int strWidth, unsigned int x, unsigned int w ) { unsigned int drawX = GetAbsoluteRect().mLeft + x + mPrintPos.mX; if( align == eALIGN_RIGHT ) { drawX += (int)(w - strWidth); } else if( align == eALIGN_CENTER ) { drawX += (int)(w - strWidth) / 2; } return drawX; } /// void cListBox::UpdateScrollBar() { if( !mpScrollBar ) return; if( GetRowCount() > mMaxRowInPage ) { /// ½ºÅ©·Ñ¹ÙÀÇ ¹Ù ¹öưÀ» ±×¸°´Ù mpScrollBar->Show(); //unsigned int scrollHeight = mpScrollBar->GetScrollBarHeight(); unsigned int scrollHeight = mpScrollBar->GetAbsoluteRect().GetHeight(); unsigned int buttonHeight = mpScrollBar->GetScrollButtonHeight() * 2; if( scrollHeight > buttonHeight ) { scrollHeight -= buttonHeight; } double hsize = scrollHeight - scrollHeight * (double)GetRowCount() / (double)mTotalMaxNum; /// ¹Ù ¹öưÀÇ ÃÖ¼Ò»çÀÌÁî¶û ºñ±³ÈÄ ¼¼ÆÃ unsigned int minsize = mpScrollBar->GetMinimumHeight(); if( hsize < minsize ) { hsize = minsize; } /// ½ºÅ©·Ñ¹Ù À§Ä¡ °è»ê.. /// ÇÑ ¾ÆÀÌÅÛ´ç ½ºÅ©·Ñ¹Ù°¡ ¿òÁ÷ÀÌ´Â °Å¸® ±¸Çϱâ 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 ); } } else { mpScrollBar->Hide(); } } /// ÁÖÀÇ»çÇ× : ¼±ÅÃµÈ À̹ÌÁö ¿µ¿ª ¾÷µ¥ÀÌÆ® void cListBox::UpdateSelectImage() { int scrollWidth = 0; if( mpScrollBar && mpScrollBar->IsVisible() ) { scrollWidth = mpScrollBar->GetAbsoluteRect().GetWidth(); } cUIRect imageRc; imageRc.mLeft = GetAbsoluteRect().mLeft; /// ½ºÅ²»ó¿¡¼­ Á¤ÇØÁø ¼±ÅÃ¹Ù ÆøÀÌ ÀÖÀ¸¸é Àû¿ë. if( mSelectBarWidth == 0 ) imageRc.mRight = imageRc.mLeft + GetAbsoluteRect().GetWidth() - scrollWidth; else imageRc.mRight = imageRc.mLeft + mSelectBarWidth; imageRc.mTop = GetAbsoluteRect().mTop + ( mRowHeight * ( mSelectedRowIdx - mTopRowIdx) ) + mPrintPos.mY; imageRc.mBottom = imageRc.mTop + mRowHeight; /// À§Ä¡ ¼¼ÆÃ if( mpSelectImage ) { mpSelectImage->SetScreenXY( (unsigned short)imageRc.mLeft, (unsigned short)imageRc.mTop ); mpSelectImage->SetScreenWH( (unsigned short)imageRc.GetWidth(), (unsigned short)imageRc.GetHeight() ); } } void cListBox::CheckShowImage() { /// ¼±ÅÃÀ̹ÌÁö ¹Ù°¡, ¸®½ºÆ®¹Ú½º¸¦ ³Ñ¾î°¡Áö ¾Êµµ·Ï ÇÑ´Ù. if( mSelectedRowIdx >= mTopRowIdx && mSelectedRowIdx < mTopRowIdx + mMaxRowInPage ) mShowImage = true; else mShowImage = false; } /// ÁÖÀÇ»çÇ× : bool cListBox::HandleEvent( const cUIEvent& event ) { if( mEnabled == false || mVisible == false ) return mpParent->HandleEvent( event ); switch( event.mType ) { case eUIEVENT_COMMAND: case eUIEVENT_BUTTON_DOWNED: CheckButtonEvent( event.mID ); break; case eUIEVENT_SCROLLBAR_MOVE: OnScrollbarMoved( event.mPos ); break; default: cUIWindow::HandleEvent( event ); break; } return true; } void cListBox::ChangeTextColor( unsigned int rowIdx, unsigned long color ) { sRowData* rData = (sRowData*)GetRowData( rowIdx ); if( rData ) { unsigned int colCount = rData->mColumes.GetSize(); for( unsigned int col = 0; col< colCount; ++col ) { /// °¢ Ä÷³ µ¥ÀÌÅÍ °¡Á®¿À±â sData* data = rData->mColumes[col]; if( data ) data->mTextColor = color; } } } unsigned int cListBox::GetColumnMaxWidth( unsigned int colIndex ) { cListBoxSkin* pListSkin = (cListBoxSkin*)mpSkin; if( !pListSkin ) { assert(0); return 0; } sListCtrlParam* pParam = pListSkin->GetCtrlParam( colIndex ); return ( pParam ) ? pParam->mColumnW : 0; } /////////////////////////////////////////////////////////////////////////////// cListBoxSkin::cListBoxSkin( eUINodeType type ) : cUINodeSkin( type ) , mTotalMaxNum( 0 ) , mRowHeight( 0 ) , mSelectBarSkin(0) , mpImgParam(0) , mpSelectBarTexture(0) , mSelectBarWidth(0) , mPrintPos(0, 0) , mPrintSize(0, 0) { mSelectBarSkin = new sSkinInfo; mpImgParam = new sListCtrlParam; mRowHeight = FONTAGENT->GetTextHeight(cFontAgent::eFont_UI); } cListBoxSkin::~cListBoxSkin() { /// for( unsigned int i = 0; i < mCtrlParamArr.GetSize(); ++i) { delete (sListCtrlParam*)mCtrlParamArr[i]; } mCtrlParamArr.Clear(); SAFE_DELETE( mpImgParam ); SAFE_DELETE( mSelectBarSkin ); } /// ÁÖÀÇ»çÇ× : bool cListBoxSkin::Load( cParser& parser ) { for( unsigned int i = 0; i < mCtrlParamArr.GetSize(); ++i) { delete (sListCtrlParam*)mCtrlParamArr[i]; } mCtrlParamArr.Clear(); if( parser.ExpectTokenString( "{" ) == false ) { return false; } cToken token; cLexer* lexer = parser.GetLexer(); while( lexer->GetNextToken( &token ) ) { if( token == "}" ) { /// ºí·Ï Å»Ãâ ^^ break; } switch( token.mType ) { case eTOKEN_PRINTPOS: { mPrintPos.mX = parser.ParseInt(); mPrintPos.mY = parser.ParseInt(); } break; case eTOKEN_PRINTSIZE: { mPrintSize.mWidth = parser.ParseInt(); mPrintSize.mHeight = parser.ParseInt(); } break; case eTOKEN_IMGCOLX: { mpImgParam->mColumnX = parser.ParseInt(); mpImgParam->mColumnW = parser.ParseInt(); if( mpImgParam->mColumnW <= 0 ) { assert(0); return 0; } } break; case eTOKEN_COLUMNX: { /// ÁÂÇ¥ unsigned columnX = parser.ParseInt(); /// ³ÐÀÌ unsigned columnW = parser.ParseInt(); if( columnW <= 0 ) { assert(0); return 0; } /// lexer->GetNextToken( &token ); /// Á¤·Ä eText_Align align = eALIGN_LEFT; if( token.mType == eTOKEN_CENTER ) { align = eALIGN_CENTER; } else if( token.mType == eTOKEN_RIGHT ) { align = eALIGN_RIGHT; } /// µ¥ÀÌÅÍ »ðÀÔ sListCtrlParam* pCtrlParam = new sListCtrlParam; pCtrlParam->mColumnX = columnX; pCtrlParam->mColumnW = columnW; pCtrlParam->mAlign = align; mCtrlParamArr.PushBack( pCtrlParam ); } break; case eTOKEN_ROWHEIGHT: { mRowHeight = parser.ParseInt(); } break; case eTOKEN_MAXITEMNUM: { mTotalMaxNum = parser.ParseInt(); } break; /// ui image °ü·Ã case eTOKEN_CHILD_IMAGEINDEX: { int i = parser.ParseInt(); mpSelectBarTexture = UIMAN->GetSkin()->GetTexture( i ); if( mpSelectBarTexture == 0 ) { assert( 0 && "failed to load texture" ); return false; } } break; case eTOKEN_CHILD_SIZE: { mSelectBarSkin->mWidth = mSelectBarSkin->mTexWidth = (unsigned short)parser.ParseInt(); mSelectBarSkin->mHeight = mSelectBarSkin->mTexHeight = (unsigned short)parser.ParseInt(); } break; case eTOKEN_CHILD_TEXPOS: { mSelectBarSkin->mTexX = (unsigned short)parser.ParseInt(); mSelectBarSkin->mTexY = (unsigned short)parser.ParseInt(); } break; case eTOKEN_SELECTWIDTH: { mSelectBarWidth = parser.ParseInt(); } break; case eTOKEN_SCROLLSKIN: { mScrollSkin = parser.ParseString(); } break; default: if( cUINodeSkin::ParseLine( parser, token ) == false ) { return false; } break; } } return true; } /// sListCtrlParam* cListBoxSkin::GetCtrlParam( unsigned int index ) { if( mCtrlParamArr.GetSize() == 0 ) return 0; if( index > mCtrlParamArr.GetSize() - 1 ) { assert(0); return 0; } sListCtrlParam* pParam = (sListCtrlParam*)mCtrlParamArr[index]; assert( pParam ); return pParam; }