#include "StdAfx.h" #include "DoubleItemIconListBox.h" #include "FontAgent.h" #include "ItemIcon.h" #include "PlaneObject.h" #include "ScrollBar.h" #include "inputsystem.h" #include "ItemManager.h" cDoubleItemIconListBox::cDoubleItemIconListBox( eUINodeType type ) : cListBox( type ) , mEnableSelect( true ) , mMaxIconCount(0) { memset( mIcon, 0, sizeof(mIcon) ); } cDoubleItemIconListBox::~cDoubleItemIconListBox() { } void cDoubleItemIconListBox::Clear() { cListBox::Clear(); /// ¾ÆÀÌÄÜ ÃʱâÈ­ for( int i = 0; i < mMaxIconCount; ++i ) { if( mIcon[i] ) { mIcon[i]->SetItemIndex(0); mIcon[i]->ChangeImage(0); } } } void cDoubleItemIconListBox::ClearText() { cListBox::Clear(); } void cDoubleItemIconListBox::CreateIcon( cString skinName, int count ) { mMaxIconCount = count; /// ¾ÆÀÌÄÜ ¼³Á¤ cString str; for( int i = 0; i < count; ++i ) { str.Format( skinName.Cstr(), i ); cItemIcon* icon = new cItemIcon; if( icon->CreateBySkinName( str, this, i ) == false ) return; mIcon[i] = icon; } } void cDoubleItemIconListBox::SetSlotIndexAllIcon( int count, unsigned short slotIndex ) { for( unsigned short i = 0; i < count; ++i ) { if( mIcon[i] ) mIcon[i]->SetSlotIndex( slotIndex + i ); } } void cDoubleItemIconListBox::RenderData( cUIFontItemKeeper* pKeeper ) { /// Àüü ¸®½ºÆ®¸¦ ¾ò¾î¿È if( GetRowCount() <= 0 ) return; /// ¸®½ºÆ® ¹Ú½ºÀÇ ÁÂÇ¥ ¹Þ¾Æ¿À±â int textposX = 0; int textPosY = GetAbsoluteRect().mTop + 1; unsigned int colY = 0; int rowCount = ( mMaxIconCount > (int)GetRowCount() ) ? (int)GetRowCount() : mMaxIconCount; for( int row = mTopRowIdx; row < (int)mTopRowIdx + rowCount; ++row ) { sRowData* rData = GetRowData( row ); if( !rData ) { /// ÇØ´ç ¿­ ÃʱâÈ­ int i = row - mTopRowIdx; if( i < 0 || i >= mMaxIconCount ) { assert(0); } if( mIcon[i] && mIcon[i]->GetItemIndex() > 0 ) { mIcon[i]->SetItemIndex(0); mIcon[i]->ChangeImage(0); } continue; } /// ¸®½ºÆ® µ¥ÀÌÅÍ Ãâ·Â unsigned int colCount = rData->mColumes.GetSize(); for( unsigned int col = 0; col< colCount; ++col ) { /// °¢ Ä÷³ µ¥ÀÌÅÍ °¡Á®¿À±â sData* data = rData->mColumes[col]; if( !data ) continue; /// ¾ÆÀÌÅÛ ¾ÆÀÌÄÜ ¼¼ÆÃ unsigned long itemIndex = (unsigned long)rData->mExtraData; cItemDefine* define = ITEMMAN->GetItemDefine( itemIndex ); int i = row - mTopRowIdx; if( i < 0 || i >= mMaxIconCount ) { assert(0); return; } if( define && mIcon[i]->GetItemIndex() != itemIndex ) { mIcon[i]->SetItemIndex( itemIndex ); mIcon[i]->ChangeImage( define->GetIconParam() ); } textposX = mIcon[i]->GetAbsoluteRect().mRight + 4; textPosY = mIcon[i]->GetAbsoluteRect().mTop + 1; /// Hover µÈ ¾ÆÀÌÅÛÀº ´Ù¸¥ »öÀ¸·Î Ç¥½Ã unsigned long color = data->mTextColor; if( mHoveredRowIdx != -1 && row - mTopRowIdx == (unsigned int)mHoveredRowIdx ) color = COLOR_RED; /// ´ÙÀ½¶óÀÎ À§Ä¡ Á¶Á¤ colY = 0; if( col > 0 ) { colY = FONTAGENT->GetTextHeight( cFontAgent::eFont_System ) + 2; /// ÃÖÁ¾ Ãâ·Â ÁÂÇ¥ °è»ê unsigned int strWidth = FONTAGENT->GetTextExtent( cFontAgent::eFont_System, (LPTSTR)data->mText.Cstr(), data->mText.GetLength() ); textposX = GetAbsoluteRect().mLeft + mSelectBarWidth - strWidth - 5; if( row % 2 != 0 ) textposX += mSelectBarWidth; } pKeeper->AddFontItem( cFontAgent::eFont_System, (LPTSTR)data->mText.Cstr(), textposX, textPosY + colY, color, mOutLine ); } } } void cDoubleItemIconListBox::OnMouseMove( const cUIPos& pos ) { cUINode::OnMouseMove( pos ); unsigned int row = (pos.mY - GetAbsoluteRect().mTop) / mRowHeight; /// ¼±ÅÃÇà °áÁ¤ int mX = (int)(pos.mX - GetAbsoluteRect().mLeft); int scrollWidth = ( mpScrollBar ) ? mpScrollBar->GetAbsoluteRect().GetWidth() : 0; int width = (int)(GetAbsoluteRect().GetWidth() * 0.5f) - scrollWidth; int selectrow = row * 2; /// ¿À¸¥ÂÊ Çà ¼±Åà if( mX > width ) selectrow = (row*2) + 1; if( selectrow >= (int)GetRowCount() ) { mHoveredRowIdx = -1; return; } /// À̹ÌÁö ¿µ¿ª üũ¿¡ °üÇÑ À̺¥Æ® unsigned int curRow = mTopRowIdx + selectrow; if( curRow >= GetRowCount() ) curRow = GetRowCount() - 1; if( mHoveredRowIdx != selectrow ) { cUIEvent event; event.mpCaller = this; event.mID = mID; event.mType = eUIEVENT_LISTBOX_ROW_HOVERED; event.mExtraData = GetExtraData( curRow ); mpParent->HandleEvent( event ); } /// ¾ÆÀÌÄÜ hover if( selectrow < mMaxIconCount ) { if( mIcon[selectrow]->ContainPoint( pos ) == true ) { cUIEvent event; event.mpCaller = this; event.mID = mID; event.mPos = pos; event.mExtraData = GetExtraData( curRow ); event.mType = eUIEVENT_LISTBOX_IMAGE_HOVERED; mpParent->HandleEvent( event ); mImageHoveredIdx = selectrow; } else { cUIEvent event; event.mpCaller = this; event.mID = mID; event.mType = eUIEVENT_LISTBOX_IMAGE_LEFT; mpParent->HandleEvent( event ); mImageHoveredIdx = -1; } } if( mEnableSelect ) mHoveredRowIdx = selectrow; } void cDoubleItemIconListBox::OnMouseLeft( const cUIPos& pos ) { cListCtrl::OnMouseLeft( pos ); mHoveredRowIdx = -1; } /// ÁÖÀÇ»çÇ× : void cDoubleItemIconListBox::OnLButtonDoubleClick( const cUIPos& pos ) { cUINode::OnLButtonDoubleClick( pos ); if( mEnableSelect == false ) return; unsigned int row = (pos.mY - GetAbsoluteRect().mTop) / mRowHeight; /// ¼±ÅÃÇà °áÁ¤ int mX = (int)(pos.mX - GetAbsoluteRect().mLeft); int scrollWidth = ( mpScrollBar ) ? mpScrollBar->GetAbsoluteRect().GetWidth() : 0; int width = (int)(GetAbsoluteRect().GetWidth() * 0.5f) - scrollWidth; unsigned int selectrow = row * 2; /// ¿À¸¥ÂÊ Çà ¼±Åà if( mX > width ) selectrow = (row*2) + 1; selectrow += mTopRowIdx; if( selectrow >= GetRowCount() ) return; mSelectedRowIdx = selectrow; mHoveredRowIdx = selectrow - mTopRowIdx; /// À̺¥Æ® º¸³»±â cUIEvent event; event.mType = eUIEVENT_LISTBOX_SELECTED; event.mpCaller = this; event.mID = mID; mpParent->HandleEvent( event ); /// ¸¶¿ì½º¸¦ ´­·¯ ¼±ÅÃÇÑ ºÎºÐÀº ´Ù¸£°Ô Ä¥ÇÑ´Ù UpdateSelectImage(); CheckShowImage(); } /// ÁÖÀÇ»çÇ× : void cDoubleItemIconListBox::OnLButtonDown( const cUIPos& pos, bool ctrl, bool alt, bool shift ) { cUINode::OnLButtonDown( pos, ctrl, alt, shift ); if( mEnableSelect == false ) return; unsigned int row = (pos.mY - GetAbsoluteRect().mTop) / mRowHeight; /// ¼±ÅÃÇà °áÁ¤ int mX = (int)(pos.mX - GetAbsoluteRect().mLeft); int scrollWidth = ( mpScrollBar ) ? mpScrollBar->GetAbsoluteRect().GetWidth() : 0; int width = (int)(GetAbsoluteRect().GetWidth() * 0.5f) - scrollWidth; unsigned int selectrow = row * 2; /// ¿À¸¥ÂÊ Çà ¼±Åà if( mX > width ) selectrow = (row*2) + 1; selectrow += mTopRowIdx; if( selectrow >= GetRowCount() ) return; if( mContinueEvent == true || mSelectedRowIdx != selectrow ) { mSelectedRowIdx = selectrow; /// À̺¥Æ® º¸³»±â cUIEvent event; event.mType = eUIEVENT_LISTBOX_CHANGED; event.mpCaller = this; event.mID = mID; event.mPos = pos; mpParent->HandleEvent( event ); /// ¸¶¿ì½º¸¦ ´­·¯ ¼±ÅÃÇÑ ºÎºÐÀº ´Ù¸£°Ô Ä¥ÇÑ´Ù UpdateSelectImage(); CheckShowImage(); } } void cDoubleItemIconListBox::OnRButtonDown( const cUIPos& pos, bool ctrl, bool alt, bool shift ) { cUINode::OnRButtonDown( pos, ctrl, alt, shift ); if( mEnableSelect == false ) return; unsigned int row = (pos.mY - GetAbsoluteRect().mTop) / mRowHeight; /// ¼±ÅÃÇà °áÁ¤ int mX = (int)(pos.mX - GetAbsoluteRect().mLeft); int scrollWidth = ( mpScrollBar ) ? mpScrollBar->GetAbsoluteRect().GetWidth() : 0; int width = (int)(GetAbsoluteRect().GetWidth() * 0.5f) - scrollWidth; unsigned int selectrow = row * 2; /// ¿À¸¥ÂÊ Çà ¼±Åà if( mX > width ) selectrow = (row*2) + 1; selectrow += mTopRowIdx; if( selectrow >= GetRowCount() ) return; mSelectedRowIdx = selectrow; mHoveredRowIdx = selectrow - mTopRowIdx; /// À̺¥Æ® º¸³»±â cUIEvent event; event.mType = eUIEVENT_LISTBOX_SELECTEDRBUTTON; event.mpCaller = this; event.mID = mID; event.mShift = shift; mpParent->HandleEvent( event ); /// ¸¶¿ì½º¸¦ ´­·¯ ¼±ÅÃÇÑ ºÎºÐÀº ´Ù¸£°Ô Ä¥ÇÑ´Ù UpdateSelectImage(); CheckShowImage(); } /// ÁÖÀÇ»çÇ× : ¹öưÀÇ »óÅ üũ void cDoubleItemIconListBox::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-=2; UpdateSelectImage(); } break; case eSCROOLBAR_DOWN: /// ³²´Â ¿µ¿ªÀÌ ¾ø°Ô²û ½ºÅ©·Ñ if( GetRowCount() - mTopRowIdx > (mMaxRowInPage*2) ) { mTopRowIdx+=2; UpdateSelectImage(); } break; default: return; } /// ½ºÅ©·Ñ¹Ù ¹öư À§Ä¡ ¾÷µ¥ÀÌÆ® UpdateScrollBar(); CheckShowImage(); } /// void cDoubleItemIconListBox::OnMouseWheel( const cUIPos& /*pos*/, int wheel ) { if( !mpScrollBar || mpScrollBar->IsVisible() == false ) return; assert(GetRowCount() > mMaxRowInPage); /// ½ºÅ©·Ñ¹Ù À§·Î ÈÙ Àû¿ë if( wheel > 0 ) { if( mTopRowIdx > 0 ) { mTopRowIdx-=2; UpdateSelectImage(); } } /// ¾Æ·¡·Î ÈÙ Àû¿ë else if ( wheel < 0 ) { /// ³²´Â ¿µ¿ªÀÌ ¾ø°Ô²û ½ºÅ©·Ñ if( GetRowCount() - mTopRowIdx > (mMaxRowInPage*2) ) { mTopRowIdx+=2; UpdateSelectImage(); } } else { assert( 0 && "error mouse wheel message" ); return; } /// ½ºÅ©·Ñ¹Ù ¾÷µ¥ÀÌÆ® UpdateScrollBar(); CheckShowImage(); } void cDoubleItemIconListBox::OnScrollbarMoved( const cUIPos& ) { if( mpScrollBar == 0) return; if( GetRowCount() <= mMaxRowInPage * 2 ) { assert(0); return; } /// ¹Ù ¹öư À§Ä¡¸¦ ¾ò¾î¿È. unsigned int barbuttonPos = mpScrollBar->GetBarButtonPosY(); double h = mpScrollBar->GetScrollMarginHeight() / (double)(GetRowCount() - (mMaxRowInPage*2)); /// ÇöÀç ¹Ù ¹öư À§Ä¡¿¡ ÇØ´çÇÏ´Â ¾ÆÀÌÅÛ À妽º ±¸Çϱâ double x = ((double)barbuttonPos / h); if( (int)x % 2 != 0 ) x++; mTopRowIdx = (int)x; mHoveredRowIdx = -1; UpdateSelectImage(); CheckShowImage(); } void cDoubleItemIconListBox::OnIconDragged( cUINode* caller, unsigned int id, const cUIPos& pos, bool shift ) { SendEvent( mpParent, eUIEVENT_ICON_DRAGGED, caller, id, shift ); } void cDoubleItemIconListBox::OnIconClicked( cUINode* , unsigned int ) { OnLButtonDown( cUIPos(MOUSE->GetMouseX(), MOUSE->GetMouseY()), false, false, false ); } void cDoubleItemIconListBox::OnIconDoubleClicked( cUINode* caller, unsigned int id ) { OnLButtonDoubleClick( cUIPos(MOUSE->GetMouseX(), MOUSE->GetMouseY()) ); } void cDoubleItemIconListBox::OnIconRightClicked( cUINode* caller, unsigned int id, bool shift ) { SendEvent( mpParent, eUIEVENT_ICON_RIGHTCLICKED, caller, id, shift ); if( mEnableSelect == false ) return; unsigned int row = (caller->GetAbsoluteRect().mTop - GetAbsoluteRect().mTop) / mRowHeight; /// ¼±ÅÃÇà °áÁ¤ int mX = (int)(caller->GetAbsoluteRect().mLeft - GetAbsoluteRect().mLeft); int scrollWidth = ( mpScrollBar ) ? mpScrollBar->GetAbsoluteRect().GetWidth() : 0; int width = (int)(GetAbsoluteRect().GetWidth() * 0.5f) - scrollWidth; unsigned int selectrow = row * 2; /// ¿À¸¥ÂÊ Çà ¼±Åà if( mX > width ) selectrow = (row*2) + 1; selectrow += mTopRowIdx; if( selectrow >= GetRowCount() ) return; mSelectedRowIdx = selectrow; // mHoveredRowIdx = selectrow - mTopRowIdx; /// ¸¶¿ì½º¸¦ ´­·¯ ¼±ÅÃÇÑ ºÎºÐÀº ´Ù¸£°Ô Ä¥ÇÑ´Ù UpdateSelectImage(); CheckShowImage(); } /// void cDoubleItemIconListBox::UpdateScrollBar() { if( !mpScrollBar ) return; /// ¾çÂÊÀ¸·Î ±×¸®´Ï±î Àç°è»ê if( GetRowCount() > (mMaxRowInPage*2) ) { mpScrollBar->Show(); 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*2)); /// ÇöÀç žÀ妽º * ÇѰ³¿µ¿ª = »õ·Î¿î ½ºÅ©·Ñ¹Ù À§Ä¡ 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 cDoubleItemIconListBox::UpdateSelectImage() { int selectRow = mSelectedRowIdx - mTopRowIdx; if( selectRow < 0 || selectRow >= mMaxIconCount ) return; cUIRect imageRc; imageRc.mLeft = ( mSelectedRowIdx % 2 == 0 ) ? GetAbsoluteRect().mLeft : GetAbsoluteRect().mLeft + mSelectBarWidth + 2; imageRc.mRight = imageRc.mLeft + mSelectBarWidth; imageRc.mTop = mIcon[selectRow]->GetAbsoluteRect().mTop - 4; imageRc.mBottom = imageRc.mTop + mRowHeight; /// À§Ä¡ ¼¼ÆÃ mpSelectImage->SetScreenXY( (unsigned short)imageRc.mLeft, (unsigned short)imageRc.mTop ); mpSelectImage->SetScreenWH( (unsigned short)imageRc.GetWidth(), (unsigned short)imageRc.GetHeight() ); } void cDoubleItemIconListBox::CheckShowImage() { if( mEnableSelect == false ) { mShowImage = false; } else { /// ¼±ÅÃÀ̹ÌÁö ¹Ù°¡, ¸®½ºÆ®¹Ú½º¸¦ ³Ñ¾î°¡Áö ¾Êµµ·Ï ÇÑ´Ù. if( mSelectedRowIdx >= mTopRowIdx && mSelectedRowIdx < mTopRowIdx + (mMaxRowInPage*2) ) mShowImage = true; else mShowImage = false; } } unsigned int cDoubleItemIconListBox::GetColumeWidth() { if( mMaxIconCount < 1 ) { assert(0); return 0; } /// ¼±ÅÃÀ̹ÌÁöÀÇ Å©±â¿¡¼­ ¾ÆÀÌÄÜ Å©±â¸¦ »©¼­ ÇØ´ç colume ³Êºñ¸¦ °è»êÇÑ´Ù. if( mIcon[0] == NULL ) { assert(0); return 0; } int colWidth = mSelectBarWidth - mIcon[0]->GetAbsoluteRect().GetWidth(); /// ÅØ½ºÆ® Ãâ·Â À§Ä¡¿Í ¾ÆÀÌÄÜ Ãâ·Â À§Ä¡¸¦ °¨¾ÈÇÏ¿© 10Á¤µµÀÇ Â÷À̸¦ µÐ´Ù. colWidth -= 10; if( colWidth < 0 ) { assert(0); return 0; } return colWidth; }