984 lines
27 KiB
C++
984 lines
27 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "GlobalUnit.h"
|
|
#include "BasePanelUnit.h"
|
|
#include "PNGButton.hpp"
|
|
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
__fastcall BasePanelUnit::TPanel::TPanel(TComponent* AOwner)
|
|
: TShowBarsPanel(AOwner)
|
|
{
|
|
m_lstStageHeader = NULL;
|
|
m_bStageHeaderDraging = false;
|
|
|
|
m_iPreApartBar = m_iPreDeleteStage =
|
|
m_iDragStage = m_iFocusCell = -1;
|
|
|
|
m_nChordWidth = 40;
|
|
m_nChordHeight = 20;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
__fastcall BasePanelUnit::TPanel::~TPanel()
|
|
{
|
|
if( m_lstStageHeader ){
|
|
m_lstStageHeader->Free();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void BasePanelUnit::TPanel::InitialVars()
|
|
{
|
|
TShowBarsPanel::InitialVars( g_lstMelodyBars.size() );
|
|
|
|
if( m_lstStageHeader && m_lstStageHeader->Count > 0 ){
|
|
m_lstStageHeader->Clear();
|
|
}
|
|
|
|
for( int i=0; i<g_lstMelodyStages.size(); i++ ){
|
|
MELODYSTAGE* pStage = g_lstMelodyStages[i];
|
|
|
|
AddStageHeader( i, pStage->iFirstBar, pStage->iVar );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
TImage * BasePanelUnit::TPanel::NewStageHeader( int iVar )
|
|
{
|
|
TImage * pImg = new TImage(NULL);
|
|
TPoint aPoints[3] = { TPoint(0,0), TPoint(0,12), TPoint(12,0) };
|
|
|
|
pImg->Tag = iVar;
|
|
pImg->Width = 12;
|
|
pImg->Height = 12;
|
|
|
|
pImg->Canvas->Brush->Color = clWhite;
|
|
TRect rc( 0, 0, 12, 12 );
|
|
pImg->Canvas->FillRect(rc);
|
|
|
|
pImg->Canvas->Brush->Color = g_clrStage[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;
|
|
pImg->Parent = this;
|
|
|
|
return pImg;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void BasePanelUnit::TPanel::UpdateStageHeader( int iStage )
|
|
{
|
|
TImage * pImg = (TImage*)(*m_lstStageHeader)[iStage];
|
|
TPoint aPoints[3] = { TPoint(0,0), TPoint(0,12), TPoint(12,0) };
|
|
|
|
pImg->Canvas->Brush->Color = g_clrStage[pImg->Tag % STAGE_VAR_NUM];
|
|
pImg->Canvas->Polygon( aPoints, 2 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void BasePanelUnit::TPanel::AddStageHeader( int iStage, int iShowBar, int iVar )
|
|
{
|
|
int iRow = iShowBar / m_nColumnNum - m_nBeginShowRow;
|
|
int iCol = iShowBar % m_nColumnNum;
|
|
TImage * pSHImg = NewStageHeader( iVar );
|
|
pSHImg->Left = iCol * m_nBarWidth + m_nLeftBound;
|
|
pSHImg->Top = iRow * m_nBarHeight + m_nTopBound + 4;
|
|
pSHImg->OnMouseDown = StageHeaderMouseDown;
|
|
pSHImg->OnMouseUp = StageHeaderMouseUp;
|
|
pSHImg->OnMouseMove = StageHeaderMouseMove;
|
|
pSHImg->ShowHint = true;
|
|
|
|
if( iStage>0 ) pSHImg->Cursor = crSizeWE;
|
|
|
|
m_lstStageHeader->Insert( iStage, pSHImg );
|
|
|
|
for( int i=iStage; i<m_lstStageHeader->Count; i++ ){
|
|
TImage * pImg = (TImage*)(*m_lstStageHeader)[i];
|
|
pImg->Hint = GetElementInfo(i, LIST_MELODYSTAGES).c_str();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void BasePanelUnit::TPanel::RemoveStageHeader( int iStage )
|
|
{
|
|
TImage * pRemoveHeader = (TImage*)(*m_lstStageHeader)[iStage];
|
|
m_lstStageHeader->Remove( pRemoveHeader );
|
|
|
|
for( int i=iStage; i<m_lstStageHeader->Count; i++ ){
|
|
TImage * pImg = (TImage*)(*m_lstStageHeader)[i];
|
|
pImg->Hint = GetElementInfo(i, LIST_MELODYSTAGES).c_str();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall BasePanelUnit::TPanel::CreateWnd(void)
|
|
{
|
|
TShowBarsPanel::CreateWnd();
|
|
|
|
if( !ParentBackground ){
|
|
m_lstStageHeader = new TComponentList( true );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall BasePanelUnit::TPanel::SetBarTitle( int iBar, String& strText )
|
|
{
|
|
MELODYBAR *pMBar = g_lstMelodyBars[iBar];
|
|
|
|
if( pMBar->iFill!=-1 ){
|
|
int nSpaceCount = 6 - strText.Length();
|
|
for( int i=0; i<nSpaceCount; i++ )
|
|
strText = strText + " ";
|
|
|
|
strText = strText + g_strFill[pMBar->iFill];
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall BasePanelUnit::TPanel::DrawBarOperation( int iBar, int leftDraw, int topDraw )
|
|
{
|
|
int iStage = -1;
|
|
|
|
if( m_bStageHeaderDraging ){
|
|
iStage = m_iDragStage;
|
|
}
|
|
else{
|
|
iStage = FindStage( iBar );
|
|
}
|
|
|
|
if( iStage>=0 && iStage<m_lstStageHeader->Count ){
|
|
TImage * pImg = (TImage*)(*m_lstStageHeader)[iStage];
|
|
|
|
if( pImg->Left>=leftDraw && pImg->Left<leftDraw+m_nBarWidth &&
|
|
pImg->Top >= topDraw && pImg->Top < topDraw+m_nRowGapHeight){
|
|
String strText = GetStageName( iStage ).c_str();
|
|
|
|
Canvas->Brush->Style = bsClear;
|
|
Canvas->TextOut( pImg->Left+15, topDraw+4, strText );
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall BasePanelUnit::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 iStage = FindStage( iBar );
|
|
if( iStage>=0 ){
|
|
MELODYSTAGE* pStage = g_lstMelodyStages[iStage];
|
|
if( m_bStageHeaderDraging && m_iDragStage>0 ){
|
|
TImage * pImg = (TImage*)(*m_lstStageHeader)[m_iDragStage];
|
|
|
|
if( iStage<m_iDragStage-1 || iStage>m_iDragStage ){
|
|
Canvas->Brush->Color = g_clrStage[pStage->iVar % STAGE_VAR_NUM];
|
|
Canvas->FillRect( rectBar );
|
|
}
|
|
else if( pImg->Left > leftDraw && pImg->Left < leftDraw+m_nBarWidth &&
|
|
pImg->Top >= (topDraw-m_nTitleHeight-m_nRowGapHeight) &&
|
|
pImg->Top < topDraw ){
|
|
rectBar.right = pImg->Left;
|
|
MELODYSTAGE* pPreStage = g_lstMelodyStages[m_iDragStage-1];
|
|
Canvas->Brush->Color = g_clrStage[pPreStage->iVar % STAGE_VAR_NUM];
|
|
Canvas->FillRect( rectBar );
|
|
|
|
MELODYSTAGE* pDragStage = g_lstMelodyStages[m_iDragStage];
|
|
rectBar.left = pImg->Left;
|
|
rectBar.right = leftDraw + m_nDataWidth;
|
|
Canvas->Brush->Color = g_clrStage[pDragStage->iVar % STAGE_VAR_NUM];
|
|
Canvas->FillRect( rectBar );
|
|
}
|
|
else if( pImg->Left <= leftDraw && pImg->Top<topDraw ||
|
|
pImg->Top < (topDraw-m_nTitleHeight-m_nRowGapHeight)){
|
|
MELODYSTAGE* pDragStage = g_lstMelodyStages[m_iDragStage];
|
|
Canvas->Brush->Color = g_clrStage[pDragStage->iVar % STAGE_VAR_NUM];
|
|
Canvas->FillRect( rectBar );
|
|
}
|
|
else{
|
|
MELODYSTAGE* pPreStage = g_lstMelodyStages[m_iDragStage-1];
|
|
Canvas->Brush->Color = g_clrStage[pPreStage->iVar % STAGE_VAR_NUM];
|
|
Canvas->FillRect( rectBar );
|
|
}
|
|
}
|
|
else if( ( m_iPreApartBar<pStage->iFirstBar || iBar<m_iPreApartBar ) &&
|
|
( m_iPreDeleteStage<0 || m_iPreDeleteStage!=iStage &&
|
|
m_iPreDeleteStage!=iStage+1 )){
|
|
Canvas->Brush->Color = g_clrStage[pStage->iVar % STAGE_VAR_NUM];
|
|
Canvas->FillRect( rectBar );
|
|
}
|
|
else{
|
|
Canvas->Brush->Color = clWhite;
|
|
Canvas->FillRect( rectBar );
|
|
}
|
|
}
|
|
|
|
//绘制选中和弦框
|
|
if( m_iFocusCell!=-1 && iBar==m_iFocusCell/2 ){
|
|
TRect rectFocus;
|
|
rectFocus.top = topDraw;
|
|
rectFocus.bottom = topDraw + m_nDataHeight;
|
|
rectFocus.left = leftDraw;
|
|
if( m_iFocusCell%2 > 0 ) rectFocus.left += m_nDataWidth/2;
|
|
int nFocusCellWidth = g_iMelodyTimeSignature==0 ? m_nDataWidth/2-1 : m_nDataWidth-1;
|
|
rectFocus.right = rectFocus.left + nFocusCellWidth;
|
|
|
|
DrawFocusedCell( rectFocus );
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall BasePanelUnit::TPanel::DrawBarContext( int iBar, int leftDraw, int topDraw )
|
|
{
|
|
MELODYBAR *pMBar = g_lstMelodyBars[iBar];
|
|
if( pMBar->iChords[0]==-1 && pMBar->iChords[1]==-1 ){
|
|
return;
|
|
}
|
|
|
|
TRect rectDest;
|
|
rectDest.top = topDraw + 4;
|
|
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 BasePanelUnit::TPanel::DrawFocusedCell( TRect& rectFocus )
|
|
{
|
|
TColor clrOld = Canvas->Pen->Color;
|
|
Canvas->Pen->Color = g_clrFocus;
|
|
Canvas->Rectangle( rectFocus );
|
|
|
|
//绘制阴影
|
|
BYTE rD = 110, gD = 108, bD = 105,
|
|
rL = 230, gL = 226, bL = 217;
|
|
for( int i=0; i<3; i++ ){
|
|
if( i<2 ){
|
|
Canvas->Pen->Color = RGB(rL, gL, bL);
|
|
Canvas->MoveTo( rectFocus.left+i+1, rectFocus.bottom-i-2 );
|
|
Canvas->LineTo( rectFocus.right-i-2, rectFocus.bottom-i-2 );
|
|
Canvas->MoveTo( rectFocus.right-i-2, rectFocus.top+i+1 );
|
|
Canvas->LineTo( rectFocus.right-i-2, rectFocus.bottom-i-2 );
|
|
rL -= 10, gL -= 10, bL -= 10;
|
|
}
|
|
|
|
Canvas->Pen->Color = RGB(rD, gD, bD);
|
|
Canvas->MoveTo( rectFocus.left+i+1, rectFocus.top+i+1 );
|
|
Canvas->LineTo( rectFocus.right-i-2, rectFocus.top+i+1 );
|
|
Canvas->MoveTo( rectFocus.left+i+1, rectFocus.top+i+1 );
|
|
Canvas->LineTo( rectFocus.left+i+1, rectFocus.bottom-i-2 );
|
|
rD += 30, gD += 30, bD += 30;
|
|
}
|
|
|
|
Canvas->Pen->Color = clrOld;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool BasePanelUnit::TPanel::SetFocusCell( int iBar, bool bSecond )
|
|
{
|
|
int iFocusCell = -1;
|
|
int iOldFocusBar = -1;
|
|
|
|
if( m_iFocusCell!=-1 ){
|
|
iOldFocusBar = m_iFocusCell / 2;
|
|
}
|
|
if( iBar!=-1 ){
|
|
iFocusCell = iBar*2+bSecond;
|
|
}
|
|
|
|
if( m_iFocusCell!=iFocusCell ){
|
|
m_iFocusCell = iFocusCell;
|
|
if( iOldFocusBar!=-1 && iOldFocusBar!=iBar ){
|
|
InvalidateBar( iOldFocusBar, 0, m_nBarWidth );
|
|
}
|
|
|
|
if( iBar!=-1 ){
|
|
InvalidateBar( iBar, 0, m_nBarWidth );
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int BasePanelUnit::TPanel::GetFocusChord( int& iMainKey, int& iAjustKey, int& iChordType )
|
|
{
|
|
int ret = -1;
|
|
|
|
if( m_iFocusCell!=-1 ){
|
|
int iBar = m_iFocusCell/2;
|
|
MELODYBAR *pMBar = g_lstMelodyBars[iBar];
|
|
|
|
if( m_iFocusCell%2>0 ){
|
|
ret = pMBar->iChords[1];
|
|
}
|
|
else{
|
|
ret = pMBar->iChords[0];
|
|
}
|
|
}
|
|
|
|
iAjustKey = 0;
|
|
if( ret!=-1 ){
|
|
int iKey = ret / CHORD_TYPE_NUM;
|
|
iChordType = ret % CHORD_TYPE_NUM;
|
|
|
|
switch( iKey ){
|
|
case 0:
|
|
case 7:
|
|
iMainKey = (iKey+1)/2;
|
|
break;
|
|
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
iMainKey = (iKey+1) / 2;
|
|
iAjustKey = -(iKey % 2);
|
|
break;
|
|
|
|
case 5:
|
|
case 6:
|
|
iMainKey = (iKey+1)/2;
|
|
iAjustKey = 1 - (iKey%2);
|
|
break;
|
|
|
|
case 8:
|
|
case 9:
|
|
case 10:
|
|
case 11:
|
|
iMainKey = (iKey+2)/2;
|
|
iAjustKey = (iKey%2) - 1;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
else{
|
|
iMainKey = -1;
|
|
iChordType = 0;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool BasePanelUnit::TPanel::SetFocusChord( int iMainKey, int iAjustKey, int iChordType )
|
|
{
|
|
int iKey=-1, iChord;
|
|
switch( iMainKey ){
|
|
case 0:
|
|
iKey = 0;
|
|
break;
|
|
|
|
case 1:
|
|
case 2:
|
|
iKey = iMainKey * 2;
|
|
if( iAjustKey<0 ) iKey += iAjustKey;
|
|
break;
|
|
|
|
case 3:
|
|
iKey = 5;
|
|
if( iAjustKey>0 ) iKey += iAjustKey;
|
|
break;
|
|
|
|
case 4:
|
|
iKey = 7;
|
|
break;
|
|
|
|
case 5:
|
|
case 6:
|
|
iKey = iMainKey * 2 - 1;
|
|
if( iAjustKey<0 ) iKey += iAjustKey;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if( iKey==-1 )
|
|
iChord = -1;
|
|
else{
|
|
iChord = iKey * CHORD_TYPE_NUM + iChordType;
|
|
}
|
|
|
|
if( m_iFocusCell!=-1 ){
|
|
int iBar = m_iFocusCell/2;
|
|
MELODYBAR *pMBar = g_lstMelodyBars[iBar];
|
|
|
|
bool bChanged = false;
|
|
int iMaxPoint = POINTS_PER_BAR;
|
|
if( m_iFocusCell%2>0 ){
|
|
if( pMBar->iChords[1] != iChord ){
|
|
pMBar->iChords[1] = iChord;
|
|
bChanged = true;
|
|
}
|
|
}
|
|
else{
|
|
if( pMBar->iChords[0] != iChord ){
|
|
pMBar->iChords[0] = iChord;
|
|
bChanged = true;
|
|
}
|
|
iMaxPoint = POINTS_PER_BAR / 2;
|
|
}
|
|
|
|
if( bChanged ){
|
|
InvalidateBar( iBar, 0, m_nBarWidth );
|
|
|
|
if( m_bPlaying && ( m_iPlayBar<iBar || m_iPlayBar==iBar
|
|
&& m_iPlayPoint<iMaxPoint ) )
|
|
Parent->Perform(UM_RELOAD, 0, 0 );
|
|
}
|
|
|
|
return true;
|
|
}
|
|
else
|
|
return false;
|
|
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int BasePanelUnit::TPanel::FindStage( int iBar )
|
|
{
|
|
if( iBar>=0 ){
|
|
int nStageNum = g_lstMelodyStages.size();
|
|
for( int i=0; i<nStageNum; i++ ){
|
|
MELODYSTAGE* pStage = g_lstMelodyStages[i];
|
|
if( pStage->iFirstBar<=iBar && pStage->iLastBar>=iBar ){
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool BasePanelUnit::TPanel::SetApartPos( int iBar, int iPoint, bool bPre )
|
|
{
|
|
bool bSuccess = false;
|
|
|
|
int iSetStage = FindStage( iBar );
|
|
int iOldStage = FindStage( m_iPreApartBar );
|
|
|
|
if( iSetStage!=iOldStage && iOldStage>=0 ){
|
|
m_iPreApartBar = -1;
|
|
|
|
MELODYSTAGE* pOldStage = g_lstMelodyStages[iOldStage];
|
|
for( int i=pOldStage->iFirstBar+1; i<=pOldStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
}
|
|
|
|
if( iSetStage>=0 ){
|
|
int iSetBar = -1;
|
|
MELODYSTAGE* pSetStage = g_lstMelodyStages[iSetStage];
|
|
if( iPoint<POINTS_PER_BAR/2 && iBar!=pSetStage->iFirstBar ){
|
|
iSetBar = iBar;
|
|
}
|
|
else if( iPoint>=POINTS_PER_BAR/2 && iBar!=pSetStage->iLastBar ){
|
|
iSetBar = iBar + 1;
|
|
}
|
|
|
|
if( bPre && iSetBar!=m_iPreApartBar ){
|
|
m_iPreApartBar = iSetBar;
|
|
|
|
for( int i=pSetStage->iFirstBar+1; i<=pSetStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
|
|
bSuccess = true;
|
|
}
|
|
else if( !bPre && iSetBar!=-1 ){
|
|
m_iPreApartBar = -1;
|
|
|
|
MELODYSTAGE* pNewStage = new MELODYSTAGE;
|
|
pNewStage->iFirstBar = iSetBar;
|
|
pNewStage->iLastBar = pSetStage->iLastBar;
|
|
pNewStage->iVar = (pSetStage->iVar + 1) % STAGE_VAR_NUM;
|
|
|
|
if( iSetStage<g_lstMelodyStages.size()-1 &&
|
|
g_lstMelodyStages[iSetStage+1]->iVar==pNewStage->iVar ){
|
|
pNewStage->iVar = ( pNewStage->iVar + 1) % STAGE_VAR_NUM;
|
|
}
|
|
|
|
pSetStage->iLastBar = iSetBar-1;
|
|
if( iSetStage<g_lstMelodyStages.size() ){
|
|
MELODYSTAGELIST::iterator iMS = g_lstMelodyStages.begin()+iSetStage+1;
|
|
g_lstMelodyStages.insert( iMS, pNewStage );
|
|
}
|
|
else{
|
|
g_lstMelodyStages.push_back( pNewStage );
|
|
}
|
|
|
|
for( int i=pNewStage->iFirstBar; i<=pNewStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
|
|
AddStageHeader( iSetStage+1, pNewStage->iFirstBar, pNewStage->iVar );
|
|
|
|
for( int i=iSetStage+1; i<g_lstMelodyStages.size(); i++ ){
|
|
MELODYSTAGE * pUpdateStage = g_lstMelodyStages[i];
|
|
InvalidateBar( pUpdateStage->iFirstBar, 0, m_nBarWidth, BAR_HEADER );
|
|
}
|
|
|
|
//BOOL bModified = m_bkMelody.CheckModified( CHECK_STAGE | CHECK_POS );
|
|
// if( m_bPlaying )
|
|
// Parent->Perform(UM_RELOAD, 0, 0 );
|
|
|
|
bSuccess = true;
|
|
}
|
|
}
|
|
|
|
return bSuccess;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool BasePanelUnit::TPanel::SetCombinePos( int iBar, int iPoint, bool bPre )
|
|
{
|
|
bool bSuccess = false;
|
|
int iDeleteStage = -1;
|
|
int iOldStage = m_iPreDeleteStage;
|
|
int iHitStage = FindStage( iBar );
|
|
|
|
if( iHitStage>=0 ){
|
|
MELODYSTAGE* pHitStage = g_lstMelodyStages[iHitStage];
|
|
if( iPoint<POINTS_PER_BAR/2 && iBar==pHitStage->iFirstBar && iHitStage>0 ){
|
|
iDeleteStage = iHitStage;
|
|
}
|
|
else if( iPoint>=POINTS_PER_BAR/2 && iBar==pHitStage->iLastBar &&
|
|
iHitStage<g_lstMelodyStages.size()-1 ){
|
|
iDeleteStage = iHitStage + 1;
|
|
}
|
|
}
|
|
|
|
if( iDeleteStage!=iOldStage && iOldStage>0 ){
|
|
m_iPreDeleteStage = -1;
|
|
if( iDeleteStage<0 || iOldStage<iDeleteStage ){
|
|
MELODYSTAGE* pOldStage = g_lstMelodyStages[iOldStage-1];
|
|
for( int i=pOldStage->iFirstBar; i<=pOldStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
}
|
|
if( iDeleteStage<0 || iOldStage<iDeleteStage-1 ){
|
|
MELODYSTAGE* pOldStage = g_lstMelodyStages[iOldStage];
|
|
for( int i=pOldStage->iFirstBar; i<=pOldStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
}
|
|
if( iDeleteStage<0 || iOldStage>iDeleteStage ){
|
|
MELODYSTAGE* pOldStage = g_lstMelodyStages[iOldStage];
|
|
for( int i=pOldStage->iFirstBar; i<=pOldStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
}
|
|
if( iDeleteStage<0 || iOldStage>iDeleteStage+1 ){
|
|
MELODYSTAGE* pOldStage = g_lstMelodyStages[iOldStage-1];
|
|
for( int i=pOldStage->iFirstBar; i<=pOldStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
}
|
|
}
|
|
|
|
if( bPre ){
|
|
m_iPreDeleteStage = iDeleteStage;
|
|
|
|
if( iDeleteStage>0 ){
|
|
MELODYSTAGE* pNewStage = g_lstMelodyStages[iDeleteStage-1];
|
|
for( int i=pNewStage->iFirstBar; i<=pNewStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
|
|
pNewStage = g_lstMelodyStages[iDeleteStage];
|
|
for( int i=pNewStage->iFirstBar; i<=pNewStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
}
|
|
|
|
bSuccess = true;
|
|
}
|
|
else if( iDeleteStage>0 ){
|
|
m_iPreDeleteStage = -1;
|
|
|
|
MELODYSTAGE* pPreStage = g_lstMelodyStages[iDeleteStage-1];
|
|
MELODYSTAGELIST::iterator iMS = g_lstMelodyStages.begin()+iDeleteStage;
|
|
pPreStage->iLastBar = (*iMS)->iLastBar;
|
|
int iInvalBar = (*iMS)->iFirstBar;
|
|
|
|
delete (*iMS);
|
|
g_lstMelodyStages.erase( iMS );
|
|
|
|
RemoveStageHeader( iDeleteStage );
|
|
InvalidateBar( iInvalBar, 0, m_nBarWidth, BAR_HEADER );
|
|
|
|
for( int i=pPreStage->iFirstBar; i<=pPreStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth );
|
|
}
|
|
|
|
for( int i=iDeleteStage; i<g_lstMelodyStages.size(); i++ ){
|
|
MELODYSTAGE * pUpdateStage = g_lstMelodyStages[i];
|
|
InvalidateBar( pUpdateStage->iFirstBar, 0, m_nBarWidth, BAR_HEADER );
|
|
}
|
|
|
|
//BOOL bModified = m_bkMelody.CheckModified( CHECK_STAGE | CHECK_POS );
|
|
// if( m_bPlaying )
|
|
// Parent->Perform(UM_RELOAD, 0, 0 );
|
|
|
|
bSuccess = true;
|
|
}
|
|
|
|
return bSuccess;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall BasePanelUnit::TPanel::StageHeaderMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
|
|
{
|
|
TPoint newPoint(X,Y);
|
|
newPoint = ((TPNGButton*)Sender)->ClientToScreen( newPoint );
|
|
newPoint = ScreenToClient( newPoint );
|
|
BasePanelUnit::TPanel::OnMouseDown( Sender, Button, Shift, newPoint.x, newPoint.y );
|
|
|
|
if( Button==mbLeft ){
|
|
TImage* pHeader = (TImage*)Sender;
|
|
int iDragStage = m_lstStageHeader->IndexOf(pHeader);
|
|
|
|
if( iDragStage>0 ){
|
|
m_bStageHeaderDraging = true;
|
|
m_iDragStage = iDragStage;
|
|
m_xDragStart = X;
|
|
pHeader->ShowHint = false;
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall BasePanelUnit::TPanel::StageHeaderMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
|
|
{
|
|
if( m_bStageHeaderDraging ){
|
|
TImage* pHeader = (TImage*)Sender;
|
|
int nInvalidWidth = pHeader->Width + 10; //刷新段号
|
|
TPoint newPoint(X, Y);
|
|
|
|
if( Y < 1 ){
|
|
newPoint.y = 1;
|
|
}
|
|
else if( Y >= pHeader->Height-5 ){
|
|
newPoint.y = pHeader->Height-5;
|
|
}
|
|
|
|
MELODYSTAGE * pDragStage = g_lstMelodyStages[m_iDragStage];
|
|
|
|
int iHitType = -1;
|
|
DWORD dwHit = HitTest( pHeader->Left, pHeader->Top, iHitType, false );
|
|
int iOldBar = LOWORD(dwHit),
|
|
iOldPoint = HIWORD(dwHit);
|
|
int iOldStage = FindStage( iOldBar );
|
|
|
|
int xPos = X - m_xDragStart;
|
|
|
|
dwHit = HitTest( pHeader->Left+xPos, pHeader->Top, iHitType, false );
|
|
int iNewBar, iNewPoint, iNewStage;
|
|
if( iHitType>=0 ){
|
|
iNewBar = LOWORD(dwHit);
|
|
iNewPoint = HIWORD(dwHit);
|
|
iNewStage = FindStage( iNewBar );
|
|
|
|
if( xPos>0 ){ //向右拖动
|
|
if( iNewBar<pDragStage->iLastBar ){
|
|
pHeader->Left += xPos;
|
|
if( iNewBar!=iOldBar ){
|
|
InvalidateBar( iOldBar, iOldPoint, m_nBarWidth, BAR_HEADER|BAR_DATA );
|
|
InvalidateBar( iNewBar, 0, nInvalidWidth+xPos, BAR_HEADER|BAR_DATA );
|
|
}
|
|
else{
|
|
InvalidateBar( iOldBar, iOldPoint, iNewPoint+nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
if( iOldPoint+nInvalidWidth+xPos>m_nBarWidth ){
|
|
InvalidateBar( iOldBar+1, 0, nInvalidWidth+xPos, BAR_HEADER );
|
|
}
|
|
}
|
|
}
|
|
else if( iOldBar!=iNewBar ){
|
|
pHeader->Left += m_nBarWidth - iOldPoint;
|
|
newPoint.x = m_xDragStart + m_nBarWidth - iOldPoint;
|
|
InvalidateBar( iOldBar, iOldPoint, m_nBarWidth, BAR_HEADER|BAR_DATA );
|
|
InvalidateBar( iNewBar, 0, nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
}
|
|
else{
|
|
newPoint.x = m_xDragStart;
|
|
}
|
|
}
|
|
else{ //向左拖动
|
|
if( iNewStage!=m_iDragStage ){
|
|
MELODYSTAGE * pPreStage = g_lstMelodyStages[iNewStage];
|
|
|
|
if( iNewBar > pPreStage->iFirstBar ){
|
|
pHeader->Left += xPos;
|
|
if( iNewBar!=iOldBar ){
|
|
InvalidateBar( iOldBar, 0, iOldPoint+nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
InvalidateBar( iNewBar, iNewPoint, m_nBarWidth, BAR_HEADER|BAR_DATA );
|
|
}
|
|
else{
|
|
InvalidateBar( iOldBar, iNewPoint, iOldPoint+nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
}
|
|
}
|
|
else if( iOldBar!=iNewBar ){
|
|
pHeader->Left -= iOldPoint;
|
|
newPoint.x = m_xDragStart - iOldPoint;
|
|
InvalidateBar( iOldBar, 0, iOldPoint+nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
}
|
|
}
|
|
else{
|
|
pHeader->Left += xPos;
|
|
if( iNewBar!=iOldBar ){
|
|
InvalidateBar( iOldBar, 0, iOldPoint+nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
InvalidateBar( iNewBar, iNewPoint, m_nBarWidth, BAR_HEADER|BAR_DATA );
|
|
}
|
|
else{
|
|
InvalidateBar( iOldBar, iNewPoint, iOldPoint+nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
newPoint.x = m_xDragStart;
|
|
newPoint.y = pHeader->Height/2;
|
|
|
|
if( xPos>0 ){ //越过了右边界
|
|
pHeader->Left = m_nLeftBound+1;
|
|
|
|
if( pHeader->Top+m_nBarHeight > m_nTopBound + m_nRowShow * m_nBarHeight ){ //超出底端
|
|
ScrollView( m_nBeginShowRow + 1 );
|
|
}
|
|
else{
|
|
pHeader->Top += m_nBarHeight;
|
|
}
|
|
|
|
InvalidateBar( iOldBar, iOldPoint, m_nBarWidth, BAR_DATA );
|
|
InvalidateBar( iOldBar, iOldPoint, iOldPoint+nInvalidWidth, BAR_HEADER );
|
|
|
|
InvalidateBar( iOldBar+1, 0, nInvalidWidth+1, BAR_HEADER|BAR_DATA );
|
|
}
|
|
else{ //越过了左边界
|
|
pHeader->Left = m_nLeftBound+m_nColumnNum*m_nBarWidth-1;
|
|
|
|
if( pHeader->Top-m_nBarHeight < m_nTopBound ){ //超出顶端
|
|
ScrollView( m_nBeginShowRow - 1 );
|
|
}
|
|
else{
|
|
pHeader->Top -= m_nBarHeight;
|
|
}
|
|
|
|
InvalidateBar( iOldBar, 0, iOldPoint+nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
InvalidateBar( iOldBar-1, m_nBarWidth-1, m_nBarWidth+nInvalidWidth-1, BAR_HEADER|BAR_DATA );
|
|
}
|
|
}
|
|
|
|
if( newPoint.x!=X || newPoint.y!=Y ){
|
|
newPoint = pHeader->ClientToScreen( newPoint );
|
|
SetCursorPos( newPoint.x, newPoint.y );
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall BasePanelUnit::TPanel::StageHeaderMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
|
|
{
|
|
if( Button==mbLeft && m_bStageHeaderDraging ){
|
|
m_bStageHeaderDraging = false;
|
|
|
|
TImage* pHeader = (TImage*)Sender;
|
|
int nInvalidWidth = pHeader->Width + 10; //刷新段号
|
|
|
|
int iHitType = -1;
|
|
DWORD dwHit = HitTest( pHeader->Left, pHeader->Top, iHitType, false );
|
|
int iDestBar = LOWORD(dwHit),
|
|
iDestPoint = HIWORD(dwHit);
|
|
|
|
int iFirstBar = iDestBar;
|
|
|
|
if( iDestPoint>=m_nBarWidth/2 ){
|
|
iFirstBar++;
|
|
|
|
pHeader->Left += m_nBarWidth-iDestPoint;
|
|
|
|
if( pHeader->Left>=m_nLeftBound+m_nColumnNum*m_nBarWidth ){
|
|
pHeader->Left = m_nLeftBound;
|
|
pHeader->Top += m_nBarHeight;
|
|
}
|
|
|
|
InvalidateBar( iDestBar+1, 0, nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
InvalidateBar( iDestBar, iDestPoint, m_nBarWidth, BAR_HEADER|BAR_DATA );
|
|
}
|
|
else{
|
|
pHeader->Left -= iDestPoint;
|
|
|
|
InvalidateBar( iDestBar, 0, iDestPoint+nInvalidWidth, BAR_HEADER|BAR_DATA );
|
|
}
|
|
|
|
MELODYSTAGE * pDragStage = g_lstMelodyStages[m_iDragStage];
|
|
int iOldFirstBar = pDragStage->iFirstBar;
|
|
if( iFirstBar!=pDragStage->iFirstBar ){
|
|
pDragStage->iFirstBar = iFirstBar;
|
|
|
|
MELODYSTAGE * pPreStage = g_lstMelodyStages[m_iDragStage-1];
|
|
pPreStage->iLastBar = iFirstBar-1;
|
|
}
|
|
|
|
//BOOL bModified = m_bkMelody.CheckModified( CHECK_POS );
|
|
if( m_bPlaying )
|
|
Parent->Perform(UM_RELOAD, 0, 0 );
|
|
|
|
m_iDragStage = -1;
|
|
pHeader->ShowHint = true;
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall BasePanelUnit::TPanel::BarPosChanged()
|
|
{
|
|
if( m_lstStageHeader && m_lstStageHeader->Count > 0 ){
|
|
for( int i=0; i<m_lstStageHeader->Count; i++ ){
|
|
if( m_bStageHeaderDraging && m_iDragStage==i )
|
|
continue;
|
|
|
|
TImage * pImg = (TImage*)(*m_lstStageHeader)[i];
|
|
MELODYSTAGE * pStage = g_lstMelodyStages[i];
|
|
int iRow = pStage->iFirstBar / m_nColumnNum - m_nBeginShowRow;
|
|
int iCol = pStage->iFirstBar % m_nColumnNum;
|
|
|
|
pImg->Left = iCol * m_nBarWidth + m_nLeftBound;
|
|
pImg->Top = iRow * m_nBarHeight + m_nTopBound + 4;
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void BasePanelUnit::TPanel::SetBarFill( int iBar, int iFill )
|
|
{
|
|
MELODYBAR *pMBar = g_lstMelodyBars[iBar];
|
|
|
|
pMBar->iFill = iFill;
|
|
|
|
InvalidateBar( iBar, 0, m_nBarWidth, BAR_TITLE );
|
|
|
|
// BOOL bModified = m_bkMelody.CheckModified( CHECK_FILL );
|
|
if( m_bPlaying && m_iPlayBar<=iBar )
|
|
Parent->Perform(UM_RELOAD, 0, 0 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void BasePanelUnit::TPanel::SetStageVar( int iStage, int iVar )
|
|
{
|
|
MELODYSTAGE * pSetStage = g_lstMelodyStages[iStage];
|
|
|
|
pSetStage->iVar = iVar;
|
|
|
|
for( int i=pSetStage->iFirstBar; i<=pSetStage->iLastBar; i++ ){
|
|
InvalidateBar( i, 0, m_nBarWidth, BAR_DATA );
|
|
}
|
|
|
|
TImage * pImg = (TImage*)(*m_lstStageHeader)[iStage];
|
|
pImg->Tag = iVar;
|
|
pImg->Hint = L"旋律" + String(GetStageName( iStage ).c_str()) +
|
|
L"段 " + String(g_strStageVar[pImg->Tag]);
|
|
UpdateStageHeader( iStage );
|
|
|
|
// BOOL bModified = m_bkMelody.CheckModified( CHECK_VAR );
|
|
if( m_bPlaying && m_iPlayBar<=pSetStage->iLastBar )
|
|
Parent->Perform(UM_RELOAD, 0, 0 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void BasePanelUnit::TPanel::DeleteAllChord()
|
|
{
|
|
for( int i=0; i<g_lstMelodyBars.size(); i++ ){
|
|
MELODYBAR *pMBar = g_lstMelodyBars[i];
|
|
pMBar->iChords[0] = -1;
|
|
pMBar->iChords[1] = -1;
|
|
//InvalidateBar( i, 0, m_nBarWidth, BAR_DATA );
|
|
}
|
|
|
|
Parent->Perform(UM_RELOAD, true, 0 );
|
|
|
|
Invalidate();
|
|
/*
|
|
BOOL bModified = m_bkMelody.CheckModified( CHECK_CHORD );
|
|
Parent->Perform(UM_ENABLERELOAD, bModified, 0 );
|
|
*/
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool BasePanelUnit::TPanel::HasChordSet()
|
|
{
|
|
for( int i=0; i<g_lstMelodyBars.size(); i++ ){
|
|
MELODYBAR *pMBar = g_lstMelodyBars[i];
|
|
if( pMBar->iChords[0]!=-1 || pMBar->iChords[1]!=-1 )
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
/*
|
|
void BasePanelUnit::TPanel::SetMelodyKey( int iKey )
|
|
{
|
|
// g_iMelodyKey = iKey;
|
|
|
|
// BOOL bModified = m_bkMelody.CheckModified( CHECK_KEY );
|
|
// Parent->Perform(UM_RELOAD, m_iFocusCell>=0, 0 );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
BOOL BasePanelUnit::TPanel::CheckModify( int iCheckType )
|
|
{
|
|
return g_bkMelody.CheckModified( iCheckType );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void BasePanelUnit::TPanel::BackupModify()
|
|
{
|
|
g_bkMelody.Backup();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall BasePanelUnit::TPanel::KeyDown(System::Word &Key, System::Classes::TShiftState Shift)
|
|
{
|
|
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
*/
|