duilib 自定义控件1 CTileLayoutUI

duilib 自定义控件1 CTileLayoutUI_第1张图片

 

XML:


                  
                    

PlayCombinationUI.xml



  
    

 

 

class CPlayCombinationUI : public CTileLayoutUI
{
public:
	enum { SCROLL_TIMERID = 10 };

	CPlayCombinationUI() : m_uButtonState(0), m_dwDelayDeltaY(0), m_dwDelayNum(0), m_dwDelayLeft(0)
	{

	}


	BOOL  AddItem( CDialogBuilder*builder,CContainerUI* pDesk)
	{
		BOOL  bIsSuc =FALSE;
		if( pDesk != NULL ) {
			if( pDesk == NULL ){
				pDesk = static_cast(builder->Create());
			}
			if( pDesk != NULL ) {
				this->Add(pDesk);
				bIsSuc  =TRUE;
			}
			else {
				this->RemoveAll();
			}
		}
		return bIsSuc;
	}
	void DoEvent(TEventUI& event)  
	{
		if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) {
			if( m_pParent != NULL ) m_pParent->DoEvent(event);
			else CTileLayoutUI::DoEvent(event);
			return;
		}

		if( event.Type == UIEVENT_TIMER && event.wParam == SCROLL_TIMERID )
		{
			if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) {
				POINT pt = m_pManager->GetMousePos();
				LONG cy = (pt.y - m_ptLastMouse.y);
				m_ptLastMouse = pt;
				SIZE sz = GetScrollPos();
				sz.cy -= cy;
				SetScrollPos(sz);
				return;
			}
			else if( m_dwDelayLeft > 0 ) {
				--m_dwDelayLeft;
				SIZE sz = GetScrollPos();
				LONG lDeltaY =  (LONG)(CalculateDelay((double)m_dwDelayLeft / m_dwDelayNum) * m_dwDelayDeltaY);
				if( (lDeltaY > 0 && sz.cy != 0)  || (lDeltaY < 0 && sz.cy != GetScrollRange().cy ) ) {
					sz.cy -= lDeltaY;
					SetScrollPos(sz);
					return;
				}
			}
			m_dwDelayDeltaY = 0;
			m_dwDelayNum = 0;
			m_dwDelayLeft = 0;
			m_pManager->KillTimer(this, SCROLL_TIMERID);
			return;
		}
		if( event.Type == UIEVENT_BUTTONDOWN && IsEnabled() )
		{
			m_uButtonState |= UISTATE_CAPTURED;
			m_ptLastMouse = event.ptMouse;
			m_dwDelayDeltaY = 0;
			m_dwDelayNum = 0;
			m_dwDelayLeft = 0;
			::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND)));
			m_pManager->SetTimer(this, SCROLL_TIMERID, 50U);
			return;
		}
		if( event.Type == UIEVENT_BUTTONUP )
		{
			if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) {
				m_uButtonState &= ~UISTATE_CAPTURED;
				::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
				if( m_ptLastMouse.y != event.ptMouse.y ) {
					m_dwDelayDeltaY = (event.ptMouse.y - m_ptLastMouse.y);
					if( m_dwDelayDeltaY > 120 ) m_dwDelayDeltaY = 120;
					else if( m_dwDelayDeltaY < -120 ) m_dwDelayDeltaY = -120;
					m_dwDelayNum = (DWORD)sqrt((double)abs(m_dwDelayDeltaY)) * 5;
					m_dwDelayLeft = m_dwDelayNum;
				}
				else 
					m_pManager->KillTimer(this, SCROLL_TIMERID);
			}
			return;
		}
// 		if( event.Type == UIEVENT_SCROLLWHEEL )
// 		{
// 			LONG lDeltaY = 0;
// 			if( m_dwDelayNum > 0 ) lDeltaY =  (LONG)(CalculateDelay((double)m_dwDelayLeft / m_dwDelayNum) * m_dwDelayDeltaY);
// 			switch( LOWORD(event.wParam) ) {
// 			case SB_LINEUP:
// 				if( m_dwDelayDeltaY >= 0 ) m_dwDelayDeltaY = lDeltaY + 8;
// 				else m_dwDelayDeltaY = lDeltaY + 12;
// 				break;
// 			case SB_LINEDOWN:
// 				if( m_dwDelayDeltaY <= 0 ) m_dwDelayDeltaY = lDeltaY - 8;
// 				else m_dwDelayDeltaY = lDeltaY - 12;
// 				break;
// 			}
// 			if( m_dwDelayDeltaY > 100 ) m_dwDelayDeltaY = 100;
// 			else if( m_dwDelayDeltaY < -100 ) m_dwDelayDeltaY = -100;
// 			m_dwDelayNum = (DWORD)sqrt((double)abs(m_dwDelayDeltaY)) * 5;
// 			m_dwDelayLeft = m_dwDelayNum;
// 			m_pManager->SetTimer(this, SCROLL_TIMERID, 50U);
// 			return;
// 		}
		CTileLayoutUI::DoEvent(event);
	}

private:
	UINT m_uButtonState;
	POINT m_ptLastMouse;
	LONG m_dwDelayDeltaY;
	DWORD m_dwDelayNum;
	DWORD m_dwDelayLeft;

};


//使用:

 

 

	void UI_LoadPlayCombinations(std::vector Temp)
	{
		std_string  playcomcount;
		std_string  playcomID;
		std_string  readnums;
		std_string  playcom_name;
		int  iSize = 0;
		iSize  = Temp.size();
		playcomcount.AppendFormat("当前共计%d条内容",iSize);
		Ctrl(_T("playcomcount"))->SetText(CA2T(playcomcount.c_str()));
		if(iSize>0)   m_pListPlayCom->RemoveAll();
		for (int i =0;i(builder.Create(_T("ui_config\\PlayCombinationUI.xml"), (UINT)0));

			playcomID.clear();
			playcomID.AppendFormat("PlaycomNo%d",Temp[i].PlayComID);
			pDesk->GetItemAt(0)->SetName(CA2T(playcomID.c_str()));

			std_string   playcombk;
			playcombk.AppendFormat("\\playcombination\\playcombk%d.png",Temp[i].PlayComID);
			pDesk->GetItemAt(1)->SetBkImage(CA2T(playcombk.c_str()));

			playcom_name.clear();
			playcom_name.AppendFormat("【%s】",Temp[i].PlayName.c_str());
			pDesk->GetItemAt(2)->SetText(CA2T(playcom_name.c_str()));

			std_string   hardlevelstar;
			hardlevelstar.AppendFormat("\\playcombination\\playcombk_star%d.png",Temp[i].HardLevel);
			pDesk->GetItemAt(3)->SetBkImage(CA2T(hardlevelstar.c_str()));

			pDesk->GetItemAt(4)->SetText(CA2T(Temp[i].PlayContext.c_str()));

			readnums.clear();
			readnums.AppendFormat("(%d人阅)",Temp[i].FondNumbers);
			pDesk->GetItemAt(5)->SetText(CA2T(readnums.c_str()));

			SIZE  sz;
			sz.cx  =412;
			sz.cy  =140;
			m_pListPlayCom->SetItemSize(sz);
			m_pListPlayCom->AddItem(&builder,pDesk);
		}
	}

 

 

 

 

 

 

 

 

你可能感兴趣的:(duilib)