379 lines
10 KiB
C++
379 lines
10 KiB
C++
// ---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
// ---------------------------------------------------------------------------
|
|
#include "StyleSelListBoxUnit.h"
|
|
#include "GlobalUnit.h"
|
|
#pragma package(smart_init)
|
|
|
|
// #define COLOR_BORDER RGB(164,115,70)
|
|
#define COLOR_BORDER RGB(231,220,193)
|
|
|
|
// ---------------------------------------------------------------------------
|
|
__fastcall StyleSelectListBoxUnit::TListBox::TListBox(System::Classes::TComponent* AOwner) : TSkinListBox(AOwner) {
|
|
m_imgBackground = new TBitmap();
|
|
m_imgBackgroundLine = new TBitmap();
|
|
m_imgSelectedFlag = new TBitmap();
|
|
m_imgSelectedBkg = new TBitmap();
|
|
m_imgBackground->LoadFromResourceName(int(HInstance), "StyleLstBkg");
|
|
m_imgBackgroundLine->LoadFromResourceName(int(HInstance), "StyleLstLine");
|
|
m_imgSelectedFlag->LoadFromResourceName(int(HInstance), "StyleLstFlag");
|
|
m_imgSelectedBkg->LoadFromResourceName(int(HInstance), "MenuHoverBar");
|
|
|
|
m_brImg = new TBrush();
|
|
|
|
m_imgDwnLoadNml = new TBitmap();
|
|
m_imgDwnLoadHot = new TBitmap();
|
|
|
|
m_pBitmapHot = new TBitmap();
|
|
m_pBitmapNml = new TBitmap();
|
|
|
|
m_imgDwnLoadHot->LoadFromResourceName(int(HInstance), "download_icon_hot");
|
|
m_imgDwnLoadNml->LoadFromResourceName(int(HInstance), "download_icon_nml");
|
|
|
|
m_pBitmapHot->LoadFromResourceName(int(HInstance), "download_state_hot");
|
|
m_pBitmapNml->LoadFromResourceName(int(HInstance), "download_state_nml");
|
|
|
|
m_clrBevelRaise = RGB(225, 181, 120);
|
|
m_clrBevelLower = RGB(101, 101, 101);
|
|
m_clrSelected = RGB(255, 0, 0);
|
|
// m_pFntText = new TFont();
|
|
// m_pFntText->Name = "黑体";
|
|
// m_pFntText->Size = int(9 * 96.0 / g_yDpi + 0.5);
|
|
|
|
m_iPlayItemIndex = -1;
|
|
m_iItemState = 1;
|
|
m_iItemIndex = -1;
|
|
m_iHotItemIndex = -1;
|
|
m_iDLoadItemIndex = -1;
|
|
m_iCurPage = 1;
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
__fastcall StyleSelectListBoxUnit::TListBox::~TListBox() {
|
|
if (m_imgBackground) {
|
|
delete m_imgBackground;
|
|
}
|
|
|
|
if (m_imgDwnLoadNml)
|
|
delete m_imgDwnLoadNml;
|
|
if (m_imgDwnLoadHot)
|
|
delete m_imgDwnLoadHot;
|
|
|
|
if (m_pBitmapNml)
|
|
delete m_pBitmapNml;
|
|
if (m_pBitmapHot)
|
|
delete m_pBitmapHot;
|
|
|
|
if (m_brImg)
|
|
delete m_brImg;
|
|
// if (m_pFntText) {
|
|
// delete m_pFntText;
|
|
// }
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall StyleSelectListBoxUnit::TListBox::WMPaint
|
|
(Winapi::Messages::TWMPaint &Message) {
|
|
DefaultHandler(&Message);
|
|
|
|
if (Items->Count == 0) {
|
|
TRect rectClient(0, 0, ClientWidth, ClientHeight);
|
|
// 绘制外边框
|
|
Canvas->Brush->Color = COLOR_BORDER;
|
|
Canvas->FrameRect(rectClient);
|
|
// 绘制底图
|
|
rectClient.left++;
|
|
rectClient.right--;
|
|
rectClient.top++;
|
|
rectClient.bottom--;
|
|
Canvas->StretchDraw(rectClient, m_imgBackground);
|
|
}
|
|
|
|
// 绘制竖线
|
|
TRect line1(88, 0, 91, Height);
|
|
Canvas->StretchDraw(line1, m_imgBackgroundLine);
|
|
TRect line2(137, 0, 140, Height);
|
|
Canvas->StretchDraw(line2, m_imgBackgroundLine);
|
|
TRect line3(287, 0, 290, Height);
|
|
Canvas->StretchDraw(line3, m_imgBackgroundLine);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
void __fastcall StyleSelectListBoxUnit::TListBox::DrawItem(int Index, const System::Types::TRect &Rect, Winapi::Windows::TOwnerDrawState State)
|
|
{
|
|
// 绘制竖线
|
|
// DebugPrint( "DrawItem %d...", Index );
|
|
TRect rcDraw, rcOrig = Rect;
|
|
if (rcOrig.Width() < Width) { // 显示滚动条
|
|
rcOrig.right = Width - 19; // 减去滚动条宽度
|
|
}
|
|
rcDraw = rcOrig;
|
|
Canvas->StretchDraw(Rect, m_imgBackground);
|
|
Canvas->Brush->Style = bsClear;
|
|
Canvas->Font->Color = RGB(79, 57, 30);
|
|
|
|
if (m_iPlayItemIndex == Index) {
|
|
|
|
// Canvas->Draw(Rect.Left+1,Rect.Top+1,m_imgSelectedFlag);
|
|
// Canvas->Font->Color = clRed;
|
|
Canvas->Font->Color = RGB(232, 212, 191);
|
|
Canvas->StretchDraw(Rect, m_imgSelectedBkg);
|
|
}
|
|
|
|
if (State.Contains(odSelected)) {
|
|
// Canvas->Pen->Color = RGB(79,57,30);
|
|
// Canvas->Rectangle(Rect);
|
|
// Canvas->Font->Color = clRed;
|
|
Canvas->Font->Color = RGB(232, 212, 191);
|
|
Canvas->StretchDraw(Rect, m_imgSelectedBkg);
|
|
// Canvas->Draw(Rect.Left+1,Rect.Top+1,m_imgSelectedFlag);
|
|
if (State.Contains(odFocused))
|
|
DrawFocusRect(Canvas->Handle, &Rect);
|
|
|
|
}
|
|
|
|
// 输出文字
|
|
String strText = Items->Strings[Index];
|
|
String strNamge;
|
|
String strBlance;
|
|
String strDecrip;
|
|
int nM = 0;
|
|
int start = 1;
|
|
for (int i = 1; i < strText.Length(); i++) {
|
|
if (strText[i] == '_') {
|
|
nM++;
|
|
if (nM == 1) {
|
|
start = i;
|
|
strNamge = strText.SubString(1, i - 1);
|
|
}
|
|
else {
|
|
strBlance = strText.SubString(start + 1, i - start - 1);
|
|
strDecrip = strText.SubString(i + 1, strText.Length() - i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
AnsiString strN = strNamge;
|
|
int nLen = strN.Length();
|
|
if (nLen > 12) {
|
|
strNamge = strN.SubString(1, 10);
|
|
strNamge += "...";
|
|
}
|
|
|
|
Canvas->TextOut(Rect.Left + 15, Rect.Top + 1, strNamge);
|
|
|
|
String strTmpTxt = strDecrip;
|
|
if (strDecrip.Length() > 12) {
|
|
strTmpTxt = strDecrip.SubString(1, 10) + L"...";
|
|
}
|
|
Canvas->TextOut(Rect.Left + 145, Rect.Top + 1, strTmpTxt);
|
|
|
|
if (g_bLogon) {
|
|
|
|
TColor clr = Canvas->Font->Color;
|
|
|
|
for (int index = 0; index < m_vciItemIndex.size(); index++) {
|
|
|
|
int iItemIndex = m_vciItemIndex[index] - (m_iCurPage - 1) * 20;
|
|
|
|
if (Index == iItemIndex) {
|
|
Canvas->Font->Style = TFontStyles() << fsStrikeOut;
|
|
Canvas->Font->Color = clBlue; // RGB(120, 220, 120);
|
|
break;
|
|
}
|
|
}
|
|
|
|
Canvas->TextOut(Rect.Left + 98, Rect.Top + 1, strBlance);
|
|
|
|
Canvas->Font->Color = clr;
|
|
Canvas->Font->Style = TFontStyles() >> fsStrikeOut;
|
|
}
|
|
else {
|
|
Canvas->TextOut(Rect.Left + 98, Rect.Top + 1, strBlance);
|
|
}
|
|
|
|
if (Index == Items->Count - 1 && Rect.bottom < Height) { // 绘制空白部分
|
|
TRect rcBlank(rcOrig.left, Rect.bottom, Rect.right, Height);
|
|
Canvas->StretchDraw(rcBlank, m_imgBackground);
|
|
}
|
|
/* // 绘制竖线
|
|
TRect line1(88, 0, 91, Height);
|
|
Canvas->StretchDraw(line1, m_imgBackgroundLine);
|
|
TRect line2(137, 0, 140, Height);
|
|
Canvas->StretchDraw(line2, m_imgBackgroundLine);
|
|
|
|
// Add by GGGrass2012年12月4日 12:58:24
|
|
// Draw the line
|
|
TRect line3(287, 0, 290, Height);
|
|
Canvas->StretchDraw(line3, m_imgBackgroundLine);
|
|
*/
|
|
if (m_vcItemsData.size() && Index < m_vcItemsData.size()) {
|
|
|
|
int iItemIndex = (m_iCurPage - 1) * 20 + Index;
|
|
if(iItemIndex < 0 || iItemIndex >= m_vcItemsData.size())
|
|
return;
|
|
|
|
//need to modify the download state
|
|
int iState = m_vcItemsData[iItemIndex].tStyleInfo.state;
|
|
if (e_UnDownload == m_vcItemsData[iItemIndex].tStyleInfo.state) {
|
|
|
|
TRect rtItem(301, Rect.top, 316, Rect.bottom);
|
|
TBrush * brOld = Canvas->Brush;
|
|
|
|
if (m_vcItemsData[iItemIndex].iStyleDownSate < 2) {
|
|
|
|
rtItem.top += 2;
|
|
rtItem.bottom -= 2;
|
|
|
|
switch (m_vcItemsData[iItemIndex].iStyleDownSate) {
|
|
case 0:
|
|
Canvas->StretchDraw(rtItem, m_imgDwnLoadNml);
|
|
break;
|
|
case 1:
|
|
Canvas->StretchDraw(rtItem, m_imgDwnLoadHot);
|
|
break;
|
|
default:
|
|
Canvas->StretchDraw(rtItem, m_imgDwnLoadNml);
|
|
break;
|
|
}
|
|
}
|
|
else if (m_vcItemsData[iItemIndex].iStyleDownSate < 12) {
|
|
DrawDownLoadImgState(rtItem,
|
|
m_vcItemsData[iItemIndex].iStyleDownSate - 2, m_pBitmapNml);
|
|
}
|
|
else if (m_vcItemsData[iItemIndex].iStyleDownSate < 22) {
|
|
DrawDownLoadImgState(rtItem,
|
|
m_vcItemsData[iItemIndex].iStyleDownSate - 12,
|
|
m_pBitmapHot);
|
|
}
|
|
else {
|
|
DrawDownLoadImgState(rtItem, 0, m_pBitmapNml);
|
|
}
|
|
}
|
|
else {;
|
|
}
|
|
}
|
|
// End Add by GGGrass 2012年12月4日 12:58:34
|
|
// DebugPrint( "done.\n" );
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
void StyleSelectListBoxUnit::TListBox::SetPlayItemIndex(int iPlayItemIndex) {
|
|
m_iPlayItemIndex = iPlayItemIndex;
|
|
}
|
|
|
|
void StyleSelectListBoxUnit::TListBox::SetItemIndex(const vector<int>vcItemIndex, int iCurPage) {
|
|
m_vciItemIndex.clear();
|
|
|
|
for (int index = 0; index < vcItemIndex.size(); index++) {
|
|
m_vciItemIndex.push_back( vcItemIndex[index] );
|
|
// m_vciItemIndex[index] = vcItemIndex[index];
|
|
}
|
|
|
|
m_iCurPage = iCurPage;
|
|
}
|
|
|
|
void __fastcall StyleSelectListBoxUnit::TListBox::Clear(void)
|
|
{
|
|
Vcl::Stdctrls::TListBox::Clear();
|
|
|
|
if(m_vciItemIndex.size())
|
|
m_vciItemIndex.clear();
|
|
if(m_vcItemsData.size())
|
|
m_vcItemsData.clear();
|
|
|
|
m_iPlayItemIndex = -1;
|
|
m_iItemState = 1;
|
|
m_iItemIndex = -1;
|
|
m_iHotItemIndex = -1;
|
|
m_iDLoadItemIndex = -1;
|
|
m_iCurPage = 1;
|
|
}
|
|
|
|
void StyleSelectListBoxUnit::TListBox::SetItemIconState(const int iItemIndex, const int iIconState)
|
|
{
|
|
m_iItemIndex = iItemIndex;
|
|
m_iItemState = iIconState;
|
|
|
|
m_iDLoadItemIndex = iItemIndex;
|
|
m_iHotItemIndex = iItemIndex;
|
|
|
|
TRect rtItem = ItemRect(iItemIndex);
|
|
InvalidateRect(Handle, &rtItem, 1);
|
|
}
|
|
|
|
void StyleSelectListBoxUnit::TListBox::ResetItemsData(vector<DEFTSTYLEINFO>vcItemsData, const int iCutPage, vector<int>vcItemsIndex, bool bIsReDraw)
|
|
{
|
|
|
|
if (m_vcItemsData.size()) {
|
|
m_vcItemsData.clear();
|
|
}
|
|
|
|
// int size = vcItemsData.size();
|
|
for (int index = 0; index < vcItemsData.size(); index++) {
|
|
// int iData = vcItemsData[index].iStyleDownSate;
|
|
m_vcItemsData.push_back(vcItemsData[index]);
|
|
}
|
|
|
|
m_iCurPage = iCutPage;
|
|
/*
|
|
if (vcItemsIndex.size())
|
|
ReDrawItemsState(vcItemsIndex, bIsReDraw);
|
|
else
|
|
Invalidate();
|
|
*/
|
|
if( bIsReDraw ){
|
|
TRect rtItemHot(301, 0, 316, Height);
|
|
InvalidateRect(Handle, &rtItemHot, true);
|
|
}
|
|
}
|
|
|
|
void StyleSelectListBoxUnit::TListBox::ReDrawItemsState(vector<int>vcItemIndexs, bool bIsReDraw)
|
|
{
|
|
|
|
if (vcItemIndexs.size() < m_vcItemsData.size()) {
|
|
for (int i = 0; i < vcItemIndexs.size(); i++) {
|
|
|
|
if (vcItemIndexs[i] != -1 && vcItemIndexs[i] % 20 < Items->Count) {
|
|
|
|
int iItemIndex = vcItemIndexs[i] % 20;
|
|
TRect rtItem = ItemRect(vcItemIndexs[i] % 20);
|
|
TRect rtItemHot(301, rtItem.top, 316, rtItem.bottom);
|
|
InvalidateRect(Handle, &rtItemHot, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void StyleSelectListBoxUnit::TListBox::DrawDownLoadImgState(const TRect rtArea, const int iImgIndex, TBitmap * tBitmap)
|
|
{
|
|
|
|
int iTopIndex = iImgIndex / 5;
|
|
int iLeftIndex = iImgIndex % 5;
|
|
|
|
// Declare a temp varible and set it's paramater
|
|
TBitmap * tTmpBmp = new TBitmap();
|
|
tTmpBmp->Width = (tBitmap->Width - 25) / 5 - 2;
|
|
tTmpBmp->Height = (tBitmap->Height - 6) / 2;
|
|
|
|
// Calculate the parameter's position and Redraw the bitmap
|
|
int iWidth = (tBitmap->Width - 24) / 5;
|
|
int iHeight = (tBitmap->Height - 6) / 2;
|
|
int iLeft = iLeftIndex * iWidth + iLeftIndex * 7; ;
|
|
int iTop = iTopIndex * iHeight + iTopIndex * 6;
|
|
|
|
tTmpBmp->Canvas->Lock();
|
|
StretchBlt(tTmpBmp->Canvas->Handle, 0, 0, iWidth, iHeight,
|
|
tBitmap->Canvas->Handle, iLeft, iTop, iWidth, iHeight, SRCCOPY);
|
|
tTmpBmp->Canvas->Unlock();
|
|
|
|
// Draw the region with new bitmap
|
|
Canvas->StretchDraw(rtArea, tTmpBmp);
|
|
|
|
if (tTmpBmp)
|
|
delete tTmpBmp;
|
|
}
|