Files
AccompanyCube/PredefineProjectSetUnit.cpp
2026-06-13 00:10:11 +08:00

300 lines
7.4 KiB
C++

//---------------------------------------------------------------------------
#pragma hdrstop
#include "PredefineProjectSetUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#define ITEM_OVER TColor(RGB(135, 91, 61))
#define ITEM_TEXT_COLOR TColor(RGB(213, 221, 232))
#define BORDER TColor(0x4673A4)
#define BACKGRND TColor(0xC8F0FF)
#define BORDER_HL TColor(RGB(30, 32, 36))
#define BACKGRND_HL TColor(RGB(67, 73, 80))
#define TEXT_COLOR TColor(RGB(213, 221, 232))
#define TEXT_DISABLE TColor(RGB(100, 108, 119))
#define BREAK TColor(RGB(100, 108, 119))
#define BOARD_FILL TColor(RGB(76, 82, 91))
#define MARGIN 2
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
__fastcall TPrefineProjectSetItem::TPrefineProjectSetItem(TWinControl *Parent) : TGraphicControl(Parent)
{
SetParentComponent(Parent);
FIsSelected = false;
FIsFocus = false;
CtrlParent = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSetItem::SetSelected(bool Value)
{
if(FIsSelected != Value) {
FIsSelected = Value;
Repaint();
}
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSetItem::Paint()
{
Canvas->Brush->Color = BACKGRND;
if(FIsSelected) {
Canvas->Brush->Color = TColor(0xA8D0DF);
Canvas->Pen->Color = TColor(0x4673A4);
Canvas->RoundRect(ClientRect, 5, 5);
}
else if(FIsFocus) {
Canvas->Brush->Color = ITEM_OVER;
Canvas->Pen->Color = ITEM_OVER;
Canvas->RoundRect(ClientRect, 5, 5);
}
else {
Canvas->FillRect(ClientRect);
}
for(int i = 0; i < 8; i++) {
int l = ClientRect.Left + i * (Width / 8);
int t = ClientRect.Top;
int r = l + (Width / 8);
int b = ClientRect.Bottom - 2;
TRect Rect(l, t, r, b);
int ch = PredefChord[i];
int type = ch & 0x03;
int key = (ch >> 2) + Key;
if( key>11 ) key -= 12;
DrawChord(Canvas, Rect, key, type);
}
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSetItem::CMMouseEnter(TMessage &Message)
{
FIsFocus = true;
Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSetItem::CMMouseLeave(TMessage &Message)
{
FIsFocus = false;
Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSetItem::WMLButtonDown(TWMLButtonDown &Message)
{
IsSelected = true;
if(CtrlParent)
CtrlParent->DoItemClick(this, Index);
}
//---------------------------------------------------------------------------
void TPrefineProjectSetItem::DrawChord(TCanvas *Canvas, TRect Rect, int iKey, int iType)
{
int iMainKey, iAjustKey; //µ÷¼¶Êý¡¢Éý½µ
TPrefineProjectSet::GetChordDisplayKey(iKey, Key, iMainKey, iAjustKey);
UniDrawChord(Canvas, Rect, iMainKey, iAjustKey, iType);
}
//---------------------------------------------------------------------------
__fastcall TPrefineProjectSet::TPrefineProjectSet(TComponent *Owner) : TCustomControl(Owner)
{
mContentArea = new TWinControl(this);
mItemList = new TList();
mItemWidth = 100;
mItemHeight = 25;
mCurrentItem = NULL;
OnHide = NULL;
OnShow = NULL;
}
//---------------------------------------------------------------------------
__fastcall TPrefineProjectSet::~TPrefineProjectSet()
{
if(mItemList) {
mItemList->Clear();
delete mItemList;
mItemList = NULL;
}
if(mContentArea) {
delete mContentArea;
mContentArea = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::AddItem(TPrefineProjectSetItem *Item)
{
Item->Width = 400;
Item->Height = mItemHeight;
Item->Top = mItemList->Count * mItemHeight;
Item->Left = 0;
Item->Parent = mContentArea;
Item->CtrlParent = this;
mItemList->Add(Item);
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::SetSelectedIndex(int Value)
{
mSelectedIndex = Value;
TPrefineProjectSetItem *Item = (TPrefineProjectSetItem *)mItemList->Items[Value];
Item->IsSelected = true;
DoItemClick(Item, Value);
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::CreateParams(TCreateParams &Params)
{
TCustomControl::CreateParams(Params);
Params.Style = 0;
Params.Style = WS_POPUP;
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::CreateWnd()
{
TCustomControl::CreateWnd();
mContentArea->Parent = this;
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::Hide()
{
TCustomControl::Hide();
// SetActiveWindow(mActiveWndBak);
if(OnHide) {
OnHide(this);
}
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::Show()
{
TCustomControl::Show();
mActiveWndBak = GetActiveWindow();
SetActiveWindow(Handle);
Height = mItemList->Count * mItemHeight + 12;
if(OnShow) {
OnShow(this);
}
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::DoItemClick(TPrefineProjectSetItem *Item, int Index)
{
if(mCurrentItem != Item) {
if(mCurrentItem)
mCurrentItem->IsSelected = false;
mCurrentItem = Item;
mSelectedIndex = Index;
}
Hide();
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::WMEraseBkgnd(TWMEraseBkgnd &Message)
{
TCanvas* tmpCanvas = new TCanvas();
tmpCanvas->Handle = Message.DC;
tmpCanvas->Brush->Color = TColor(RGB(215, 178, 147));
tmpCanvas->FillRect(ClientRect);
tmpCanvas->Brush->Color = BORDER;
tmpCanvas->FrameRect(ClientRect);
tmpCanvas->Brush->Color = BORDER;
TRect rect = ClientRect;
rect.Top += 4;
rect.Left += 4;
rect.Bottom -= 4;
rect.Right -= 4;
tmpCanvas->FrameRect(rect);
delete tmpCanvas;
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::WMSize(TWMSize &Message)
{
mContentArea->Width = Width - 12;
mContentArea->Height = Height - 12;
mContentArea->Top = 6;
mContentArea->Left = 6;
for(int i = 0; i < mItemList->Count; i++) {
TPrefineProjectSetItem *Item = (TPrefineProjectSetItem *)mItemList->Items[i];
Item->Width = mContentArea->Width;
}
mItemWidth = mContentArea->Width;
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::WMKillFocus(TMessage &Message)
{
Hide();
}
//---------------------------------------------------------------------------
void __fastcall TPrefineProjectSet::GetChordDisplayKey(int iKey, int iBaseKey, int& iMainKey, int& iAjustKey)
{
iMainKey = -1;
iAjustKey = 0;
if( iKey<0 )
return;
if( !g_iShowType ){
iKey -= iBaseKey;
if( iKey<0 ) iKey += 12;
}
switch( iKey ){
case 0: iMainKey = 0;
break;
case 1: iAjustKey = -1;
case 2: iMainKey = 1;
break;
case 3: iAjustKey = -1;
case 4: iMainKey = 2;
break;
case 6: iAjustKey = 1;
case 5: iMainKey = 3;
break;
case 7: iMainKey = 4;
break;
case 8: iAjustKey = -1;
case 9: iMainKey = 5;
break;
case 10: iAjustKey = -1;
case 11: iMainKey = 6;
break;
}
}
//---------------------------------------------------------------------------