XML:
<HorizontalLayout name="hor_playcombination" visible="false">
<Label visible="false" name="playcomcount" text="" textcolor="FFa7b5d0" float ="true" pos="20,5,0,0" width="200" height="25" />
<Container visible="false" bordersize="1" bordercolor="#FF727c90" float ="true" width="870" pos="5,28,0,0" height="1" > </Container>
<PlayCombinationList visible="false" float="true" padding="5,5,5,5" pos="5,30,0,0" name="playcomlist" vscrollbar="true" width="870" height="303"/>
<Container visible="false" bordersize="1" bordercolor="#FF727c90" float ="true" pos="5,334,0,0" width="870" height="1" > </Container>
</HorizontalLayout>
PlayCombinationUI.xml
<?xml version="1.0" encoding="UTF-8"?>
<Window>
<Container width="412" bkcolor="#FF1E222C" padding="5,8" height="140" inset="1,1,1,1" bordersize="1" bordercolor="#FF000000">
<Button float="true" pos="321,108,0,0" width="77" height="24" normalimage="playcombination\1_btn_nor.png" hotimage="playcombination\1_btn_foc.png" pushedimage="playcombination\1_btn_cli.png" />
<Label float="true" bordersize="1" bordercolor="#FF727c90" width="200" height="130" name ="pic" text="" textcolor="#FFDDDDDD" align="center" mouse="false" pos="6,6,0,0" />
<Label float="true" name ="name" text="" textcolor="#FF7CFF04" pos="218,6,0,0" width="185" height="20" mouse="false" font="2"/>
<Label float="true" name="hardlevel" text="" textcolor="#FF7CFF04" pos="285,33,0,0" width="43" height="9" mouse="false" />
<RichEdit name="context" float="true" pos="225,58,0,0" width="179" height="32" text="" visible="true" align="left" readonly="true" multiline="true" enabled ="false" textcolor="#FFa7b5d0" font="11"/>
<Label float="true" name="readnums" text ="" width="200" height="20" textcolor="#FFDDDDDD" align="left" mouse="false" pos="219,114,0,0" />
<Label float="true" name="tips" text="战术难度:" pos="216,28,0,0" width="80" height="20" textcolor="#FF7CFF04" align="center" mouse="false"/>
</Container>
</Window>
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<CContainerUI*>(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<PlayCombinations> 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<iSize;i++)
{
CDialogBuilder builder;
CContainerUI* pDesk = static_cast<CContainerUI*>(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);
}
}