www.gusucode.com > VC++高仿迅雷7漂亮界面开源源码-源码程序 > VC++高仿迅雷7漂亮界面开源源码-源码程序/code/LEinGUI/XLframe.cpp
// XLframe.cpp: implementation of the CXLframe class. // Download by http://www.NewXing.com ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "CLAYUIEXP3.h" #include "XLframe.h" #include <math.h> #include "../clayui/UI_ANIMATION/CLAYUI_ALPHA_ANIM.h" #include "../clayui/UI_ANIMATION/CLAYUI_MOVE_ANIM.h" #include "../clayui/ui_control/CLAYUI_RadioBox.h" #include "../clayui/ui_control/CLAYUI_ComboBox.h" #include "EXP3FRAME.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CXLframe::CXLframe() { m_curfocuscombo = NULL; } CXLframe::~CXLframe() { } void CXLframe::LoadFromMem(BYTE *filebuffer, DWORD filesize, BOOL isMemMgr) { CLAYUI_BFRAME::LoadFromMem(filebuffer, filesize, isMemMgr); //动画 /*float w, h; GetFrameSize(w, h); float centerx, centery; int random = rand()%3; float dis; if(random == 0) { centerx = w / 2; centery = h / 2; dis = 250; } else if(random == 1) { dis = 500; centerx = w + dis; centery = h / 2; } else if(random == 2) { dis = 500; centerx = -dis; centery = h / 2; } int i; int num = m_framelist.m_spritenum; char aname[10]; int duration = 500; for(i = 0; i < num; i ++) { CLAYUI_FRAME* frame = GetChildByIndex(i); float tx, ty, tz; frame->GetTrans(tx, ty, tz); float vx, vy; vx = tx - centerx; vy = ty - centery; float len = sqrt(pow(vx, 2) + pow(vy, 2)); vx = vx / len; vy = vy / len; sprintf(aname, "aa%d", i); //创建动画 CLAYUI_ALPHA_ANIM* alpha = new CLAYUI_ALPHA_ANIM(); //设置动画的标识 alpha->SetIdname(aname); //初始化 alpha->Init(0, 100, duration, this); //将动画对象加入到m_sys_listbox中 AddAnimation(alpha); alpha->SetTarget(frame); //播放动画 alpha->Play(); sprintf(aname, "am%d", i); CLAYUI_MOVE_ANIM* move = new CLAYUI_MOVE_ANIM(); move->SetIdname(aname); move->Init(tx + dis * vx, ty + dis * vy, tx, ty, duration, this); AddAnimation(move); move->SetTarget(frame); move->Play(); }*/ if(GetChildFrame("ra1")) { CLAYUI_RadioBox* ra = dynamic_cast<CLAYUI_RadioBox*>(GetChildFrame("ra1")); CLAYUI_RadioBox* ra1 = dynamic_cast<CLAYUI_RadioBox*>(GetChildFrame("ra1_0")); if(ra1) ra->SetRelativeRadio(ra1); } //往COMBO里添加ITEM CLAYUI_ComboBox* combo = dynamic_cast<CLAYUI_ComboBox*>(GetChildFrame("co1")); CLAYUI_ComboBox* combo1 = dynamic_cast<CLAYUI_ComboBox*>(GetChildFrame("co1_0")); CLAYUI_ComboBox* combo2 = dynamic_cast<CLAYUI_ComboBox*>(GetChildFrame("co1_1")); if(combo && combo1 && combo2) { int listheight = 80; combo->SetListHeight(listheight); combo->GetChildFrame("_SYS_TEXT_")->m_frameItemlist.DeleteAllSprite(); CLAYUI_BFRAME* lw = (CLAYUI_BFRAME*)combo->GetChildFrame("_SYS_LISTBOX_"); lw->GetChildFrame("_SYS_LISTBOX_")->m_frameItemlist.DeleteAllSprite(); combo->SetItemsDepth(2); combo->AddString(L"测试一"); combo->AddString(L"测试二"); combo1->SetListHeight(listheight); combo1->GetChildFrame("_SYS_TEXT_")->m_frameItemlist.DeleteAllSprite(); lw = (CLAYUI_BFRAME*)combo1->GetChildFrame("_SYS_LISTBOX_"); lw->GetChildFrame("_SYS_LISTBOX_")->m_frameItemlist.DeleteAllSprite(); combo1->SetItemsDepth(2); combo1->AddString(L"测试一"); combo1->AddString(L"测试二"); combo2->SetListHeight(listheight); combo2->GetChildFrame("_SYS_TEXT_")->m_frameItemlist.DeleteAllSprite(); lw = (CLAYUI_BFRAME*)combo2->GetChildFrame("_SYS_LISTBOX_"); lw->GetChildFrame("_SYS_LISTBOX_")->m_frameItemlist.DeleteAllSprite(); combo2->SetItemsDepth(2); combo2->AddString(L"测试一"); combo2->AddString(L"测试二"); } //加入在COMBO之间跳动的框 BYTE* filebuf1 = NULL; DWORD filesize1 = 0; CFile file; CString framename = "combobox_bbox.ci"; CEXP3FRAME* exp3frame = (CEXP3FRAME*)GetParent(); if(file.Open(exp3frame->m_exepath + framename, CFile::modeRead)) { filesize1 = file.GetLength(); filebuf1 = new BYTE[filesize1]; file.Read(filebuf1, filesize1); file.Close(); m_combobox_bbox = new CLAYUI_BFRAME(); m_combobox_bbox->InitBFrame(m_gitemframe, this, m_draw, FALSE); m_combobox_bbox->LoadFromMem(filebuf1, filesize1, FALSE); delete [] filebuf1; AddCustomFrame(0, framename.GetBuffer(0), 0, 0, 353, 327, 100, m_combobox_bbox); m_combobox_bbox->Enable(FALSE); m_combobox_bbox->SetColorTrans(0, 100, 100, 100, 0, 0, 0, 0); m_combobox_bbox->SetBmpEffect(TYPE_BMPEFT_SHADOW, 3, 0, 0, 0, 200, 0, 255); } } void CXLframe::Update() { CLAYUI_BFRAME::Update(); CLAYUI_FRAME* frame = CLAYUI_HL_GetFocusFrame(GetParent()->GetParent()->GetParent(), this); CLAYUI_ComboBox* ra = dynamic_cast<CLAYUI_ComboBox*>(frame); if(ra) { //如果前一桢没有COMBO被设为焦点,就让m_combobox_bbox透明度变为100 if(m_curfocuscombo == NULL) { CLAYUI_ALPHA_ANIM* alpha = new CLAYUI_ALPHA_ANIM(); //设置动画的标识 alpha->SetIdname("combba"); //初始化 alpha->Init(0, 100, 300, this); //将动画对象加入到m_sys_listbox中 AddAnimation(alpha); alpha->SetTarget(m_combobox_bbox); //播放动画 alpha->Play(); } //如果前一桢已经有了焦点COMBO,就在2个COMBO间移动 if(m_curfocuscombo != ra) { if(m_curfocuscombo) m_curfocuscombo->TriggerAnimation("_ka1"); float x, y, z; ra->GetTrans(x, y, z); CLAYUI_MOVE_ANIM* move = (CLAYUI_MOVE_ANIM*)GetAnimation("combbm"); if(move != NULL) { move->End(); move->SetTo(x, y); move->Play(); } else { move = new CLAYUI_MOVE_ANIM(); move->SetIdname("combbm"); move->Init(m_combobox_bbox, x, y, 300, this); AddAnimation(move); move->SetTarget(m_combobox_bbox); move->Play(); } m_curfocuscombo = ra; m_curfocuscombo->TriggerAnimation("_ka0"); SetForeground(m_combobox_bbox); SetForeground(m_curfocuscombo); } } //不断更新让m_combobox_bbox的大小与COMBO的大小一致 if(m_curfocuscombo) { float w, h; GetComboWH(m_curfocuscombo, w, h); float w1, h1; m_combobox_bbox->GetFrameSize(w1, h1); float scalex, scaley, scalez; m_curfocuscombo->GetScale(scalex, scaley, scalez); m_combobox_bbox->ScaleTo(w / (w1 * scalex), (h + 2) / (h1 * scaley), scalez); } } void CXLframe::GetComboWH(CLAYUI_ComboBox* combo, float &w, float &h) { //得到COMBO的包围盒的高宽 float width, height; combo->GetFrameSize(w, height); float x, y, z; combo->GetTrans(x, y, z); CLAYUI_BFRAME* lw = (CLAYUI_BFRAME*)combo->GetChildFrame("_SYS_LISTBOX_"); float x1, y1, z1; lw->GetTrans(x1, y1, z1); float x2, y2, z2; lw = (CLAYUI_BFRAME*)lw->GetChildFrame("_SYS_LISTBOX_"); lw->GetTrans(x2, y2, z2); float width2, height2; lw->GetFrameSize(width2, height2); float fx, fy; fx = x2 + x1; fy = y2 + y1; if(fy + height2 < height) h = height; else h = fy + height2; }