983 lines
27 KiB
C++
983 lines
27 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "GlobalUnit.h"
|
|
#include "PNGButton.hpp"
|
|
#include "ComposePanelUnit.h"
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
#define DOTIP_WIDTH 15
|
|
//---------------------------------------------------------------------------
|
|
|
|
__fastcall ComposePanelUnit::TPanel::TPanel(TComponent* AOwner)
|
|
: TShowBarsPanel(AOwner)
|
|
{
|
|
m_lstStageHeader = NULL;
|
|
|
|
m_iFocusStage = -1;
|
|
|
|
m_imgDrag = NULL;
|
|
m_xImgDrag = m_yImgDrag = 0;
|
|
m_iDragOverPos = m_iDragingStage = -100;
|
|
m_bDraging = m_bAddStage = false;
|
|
m_iDragingStage = -1;
|
|
|
|
m_nChordWidth = 40;
|
|
m_nChordHeight = 20;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
__fastcall ComposePanelUnit::TPanel::~TPanel()
|
|
{
|
|
if( m_lstStageHeader ){
|
|
m_lstStageHeader->Free();
|
|
// delete m_lstStageHeader;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::InitialVars()
|
|
{
|
|
TShowBarsPanel::InitialVars(0);
|
|
|
|
if( m_lstStageHeader && m_lstStageHeader->Count > 0 ){
|
|
m_lstStageHeader->Clear();
|
|
}
|
|
//计算总小节数
|
|
int nTotalBarCount = 0;
|
|
for( int i=0; i<g_lstComposeStages.size(); i++ ){
|
|
COMPOSESTAGE* pCStage = g_lstComposeStages[i];
|
|
|
|
AddStageHeader( i, nTotalBarCount, i );
|
|
|
|
nTotalBarCount += pCStage->nStageBars;
|
|
}
|
|
|
|
TShowBarsPanel::InitialVars( nTotalBarCount );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
TImage * ComposePanelUnit::TPanel::NewStageHeader( int iStage )
|
|
{
|
|
PCOMPOSESTAGE pCStage = g_lstComposeStages[iStage];
|
|
|
|
TImage * pImg = new TImage(NULL);
|
|
pImg->Parent = this;
|
|
pImg->Tag = MAKELONG( pCStage->iMelodyStage, pCStage->iVar );
|
|
pImg->Width = 12;
|
|
pImg->Height = 12;
|
|
|
|
pImg->Canvas->Brush->Color = clWhite;
|
|
TRect rc( 0, 0, 12, 12 );
|
|
pImg->Canvas->FillRect(rc);
|
|
|
|
TPoint aPoints[3] = { TPoint(0,0), TPoint(0,12), TPoint(12,0) };
|
|
|
|
if( pCStage->iMelodyStage>=COMPOSE_ENDING_1 ){
|
|
pImg->Canvas->Brush->Color = g_clrEnding[pCStage->iMelodyStage - COMPOSE_ENDING_1];
|
|
}
|
|
else if( pCStage->iMelodyStage>=COMPOSE_INTRO_1 ){
|
|
pImg->Canvas->Brush->Color = g_clrIntro[pCStage->iMelodyStage - COMPOSE_INTRO_1];
|
|
}
|
|
else{
|
|
pImg->Canvas->Brush->Color = g_clrStage[pCStage->iVar % STAGE_VAR_NUM];
|
|
}
|
|
|
|
pImg->Canvas->Pen->Color = COLOR_BORDER;
|
|
pImg->Canvas->Polygon( aPoints, 2 );
|
|
|
|
pImg->Picture->Bitmap->Transparent = true;
|
|
pImg->Picture->Bitmap->TransparentMode = tmFixed;
|
|
pImg->Picture->Bitmap->TransparentColor = clWhite;
|
|
pImg->Transparent = true;
|
|
|
|
return pImg;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::UpdateStageHeader( int iStage )
|
|
{
|
|
TImage * pImg = (TImage*)(*m_lstStageHeader)[iStage];
|
|
TPoint aPoints[3] = { TPoint(0,0), TPoint(0,12), TPoint(12,0) };
|
|
int iMelodyStage = LOWORD( pImg->Tag ),
|
|
iVar = HIWORD( pImg->Tag );
|
|
|
|
if( iMelodyStage>=COMPOSE_ENDING_1 ){
|
|
pImg->Canvas->Brush->Color = g_clrEnding[iMelodyStage - COMPOSE_ENDING_1];
|
|
}
|
|
else if( iMelodyStage>=COMPOSE_INTRO_1 ){
|
|
pImg->Canvas->Brush->Color = g_clrIntro[iMelodyStage - COMPOSE_INTRO_1];
|
|
}
|
|
else{
|
|
pImg->Canvas->Brush->Color = g_clrStage[iVar % STAGE_VAR_NUM];
|
|
}
|
|
|
|
pImg->Canvas->Polygon( aPoints, 2 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::AddStageHeader( int iInsStage, int iShowBar, int iComposeStage )
|
|
{
|
|
int iRow = iShowBar / m_nColumnNum - m_nBeginShowRow;
|
|
int iCol = iShowBar % m_nColumnNum;
|
|
TImage * pSHImg = NewStageHeader( iComposeStage );
|
|
pSHImg->Left = iCol * m_nBarWidth + m_nLeftBound;
|
|
pSHImg->Top = iRow * m_nBarHeight + m_nTopBound + 4;
|
|
pSHImg->OnMouseDown = StageHeaderMouseDown;
|
|
|
|
|
|
pSHImg->Hint = GetElementInfo( iComposeStage, LIST_COMPOSESTAGES ).c_str();
|
|
pSHImg->ShowHint = true;
|
|
|
|
m_lstStageHeader->Insert( iInsStage, pSHImg );
|
|
if( iInsStage<m_lstStageHeader->Count-1 )
|
|
UpdateHeaders( iInsStage+1 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::RemoveStageHeader( int iDelStage )
|
|
{
|
|
TImage * pRemoveHeader = (TImage*)(*m_lstStageHeader)[iDelStage];
|
|
m_lstStageHeader->Remove( pRemoveHeader );
|
|
|
|
if( iDelStage<m_lstStageHeader->Count )
|
|
UpdateHeaders( iDelStage );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall ComposePanelUnit::TPanel::CreateWnd(void)
|
|
{
|
|
TShowBarsPanel::CreateWnd();
|
|
|
|
if( !ParentBackground ){
|
|
m_lstStageHeader = new TComponentList( true );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall ComposePanelUnit::TPanel::Paint()
|
|
{
|
|
if( !ParentBackground ){
|
|
TShowBarsPanel::Paint();
|
|
|
|
if( m_bDraging ){
|
|
//绘制半透明图片
|
|
TBlendFunction Blend;
|
|
Blend.BlendOp = AC_SRC_OVER;
|
|
Blend.BlendFlags = 0;
|
|
Blend.AlphaFormat = 0;
|
|
Blend.SourceConstantAlpha =205;
|
|
|
|
::AlphaBlend (Canvas->Handle,
|
|
m_xImgDrag,
|
|
m_yImgDrag,
|
|
m_imgDrag->Width,
|
|
m_imgDrag->Height,
|
|
m_imgDrag->Canvas->Handle,
|
|
0,
|
|
0,
|
|
m_imgDrag->Width,
|
|
m_imgDrag->Height,
|
|
Blend
|
|
);
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall ComposePanelUnit::TPanel::SetBarTitle( int iBar, String& strText )
|
|
{
|
|
int iFirstBar, iStage = FindStage( iBar, &iFirstBar );
|
|
|
|
if( iStage>=0 ){
|
|
COMPOSESTAGE *pCStage = g_lstComposeStages[iStage];
|
|
for( int i=0; i<pCStage->aFills.size(); i++ ){
|
|
int iPos = LOWORD(pCStage->aFills[i]),
|
|
iType = HIWORD(pCStage->aFills[i]);
|
|
|
|
if( iPos==iBar-iFirstBar ){
|
|
int nSpaceCount = 6 - strText.Length();
|
|
for( int i=0; i<nSpaceCount; i++ )
|
|
strText = strText + " ";
|
|
|
|
strText = strText + g_strFill[iType];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall ComposePanelUnit::TPanel::DrawBarOperation( int iBar, int leftDraw, int topDraw )
|
|
{
|
|
int iStage = FindStage( iBar );
|
|
|
|
if( iStage>=0 && iStage<m_lstStageHeader->Count ){
|
|
COMPOSESTAGE *pCStage = g_lstComposeStages[iStage];
|
|
if( pCStage->iMelodyStage<COMPOSE_INTRO_1 ){
|
|
TImage* pImg = (TImage*)(*m_lstStageHeader)[iStage];
|
|
|
|
if( pImg->Left>=leftDraw && pImg->Left<leftDraw+m_nBarWidth &&
|
|
pImg->Top >= topDraw && pImg->Top < topDraw+m_nRowGapHeight){
|
|
Canvas->Brush->Style = bsClear;
|
|
Canvas->TextOut( pImg->Left+15, topDraw+4, GetStageName(LOWORD(pImg->Tag)).c_str() );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall ComposePanelUnit::TPanel::DrawBarBkgnd( int iBar, int leftDraw, int topDraw )
|
|
{
|
|
TRect rectBar;
|
|
rectBar.left = leftDraw;
|
|
rectBar.right = rectBar.left + m_nDataWidth;
|
|
rectBar.top = topDraw;
|
|
rectBar.bottom = rectBar.top + m_nDataHeight;
|
|
|
|
int iFirstBar, iStage = FindStage( iBar, &iFirstBar );
|
|
|
|
if( iStage<0 ) return;
|
|
|
|
COMPOSESTAGE* pStage = g_lstComposeStages[iStage];
|
|
|
|
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){
|
|
Canvas->Brush->Color = g_clrEnding[pStage->iMelodyStage - COMPOSE_ENDING_1];
|
|
Canvas->FillRect( rectBar );
|
|
}
|
|
else if( pStage->iMelodyStage>=COMPOSE_INTRO_1 ){
|
|
Canvas->Brush->Color = g_clrIntro[pStage->iMelodyStage - COMPOSE_INTRO_1];
|
|
Canvas->FillRect( rectBar );
|
|
}
|
|
else{
|
|
Canvas->Brush->Color = g_clrStage[pStage->iVar % STAGE_VAR_NUM];
|
|
Canvas->FillRect( rectBar );
|
|
}
|
|
|
|
//绘制选中段落框
|
|
if( m_iFocusStage==iStage ){
|
|
TColor clrOld = Canvas->Pen->Color;
|
|
Canvas->Pen->Color = g_clrFocus;
|
|
if( iBar==iFirstBar ){ //绘制左边框
|
|
Canvas->MoveTo( rectBar.left, rectBar.top );
|
|
Canvas->LineTo( rectBar.left, rectBar.bottom );
|
|
}
|
|
|
|
if( iBar==iFirstBar+pStage->nStageBars-1 ){ //绘制右边框
|
|
Canvas->MoveTo( rectBar.right-2, rectBar.top );
|
|
Canvas->LineTo( rectBar.right-2, rectBar.bottom );
|
|
}
|
|
|
|
//绘制上边框
|
|
Canvas->MoveTo( rectBar.left, rectBar.top );
|
|
Canvas->LineTo( rectBar.right-1, rectBar.top );
|
|
|
|
//绘制下边框
|
|
Canvas->MoveTo( rectBar.left, rectBar.bottom-1 );
|
|
Canvas->LineTo( rectBar.right-1, rectBar.bottom-1 );
|
|
|
|
Canvas->Pen->Color = clrOld;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall ComposePanelUnit::TPanel::DrawBarContext( int iBar, int leftDraw, int topDraw )
|
|
{
|
|
int iFirstBar, iStage = FindStage( iBar, &iFirstBar );
|
|
COMPOSESTAGE * pCStage = g_lstComposeStages[iStage];
|
|
|
|
//绘制Drop提示
|
|
if( m_bDraging ){
|
|
TRect rcTip;
|
|
rcTip.left = leftDraw,
|
|
rcTip.top = topDraw,
|
|
rcTip.right = leftDraw+m_nBarWidth,
|
|
rcTip.bottom = topDraw+m_nDataHeight;
|
|
|
|
if( iBar==m_iDragOverPos ){
|
|
rcTip.right = rcTip.left + DOTIP_WIDTH;
|
|
|
|
Canvas->Brush->Color = clWhite;
|
|
Canvas->FillRect( rcTip );
|
|
|
|
Canvas->MoveTo( rcTip.right, rcTip.top );
|
|
Canvas->LineTo( rcTip.right, rcTip.bottom );
|
|
}
|
|
|
|
if( iBar==m_iDragOverPos-1 ){
|
|
rcTip.left = rcTip.right - DOTIP_WIDTH;
|
|
|
|
Canvas->Brush->Color = clWhite;
|
|
Canvas->FillRect( rcTip );
|
|
|
|
Canvas->MoveTo( rcTip.left, rcTip.top );
|
|
Canvas->LineTo( rcTip.left, rcTip.bottom );
|
|
}
|
|
}
|
|
|
|
if( pCStage->iMelodyStage>=COMPOSE_INTRO_1 ) //插入段无需绘制和弦
|
|
return;
|
|
|
|
MELODYSTAGE *pMStage = g_lstMelodyStages[pCStage->iMelodyStage];
|
|
int iMelodyBar = iBar - iFirstBar + pMStage->iFirstBar;
|
|
MELODYBAR *pMBar = g_lstMelodyBars [iMelodyBar];
|
|
if( pMBar->iChords[0]==-1 && pMBar->iChords[1]==-1 ){
|
|
return;
|
|
}
|
|
|
|
TRect rectDest;
|
|
rectDest.top = topDraw + ( m_nDataHeight - m_nChordHeight ) / 2;
|
|
rectDest.bottom = rectDest.top + m_nChordHeight;
|
|
|
|
if( g_iMelodyTimeSignature==0 ){
|
|
//绘制第一个和弦
|
|
rectDest.left = leftDraw + ( m_nDataWidth/2 - m_nChordWidth ) / 2;
|
|
rectDest.right = rectDest.left + m_nChordWidth;
|
|
|
|
DrawChord( rectDest, pMBar->iChords[0] );
|
|
|
|
//绘制第二个和弦
|
|
if( pMBar->iChords[1]!=-1 ){
|
|
rectDest.left = leftDraw + m_nDataWidth/2 + ( m_nDataWidth/2 - m_nChordWidth ) / 2;
|
|
rectDest.right = rectDest.left + m_nChordWidth;
|
|
|
|
DrawChord( rectDest, pMBar->iChords[1] );
|
|
}
|
|
}
|
|
else{
|
|
//只绘制一个和弦
|
|
rectDest.left = leftDraw + ( m_nDataWidth - m_nChordWidth ) / 2;
|
|
rectDest.right = rectDest.left + m_nChordWidth;
|
|
|
|
DrawChord( rectDest, pMBar->iChords[0] );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall ComposePanelUnit::TPanel::BarPosChanged()
|
|
{
|
|
if( m_lstStageHeader && m_lstStageHeader->Count > 0 ){
|
|
int iFirstBar = 0;
|
|
for( int i=0; i<m_lstStageHeader->Count; i++ ){
|
|
int iRow = iFirstBar / m_nColumnNum - m_nBeginShowRow;
|
|
int iCol = iFirstBar % m_nColumnNum;
|
|
|
|
TImage* pImg = (TImage*)(*m_lstStageHeader)[i];
|
|
pImg->Left = iCol * m_nBarWidth + m_nLeftBound;
|
|
pImg->Top = iRow * m_nBarHeight + m_nTopBound + 4;
|
|
|
|
iFirstBar += g_lstComposeStages[i]->nStageBars;
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int ComposePanelUnit::TPanel::FindStage( int iBar, int *piFirstBar )
|
|
{
|
|
if( iBar>=0 ){
|
|
int nStageNum = g_lstComposeStages.size();
|
|
int nBarCount = 0;
|
|
for( int i=0; i<nStageNum; i++ ){
|
|
COMPOSESTAGE* pStage = g_lstComposeStages[i];
|
|
|
|
if( piFirstBar )
|
|
*piFirstBar = nBarCount;
|
|
|
|
nBarCount += pStage->nStageBars;
|
|
|
|
if( iBar<nBarCount ){
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int ComposePanelUnit::TPanel::FirstBar( int iStage )
|
|
{
|
|
if( iStage>=g_lstComposeStages.size() )
|
|
return -1;
|
|
|
|
int nBarCount = 0;
|
|
for( int i=0; i<iStage; i++ ){
|
|
COMPOSESTAGE* pStage = g_lstComposeStages[i];
|
|
|
|
nBarCount += pStage->nStageBars;
|
|
}
|
|
|
|
return nBarCount;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::InvalidateStage( int iStage, int iArea )
|
|
{
|
|
int iFirstBar = FirstBar( iStage );
|
|
COMPOSESTAGE * pStage = g_lstComposeStages[iStage];
|
|
for( int i=0; i<pStage->nStageBars; i++ ){
|
|
InvalidateBar( iFirstBar+i, 0, m_nBarWidth, iArea );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::SetFocusStage( int iStage )
|
|
{
|
|
int iOldFocusStage = m_iFocusStage;
|
|
m_iFocusStage = iStage;
|
|
|
|
if( iOldFocusStage!=-1 && iOldFocusStage!=iStage ){
|
|
//去除原选中框
|
|
InvalidateStage( iOldFocusStage );
|
|
}
|
|
|
|
if( iStage!=-1 ){
|
|
//绘制选中框
|
|
InvalidateStage( iStage );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall ComposePanelUnit::TPanel::StageHeaderMouseDown(TObject *Sender,
|
|
TMouseButton Button, TShiftState Shift, int X, int Y)
|
|
{
|
|
TPoint newPoint(X,Y);
|
|
newPoint = ((TImage*)Sender)->ClientToScreen( newPoint );
|
|
newPoint = ScreenToClient( newPoint );
|
|
ComposePanelUnit::TPanel::OnMouseDown( Sender, Button, Shift, newPoint.x, newPoint.y );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::SetBarFill( int iBar, int iFill )
|
|
{
|
|
int iFirstBar, iSetStage = FindStage( iBar, &iFirstBar );
|
|
COMPOSESTAGE * pSetStage = g_lstComposeStages[iSetStage];
|
|
if( pSetStage->iMelodyStage>=COMPOSE_INTRO_1 )
|
|
return;
|
|
|
|
int iInsPos = 0;
|
|
bool bSet = false;
|
|
for( int i=0; i<pSetStage->aFills.size(); i++ ){
|
|
int iPos = LOWORD( pSetStage->aFills[i] );
|
|
if( iBar-iFirstBar<iPos ){
|
|
iInsPos = i;
|
|
break;
|
|
}
|
|
else if( iBar-iFirstBar==iPos ){
|
|
if( iFill<0 ){
|
|
vector<DWORD>::iterator iter = pSetStage->aFills.begin() + i;
|
|
pSetStage->aFills.erase( iter );
|
|
}
|
|
else{
|
|
pSetStage->aFills[i] = MAKELONG( iPos, iFill );
|
|
}
|
|
|
|
bSet = true;
|
|
break;
|
|
}
|
|
}
|
|
if( iFill>=0 && !bSet ){
|
|
vector<DWORD>::iterator iter = pSetStage->aFills.begin()+iInsPos;
|
|
pSetStage->aFills.insert( iter, MAKELONG( iBar-iFirstBar, iFill ) );
|
|
}
|
|
|
|
InvalidateBar( iBar, 0, m_nBarWidth, BAR_TITLE );
|
|
|
|
// BOOL bModified = m_bkCompose.CheckModified( CHECK_FILL );
|
|
if( m_bPlaying && m_iPlayBar<=iBar )
|
|
Parent->Perform(UM_RELOAD, 0, 0 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::SetStageVar( int iStage, int iVar )
|
|
{
|
|
COMPOSESTAGE * pSetStage = g_lstComposeStages[iStage];
|
|
|
|
if( pSetStage->iMelodyStage>=COMPOSE_INTRO_1 )
|
|
return;
|
|
|
|
pSetStage->iVar = iVar;
|
|
int iFirstBar = 0;
|
|
for( int i=0; i<iStage; i++ ){
|
|
iFirstBar += g_lstComposeStages[i]->nStageBars;
|
|
}
|
|
|
|
for( int i=0; i<pSetStage->nStageBars; i++ ){
|
|
InvalidateBar( iFirstBar+i, 0, m_nBarWidth, BAR_DATA );
|
|
}
|
|
|
|
TImage* pImg = (TImage*)(*m_lstStageHeader)[iStage];
|
|
pImg->Tag = MAKELONG( pSetStage->iMelodyStage, iVar );
|
|
UpdateStageHeader( iStage );
|
|
pImg->Hint = GetElementInfo( iStage, LIST_COMPOSESTAGES ).c_str();
|
|
|
|
// BOOL bModified = m_bkCompose.CheckModified( CHECK_VAR );
|
|
if( m_bPlaying && m_iPlayBar<=iFirstBar+pSetStage->nStageBars )
|
|
Parent->Perform(UM_RELOAD, 0, 0 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::SetStageStyle( int iStage, int idStyle )
|
|
{
|
|
COMPOSESTAGE * pSetStage = g_lstComposeStages[iStage];
|
|
|
|
pSetStage->idStyle = idStyle;
|
|
|
|
// BOOL bModified = m_bkCompose.CheckModified( CHECK_STYLE );
|
|
// Parent->Perform(UM_RELOAD, 0, 0 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::SetDragState( bool bDraging )
|
|
{
|
|
if( m_bDraging != bDraging ){
|
|
if( !bDraging ){
|
|
RECT rcDrag;
|
|
rcDrag.left = m_xImgDrag;
|
|
rcDrag.top = m_yImgDrag;
|
|
rcDrag.right = m_xImgDrag+m_imgDrag->Width;
|
|
rcDrag.bottom = m_yImgDrag+m_imgDrag->Height;
|
|
|
|
m_xImgDrag = m_yImgDrag = -100;
|
|
|
|
m_bAddStage = false;
|
|
m_iDragingStage = -1;
|
|
|
|
InvalidateRect( Handle, &rcDrag, false );
|
|
UpdateDragOverPos( -1 );
|
|
}
|
|
|
|
m_bDraging = bDraging;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::SetDragStage( bool bAdd, int iStage )
|
|
{
|
|
m_bAddStage = bAdd;
|
|
m_iDragingStage = iStage;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::SetDragImgPos( int X, int Y )
|
|
{
|
|
TPoint ptScreen(X, Y),
|
|
ptClient = ScreenToClient( ptScreen );
|
|
TRect rcClient = GetClientRect();
|
|
|
|
RECT rcDrag;
|
|
if( ptClient.x!=m_xImgDrag || ptClient.y!=m_yImgDrag ){
|
|
rcDrag.left = m_xImgDrag;
|
|
rcDrag.top = m_yImgDrag;
|
|
rcDrag.right = m_xImgDrag+m_imgDrag->Width;
|
|
rcDrag.bottom = m_yImgDrag+m_imgDrag->Height;
|
|
|
|
//拖动图像在框内
|
|
if( rcClient.PtInRect( TPoint(rcDrag.left, rcDrag.top) ) ||
|
|
rcClient.PtInRect( TPoint(rcDrag.left, rcDrag.bottom) ) ||
|
|
rcClient.PtInRect( TPoint(rcDrag.right, rcDrag.bottom) ) ||
|
|
rcClient.PtInRect( TPoint(rcDrag.right, rcDrag.top) ) ){
|
|
InvalidateRect( Handle, &rcDrag, false );
|
|
}
|
|
}
|
|
|
|
m_xImgDrag = ptClient.x, m_yImgDrag = ptClient.y;
|
|
|
|
rcDrag.left = m_xImgDrag;
|
|
rcDrag.top = m_yImgDrag;
|
|
rcDrag.right = m_xImgDrag+m_imgDrag->Width;
|
|
rcDrag.bottom = m_yImgDrag+m_imgDrag->Height;
|
|
|
|
//拖动图像在框内
|
|
if( rcClient.PtInRect( TPoint(rcDrag.left, rcDrag.top) ) ||
|
|
rcClient.PtInRect( TPoint(rcDrag.left, rcDrag.bottom) ) ||
|
|
rcClient.PtInRect( TPoint(rcDrag.right, rcDrag.bottom) ) ||
|
|
rcClient.PtInRect( TPoint(rcDrag.right, rcDrag.top) ) ){
|
|
|
|
InvalidateRect( Handle, &rcDrag, false );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
BOOL ComposePanelUnit::TPanel::SetDragingPoint( int X, int Y )
|
|
{
|
|
BOOL bCanDrop = false;
|
|
int iNewPos = -1, iHitType = -1;
|
|
DWORD dwHit = HitTest( X, Y, iHitType, false, true );
|
|
|
|
if( g_lstComposeStages.size()==0 ){
|
|
return true;
|
|
}
|
|
|
|
if( iHitType>0 ){
|
|
int iHitBar = LOWORD(dwHit),
|
|
iHitPoint = HIWORD(dwHit);
|
|
|
|
int iFirstBar, iHitStage = FindStage( iHitBar, &iFirstBar );
|
|
COMPOSESTAGE * pHitStage = g_lstComposeStages[iHitStage];
|
|
|
|
int nTotalLen = pHitStage->nStageBars * m_nBarWidth;
|
|
int nHitLen = (iHitBar-iFirstBar)*m_nBarWidth + iHitPoint;
|
|
int iDragOverStage = iHitStage;
|
|
iNewPos = iFirstBar;
|
|
|
|
if( nHitLen > nTotalLen / 2 ){
|
|
iDragOverStage++;
|
|
iNewPos += pHitStage->nStageBars;
|
|
}
|
|
|
|
//检查是否可Drop
|
|
bCanDrop = true;
|
|
COMPOSESTAGE* pStage = NULL;
|
|
int nStageSize = g_lstComposeStages.size();
|
|
if( m_bAddStage ){
|
|
if( m_iDragingStage>=COMPOSE_ENDING_1 ){ //拖动的是尾奏
|
|
if( iDragOverStage<nStageSize ){
|
|
bCanDrop = false;
|
|
}
|
|
else{
|
|
pStage = g_lstComposeStages[nStageSize-1];
|
|
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){ //曲式中已有尾奏
|
|
bCanDrop = false;
|
|
}
|
|
}
|
|
}
|
|
else if( iDragOverStage>0 ){
|
|
pStage = g_lstComposeStages[iDragOverStage-1];
|
|
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){ //放置在尾奏后
|
|
bCanDrop = false;
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
if( m_iDragingStage==iDragOverStage || m_iDragingStage==iDragOverStage-1 ){
|
|
iNewPos = -1;
|
|
}
|
|
else{
|
|
COMPOSESTAGE* pStage = g_lstComposeStages[m_iDragingStage];
|
|
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){
|
|
bCanDrop = false;
|
|
}
|
|
else if( iDragOverStage==nStageSize ){
|
|
pStage = g_lstComposeStages[iDragOverStage-1];
|
|
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){
|
|
bCanDrop = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//更新Drop提示
|
|
if( !bCanDrop )
|
|
iNewPos = -1;
|
|
UpdateDragOverPos( iNewPos );
|
|
|
|
return bCanDrop;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::UpdateDragOverPos( int iNewPos )
|
|
{
|
|
int iOldPos = m_iDragOverPos;
|
|
|
|
if( iOldPos!=iNewPos ){
|
|
m_iDragOverPos = iNewPos;
|
|
|
|
if( iOldPos!=-1 ){
|
|
//清除原提示
|
|
if( iOldPos<m_nBarNum )
|
|
InvalidateBar( iOldPos, 0, DOTIP_WIDTH, BAR_DATA );
|
|
|
|
if( iOldPos>0 )
|
|
InvalidateBar( iOldPos-1, m_nBarWidth-DOTIP_WIDTH, m_nBarWidth, BAR_DATA );
|
|
}
|
|
|
|
if( iNewPos!=-1 ){
|
|
//显示提示
|
|
if( iNewPos<m_nBarNum )
|
|
InvalidateBar( iNewPos, 0, DOTIP_WIDTH, BAR_DATA );
|
|
|
|
if( iNewPos>0 )
|
|
InvalidateBar( iNewPos-1, m_nBarWidth-DOTIP_WIDTH, m_nBarWidth, BAR_DATA );
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int ComposePanelUnit::TPanel::SetDropPoint( int X, int Y )
|
|
{
|
|
int iInsertPos = 0;
|
|
if( g_lstComposeStages.size()>0 ){
|
|
int iHitType = -1;
|
|
DWORD dwHit = HitTest( X, Y, iHitType, false, true );
|
|
|
|
if( iHitType>0 ){
|
|
int iHitBar = LOWORD(dwHit),
|
|
iHitPoint = HIWORD(dwHit);
|
|
|
|
int iFirstBar, iHitStage = FindStage( iHitBar, &iFirstBar );
|
|
COMPOSESTAGE * pHitStage = g_lstComposeStages[iHitStage];
|
|
|
|
int nTotalLen = pHitStage->nStageBars * m_nBarWidth;
|
|
int nHitLen = (iHitBar-iFirstBar)*m_nBarWidth + iHitPoint;
|
|
iInsertPos = iHitStage;
|
|
|
|
if( nHitLen > nTotalLen / 2 ){
|
|
iInsertPos++;
|
|
}
|
|
|
|
//检查是否可Drop
|
|
COMPOSESTAGE* pStage = NULL;
|
|
int nStageSize = g_lstComposeStages.size();
|
|
if( m_bAddStage ){
|
|
if( m_iDragingStage>=COMPOSE_ENDING_1 ){ //拖动的是尾奏
|
|
if( iInsertPos<nStageSize ){
|
|
iInsertPos = -1;
|
|
}
|
|
else{
|
|
pStage = g_lstComposeStages[nStageSize-1];
|
|
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){ //曲式中已有尾奏
|
|
iInsertPos = -1;
|
|
}
|
|
}
|
|
}
|
|
else if( iInsertPos>0 ){
|
|
pStage = g_lstComposeStages[iInsertPos-1];
|
|
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){ //放置在尾奏后
|
|
iInsertPos = -1;
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
if( m_iDragingStage==iInsertPos || m_iDragingStage==iInsertPos-1 ){
|
|
iInsertPos = -1;
|
|
}
|
|
else{
|
|
COMPOSESTAGE* pStage = g_lstComposeStages[m_iDragingStage];
|
|
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){
|
|
iInsertPos = -1;
|
|
}
|
|
else if( iInsertPos==nStageSize ){
|
|
pStage = g_lstComposeStages[iInsertPos-1];
|
|
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){
|
|
iInsertPos = -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
iInsertPos = -1;
|
|
}
|
|
}
|
|
|
|
if( iInsertPos>=0 ){
|
|
if( m_bAddStage ){
|
|
InsertStage( m_iDragingStage, iInsertPos );
|
|
}
|
|
else{
|
|
MoveStage( m_iDragingStage, iInsertPos );
|
|
}
|
|
}
|
|
|
|
return iInsertPos;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::InsertStage( int iStage, int iInsertPos )
|
|
{
|
|
m_iDragOverPos = -1;
|
|
|
|
MELODYSTAGE *pMStage = NULL;
|
|
COMPOSESTAGE* pCStage = new COMPOSESTAGE;
|
|
|
|
if( iStage>=COMPOSE_ENDING_1 ){
|
|
int iEnding = iStage - COMPOSE_ENDING_1;
|
|
pCStage->iMelodyStage = iStage;
|
|
pCStage->nStageBars = g_arrEndingBarNum[iEnding];
|
|
pCStage->idStyle = g_iSelectedStyleID;
|
|
}
|
|
else if( iStage>=COMPOSE_INTRO_1 ){
|
|
int iIntro = iStage - COMPOSE_INTRO_1;
|
|
pCStage->iMelodyStage = iStage;
|
|
pCStage->nStageBars = g_arrIntroBarNum[iIntro];
|
|
pCStage->idStyle = g_iSelectedStyleID;
|
|
}
|
|
else{
|
|
pMStage = g_lstMelodyStages[iStage];
|
|
pCStage->iMelodyStage = iStage;
|
|
pCStage->nStageBars = pMStage->iLastBar - pMStage->iFirstBar + 1;
|
|
pCStage->iVar = pMStage->iVar;
|
|
pCStage->idStyle = g_iSelectedStyleID;
|
|
for( int k=pMStage->iFirstBar; k<=pMStage->iLastBar; k++ ){
|
|
MELODYBAR *pMBar = g_lstMelodyBars[k];
|
|
if( pMBar->iFill!=-1 ){
|
|
DWORD dwFill = MAKELONG( k - pMStage->iFirstBar, pMBar->iFill );
|
|
pCStage->aFills.push_back( dwFill );
|
|
}
|
|
}
|
|
}
|
|
|
|
COMPOSESTAGELIST::iterator iCS = g_lstComposeStages.begin()+iInsertPos;
|
|
g_lstComposeStages.insert( iCS, pCStage );
|
|
|
|
AddStageHeader( iInsertPos, FirstBar(iInsertPos), iInsertPos );
|
|
|
|
TShowBarsPanel::InitialVars( m_nBarNum + pCStage->nStageBars );
|
|
|
|
SetFocusStage( iInsertPos );
|
|
|
|
// BOOL bModified = m_bkCompose.CheckModified( CHECK_STAGE | CHECK_POS );
|
|
Parent->Perform(UM_RELOAD, 1, 0 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::AddStage( int iStage )
|
|
{
|
|
int iInsertPos = 0,
|
|
nStageSize = g_lstComposeStages.size();
|
|
|
|
if( nStageSize>0 ){
|
|
COMPOSESTAGE* pCStage = g_lstComposeStages[nStageSize-1];
|
|
if( pCStage->iMelodyStage>=COMPOSE_ENDING_1 ){ //已有尾奏
|
|
if( iStage>=COMPOSE_ENDING_1 ){
|
|
if( iStage!=pCStage->iMelodyStage ){ //替换尾奏
|
|
DeleteStage( nStageSize-1 );
|
|
}
|
|
else{
|
|
return;
|
|
}
|
|
}
|
|
|
|
iInsertPos = nStageSize - 1; //添加到尾奏前
|
|
}
|
|
else{
|
|
iInsertPos = nStageSize; //添加到最后
|
|
}
|
|
}
|
|
|
|
InsertStage( iStage, iInsertPos );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::DeleteStage( int iStage )
|
|
{
|
|
if( iStage>=0 ){
|
|
COMPOSESTAGELIST::iterator iCS = g_lstComposeStages.begin()+iStage;
|
|
int nRemoveBars = (*iCS)->nStageBars;
|
|
|
|
delete (*iCS);
|
|
g_lstComposeStages.erase( iCS );
|
|
|
|
TShowBarsPanel::InitialVars( m_nBarNum - nRemoveBars );
|
|
|
|
RemoveStageHeader( iStage );
|
|
|
|
SetFocusStage( -1 );
|
|
|
|
// BOOL bModified = m_bkCompose.CheckModified( CHECK_STAGE | CHECK_POS );
|
|
Parent->Perform(UM_RELOAD, 1, 0 );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::MoveStage( int iSource, int iDest )
|
|
{
|
|
m_iDragOverPos = -1;
|
|
int iStartUpdate = iDest;
|
|
if( iSource<iDest ){
|
|
iStartUpdate = iSource;
|
|
iDest--;
|
|
}
|
|
|
|
COMPOSESTAGE* pCStage = g_lstComposeStages[iSource];
|
|
|
|
COMPOSESTAGELIST::iterator iCS = g_lstComposeStages.begin()+iSource;
|
|
g_lstComposeStages.erase( iCS );
|
|
iCS = g_lstComposeStages.begin()+iDest;
|
|
g_lstComposeStages.insert( iCS, pCStage );
|
|
TComponent* pHeader = (TComponent*)(*m_lstStageHeader)[iSource];
|
|
m_lstStageHeader->Extract( pHeader );
|
|
m_lstStageHeader->Insert( iDest, pHeader );
|
|
UpdateHeaders( iStartUpdate );
|
|
|
|
Invalidate();
|
|
|
|
SetFocusStage( iDest );
|
|
|
|
// BOOL bModified = m_bkCompose.CheckModified( CHECK_POS );
|
|
Parent->Perform(UM_RELOAD, 1, 0 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::UpdateHeaders( int iStart )
|
|
{
|
|
for( int i=iStart; i<g_lstComposeStages.size(); i++ ){
|
|
TControl* pStageHeader = (TControl*)(*m_lstStageHeader)[i];
|
|
int iShowBar = FirstBar( i );
|
|
int iRow = iShowBar / m_nColumnNum - m_nBeginShowRow;
|
|
int iCol = iShowBar % m_nColumnNum;
|
|
|
|
pStageHeader->Left = iCol * m_nBarWidth + m_nLeftBound;
|
|
pStageHeader->Top = iRow * m_nBarHeight + m_nTopBound + 4;
|
|
|
|
int iMStage = LOWORD(pStageHeader->Tag);
|
|
if( iMStage>=COMPOSE_INTRO_1 && iMStage<COMPOSE_ENDING_1 ){
|
|
pStageHeader->Hint = GetElementInfo(i, LIST_COMPOSESTAGES ).c_str();
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
/*
|
|
BOOL ComposePanelUnit::TPanel::CheckModify( int iCheckType )
|
|
{
|
|
BOOL bModified = 0;
|
|
if( iCheckType & CHECK_CHORD ){
|
|
bModified = m_bkMelody.CheckModified( CHECK_CHORD );
|
|
}
|
|
|
|
if( iCheckType!=CHECK_CHORD ){
|
|
bModified |= m_bkCompose.CheckModified( iCheckType );
|
|
}
|
|
|
|
return bModified;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::BackupModify()
|
|
{
|
|
m_bkMelody.Backup();
|
|
m_bkCompose.Backup();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void ComposePanelUnit::TPanel::RestoreModify()
|
|
{
|
|
m_bkCompose.Restore();
|
|
|
|
for( int i=m_lstStageHeader->Count-1; i>=0; i-- ){
|
|
delete (TImage*)(*m_lstStageHeader)[i];
|
|
}
|
|
|
|
int nTotalBarCount = 0;
|
|
for( int i=0; i<g_lstComposeStages.size(); i++ ){
|
|
COMPOSESTAGE* pCStage = g_lstComposeStages[i];
|
|
|
|
AddStageHeader( i, nTotalBarCount, i );
|
|
|
|
nTotalBarCount += pCStage->nStageBars;
|
|
}
|
|
|
|
TShowBarsPanel::InitialVars( nTotalBarCount );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall ComposePanelUnit::TPanel::KeyDown(System::Word &Key,
|
|
System::Classes::TShiftState Shift)
|
|
{
|
|
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
*/
|