Reorganize sources into Src/ and add README

This commit is contained in:
2026-09-13 10:47:56 +08:00
parent 2191c1aed4
commit 1c935b424d
163 changed files with 1131 additions and 307 deletions
+77
View File
@@ -0,0 +1,77 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "AboutFormUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TAboutForm *AboutForm;
//---------------------------------------------------------------------------
__fastcall TAboutForm::TAboutForm(TComponent* Owner)
: TForm(Owner)
{
Font->Color = RGB(60,43,23);
}
//---------------------------------------------------------------------------
void __fastcall TAboutForm::FormCreate(TObject *Sender)
{
SetTransparent( this );
m_lblVersion->Caption = g_strCurrentVersion;
int wMaj, wMin, wMod, wBld;
sscanf( g_strCurrentVersion, "%d.%d.%d.%d", &wMaj, &wMin, &wMod, &wBld );
if( wMaj==0 )
m_lblType->Caption = L"测试版";
else
m_lblType->Caption = L"正式版";
m_lblType->Left = m_lblVersion->Left + m_lblVersion->Width + 3;
int nOnline, nLocal;
f_CS_GetStyleNums( nOnline, nLocal );
char strNums[64];
sprintf( strNums, "在线/已下载风格数: %d/%d", nOnline, nLocal );
m_lblStyleNums->Caption = strNums;
m_lblURL->Caption = g_strServerURL;
//绘制圆角窗体
HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+2, 20, 20 );
SetWindowRgn( Handle, hRgn, false );
DeleteObject( hRgn );
}
//---------------------------------------------------------------------------
void __fastcall TAboutForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if( Msg.Result==HTCLIENT && Msg.YPos<Top+24 && Msg.XPos<Left+275 )
Msg.Result = HTCAPTION;
}
//---------------------------------------------------------------------------
void __fastcall TAboutForm::URLClick(TObject *Sender)
{
if( m_lblURL->Caption.Length()>0 ){
ShellExecute(Handle,NULL, m_lblURL->Caption.c_str(), NULL,NULL,SW_SHOWNORMAL);
}
}
//---------------------------------------------------------------------------
void __fastcall TAboutForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
switch( Key ){
case VK_RETURN:
case VK_ESCAPE:
case ' ':
ModalResult = mrCancel;
break;
}
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+39
View File
@@ -0,0 +1,39 @@
//---------------------------------------------------------------------------
#ifndef AboutFormUnitH
#define AboutFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include "PNGButton.hpp"
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.jpeg.hpp>
//---------------------------------------------------------------------------
class TAboutForm : public TForm
{
__published: // IDE-managed Components
TImage *m_imgBkgrnd;
TLabel *m_lblVersion;
TLabel *m_lblTitle;
TLabel *m_lblURL;
TPNGButton *m_btnClose;
TLabel *m_lblStyleNums;
TLabel *m_lblType;
void __fastcall FormCreate(TObject *Sender);
void __fastcall URLClick(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
private: // User declarations
void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TAboutForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TAboutForm *AboutForm;
//---------------------------------------------------------------------------
#endif
+125
View File
@@ -0,0 +1,125 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "AudioEffectFormUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TAudioEffectForm *AudioEffectForm;
//---------------------------------------------------------------------------
__fastcall TAudioEffectForm::TAudioEffectForm(TComponent* Owner, bool bSong)
: TForm(Owner)
{
m_bSong = bSong;
}
//---------------------------------------------------------------------------
void __fastcall TAudioEffectForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if( Msg.Result==HTCLIENT && Msg.YPos<Top+24 && Msg.XPos<Left+390)
Msg.Result = HTCAPTION;
}
//---------------------------------------------------------------------------
void __fastcall TAudioEffectForm::FormCreate(TObject *Sender)
{
SetTransparent( this );
Font->Color = RGB(60,43,23);
//»æÖÆÔ²½Ç´°Ìå
HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+1, 16, 16 );
SetWindowRgn( Handle, hRgn, false );
DeleteObject( hRgn );
m_aCombos[0] = m_cbBox0;
m_aCombos[1] = NULL;
m_aCombos[2] = NULL;
m_aCombos[3] = m_cbBox3;
m_aCombos[4] = m_cbBox4;
m_aCombos[5] = m_cbBox5;
m_aCombos[6] = m_cbBox6;
m_aCombos[7] = m_cbBox7;
m_aCombos[8] = m_cbBox8;
m_aCombos[9] = m_cbBox9;
m_aCombos[10] = m_cbBox10;
}
void __fastcall TAudioEffectForm::FormActivate(TObject *Sender)
{
for( int i=0; i<MAX_FX_NUM; i++ ){
if( m_aCombos[i] )
m_aCombos[i]->ItemIndex = g_aAudioEffects[i];
}
}
//---------------------------------------------------------------------------
void __fastcall TAudioEffectForm::ComboChange(TObject *Sender)
{
TComboBox* pCombo = (TComboBox*)Sender;
f_MM_SetFxPreset( pCombo->Tag, pCombo->ItemIndex );
}
//---------------------------------------------------------------------------
void __fastcall TAudioEffectForm::PreviewClick(TObject *Sender)
{
if( Sender==m_btnPreview0 ){
m_btnPreview0->Hide();
m_btnPreview1->Show();
f_MM_Play( Handle, 0, TYPE_AUDIO|TYPE_LOOPPLAY );
}
else{
m_btnPreview0->Show();
m_btnPreview1->Hide();
f_MM_Stop();
}
}
//---------------------------------------------------------------------------
void __fastcall TAudioEffectForm::OkClick(TObject *Sender)
{
f_MM_Stop();
bool bChanged = false;
for( int i=0; i<MAX_FX_NUM; i++ ){
if( m_aCombos[i] && g_aAudioEffects[i]!=m_aCombos[i]->ItemIndex ){
g_aAudioEffects[i] = m_aCombos[i]->ItemIndex;
bChanged = true;
}
}
if( bChanged )
g_strMP3File = "";
}
//---------------------------------------------------------------------------
void __fastcall TAudioEffectForm::CancelClick(TObject *Sender)
{
f_MM_Stop();
for( int i=0; i<MAX_FX_NUM; i++ ){
f_MM_SetFxPreset( g_aAudioEffectTypes[i], g_aAudioEffects[i] );
}
}
//---------------------------------------------------------------------------
void __fastcall TAudioEffectForm::ClearAllClick(TObject *Sender)
{
for( int i=0; i<MAX_FX_NUM; i++ ){
if( m_aCombos[i] ){
m_aCombos[i]->ItemIndex = 0;
f_MM_SetFxPreset( g_aAudioEffectTypes[i], 0 );
}
}
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+75
View File
@@ -0,0 +1,75 @@
//---------------------------------------------------------------------------
#ifndef AudioEffectFormUnitH
#define AudioEffectFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include "PNGButton.hpp"
#include <Vcl.Imaging.pngimage.hpp>
#include <vector>
using namespace std;
//---------------------------------------------------------------------------
class TAudioEffectForm : public TForm
{
__published: // IDE-managed Components
TLabel *m_lblCaption;
TPNGButton *m_btnCancel;
TPNGButton *m_btnOk;
TComboBox *m_cbBox0;
TLabel *Label1;
TComboBox *m_cbBox10;
TLabel *Label4;
TComboBox *m_cbBox3;
TLabel *Label5;
TComboBox *m_cbBox4;
TLabel *Label6;
TComboBox *m_cbBox5;
TLabel *Label7;
TComboBox *m_cbBox8;
TLabel *Label8;
TComboBox *m_cbBox6;
TLabel *Label9;
TComboBox *m_cbBox7;
TLabel *Label10;
TLabel *Label11;
TComboBox *m_cbBox9;
TImage *m_imgBk;
TPNGButton *m_btnClose;
TGroupBox *GroupBox1;
TPNGButton *m_btnPreview1;
TPNGButton *m_btnPreview0;
TImage *m_imgIcon;
TButton *m_btnClear;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormActivate(TObject *Sender);
void __fastcall ComboChange(TObject *Sender);
void __fastcall PreviewClick(TObject *Sender);
void __fastcall OkClick(TObject *Sender);
void __fastcall CancelClick(TObject *Sender);
void __fastcall ClearAllClick(TObject *Sender);
private: // User declarations
TComboBox *m_aCombos[11];
bool m_bSong;
void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TAudioEffectForm(TComponent* Owner, bool bSong);
};
//---------------------------------------------------------------------------
extern PACKAGE TAudioEffectForm *AudioEffectForm;
//---------------------------------------------------------------------------
#endif
+64
View File
@@ -0,0 +1,64 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#include <Vcl.Imaging.pngimage.hpp>
#pragma hdrstop
#include "BackgroundForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
TPngImage *u_pImgCellTile = NULL;
__fastcall TBackgroundForm::TBackgroundForm(TComponent* AOwner)
: TForm(AOwner)
{
m_yLeftSide = -1;
if( !u_pImgCellTile ){
u_pImgCellTile = new TPngImage();
u_pImgCellTile->LoadFromResourceName(int(HInstance), L"PngBackTile");
}
}
//---------------------------------------------------------------------------
__fastcall TBackgroundForm::~TBackgroundForm()
{
if( u_pImgCellTile ){
delete u_pImgCellTile;
u_pImgCellTile = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TBackgroundForm::WMEraseBkgnd(Winapi::Messages::TWMEraseBkgnd &Message)
{
if( u_pImgCellTile ){
TCanvas* tempCanvas = new TCanvas;
tempCanvas->Handle = Message.DC;
int nBottom = ClientHeight - u_pImgCellTile->Height;
//绘制面板上下部分
for (int i=0; i<2; i++){
int y = i==0 ? 0 : nBottom;
for (int x=0; x<ClientWidth; x+=u_pImgCellTile->Width){
tempCanvas->Draw( x, y, u_pImgCellTile );
}
}
if( m_yLeftSide>=0 ){ //ComposeForm列表框最小化时须填充左侧
for(int y=m_yLeftSide; y<nBottom; y+=u_pImgCellTile->Height ){
tempCanvas->Draw( 0, y, u_pImgCellTile );
}
}
delete tempCanvas;
Message.Result = true;
}
else{
DefaultHandler( &Message );
}
}
//---------------------------------------------------------------------------
+21
View File
@@ -0,0 +1,21 @@
//---------------------------------------------------------------------------
#ifndef BackgroundFormH
#define BackgroundFormH
#include <Vcl.ComCtrls.hpp>
//---------------------------------------------------------------------------
class TBackgroundForm : public TForm
{
private:
int m_yLeftSide;
protected:
void FillLeftSide(int y){m_yLeftSide=y;};
MESSAGE void __fastcall WMEraseBkgnd(Winapi::Messages::TWMEraseBkgnd &Message);
public:
__fastcall TBackgroundForm(TComponent* AOwner);
__fastcall ~TBackgroundForm();
};
#endif
+344
View File
@@ -0,0 +1,344 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "BackupUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
TMelodyBackup::TMelodyBackup()
{
m_iKey = -1;
m_nBarCount = 0;
m_nStageCount = 0;
m_bModified = false;
m_aChords = NULL;
m_aFills = NULL;
m_aStages = NULL;
}
TMelodyBackup::~TMelodyBackup()
{
Clear();
}
void TMelodyBackup::Clear()
{
m_iKey = -1;
m_nBarCount = 0;
m_nStageCount = 0;
m_bModified = false;
if( m_aChords ){
delete[] m_aChords;
m_aChords = NULL;
}
if( m_aFills ){
delete[] m_aFills;
m_aFills = NULL;
}
if( m_aStages ){
delete[] m_aStages;
m_aStages = NULL;
}
}
void TMelodyBackup::Backup()
{
//±¸·ÝMelodyÊý¾Ý
m_iKey = g_iMelodyKey;
if( m_nBarCount!=g_lstMelodyBars.size() ){
m_nBarCount = g_lstMelodyBars.size();
if( m_aChords ){
delete m_aChords;
m_aChords = NULL;
}
m_aChords = new int[m_nBarCount][2];
if( m_aFills ){
delete m_aFills;
m_aFills = NULL;
}
m_aFills = new int[m_nBarCount];
}
if( m_nStageCount!=g_lstMelodyStages.size() ){
m_nStageCount = g_lstMelodyStages.size();
if( m_aStages ){
delete m_aStages;
m_aStages = NULL;
}
m_aStages = new int[g_lstMelodyStages.size()][3];
}
for( int i=0; i<g_lstMelodyBars.size(); i++ ){
MELODYBAR *pMBar = g_lstMelodyBars[i];
m_aChords[i][0] = pMBar->iChords[0];
m_aChords[i][1] = pMBar->iChords[1];
m_aFills[i] = pMBar->iFill;
}
for( int i=0; i<g_lstMelodyStages.size(); i++ ){
MELODYSTAGE* pStage = g_lstMelodyStages[i];
m_aStages[i][0] = pStage->iFirstBar;
m_aStages[i][1] = pStage->iLastBar;
m_aStages[i][2] = pStage->iVar;
}
m_bModified = false;
}
void TMelodyBackup::Restore()
{
g_iMelodyKey = m_iKey;
for( int i=0; i<g_lstMelodyBars.size(); i++ ){
MELODYBAR *pMBar = g_lstMelodyBars[i];
pMBar->iChords[0] = m_aChords[i][0];
pMBar->iChords[1] = m_aChords[i][1];
pMBar->iFill = m_aFills[i];
}
if( m_nStageCount!=g_lstMelodyStages.size() ){
ClearGlobalVars( LIST_MELODYSTAGES );
for( int i=0; i<m_nStageCount; i++ ){
MELODYSTAGE * pStage = new MELODYSTAGE;
pStage->iFirstBar = m_aStages[i][0];
pStage->iLastBar = m_aStages[i][1];
pStage->iVar = m_aStages[i][2];
g_lstMelodyStages.push_back( pStage );
}
}
else{
for( int i=0; i<m_nStageCount; i++ ){
MELODYSTAGE * pStage = g_lstMelodyStages[i];
pStage->iFirstBar = m_aStages[i][0];
pStage->iLastBar = m_aStages[i][1];
pStage->iVar = m_aStages[i][2];
}
}
m_bModified = false;
}
BOOL TMelodyBackup::CheckModified( int iCheckType )
{
if( iCheckType==CHECK_GET ){
return m_bModified;
}
m_bModified &= ~iCheckType;
if( iCheckType & CHECK_KEY ){
if( m_iKey != g_iMelodyKey )
m_bModified |= CHECK_KEY;
}
if( iCheckType & CHECK_BAR ){
if( m_nBarCount!=g_lstMelodyBars.size() ){
m_bModified |= CHECK_BAR;
}
}
if( !(m_bModified & CHECK_BAR) && ((iCheckType & CHECK_CHORD)||(iCheckType & CHECK_FILL) )){
for( int i=0; i<m_nBarCount; i++ ){
MELODYBAR *pMBar = g_lstMelodyBars[i];
if( !(m_bModified & CHECK_CHORD) && (iCheckType & CHECK_CHORD) ){
if( m_aChords[i][0]!=pMBar->iChords[0] || m_aChords[i][1]!=pMBar->iChords[1] ){
m_bModified |= CHECK_CHORD;
}
}
if( !(m_bModified & CHECK_FILL ) && (iCheckType & CHECK_FILL ) ){
if( m_aFills[i]!=pMBar->iFill ){
m_bModified |= CHECK_FILL;
}
}
}
}
if( iCheckType & CHECK_STAGE ){
if( m_nStageCount!=g_lstMelodyStages.size() ){
m_bModified |= CHECK_STAGE;
}
}
if( !(m_bModified & CHECK_STAGE) && ((iCheckType & CHECK_POS)||(iCheckType & CHECK_VAR))){
for( int i=0; i<m_nStageCount; i++ ){
MELODYSTAGE* pStage = g_lstMelodyStages[i];
if( !(m_bModified & CHECK_POS) && (iCheckType & CHECK_POS) ){
if( m_aStages[i][0]!=pStage->iFirstBar || m_aStages[i][1]!=pStage->iLastBar ){
m_bModified |= CHECK_POS;
}
}
if( !(m_bModified & CHECK_VAR) && (iCheckType & CHECK_VAR ) ){
if( m_aStages[i][2]!=pStage->iVar ){
m_bModified |= CHECK_VAR;
}
}
}
}
return m_bModified;
}
TComposeBackup::TComposeBackup()
{
m_nStageCount = 0;
m_bModified = false;
m_iKey = -1;
}
TComposeBackup::~TComposeBackup()
{
Clear();
}
void TComposeBackup::Backup( int iKey )
{
Clear();
m_iKey = iKey;
m_nStageCount = g_lstComposeStages.size();
for( int i=0; i<m_nStageCount; i++ ){
COMPOSESTAGE *pNewStage = new COMPOSESTAGE;
COMPOSESTAGE *pBkStage = g_lstComposeStages[i];
pNewStage->iMelodyStage = pBkStage->iMelodyStage;
pNewStage->nStageBars = pBkStage->nStageBars;
pNewStage->iVar = pBkStage->iVar;
pNewStage->idStyle = pBkStage->idStyle;
pNewStage->strStyleName = pBkStage->strStyleName;
for( int j=0; j<pBkStage->aFills.size(); j++ ){
pNewStage->aFills.push_back(pBkStage->aFills[j]);
}
m_lstStages.push_back( pNewStage );
}
m_bModified = false;
}
void TComposeBackup::Restore()
{
if( m_nStageCount!=g_lstComposeStages.size() ){
ClearGlobalVars( LIST_COMPOSESTAGES );
for( int i=0; i<m_nStageCount; i++ ){
COMPOSESTAGE *pNewStage = new COMPOSESTAGE;
COMPOSESTAGE *pBkStage = m_lstStages[i];
pNewStage->iMelodyStage = pBkStage->iMelodyStage;
pNewStage->nStageBars = pBkStage->nStageBars;
pNewStage->iVar = pBkStage->iVar;
pNewStage->idStyle = pBkStage->idStyle;
pNewStage->strStyleName = pBkStage->strStyleName;
for( int j=0; j<pBkStage->aFills.size(); j++ ){
pNewStage->aFills.push_back(pBkStage->aFills[j]);
}
g_lstComposeStages.push_back( pNewStage );
}
}
else{
for( int i=0; i<m_nStageCount; i++ ){
COMPOSESTAGE *pCStage = g_lstComposeStages[i];
COMPOSESTAGE *pBkStage = m_lstStages[i];
pCStage->iMelodyStage = pBkStage->iMelodyStage;
pCStage->nStageBars = pBkStage->nStageBars;
pCStage->iVar = pBkStage->iVar;
pCStage->idStyle = pBkStage->idStyle;
pCStage->aFills.clear();
for( int j=0; j<pBkStage->aFills.size(); j++ ){
pCStage->aFills.push_back(pBkStage->aFills[j]);
}
}
}
m_bModified = false;
}
BOOL TComposeBackup::CheckModified( int iCheckType )
{
if( iCheckType==CHECK_GET ){
return m_bModified;
}
m_bModified &= ~iCheckType;
if( iCheckType & CHECK_STAGE ){
if( m_nStageCount!=g_lstComposeStages.size() ){
m_bModified |= CHECK_STAGE;
}
}
if( !(m_bModified & CHECK_STAGE) && (iCheckType & CHECK_STAGE || iCheckType & CHECK_POS ||
iCheckType & CHECK_VAR || iCheckType & CHECK_FILL ||
iCheckType & CHECK_STYLE ) ){
for( int i=0; i<m_nStageCount; i++ ){
COMPOSESTAGE* pCpStage = g_lstComposeStages[i];
COMPOSESTAGE* pBkStage = m_lstStages[i];
if( !(m_bModified & CHECK_POS) && (iCheckType & CHECK_POS) ){
if( pCpStage->iMelodyStage!=pBkStage->iMelodyStage ||
pCpStage->nStageBars!=pBkStage->nStageBars ){
m_bModified |= CHECK_POS;
}
}
if( !(m_bModified & CHECK_VAR) && (iCheckType & CHECK_VAR) ){
if( pCpStage->iVar!=pBkStage->iVar ){
m_bModified |= CHECK_VAR;
}
}
if( !(m_bModified & CHECK_STYLE) && (iCheckType & CHECK_STYLE) ){
if( pCpStage->idStyle!=pBkStage->idStyle ){
m_bModified |= CHECK_STYLE;
}
}
if( !(m_bModified & CHECK_FILL) && (iCheckType & CHECK_FILL) ){
if( pCpStage->aFills.size()!=pBkStage->aFills.size() ){
m_bModified |= CHECK_FILL;
}
else{
for( int j=0; j<pBkStage->aFills.size(); j++ ){
if( pCpStage->aFills[j]!=pBkStage->aFills[j] ){
m_bModified |= CHECK_FILL;
break;
}
}
}
}
}
}
return m_bModified;
}
void TComposeBackup::Clear()
{
m_iKey = -1;
for( int i=0; i<m_nStageCount; i++ ){
delete m_lstStages[i];
}
m_lstStages.clear();
m_nStageCount = 0;
}
TMelodyBackup g_bkMelody;
TComposeBackup g_bkCompose;
+62
View File
@@ -0,0 +1,62 @@
//---------------------------------------------------------------------------
#ifndef BackupUnitH
#define BackupUnitH
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#define CHECK_GET 0x0000
#define CHECK_KEY 0x0001
#define CHECK_BAR 0x0002
#define CHECK_CHORD 0x0004
#define CHECK_FILL 0x0008
#define CHECK_STAGE 0x0010
#define CHECK_POS 0x0020
#define CHECK_VAR 0x0040
#define CHECK_STYLE 0X0080
#define CHECK_ALL 0x00FF
class TMelodyBackup
{
private:
BOOL m_bModified;
int m_iKey;
int m_nBarCount;
int m_nStageCount;
int (*m_aChords)[2];
int *m_aFills;
int (*m_aStages)[3];
public:
TMelodyBackup();
~TMelodyBackup();
void Backup();
void Restore();
void Clear();
BOOL CheckModified( int iCheckType=CHECK_ALL );
};
class TComposeBackup
{
private:
BOOL m_bModified;
int m_nStageCount;
COMPOSESTAGELIST m_lstStages;
public:
TComposeBackup();
~TComposeBackup();
int m_iKey;
void Clear();
void Backup( int iKey );
void Restore();
BOOL CheckModified( int iCheckType=CHECK_ALL );
};
extern TMelodyBackup g_bkMelody;
extern TComposeBackup g_bkCompose;
#endif
+1473
View File
File diff suppressed because it is too large Load Diff
+8679
View File
File diff suppressed because it is too large Load Diff
+198
View File
@@ -0,0 +1,198 @@
//---------------------------------------------------------------------------
#ifndef BaseFormUnitH
#define BaseFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include <Vcl.StdCtrls.hpp>
#include "PNGButton.hpp"
#include "CommonListboxUnit.h"
#include "BasePanelUnit.h"
#include <Vcl.Imaging.pngimage.hpp>
#include <Vcl.Graphics.hpp>
#include "PopMenuUnit.h"
#include "BackgroundForm.h"
//---------------------------------------------------------------------------
class TBaseForm : public TBackgroundForm
{
__published: // IDE-managed Components
// TImage *m_imgBk;
// TImage *m_imgLeftBottomConner;
// TImage *m_imgBottomSide;
// TImage *m_imgRightSide;
// TImage *m_imgRightBottomConner;
TImage *m_imgBreakH;
TImage *m_imgBreakI;
TImage *m_imgBreakM;
TImage *m_imgBreakR;
TPNGButton *m_btnRecord;
TPNGButton *m_btnStop;
TPNGButton *m_btnPlay;
TPNGButton *m_btnPause;
TPNGButton *m_btnApart;
TPNGButton *m_btnCombine;
TPNGButton *m_btnPrevStep;
TPNGButton *m_btnNextStep;
BasePanelUnit::TPanel *m_panelBarsShow;
TPNGButton *m_btnVolAudioSet;
TPNGButton *m_btnVolMusicSet;
Vcl::Extctrls::TPanel *m_panelMusicInfo;
TImage *m_imgMusicInfoBk;
TLabel *m_lblPlayTime;
TLabel *m_lblBeat;
TLabel *m_lblTempo;
TLabel *m_lblKey;
TPNGButton *m_btnKeyChange;
CommonListBoxUnit::TListBox *m_lbKeySelect;
Vcl::Extctrls::TPanel *m_panelMusicVolSet;
TImage *m_imgMusicVolSet;
TPNGButton *m_btnMusicVolPos;
Vcl::Extctrls::TPanel *m_panelAudioVolSet;
TImage *m_imgAudioVolSet;
TPNGButton *m_btnAudioVolPos;
TPNGButton *m_btnStyleChange;
Vcl::Extctrls::TPanel *m_panelStyleName;
TImage *m_imgStyleNameBk;
TLabel *m_lblStyleName;
TPNGButton *m_btnMainKey1;
TPNGButton *m_btnMainKey0;
TPNGButton *m_btnMainKey2;
TPNGButton *m_btnMainKey3;
TPNGButton *m_btnMainKey4;
TPNGButton *m_btnMainKey5;
TPNGButton *m_btnMainKey6;
TPNGButton *m_btnAjustKey0;
TPNGButton *m_btnAjustKey1;
TPNGButton *m_btnChordType0;
TPNGButton *m_btnChordType1;
TPNGButton *m_btnChordType2;
TPNGButton *m_btnAudioEffect;
TPNGButton *m_btnMicSet;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall FormActivate(TObject *Sender);
void __fastcall StepClick(TObject *Sender);
void __fastcall PlayClick(TObject *Sender);
void __fastcall StopClick(TObject *Sender);
void __fastcall PauseClick(TObject *Sender);
void __fastcall PlayTimeClick(TObject *Sender);
void __fastcall BtnKeyChangeClick(TObject *Sender);
void __fastcall LBKeySelectMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BtnVolSetClick(TObject *Sender);
void __fastcall ImgVolSetMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BtnVolPosMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BtnVolPosMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
void __fastcall BtnVolPosMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall ApartClick(TObject *Sender);
void __fastcall CombineClick(TObject *Sender);
void __fastcall BarsShowMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BarsShowMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
void __fastcall BtnMainKeyClick(TObject *Sender);
void __fastcall BtnAjustKeyClick(TObject *Sender);
void __fastcall BtnChordTypeClick(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall BtnStyleChangeClick(TObject *Sender);
void __fastcall FormDeactivate(TObject *Sender);
void __fastcall AudioEffectClick(TObject *Sender);
void __fastcall MicSetClick(TObject *Sender);
private: // User declarations
//音量相关
int m_nAudioVolPos,
m_nMusicVolPos,
m_yPosDragBegin;
bool m_bPosDraging;
//录音/播放相关
int m_iStartBar,
m_iLastStartBar;
double m_dblStartPoint,
m_dblLastStartPoint;
UINT m_tTimer, m_tAccuracy, m_tMusicLen;
//和弦相关
bool m_bCanErase;
TPNGButton* m_lstMainKeys[7];
// TPNGButton* m_lstDefaultMainKeys[7];
TPNGButton* m_lstAjustKeys[2];
TPNGButton* m_lstChordTypes[3];
DWORD m_dwOriginChord;
TPngImage *m_aImagKeyLM[7],
*m_aImagKeyEG[7];
//菜单操作相关
TPopMenu * m_pPopMenu;
int m_iPopBar, m_iPopPoint;
// void AutoCompose();
// bool BaseCompose();
void ShowPlayTime();
void EnableChordModify( bool bEnable, int iMainKey, int iAjustKey, int iChordType );
int GetMainKey();
int GetAjustKey();
int GetChordType();
void HidePopList(CommonListBoxUnit::TListBox* pList);
int HidePopControls();
void BarsLButtonDown( int iHitType, int iHitBar, int iHitPoint );
void BarsRButtonDown( int iHitType, int iHitBar, int iHitPoint, int X, int Y );
void GetSelectKey( int& iMain, int& iAdjust );
void SetSelectKey( int iMain, int iAdjust );
void SetChordType( int iType );
void __fastcall OnSelectStageVar( TObject* Sender );
void __fastcall OnSelectBarFill( TObject* Sender );
void __fastcall OnDeleteChord( TObject* Sender );
void __fastcall OnChangeChordMode( TObject* Sender=NULL );
MESSAGE void __fastcall UMMediaTime(TMessage &Message);
// MESSAGE void __fastcall UMEnableReload(TMessage &Message);
MESSAGE void __fastcall UMSelectStyle(TMessage &msg);
MESSAGE void __fastcall UMReload(TMessage &msg);
MESSAGE void __fastcall UMSetFontPosition(TMessage &msg);
MESSAGE void __fastcall UMHidePopControl(TMessage &msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(MSG_MEDIATIME, TMessage, UMMediaTime)
// MESSAGE_HANDLER(UM_ENABLERELOAD, TMessage, UMEnableReload)
MESSAGE_HANDLER(UM_SELECTSTYLE, TMessage, UMSelectStyle)
MESSAGE_HANDLER(UM_RELOAD, TMessage, UMReload)
MESSAGE_HANDLER(UM_SETFONTPOSITION, TMessage, UMSetFontPosition)
MESSAGE_HANDLER(UM_HIDEPOPCONTROL, TMessage, UMHidePopControl)
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TBaseForm(TComponent* Owner);
void __fastcall ChangeChordMode( bool bAlpha );
};
//---------------------------------------------------------------------------
extern PACKAGE TBaseForm *BaseForm;
//---------------------------------------------------------------------------
#endif
+983
View File
@@ -0,0 +1,983 @@
//---------------------------------------------------------------------------
#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)
{
}
//---------------------------------------------------------------------------
*/
+77
View File
@@ -0,0 +1,77 @@
//---------------------------------------------------------------------------
#ifndef BasePanelUnitH
#define BasePanelUnitH
#include "ShowBarsPanelUnit.h"
//#include "BackupUnit.h"
namespace BasePanelUnit
{
//---------------------------------------------------------------------------
class TPanel : public TShowBarsPanel
{
__published:
void __fastcall StageHeaderMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall StageHeaderMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
void __fastcall StageHeaderMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
private:
TComponentList * m_lstStageHeader;
int m_nChordWidth,
m_nChordHeight,
m_iFocusCell,
m_iPreApartBar,
m_iPreDeleteStage,
m_iDragStage,
m_xDragStart;
bool m_bStageHeaderDraging;
TImage * NewStageHeader( int iStage );
void UpdateStageHeader( int iStage );
void DrawFocusedCell( TRect& rectFocus );
void AddStageHeader( int iStage, int iShowBar, int iVar );
void RemoveStageHeader( int iVar );
protected:
virtual void __fastcall CreateWnd();
virtual void __fastcall BarPosChanged();
virtual void __fastcall SetBarTitle( int iBar, String& strText );
virtual void __fastcall DrawBarBkgnd( int iBar, int leftDraw, int topDraw );
virtual void __fastcall DrawBarContext( int iBar, int leftDraw, int topDraw );
virtual void __fastcall DrawBarOperation( int iBar, int leftDraw, int topDraw );
// DYNAMIC void __fastcall KeyDown(System::Word &Key, System::Classes::TShiftState Shift);
public:
__fastcall virtual TPanel(System::Classes::TComponent* AOwner);
__fastcall ~TPanel();
void InitialVars();
int GetBarNum(){ return m_nBarNum; };
// BOOL CheckModify( int iCheckType=CHECK_ALL );
// void BackupModify();
// void SetMelodyKey( int iKey );
void SetBarFill( int iBar, int iFill );
int FindStage( int iBar );
void SetStageVar( int iStage, int iVar );
bool SetFocusCell( int iBar, bool bSecond=false );
int GetFocusChord( int& iMainKey, int& iAjustKey, int& iChordType );
bool SetFocusChord( int iMainKey, int iAjustKey, int iChordType );
bool HasChordSet();
void DeleteAllChord();
bool SetApartPos( int iBar, int iPoint, bool bPre=false );
bool SetCombinePos( int iBar, int iPoint, bool bPre=false );
};
}
using namespace BasePanelUnit;
#endif
+527
View File
@@ -0,0 +1,527 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "BtnPanelUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
VCTBtnPanel::iterator vc_pFindVCTBtnPanel;
//---------------------------------------------------------------------------
__fastcall TBtnPanel::TBtnPanel(TWinControl *pTWnCtl)
: TComponent(pTWnCtl)
{
m_pTWnCtl = pTWnCtl;
m_pAppEvents = new TApplicationEvents(this);
m_pAppEvents->OnMessage = OnAppEvents;
m_bPalEn = false;
m_bPalLD = false;
m_bPalRD = false;
m_bBtnEn = m_bBtnLD = m_bBtnRD = false;
m_pParentBtn = NULL;
FLeft = FTop = FWidth = FHeight = 0;
FEnabled = true;
FDown = false;
FStateEnter = true;
FStateCount = 3;
FBtnCurState = Bs_NORMAL;
FTransparent = false;
FTransparentValue = 255;
m_BtnCurStateBac = Bs_NORMAL;
}
//---------------------------------------------------------------------------
__fastcall TBtnPanel::~TBtnPanel()
{
SAFE_DELETE(m_pAppEvents)
}
//---------------------------------------------------------------------------
bool __fastcall TBtnPanel::IsPtInSubtn(int XPos, int YPos)
{
for(vc_pFindVCTBtnPanel =m_VCSubtn.begin();
vc_pFindVCTBtnPanel!=m_VCSubtn.end();
vc_pFindVCTBtnPanel++ )
{
TRect TRectTmpSubView
= TRect((*vc_pFindVCTBtnPanel)->Left, (*vc_pFindVCTBtnPanel)->Top,
(*vc_pFindVCTBtnPanel)->Left+(*vc_pFindVCTBtnPanel)->Width,
(*vc_pFindVCTBtnPanel)->Top+(*vc_pFindVCTBtnPanel)->Height);
if( PtInRect(TRectTmpSubView, TPoint(XPos, YPos) ) ) {
return true;
}
}
return false;
}
//---------------------------------------------------------------------------
bool __fastcall TBtnPanel::IsBtnHandleAppEvent(unsigned int message, int XPos, int YPos)
{
if( IsPtInSubtn(XPos, YPos) ) {
if( Bs_NORMAL==FBtnCurState )
return false;
}
return true;
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::OnAppEvents(tagMSG &Msg, bool &Handled)
{
// -----
if( false == FEnabled ||
false == m_pTWnCtl->Enabled ||
(false == m_bPalEn &&
Msg.hwnd != m_pTWnCtl->Handle) )
return;
if( WM_LBUTTONDOWN == Msg.message ||
WM_LBUTTONUP == Msg.message ||
WM_LBUTTONDBLCLK == Msg.message ||
WM_RBUTTONDOWN == Msg.message ||
WM_RBUTTONUP == Msg.message ||
WM_MOUSEMOVE == Msg.message )
{
}else return;
// -----
TRect rtSelf = TRect(Left, Top, Left+Width, Top+Height);
TPoint pt = m_pTWnCtl->ScreenToClient(TPoint(Msg.pt.x, Msg.pt.y));
TWMMouse Message;
Message.Msg = Msg.message;
Message.XPos = pt.x;
Message.YPos = pt.y;
if( false==IsBtnHandleAppEvent(Message.Msg, Message.XPos, Message.YPos) ) return;
// -----
MsState MsStatus = Ms_NONE;
//刚离开区域
if( m_bPalEn && !PtInRect( rtSelf, pt ) ) {
if( WM_MOUSEMOVE != Msg.message ) {
return;
}else if( WM_MOUSEMOVE==Msg.message ) {
m_bPalEn = false;
MsStatus = Ms_LEAVE;
BtnHandleAppEvent(MsStatus, Message.XPos, Message.YPos);
return;
}
//已经离开了区域
} else if(!m_bPalEn && !PtInRect( rtSelf, pt ) ) {
if( m_bPalLD ) { //处理拖动事件
MsStatus = Ms_DRAG;
BtnHandleAppEvent(MsStatus, Message.XPos, Message.YPos);
}
//除了 WM_LBUTTONUP WM_RBUTTONUP 都不再处理
if((WM_LBUTTONUP != Msg.message && WM_RBUTTONUP != Msg.message) ||
(false==m_bPalLD && WM_LBUTTONUP == Msg.message ) || //没有按下键 不再处理
(false==m_bPalRD && WM_RBUTTONUP == Msg.message ) )
return;
}
// -----
switch( Msg.message )
{
case WM_LBUTTONDOWN:
{
MsStatus = Ms_LDOWN;
m_bPalLD = true;
} break;
case WM_LBUTTONUP:
{
if( m_bPalLD ) {
MsStatus = Ms_LUP;
m_bPalLD = false;
}
} break;
case WM_LBUTTONDBLCLK:
{
MsStatus = Ms_LLDOWN;
} break;
case WM_RBUTTONDOWN:
{
MsStatus = Ms_RDOWN;
m_bPalRD = true;
} break;
case WM_RBUTTONUP:
{
if(m_bPalRD) {
MsStatus = Ms_RUP;
m_bPalRD = false;
}
} break;
case WM_MOUSEMOVE:
{
if( m_bPalEn )
{
if(m_bPalLD)
MsStatus = Ms_DRAG;
else
MsStatus = Ms_MOVE;
}else MsStatus = Ms_ENTER;
m_bPalEn = true;
} break;
default: break;
}
if(Ms_NONE!=MsStatus ) BtnHandleAppEvent(MsStatus, Message.XPos, Message.YPos);
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::BtnHandleAppEvent(MsState MsSrcTmp, int XPos, int YPos)
{
MsState MsTmp = Ms_NONE;
BtnState BsTmp = Bs_NONE;
switch( MsSrcTmp )
{
case Ms_LDOWN:
{
m_bBtnLD = true;
BsTmp = Bs_DOWN;
FBtnCurState = BsTmp;
MsTmp = Ms_LDOWN;
} break;
case Ms_LLDOWN:
{
MsTmp = Ms_LLDOWN;
} break;
case Ms_LUP:
{
m_bBtnLD = false;
if( PtInRect( TRect(Left, Top, Left+Width, Top+Height),
TPoint(XPos, YPos) ) )
BsTmp = Bs_ENTER;
else
BsTmp = Bs_NORMAL;
FBtnCurState = BsTmp;
MsTmp = Ms_LUP;
} break;
case Ms_RDOWN:
{
MsTmp = Ms_RDOWN;
} break;
case Ms_RUP:
{
MsTmp = Ms_RUP;
} break;
case Ms_ENTER:
{
if( true!=m_bBtnLD ) {
m_bBtnEn = true;
BsTmp = Bs_ENTER;
FBtnCurState = BsTmp;
MsTmp = Ms_ENTER;
}
} break;
case Ms_LEAVE:
{
if( true!=m_bBtnLD ) {
m_bBtnEn = false;
BsTmp = Bs_NORMAL;
FBtnCurState = BsTmp;
MsTmp = Ms_LEAVE;
}
} break;
case Ms_MOVE:
{
if( m_bBtnEn ) {
bool bIsPtInSubtn = IsPtInSubtn(XPos, YPos);
if( bIsPtInSubtn ) {
m_bBtnEn = false;
BsTmp = Bs_NORMAL;
FBtnCurState = BsTmp;
MsTmp = Ms_LEAVE;
}else {
MsTmp = Ms_MOVE;
}
}else{
m_bBtnEn = true;
BsTmp = Bs_ENTER;
FBtnCurState = BsTmp;
MsTmp = Ms_ENTER;
}
} break;
case Ms_DRAG:
{
MsTmp = Ms_DRAG;
} break;
default: break;
}
if( Ms_NONE != MsTmp ) BtnMsEvent(MsTmp, XPos, YPos);
if( Bs_NONE != BsTmp ) BtnDrEvent(FBtnCurState, XPos, YPos);
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::BtnHandleState()
{
BtnState BtnStateTmp = this->FBtnCurState;
if( false==m_pTWnCtl->Enabled ||
false==FEnabled ) {
BtnStateTmp = Bs_DISABLE;
}else {
if( false==FStateEnter && Bs_ENTER==this->FBtnCurState )
BtnStateTmp = Bs_NORMAL;
if( FDown ) BtnStateTmp = Bs_DOWN;
if( FStateCount<=BtnStateTmp ) BtnStateTmp = FStateCount-1;
}
m_BtnCurStateBac = FBtnCurState = BtnStateTmp;
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::BtnDrEvent(BtnState BsTmp, int XPos, int YPos)
{
if( Bs_DOWN == BsTmp ||
Bs_ENTER == BsTmp ||
Bs_NORMAL == BsTmp )
{
int BtnCurStateBac = m_BtnCurStateBac;
BtnHandleState();
if( BtnCurStateBac==m_BtnCurStateBac ) return;
Paint();
}
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::BtnMsEvent(MsState MsTmp, int XPos, int YPos)
{
if( Ms_LDOWN == MsTmp ||
Ms_LUP == MsTmp ||
Ms_LLDOWN == MsTmp ||
Ms_RDOWN == MsTmp ||
Ms_RUP == MsTmp ||
Ms_ENTER == MsTmp ||
Ms_LEAVE == MsTmp ||
Ms_MOVE == MsTmp ||
Ms_DRAG == MsTmp )
{
if( OnPanelMsEvent ) OnPanelMsEvent(MsTmp, XPos, YPos);
}
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::AddSubPanel(TBtnPanel *pTBtnPanel)
{
m_VCSubtn.push_back(pTBtnPanel);
pTBtnPanel->m_pParentBtn = this;
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::SetBounds(int nLeft, int nTop, int nWidth, int nHeight)
{
FLeft = nLeft;
FTop = nTop;
FWidth = nWidth;
FHeight = nHeight;
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::PaintParent(TCanvas *CanvasDrawCus)
{
if( this->m_pParentBtn ) {
this->m_pParentBtn->Paint(CanvasDrawCus, false);
}
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::PaintSub(TCanvas *CanvasParent)
{
if( m_VCSubtn.size() ) {
for(vc_pFindVCTBtnPanel =m_VCSubtn.begin();
vc_pFindVCTBtnPanel!=m_VCSubtn.end();
vc_pFindVCTBtnPanel++ )
{
((TBtnPanel *)(*vc_pFindVCTBtnPanel))->Paint(CanvasParent, false);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::Paint(TCanvas *Canvas, bool bParent)
{
TCanvas *CanvasDraw = Canvas;
TRect rtThis = TRect(this->Left, this->Top,
this->Left+this->Width,
this->Top +this->Height);
TRect rtCreate = TRect(this->m_pTWnCtl->Left, this->m_pTWnCtl->Top,
this->m_pTWnCtl->Left+this->m_pTWnCtl->Width,
this->m_pTWnCtl->Top +this->m_pTWnCtl->Height);
//自身创建
HDC ParentDC = GetDC(this->m_pTWnCtl->Handle);
HDC DCCreate;
HBITMAP BmpCreate;
TCanvas *CanvasCreate;
if( NULL==Canvas ) {
DCCreate = CreateCompatibleDC(ParentDC);
BmpCreate = CreateCompatibleBitmap(ParentDC,
rtCreate.Width(),
rtCreate.Height());
SelectObject(DCCreate, BmpCreate);
PerformEraseBackground(this->m_pTWnCtl, DCCreate);
CanvasCreate = new TCanvas();
CanvasCreate->Handle = DCCreate;
CanvasDraw = CanvasCreate;
if( FTransparent ) {
SetBkMode( CanvasDraw->Handle, TRANSPARENT);
StyleServices()->DrawParentBackground(
this->m_pTWnCtl->Handle,
CanvasDraw->Handle,
NULL, false, rtThis);
}
}
//绘制
if( FPanelDrEvent )
{
BtnHandleState();
//新建绘制
TCanvas *CanvasCusDraw = new TCanvas();
HDC DCCusDraw;
HBITMAP BmpCusDraw;
DCCusDraw = CreateCompatibleDC(ParentDC);
BmpCusDraw = CreateCompatibleBitmap(ParentDC, rtCreate.Width(),
rtCreate.Height());
SelectObject(DCCusDraw, BmpCusDraw);
PerformEraseBackground(this->m_pTWnCtl, DCCusDraw);
CanvasCusDraw->Handle = DCCusDraw;
if( FTransparent ) {
SetBkMode( CanvasCusDraw->Handle, TRANSPARENT);
StyleServices()->DrawParentBackground(
this->m_pTWnCtl->Handle,
CanvasCusDraw->Handle,
NULL, false, rtThis);
//parent贴图到自身区域
if( this->m_pParentBtn ) {
if( true==bParent ) {
if( NULL==Canvas ) PaintParent(CanvasDraw);
}
StretchBlt(CanvasCusDraw->Handle,
rtThis.Left, rtThis.Top,
rtThis.Width(), rtThis.Height(),
CanvasDraw->Handle,
rtThis.Left, rtThis.Top,
rtThis.Width(), rtThis.Height(),
SRCCOPY);
}
}
FPanelDrEvent(FBtnCurState, rtThis, CanvasCusDraw);
if( FTransparent ) {
BLENDFUNCTION BFun;
BFun.BlendOp = AC_SRC_OVER;
BFun.BlendFlags = 0;
BFun.SourceConstantAlpha = FTransparentValue;
BFun.AlphaFormat = 0;
::AlphaBlend( CanvasDraw->Handle,
rtThis.Left, rtThis.Top,
rtThis.Width(), rtThis.Height(),
CanvasCusDraw->Handle,
rtThis.Left, rtThis.Top,
rtThis.Width(), rtThis.Height(),
BFun);
}else{
StretchBlt(CanvasDraw->Handle,
rtThis.Left, rtThis.Top,
rtThis.Width(), rtThis.Height(),
CanvasCusDraw->Handle,
rtThis.Left, rtThis.Top,
rtThis.Width(), rtThis.Height(),
SRCCOPY);
}
if( true==bParent )
PaintSub(CanvasDraw);
DeleteDC(DCCusDraw);
DeleteObject(BmpCusDraw);
SAFE_DELETE(CanvasCusDraw)
}
if( NULL==Canvas ) {
StretchBlt(ParentDC,
this->Left, this->Top,
this->Width, this->Height,
CanvasDraw->Handle,
this->Left, this->Top,
this->Width, this->Height,
SRCCOPY);
DeleteDC(DCCreate);
DeleteObject(BmpCreate);
SAFE_DELETE(CanvasCreate)
}
}
//---------------------------------------------------------------------------
void __fastcall TBtnPanel::Update(bool bEreaseBkg)
{
if( m_pParentBtn && bEreaseBkg ) {
((TBtnPanel *)m_pParentBtn)->Update(bEreaseBkg);
}else {
Paint();
}
}
//---------------------------------------------------------------------------
+126
View File
@@ -0,0 +1,126 @@
//---------------------------------------------------------------------------
#ifndef BtnPanelUnitH
#define BtnPanelUnitH
//---------------------------------------------------------------------------
#include <Vcl.AppEvnts.hpp>
//---------------------------------------------------------------------------
#include <vector>
using namespace std;
//---------------------------------------------------------------------------
#ifndef SAFE_DELETE(p)
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#endif
//---------------------------------------------------------------------------
typedef enum{
Bs_NORMAL=0,
Bs_ENTER,
Bs_DOWN,
Bs_DISABLE,
Bs_NONE
}BtnState;
typedef enum{
Ms_LDOWN=0,
Ms_LUP,
Ms_LLDOWN,
Ms_RDOWN,
Ms_RUP,
Ms_ENTER,
Ms_LEAVE,
Ms_MOVE,
Ms_DRAG,
Ms_NONE
}MsState;
//---------------------------------------------------------------------------
class TBtnPanel;
typedef vector<TBtnPanel *> VCTBtnPanel;
extern VCTBtnPanel::iterator vc_pFindVCTBtnPanel;
//---------------------------------------------------------------------------
typedef void __fastcall (__closure *PanelMsEvent)(int MsTmp, int XPos, int YPos);
typedef void __fastcall (__closure *PanelDrEvent)(int BsTmp, TRect TRectTmp, TCanvas *pCanvas);
//---------------------------------------------------------------------------
class TBtnPanel: public TComponent
{
private:
TApplicationEvents *m_pAppEvents;
bool m_bPalEn, m_bPalLD, m_bPalRD;
void __fastcall OnAppEvents(tagMSG &Msg, bool &Handled);
TBtnPanel *m_pParentBtn;
VCTBtnPanel m_VCSubtn;
bool m_bBtnEn, m_bBtnLD, m_bBtnRD;
int m_BtnCurStateBac;
bool __fastcall IsBtnHandleAppEvent(unsigned int message, int XPos, int YPos);
bool __fastcall IsPtInSubtn(int XPos, int YPos);
void __fastcall BtnHandleAppEvent(MsState MsSrcTmp, int XPos, int YPos);
void __fastcall BtnHandleState();
void __fastcall BtnMsEvent(MsState MsTmp, int XPos, int YPos);
void __fastcall BtnDrEvent(BtnState BsTmp, int XPos, int YPos);
void __fastcall PaintParent(TCanvas *CanvasDrawCus);
void __fastcall PaintSub(TCanvas *CanvasDraw);
// -----
int FLeft, FTop, FWidth, FHeight;
bool FEnabled;
bool FDown;
bool FStateEnter;
int FStateCount;
int FBtnCurState;
bool FTransparent;
BYTE FTransparentValue;
PanelMsEvent FPanelMsEvent;
PanelDrEvent FPanelDrEvent;
public:
TWinControl *m_pTWnCtl;
void __fastcall SetBounds(int nLeft, int nTop, int nWidth, int nHeight);
void __fastcall AddSubPanel(TBtnPanel *pTBtnPanel);
void __fastcall Update(bool bEreaseBkg=true);
void __fastcall Paint(TCanvas *Canvas=NULL, bool bParent=true);
__fastcall TBtnPanel(TWinControl *pTWnCtl);
__fastcall ~TBtnPanel();
__published:
__property int Left = { read=FLeft, write=FLeft, default=0 };
__property int Top = { read=FTop, write=FTop, default=0 };
__property int Width = { read=FWidth, write=FWidth, default=0 };
__property int Height = { read=FHeight, write=FHeight, default=0 };
__property bool StateEnter = { read=FStateEnter, write=FStateEnter, default=true };
__property bool Enabled = { read=FEnabled, write=FEnabled, default=true };
__property bool Down = { read=FDown, write=FDown, default=false };
__property int BtnCurState = { read=FBtnCurState,write=FBtnCurState,default=Bs_NORMAL};
__property int StateCount = { read=FStateCount, write=FStateCount, default=3 };
__property bool Transparent = { read=FTransparent, write=FTransparent, default=false };
__property BYTE TransparentValue = { read=FTransparentValue, write=FTransparentValue, default=255 };
__property PanelMsEvent OnPanelMsEvent = { read=FPanelMsEvent , write=FPanelMsEvent };
__property PanelDrEvent OnPanelDrEvent = { read=FPanelDrEvent , write=FPanelDrEvent };
};
//---------------------------------------------------------------------------
#endif
/******************************************
******************READ ME******************
*******************************************
@ 先触发鼠标事件,在触发绘制事件
@ 事件坐标体系是绝对坐标;
@ 绘制坐标体系是相对坐标;
@ 自身重绘,子view相应重绘;
@ 自身rect发生变化,父view相应重绘;
@ 只画png需要设置trans
@ StateCount-->BtnState;
@ Ms_LLDOWN-->event no paint;
*******************************************
*******************************************
*******************************************/
+963
View File
@@ -0,0 +1,963 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <Vcl.Imaging.pngimage.hpp>
#include "CDSkinScrollBarUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//add by tj 2013/11/21
#define PIXEL_EXTERNAL_FRAME 1
#define PIXEL_EX2INTERNAL 1
#define PIXEL_INTERNAL_FARME 1
#define PIXEL_INTERNAL_BOUND 1
#define PIXEL_INTERNAL_LINE 6 //add by tj 2013/12/10
static const COLORREF
RGB_EXTERNAL_FRAME = RGB(29,31,35),
RGB_EXTERNAL_NOR = RGB(60,66,72),
RGB_EXTERNAL_HIG = RGB(74,80,88),
RGB_INTERNAL_NOR = RGB(39,42,47), //272a2f
RGB_INTERNAL_HIG = RGB(74,80,88), //4a5058
RGB_INTERNAL_PUSH = RGB(50,54,60), //32363c
RGB_INTERNAL_LINE_NOR = RGB(25,27,30), //191b1e
RGB_INTERNAL_LINE_HIG = RGB(58,63,69), //3a3f45
RGB_INTERNAL_LINE_PUSH = RGB(38,41,45), //26292d
RGB_INTERNAL_LINE_NOR_TRANS[6] ={ RGB(44,47,53), //2c2f35
RGB(47,51,57),
RGB(52,55,62),
RGB(56,59,67),
RGB(57,59,69),
RGB(59,61,71)
},
RGB_INTERNAL_LINE_HIG_TRANS[6] ={ RGB(79,86,94),//4f565e
RGB(83,90,99),
RGB(87,94,104),
RGB(91,99,109),
RGB(92,100,111),
RGB(94,104,115),
},
RGB_INTERNAL_LINE_PUSH_TRANS[6] ={ RGB(55,59,66), //373b42
RGB(60,65,72),
RGB(64,69,77),
RGB(69,75,83),
RGB(70,77,86),
RGB(72,79,88)
},
RGB_INTERNAL_FRAME_NOR = RGB(34,36,41),
RGB_INTERNAL_ROUND_BKG_N_NOR = RGB(41,44,49),
RGB_INTERNAL_ROUND_BKG_N_HIG = RGB(51,55,61),
RGB_INTERNAL_ROUND_BKG_H_NOR = RGB(43,46,52),
RGB_INTERNAL_ROUND_BKG_H_HIG = RGB(56,61,67);
//---------------------------------------------------------------------------
static TBitmap *u_pPicLineUp = NULL,
*u_pPicLineDown = NULL;
static int u_nPicRef = 0;
static void InitialPictures()
{
if( u_nPicRef==0 ){
u_pPicLineUp = new TBitmap();
u_pPicLineUp->LoadFromResourceName(int(HInstance), L"line_up");
u_pPicLineDown = new TBitmap();
u_pPicLineDown->LoadFromResourceName(int(HInstance), L"line_Down");
}
u_nPicRef++;
}
static void ReleasePictures()
{
u_nPicRef--;
if( u_nPicRef==0 ){
delete u_pPicLineUp;
delete u_pPicLineDown;
}
}
//---------------------------------------------------------------------------
__fastcall CDTSkinScrollBar::CDTSkinScrollBar(TComponent* AOwner)
: TScrollBar(AOwner)
{
Visible = false;
ParentCtl3D = false; //add by tj 2013/11/14
InitialPictures();
Kind = sbVertical;
Width = u_pPicLineUp->Height;//add by tj 2013/11/19
DoubleBuffered = TRUE;
m_nThumbHeight = 0;
m_nThumbTop = Width;
m_nPreThumbTop = Width;
// m_nTileHeight = 18; //add by tj 2013/11/14
m_nTrackPos = m_nMax = m_nMin = m_nPos = m_nPage = 0;
m_iClicked = -1;
m_iHitPrev = -1;
m_bAction = m_bPause = m_bNotify = m_bDrag = m_bTrace = false;
m_pCanvas = new TControlCanvas();
((TControlCanvas*)m_pCanvas)->Control = this;
Ctl3D = false;
//鼠标长期按下的计时器
m_pTimer = new TTimer(NULL);
m_pTimer->Enabled = false;
m_pTimer->OnTimer = TimerProc;
OnMouseLeave = CMMouseLeave;
}
//---------------------------------------------------------------------------
__fastcall CDTSkinScrollBar::~CDTSkinScrollBar()
{
if( m_pCanvas ){
delete m_pCanvas;
m_pCanvas = NULL;
}
if( m_pTimer ){
delete m_pTimer;
m_pTimer = NULL;
}
ReleasePictures();
}
//---------------------------------------------------------------------------
int CDTSkinScrollBar::HitTest( int X, int Y )
{
if( Y<0 )
return -1;
else if( Y<Width )
return SB_LINEUP;
else if( Y<m_nThumbTop )
return SB_PAGEUP;
else if( Y<m_nThumbTop+m_nThumbHeight )
return SB_THUMBTRACK;
else if( Y<Height-Width )
return SB_PAGEDOWN;
else if( Y<Height )
return SB_LINEDOWN;
else
return -1;
}
//---------------------------------------------------------------------------
void CDTSkinScrollBar::CalcThumbHeight()
{
int hInter = Height - 2 * Width;
int hThumb = m_nPage * hInter / (m_nMax-m_nMin+1);
if( hThumb<THUMB_MINSIZE )
hThumb = THUMB_MINSIZE;
if( hInter<THUMB_MINSIZE )
hThumb = 0;
if( m_nMax-m_nMin-m_nPage+1 == 0 )
hThumb = 0;
m_nThumbHeight = hThumb;
}
//---------------------------------------------------------------------------
void CDTSkinScrollBar::CalcThumbTop()
{
int nPos;
if( m_bDrag )
nPos = m_nTrackPos;
else
nPos = m_nPos;
if( nPos==0 )
m_nThumbTop = Width;
else{
int nTrackLen = Height - 2*Width - m_nThumbHeight;
int nLenInSi = m_nMax-m_nMin-m_nPage+1;
if( nLenInSi==0 )
m_nThumbTop = nTrackLen / 2 + Width;
else
m_nThumbTop = (nTrackLen * nPos / nLenInSi) + Width;
}
}
//---------------------------------------------------------------------------
void CDTSkinScrollBar::DrawArrow( int iDirection, int iState )
{
int x, y;
TRect tmpRect;
TBitmap * pPic = NULL;
if( iDirection==SB_LINEUP ){
pPic = u_pPicLineUp;
x = - iState * Width;
y = 0;
}
else {
pPic = u_pPicLineDown;
x = - iState * Width;
y = Height - Width;
}
if( Width==pPic->Width/3 )
m_pCanvas->Draw( x, y, pPic );
else{
tmpRect.Left = x;
tmpRect.Right = tmpRect.Left + Width*3;
tmpRect.Top = y;
tmpRect.Bottom = tmpRect.top + Width;
m_pCanvas->StretchDraw( tmpRect, pPic);
}
}
//---------------------------------------------------------------------------
void CDTSkinScrollBar::DrawThumb( int iState, bool bEraseBk, int iPageUD )
{
//add by tj 2013/11/14
TRect rectDraw;
//===========================
//绘制 轨道
rectDraw.Left = PIXEL_EXTERNAL_FRAME;
rectDraw.Right = Width -rectDraw.Left;
//绘制 上轨道
if(iPageUD == SB_PAGEUP || iState== STATE_PUSH ){
m_pCanvas->Brush->Color = RGB_EXTERNAL_HIG;
m_pCanvas->Pen->Color = RGB_EXTERNAL_HIG;
}else {
m_pCanvas->Brush->Color = RGB_EXTERNAL_NOR;
m_pCanvas->Pen->Color = RGB_EXTERNAL_NOR;
}
if( bEraseBk ) //重绘轨道
rectDraw.Top = Width;
else if( m_nPreThumbTop<m_nThumbTop ) //滚动条往下滑动
rectDraw.Top = m_nPreThumbTop;
else //滚动条往上滑动
rectDraw.Top = Width;
if( rectDraw.Top<m_nThumbTop ){
rectDraw.Bottom = m_nThumbTop;
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
}
//绘制 下轨道
if(iPageUD == SB_PAGEDOWN || iState== STATE_PUSH){
m_pCanvas->Brush->Color = RGB_EXTERNAL_HIG;
m_pCanvas->Pen->Color = RGB_EXTERNAL_HIG;
}else {
m_pCanvas->Brush->Color = RGB_EXTERNAL_NOR;
m_pCanvas->Pen->Color = RGB_EXTERNAL_NOR;
}
rectDraw.Top = m_nThumbTop + m_nThumbHeight;
if( bEraseBk )
rectDraw.bottom = Height - Width;
else if( m_nPreThumbTop>m_nThumbTop ){ //如果向上,则为当前滑动块底部的值
rectDraw.bottom = m_nThumbHeight+m_nPreThumbTop;
if( rectDraw.bottom>Height-Width )
rectDraw.bottom = Height-Width;
}else
rectDraw.Bottom = Height - Width; //如果向下,则为当前滑动块底部的值
if( rectDraw.Height()>0 ){
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
}
//===========================
//绘制 滑块
if( m_nThumbHeight>0 ){
//===========================
//绘制 滑块左右区域
if(iState==STATE_NORMAL || iState == STATE_HIGHLIGHT){
m_pCanvas->Brush->Color = RGB_EXTERNAL_NOR;
m_pCanvas->Pen->Color = RGB_EXTERNAL_NOR;
}else if(iState== STATE_PUSH ){
m_pCanvas->Brush->Color = RGB_EXTERNAL_HIG;
m_pCanvas->Pen->Color = RGB_EXTERNAL_HIG;
}
rectDraw.Top = m_nThumbTop;
rectDraw.Bottom = m_nThumbTop + m_nThumbHeight;
//左区域
rectDraw.Left = PIXEL_EXTERNAL_FRAME;
rectDraw.Right = rectDraw.Left+PIXEL_EX2INTERNAL;
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
//右区域
rectDraw.Left = Width - PIXEL_EXTERNAL_FRAME-PIXEL_EX2INTERNAL;
rectDraw.Right = Width - PIXEL_EXTERNAL_FRAME;
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
//===========================
//绘制 滑块矩形区域
if(iState == STATE_NORMAL){
m_pCanvas->Brush->Color = RGB_INTERNAL_NOR;
m_pCanvas->Pen->Color = RGB_INTERNAL_NOR;
}else if(iState == STATE_HIGHLIGHT){
m_pCanvas->Brush->Color = RGB_INTERNAL_HIG;
m_pCanvas->Pen->Color = RGB_INTERNAL_HIG;
}else if(iState == STATE_PUSH){
m_pCanvas->Brush->Color = RGB_INTERNAL_PUSH;
m_pCanvas->Pen->Color = RGB_INTERNAL_PUSH;
}
rectDraw.left = PIXEL_EXTERNAL_FRAME+PIXEL_EX2INTERNAL+PIXEL_INTERNAL_FARME;
rectDraw.right = Width-rectDraw.left;
rectDraw.Top = m_nThumbTop + PIXEL_INTERNAL_BOUND;
rectDraw.Bottom = m_nThumbTop + m_nThumbHeight - PIXEL_INTERNAL_BOUND;
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
//add by tj 2013/12/10
//绘制 滑块矩形区域 横线
//===========================
//绘制 滑块矩形区域
COLORREF colLine, *colLineTrans, *colLineLight;
if(iState == STATE_NORMAL){
colLine = RGB_INTERNAL_LINE_NOR;
colLineTrans = (COLORREF *)RGB_INTERNAL_LINE_NOR_TRANS;
}else if(iState == STATE_HIGHLIGHT){
colLine = RGB_INTERNAL_LINE_HIG;
colLineTrans = (COLORREF *)RGB_INTERNAL_LINE_HIG_TRANS;
}else if(iState == STATE_PUSH){
colLine = RGB_INTERNAL_LINE_PUSH;
colLineTrans = (COLORREF *)RGB_INTERNAL_LINE_PUSH_TRANS;
}
int X,Y,iPixlX,iPixlY;
iPixlY = Y = m_nThumbTop + m_nThumbHeight/2 - 3;
iPixlX = X = rectDraw.left + (Width - 2*rectDraw.left - PIXEL_INTERNAL_LINE)/2;
for(int i=0; i<3; i++){
iPixlY = Y;
iPixlX = X;
iPixlY += 1;
for(int j=0; j<6; j++){
m_pCanvas->Pixels[iPixlX][iPixlY] = colLineTrans[j];
iPixlX += 1;
}
iPixlX = X;
iPixlY = Y;
m_pCanvas->Pen->Color = colLine;
m_pCanvas->MoveTo(iPixlX,iPixlY);
iPixlX = Width - iPixlX;
m_pCanvas->LineTo(iPixlX,iPixlY);
Y += 3;
}
//===========================
//绘制 滑块边框
m_pCanvas->Brush->Color = RGB_INTERNAL_FRAME_NOR;
m_pCanvas->Pen->Color = RGB_INTERNAL_FRAME_NOR;
//左边框
rectDraw.left = PIXEL_EXTERNAL_FRAME + PIXEL_EX2INTERNAL;
rectDraw.right = PIXEL_EXTERNAL_FRAME + PIXEL_EX2INTERNAL + PIXEL_INTERNAL_FARME;
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
//右边框
rectDraw.left = Width - (PIXEL_EXTERNAL_FRAME+PIXEL_EX2INTERNAL+PIXEL_INTERNAL_FARME);
rectDraw.right = Width - (PIXEL_EXTERNAL_FRAME+PIXEL_EX2INTERNAL);
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
//上边框
rectDraw.left = PIXEL_EXTERNAL_FRAME + PIXEL_EX2INTERNAL + PIXEL_INTERNAL_FARME;
rectDraw.right = Width - rectDraw.left;
rectDraw.Top = m_nThumbTop;
rectDraw.Bottom = m_nThumbTop + PIXEL_INTERNAL_BOUND;
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
//下边框
rectDraw.Top = m_nThumbTop + m_nThumbHeight-PIXEL_INTERNAL_BOUND;
rectDraw.Bottom = m_nThumbTop + m_nThumbHeight;
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
//===========================
//绘制 滑块角
if(iState == STATE_NORMAL){
m_pCanvas->Pen->Color = RGB_INTERNAL_ROUND_BKG_N_NOR;
}else if(iState == STATE_HIGHLIGHT ){
m_pCanvas->Pen->Color = RGB_INTERNAL_ROUND_BKG_N_HIG;
}else if( iState == STATE_PUSH){
m_pCanvas->Pen->Color = RGB_INTERNAL_ROUND_BKG_H_HIG;
}
//左上角
rectDraw.left = PIXEL_EXTERNAL_FRAME + PIXEL_EX2INTERNAL;
rectDraw.Top = m_nThumbTop;
m_pCanvas->Pixels[rectDraw.left][rectDraw.top] = m_pCanvas->Pen->Color;
//左下角
rectDraw.Top = m_nThumbTop + m_nThumbHeight - PIXEL_INTERNAL_BOUND;
m_pCanvas->Pixels[rectDraw.left][rectDraw.top] = m_pCanvas->Pen->Color;
//右上角
rectDraw.left = Width - (PIXEL_EXTERNAL_FRAME+PIXEL_EX2INTERNAL+PIXEL_INTERNAL_BOUND);
rectDraw.Top = m_nThumbTop;
m_pCanvas->Pixels[rectDraw.left][rectDraw.top] = m_pCanvas->Pen->Color;
//右下角
rectDraw.Top = m_nThumbTop + m_nThumbHeight - PIXEL_INTERNAL_BOUND;
m_pCanvas->Pixels[rectDraw.left][rectDraw.top] = m_pCanvas->Pen->Color;
}
/* TBitmap *pBmp = NULL;
rectDraw.Left = 0;
rectDraw.Right = rectDraw.Left + Width;
// 需要拉伸
if( Width!=u_pPicPageUpTile->Width ){
pBmp = new TBitmap();
pBmp->Width = Width;
pBmp->Height = m_nTileHeight;
tmpRect.Left = 0;
tmpRect.Top = 0;
tmpRect.Right = Width;
tmpRect.Bottom = m_nTileHeight;
pBmp->Canvas->StretchDraw( tmpRect, u_pPicPageUpTile );
}
// 绘制上轨道
if( bEraseBk )
rectDraw.Top = Width;
else if( m_nPreThumbTop<m_nThumbTop )
rectDraw.Top = (m_nPreThumbTop-Width) / m_nTileHeight * m_nTileHeight + Width;
else
rectDraw.Top = Width;
if( rectDraw.Top<m_nThumbTop ){
rectDraw.Bottom = m_nThumbTop;
if( !pBmp )
m_pCanvas->Brush->Bitmap = u_pPicPageUpTile;
else{
m_pCanvas->Brush->Bitmap = pBmp;
}
m_pCanvas->FillRect( rectDraw );
}
// 绘制下轨道
rectDraw.Top = m_nThumbTop + m_nThumbHeight;
if( bEraseBk )
rectDraw.bottom = Height - Width;
else if( m_nPreThumbTop>m_nThumbTop ){
rectDraw.bottom = m_nThumbHeight+m_nPreThumbTop;
if( rectDraw.bottom>Height-Width ){
rectDraw.bottom = Height-Width;
}
}
else
rectDraw.Bottom = rectDraw.Top;
if( rectDraw.Height()>0 ){
if( !pBmp )
m_pCanvas->Brush->Bitmap = u_pPicPageDownTile;
else{
tmpRect.Left = 0;
tmpRect.Top = 0;
tmpRect.Right = Width;
tmpRect.Bottom = m_nTileHeight;
pBmp->Canvas->StretchDraw( tmpRect, u_pPicPageDownTile );
m_pCanvas->Brush->Bitmap = pBmp;
}
m_pCanvas->FillRect( rectDraw );
}
// 绘制滑块
if( m_nThumbHeight>0 ){
int x = - iState * Width,
y = m_nThumbTop,
hTileUp,
hTileDown;
if( m_nThumbHeight>=THUMB_MINSIZE*2 ){
hTileUp = (m_nThumbHeight-THUMB_MINSIZE*2+1)/2,
hTileDown = m_nThumbHeight - THUMB_MINSIZE*2 - hTileUp;
}
else{
hTileUp = (m_nThumbHeight-THUMB_MINSIZE+1)/2,
hTileDown = m_nThumbHeight - THUMB_MINSIZE - hTileUp;
}
rectDraw.left = x;
rectDraw.right = rectDraw.left + Width*3;
if( !pBmp ){
//滑块顶部圆弧
m_pCanvas->Draw( x, y, u_pPicThumbTop ); y += THUMB_BORDER;
//滑块上部平铺
if( hTileUp>0 ){
for( int i=0; i<hTileUp/u_pPicThumbTile->Height+1; i++ ){
m_pCanvas->Draw( x, y+u_pPicThumbTile->Height*i, u_pPicThumbTile );
}
y += hTileUp;
}
//滑块中部条纹
if( m_nThumbHeight>=THUMB_MINSIZE*2 ){
m_pCanvas->Draw( x, y, u_pPicThumbMid ); y += THUMB_BORDER * 2;
}
//滑块下部平铺
if( hTileDown>0 ){
for( int i=0; i<hTileDown/u_pPicThumbTile->Height+1; i++ ){
m_pCanvas->Draw( x, y+u_pPicThumbTile->Height*i, u_pPicThumbTile );
}
y += hTileDown;
}
//滑块底部圆弧
m_pCanvas->Draw( x, y, u_pPicThumbBottom );
}
}
// 清除临时图画
if( pBmp ){
delete pBmp;
pBmp = NULL;
}
*/
m_nPreThumbTop = m_nThumbTop;
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::PaintWindow(HDC DC)
{
if( !m_pCanvas->Handle )
m_pCanvas->Handle = DC;
// 绘制上箭头
DrawArrow( SB_LINEUP, STATE_NORMAL );
// 绘制滑块
DrawThumb( STATE_NORMAL, true );
// 绘制下箭头
DrawArrow( SB_LINEDOWN, STATE_NORMAL );
TRect rectDraw;
//add by tj 2013/11/14
//===========================
//绘制 外面左右边框
m_pCanvas->Brush->Color = RGB_EXTERNAL_FRAME;
m_pCanvas->Pen->Color = RGB_EXTERNAL_FRAME;
rectDraw.Top = Width;
rectDraw.Bottom = Height - Width;
rectDraw.Left = 0;
rectDraw.Right = rectDraw.Left + PIXEL_EXTERNAL_FRAME;
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
rectDraw.Left = Width - PIXEL_EXTERNAL_FRAME;
rectDraw.Right = Width;
m_pCanvas->Rectangle(rectDraw.Left, rectDraw.Top,
rectDraw.Right, rectDraw.Bottom);
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::WMPaint(TWMPaint &Message)
{
PaintHandler(Message);
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::SetPosition(int Value, bool bRedraw)
{
if( m_nPos!=Value ){
m_nPos = Value;
CalcThumbTop();
if( bRedraw ) DrawThumb( STATE_NORMAL, false );
}
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::SetPageSize(int Value, bool bRedraw)
{
if( m_nPage!=Value ){
m_nPage = Value;
CalcThumbHeight();
if( bRedraw ){
DrawThumb( STATE_NORMAL, true );
Invalidate();
}
}
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::SetRange(int AMin, int AMax, bool bRedraw)
{
if( m_nMin!=AMin || m_nMax!=AMax ){
m_nMin = AMin;
m_nMax = AMax;
CalcThumbHeight();
if( bRedraw ){
DrawThumb( STATE_NORMAL, true );
Invalidate();
}
}
}
//---------------------------------------------------------------------------
int __fastcall CDTSkinScrollBar::GetScrollPos()
{
return m_nPos;
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::GetScrollRange(int* nMin, int* nMax)
{
*nMin = m_nMin;
*nMax = m_nMax;
}
//---------------------------------------------------------------------------
int __fastcall CDTSkinScrollBar::GetPageSize()
{
return m_nPage;
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::SBMSetScrollInfo(TMessage &Message)
{
/* //add by tj 2013/11/14
bool bRedraw = bool(Message.WParam) && Visible;
PScrollInfo pSi = PScrollInfo(Message.LParam);
if( pSi->fMask & SIF_RANGE )
SetRange( pSi->nMin, pSi->nMax, bRedraw );
if( pSi->fMask & SIF_PAGE )
SetPageSize( pSi->nPage, bRedraw );
if( pSi->fMask & SIF_POS )
SetPosition( pSi->nPos, bRedraw );
*/
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::SBMGetScrollInfo(TMessage &Message)
{
/* //add by tj 2013/11/14
PScrollInfo pSi = PScrollInfo(Message.LParam);
if( pSi->fMask & SIF_PAGE )
pSi->nPage = m_nPage;
if( pSi->fMask & SIF_POS )
pSi->nPos = m_nPos;
if( pSi->fMask & SIF_TRACKPOS )
pSi->nTrackPos = m_nTrackPos;
if( pSi->fMask & SIF_RANGE ){
pSi->nMin = m_nMin;
pSi->nMax = m_nMax;
}
*/
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::WMLButtonDown(TWMMouse &Message)
{
SetCapture(Handle);
m_bAction = true;
m_pWndCtrl->SetFocus();
int iHit = HitTest( Message.XPos, Message.YPos );
if( iHit==SB_THUMBTRACK ){
m_bDrag = TRUE;
m_nDragPoint = Message.YPos;
m_nDragPos = m_nPos;
m_nTrackPos = m_nDragPos;
DrawThumb( STATE_PUSH, false );
}
else{
m_iClicked = iHit;
m_pWndCtrl->Perform( WM_VSCROLL, MAKELONG(m_iClicked,0), LPARAM(Handle) );
m_pTimer->Interval = TIME_DELAY;
m_pTimer->Enabled = true;
m_bPause = false;
int nNewPos = m_nPos;
if( iHit==SB_LINEUP || iHit==SB_LINEDOWN ){
DrawArrow( iHit, STATE_PUSH );
nNewPos += (iHit==SB_LINEUP) ? -1 : 1;
}
else if( iHit==SB_PAGEUP || iHit==SB_PAGEDOWN ){
nNewPos += (iHit==SB_PAGEUP) ? -m_nPage : m_nPage;
}
int nLenInSi = m_nMax-m_nMin-m_nPage+1;
if( nNewPos<m_nMin )
nNewPos = m_nMin;
else if( nNewPos>nLenInSi )
nNewPos = nLenInSi;
if( nNewPos!=m_nPos ){
m_nPos = nNewPos;
CalcThumbTop();
//add by tj 2013/11/14
DrawThumb( STATE_NORMAL, false, iHit );
}
}
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::WMLButtonUp(TWMMouse &Message)
{
ReleaseCapture();
if( m_bDrag ){
m_bDrag = false;
m_pWndCtrl->Perform(WM_VSCROLL, MAKELONG(SB_THUMBPOSITION, m_nTrackPos), LPARAM(Handle) );
if( m_nTrackPos!=m_nPos ){
m_nPos = m_nTrackPos;
}
m_nTrackPos = 0;
CalcThumbTop();
int iHit = HitTest( Message.XPos, Message.YPos );
if( iHit==SB_THUMBTRACK )
DrawThumb( STATE_HIGHLIGHT, false );
else
DrawThumb( STATE_NORMAL, false );
}
else if( m_iClicked!=-1 ){
m_pTimer->Enabled = false;
if( m_bNotify ){
m_bNotify = false;
}
if( m_iClicked==SB_LINEUP || m_iClicked==SB_LINEDOWN )
DrawArrow( m_iClicked, STATE_NORMAL );
//add by tj 2013/11/14
if( m_iClicked==SB_PAGEUP || m_iClicked==SB_PAGEDOWN )
DrawThumb( STATE_NORMAL, false);
m_iClicked = -1;
}
m_bAction = false;
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::WMLButtonDblClk(TWMMouse &Message)
{
int uHit = HitTest( Message.XPos, Message.YPos );
if( uHit!=SB_THUMBTRACK ){
m_iClicked = uHit;
WMLButtonDown( Message );
m_bAction = false;
}
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::WMMouseMove(TWMMouse &Message)
{
if( ((Extctrls::TPanel*)m_pWndCtrl)->OnMouseLeave ){
((Extctrls::TPanel*)m_pWndCtrl)->OnMouseLeave(NULL);
}
Windows::TTrackMouseEvent tme;
int nDragLen, nLenInSi, nSlide, nTrackLen, nNewPos, iHit, iState;
if( !m_bTrace && (Message.Keys & MK_LBUTTON) ){
tme.cbSize = sizeof(tme);
tme.hwndTrack = Handle;
tme.dwFlags = TME_LEAVE;
tme.dwHoverTime = 1;
m_bTrace = _TrackMouseEvent(&tme);
}
if( m_bDrag ){
nTrackLen = Height - 2 * Width - m_nThumbHeight;
nLenInSi = m_nMax-m_nMin-m_nPage+1;
nDragLen = Message.YPos - m_nDragPoint;
if( nTrackLen==0 )
nSlide = 0;
else
nSlide = nDragLen * nLenInSi / nTrackLen;
nNewPos = m_nDragPos + nSlide;
if( nNewPos<m_nMin )
nNewPos = m_nMin;
else if( nNewPos>nLenInSi )
nNewPos = nLenInSi;
if( nNewPos!=m_nTrackPos ){
m_nTrackPos = nNewPos;
CalcThumbTop();
DrawThumb( STATE_PUSH, false );
m_pWndCtrl->Perform(WM_VSCROLL, MAKELONG(SB_THUMBTRACK, m_nTrackPos), LPARAM(Handle) );
}
}
else if( m_iClicked!=-1 ){
iHit = HitTest( Message.XPos, Message.YPos );
if( iHit==m_iClicked ){
m_bPause = false;
iState = STATE_PUSH; //add by tj 2013/11/18
}
else{
m_bPause = true;
iState = STATE_NORMAL;
}
if( m_iClicked==SB_LINEUP || m_iClicked==SB_LINEDOWN )
DrawArrow( m_iClicked, iState );
}
else{
iHit = HitTest( Message.XPos, Message.YPos );
if( iHit!=m_iHitPrev ){
if( m_iHitPrev!=-1 ){
if( m_iHitPrev==SB_THUMBTRACK )
DrawThumb( STATE_NORMAL, FALSE );
else if( m_iHitPrev==SB_LINEUP || m_iHitPrev==SB_LINEDOWN )
DrawArrow( m_iHitPrev, STATE_NORMAL );
}
if( iHit!=-1 ){
if( iHit==SB_THUMBTRACK )
DrawThumb( STATE_HIGHLIGHT, FALSE );
else if( iHit==SB_LINEUP || iHit==SB_LINEDOWN )
DrawArrow( iHit, STATE_HIGHLIGHT );
}
m_iHitPrev = iHit;
}
}
}
//---------------------------------------------------------------------------
/*
void __fastcall CDTSkinScrollBar::CMMouseLeave(TMessage &Message)
{
if( m_iHitPrev!=-1 ){
if( m_iHitPrev==SB_THUMBTRACK )
DrawThumb( STATE_NORMAL, false );
else if( m_iHitPrev==SB_LINEUP || m_iHitPrev==SB_LINEDOWN )
DrawArrow( m_iHitPrev, STATE_NORMAL );
m_iHitPrev = -1;
}
}
*/
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::CMMouseLeave(TObject *Sender)
{
if( m_iHitPrev!=-1 ){
if( m_iHitPrev==SB_THUMBTRACK )
DrawThumb( STATE_NORMAL, false );
else if( m_iHitPrev==SB_LINEUP || m_iHitPrev==SB_LINEDOWN )
DrawArrow( m_iHitPrev, STATE_NORMAL );
m_iHitPrev = -1;
}
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::WMRButtonDown(TWMMouse &Message)
{
// DefaultHandler(&Message); //add by tj 2013/11/18
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::WMRButtonUp(TWMMouse &Message)
{
// DefaultHandler(&Message); //add by tj 2013/11/18
}
//---------------------------------------------------------------------------
void __fastcall CDTSkinScrollBar::TimerProc(TObject* Sender)
{
if( m_pTimer->Interval==TIME_DELAY ){
m_bNotify = true;
m_pTimer->Enabled = false;
m_pTimer->Interval = TIME_NOTIFY;
m_pTimer->Enabled = true;
}
else if( m_pTimer->Interval==TIME_NOTIFY && !m_bPause ){
int nNewPos = m_nPos;
//add by tj 2013/11/14
bool bPageUD = false;
int iHit;
switch( m_iClicked ){
case SB_LINEUP:
nNewPos -= 1;
if( m_nPos==m_nMin ){
m_pTimer->Enabled = false;
return;
}
break;
case SB_LINEDOWN:
nNewPos += 1;
if( m_nPos==m_nMax ){
m_pTimer->Enabled = false;
return;
}
break;
case SB_PAGEUP:
case SB_PAGEDOWN:
{
TPoint pt;
GetCursorPos(&pt);
pt = ScreenToClient(pt);
iHit = HitTest( pt.X, pt.Y );
if( iHit==SB_THUMBTRACK ){
m_pTimer->Enabled = false;
return;
}
nNewPos += (m_iClicked==SB_PAGEUP) ? -m_nPage+1 : m_nPage-1;
bPageUD = true;
}
break;
}
int nLenInSi = m_nMax-m_nMin-m_nPage+1;
if( nNewPos<m_nMin )
nNewPos = m_nMin;
else if( nNewPos>nLenInSi )
nNewPos = nLenInSi;
if( nNewPos!=m_nPos ){
m_nPos = nNewPos;
CalcThumbTop();
//add by tj 2013/11/14
if(bPageUD)
DrawThumb( STATE_NORMAL, false, iHit );
else
DrawThumb( STATE_NORMAL, false );
}
m_pWndCtrl->Perform( WM_VSCROLL, MAKELONG(m_iClicked,0), LPARAM(Handle) );
}
}
+94
View File
@@ -0,0 +1,94 @@
//---------------------------------------------------------------------------
#ifndef CDSkinScrollBarUnitH
#define CDSkinScrollBarUnitH
#define TIME_DELAY 200
#define TIME_NOTIFY 100
#define THUMB_BORDER 7
#define THUMB_MINSIZE (THUMB_BORDER * 2)
#define STATE_NORMAL 0
#define STATE_HIGHLIGHT 1
#define STATE_PUSH 2
class CDTSkinScrollBar : public TScrollBar
{
private:
// int m_nTileHeight, //add by tj 2013/11/18
int m_nThumbHeight,
m_nThumbTop,
m_nPreThumbTop,
m_nDragPos,
m_nDragPoint,
m_iClicked,
m_iHitPrev,
m_nMax,
m_nMin,
m_nPos,
m_nPage,
m_nTrackPos;
bool m_bPause,
m_bNotify,
m_bDrag,
m_bTrace;
TTimer *m_pTimer;
TCanvas *m_pCanvas;
int HitTest( int X, int Y );
void CalcThumbHeight();
void CalcThumbTop();
void DrawArrow( int iDirection, int iState );
void DrawThumb( int iState, bool bEraseBk, int iPageUD=-1 );
void __fastcall TimerProc(TObject* Sender);
MESSAGE void __fastcall WMPaint(Winapi::Messages::TWMPaint &Message);
MESSAGE void __fastcall WMLButtonDown(TWMMouse &Message);
MESSAGE void __fastcall WMLButtonUp(TWMMouse &Message);
MESSAGE void __fastcall WMLButtonDblClk(TWMMouse &Message);
MESSAGE void __fastcall WMRButtonDown(TWMMouse &Message); //add by tj 2013/11/18
MESSAGE void __fastcall WMRButtonUp(TWMMouse &Message); //add by tj 2013/11/18
MESSAGE void __fastcall WMMouseMove(TWMMouse &Message);
// MESSAGE void __fastcall CMMouseLeave(TMessage &Message); //add by tj 2013/11/25 12:35
MESSAGE void __fastcall SBMSetScrollInfo(TMessage &Message);
MESSAGE void __fastcall SBMGetScrollInfo(TMessage &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_PAINT, TWMPaint, WMPaint)
MESSAGE_HANDLER(WM_LBUTTONDOWN, TWMLButtonDown, WMLButtonDown)
MESSAGE_HANDLER(WM_LBUTTONUP, TWMLButtonUp, WMLButtonUp)
MESSAGE_HANDLER(WM_LBUTTONDBLCLK, TWMLButtonDblClk, WMLButtonDblClk)
MESSAGE_HANDLER(WM_RBUTTONDOWN, TWMRButtonDown, WMRButtonDown)
MESSAGE_HANDLER(WM_RBUTTONUP, TWMRButtonUp, WMRButtonUp) //add by tj 2013/11/18
MESSAGE_HANDLER(WM_MOUSEMOVE, TWMMouseMove, WMMouseMove) //add by tj 2013/11/18
// MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave) //add by tj 2013/11/25 12:35
MESSAGE_HANDLER(SBM_SETSCROLLINFO, TMessage, SBMSetScrollInfo)
MESSAGE_HANDLER(SBM_GETSCROLLINFO, TMessage, SBMGetScrollInfo)
END_MESSAGE_MAP(TScrollBar)
protected:
virtual void __fastcall PaintWindow(HDC DC);
public:
TWinControl *m_pWndCtrl;
bool m_bAction;
__fastcall virtual CDTSkinScrollBar(System::Classes::TComponent* AOwner);
__fastcall ~CDTSkinScrollBar();
void __fastcall CMMouseLeave(TObject *Sender); //add by tj 2013/11/25 12:35
bool IsDraging(){ return m_bDrag; };
void __fastcall SetPosition(int Value, bool bRedraw=true);
void __fastcall SetPageSize(int Value, bool bRedraw=true);
void __fastcall SetRange(int AMin, int AMax, bool bRedraw=true);
void __fastcall GetScrollRange(int* nMin, int* nMax);
int __fastcall GetScrollPos();
int __fastcall GetPageSize();
};
//---------------------------------------------------------------------------
#endif
+15
View File
@@ -0,0 +1,15 @@
// ---------------------------------------------------------------------------
#pragma hdrstop
#include "CharactorStringUnit.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
CharactorStringUnit::CharactorStringUnit() {
}
CharactorStringUnit::~CharactorStringUnit() {
}
+49
View File
@@ -0,0 +1,49 @@
// ---------------------------------------------------------------------------
#ifndef CharactorStringUnitH
#define CharactorStringUnitH
#include "system.hpp"
const String g_strNoticeAry[2][20] = {{
L"将节拍设为[4/4]",
L"将音乐速度设置[75].可用鼠标拖动指针进行音乐速度设置.",
L"鼠标点击唱片图标,任意设置一种伴奏风格...(若不选择,系统会为您自动配置一个合适的风格.)",
L"请点击按钮【下一步】进入弦律录音页面...",
L"点击录音按钮开始录音,跟随提示节奏录入一段歌曲...",
L"请点击按钮【下一步】进入和弦配置页面...",
L"试听伴奏后的效果...", L"请点击按钮【下一步】进入段落调整页面...",
L"点击【登录】按钮登录后继续操作...(没有帐号请先注册)",
L"请点击按钮【下一步】进入全曲录存界面保存录音.",
L"请点击按钮【保存...】保存歌曲.",
L"恭喜您完成了新手任务!|并获得了额外赠送的20个免费风格!!!;现在,您已经了解了本软件的基本操作,更多功能期待您的探索....",
L"恭喜您完成了新手任务!;更多功能等待您的探索...",
L""
},
{
L"节拍:是指音乐里节奏强弱的交替规律。流行歌曲常见为4/4拍.",
L"速度:歌曲的快慢程度. 慢速(<70) 中速(70~90) 快速(>90)",
L"风格:软件中的风格指的是歌曲伴奏的各种不同的方式.系统为您准备了一些经典的风格,缺省情况下系统会给您自动配置一个合适的风格",
L"风格:软件中的风格指的是歌曲伴奏的各种不同的方式.系统为您准备了一些经典的风格,缺省情况下系统会给您自动配置一个合适的风格",
L"录音:录制歌曲主旋律.<注意事项>打开话筒,确认系统录音设备是否为麦克风输入,音量是否过低或者被静音,为了避免把这个节奏也录入到人声里,所以请大家在录音的时候一定要佩戴耳机。并让录音环境处于相对安静的状态.",
L"录音:录制歌曲主旋律.<注意事项>打开话筒,确认系统录音设备是否为麦克风输入,音量是否过低或者被静音,为了避免把这个节奏也录入到人声里,所以请大家在录音的时候一定要佩戴耳机。并让录音环境处于相对安静的状态.",
L"和弦配置:系统已为您配置好每小节的和弦.点击播放可以试听伴奏效果.如需更改和弦请点击上方和弦编辑框.更换伴奏风格请点击伴奏风格按钮.",
L"和弦配置:系统已为您配置好每小节的和弦.点击播放可以试听伴奏效果.如需更改和弦请点击上方和弦编辑框.更换伴奏风格请点击伴奏风格按钮.",
L"段落调整:系统为您配置好了一个基本的段落格式。鼠标拖动每一段可以调整段落之间的顺序.",
L"段落调整:系统为您配置好了一个基本的段落格式。鼠标拖动每一段可以调整段落之间的顺序.",
L"全曲录存:本页面可以跟伴奏进行全曲重新录音.点击保存选择文件格式、存放路径及文件名.",
L"",
L"",
}
};
const String g_strNewcomerInfo = L"【任务目标】按照提示制作一首歌曲.\n【任务奖励】完成任务后您将获得额外赠送的20个免费风格.";
// ---------------------------------------------------------------------------
class CharactorStringUnit {
public:
CharactorStringUnit();
~CharactorStringUnit();
};
#endif
+125
View File
@@ -0,0 +1,125 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CommonListBoxUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#define COLOR_BORDER RGB(150,118,80)
#define UM_HIDEPOPCONTROL WM_USER + 0x1121
//---------------------------------------------------------------------------
__fastcall CommonListBoxUnit::TListBox::TListBox(System::Classes::TComponent* AOwner)
: TSkinListBox(AOwner)
{
m_pNormal = new TBitmap;
m_pNormal->LoadFromResourceName(int(HInstance), "LBNormal");
m_pHover = new TBitmap;
m_pHover->LoadFromResourceName(int(HInstance), "LBHover");
ApplicationEvents = NULL;
}
//---------------------------------------------------------------------------
__fastcall CommonListBoxUnit::TListBox::~TListBox()
{
if( m_pNormal ){
delete m_pNormal;
m_pNormal = NULL;
}
if( m_pHover ){
delete m_pHover;
m_pHover = NULL;
}
if( ApplicationEvents!=NULL ){
delete ApplicationEvents;
ApplicationEvents = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall CommonListBoxUnit::TListBox::DoHandleMessage(MSG &Msg, bool &Handled)
{
if( Visible && (Msg.message == WM_NCLBUTTONDOWN || Msg.message == WM_NCRBUTTONDOWN
|| (Msg.message == WM_LBUTTONDOWN || Msg.message == WM_RBUTTONDOWN)
&& Msg.hwnd != Handle && Msg.hwnd != GetSBHandle() )){
PostMessage( Parent->Handle, UM_HIDEPOPCONTROL, 0, (LPARAM)this );
}
}
//---------------------------------------------------------------------------
void __fastcall CommonListBoxUnit::TListBox::DrawItem(int Index, const System::Types::TRect &Rect, Winapi::Windows::TOwnerDrawState State)
{
TRect rcDraw, rcOrig = Rect;
if( rcOrig.Width()<Width ){ //显示滚动条
rcOrig.right = Width-19; //减去滚动条宽度
}
rcDraw = rcOrig;
Canvas->Pen->Color = COLOR_BORDER;
if( Index==TopIndex ){ //绘制上边框
Canvas->MoveTo(Rect.left, Rect.top);
Canvas->LineTo(Rect.right, Rect.top);
rcDraw.top++;
}
int iBottomIndex = TopIndex + Height/ItemHeight-1;
if( Index==iBottomIndex ){ //绘制下边框
Canvas->MoveTo(Rect.left, Rect.bottom-1);
Canvas->LineTo(Rect.right, Rect.bottom-1);
rcDraw.bottom--;
}
if( State.Contains(odSelected) ){// || State.Contains(odFocused) ){
//绘制选中项
Canvas->Font->Color = RGB(232,212,191);
Canvas->StretchDraw( rcDraw, m_pHover );
}
else{
Canvas->Font->Color = RGB(60,43,23);
Canvas->StretchDraw( rcDraw, m_pNormal );
//绘制左边框
Canvas->MoveTo( rcDraw.left, rcDraw.top );
Canvas->LineTo( rcDraw.left, rcDraw.bottom );
//绘制右边框
Canvas->MoveTo( rcDraw.right-1, rcDraw.top );
Canvas->LineTo( rcDraw.right-1, rcDraw.bottom );
}
String strText = Items->Strings[Index];
Canvas->Brush->Style = bsClear;
Canvas->TextOut( Rect.left+5, Rect.top, strText );
}
//---------------------------------------------------------------------------
void __fastcall CommonListBoxUnit::TListBox::Show(void)
{
TSkinListBox::Show();
if( ApplicationEvents==NULL ){
ApplicationEvents = new TApplicationEvents(Application->MainForm);
ApplicationEvents->OnMessage = DoHandleMessage;
}
}
//---------------------------------------------------------------------------
void __fastcall CommonListBoxUnit::TListBox::Hide(void)
{
TSkinListBox::Hide();
if( ApplicationEvents!=NULL ){
delete ApplicationEvents;
ApplicationEvents = NULL;
}
}
//---------------------------------------------------------------------------
+34
View File
@@ -0,0 +1,34 @@
//---------------------------------------------------------------------------
#ifndef CommonListBoxUnitH
#define CommonListBoxUnitH
#include "SkinListBoxUnit.h"
#include <Vcl.AppEvnts.hpp>
namespace CommonListBoxUnit
{
//---------------------------------------------------------------------------
class TListBox : public TSkinListBox
{
private:
TBitmap *m_pNormal, *m_pHover;
TFont *m_pFntText;
TApplicationEvents *ApplicationEvents;
void __fastcall DoHandleMessage(MSG &Msg, bool &Handled);
protected:
virtual void __fastcall DrawItem(int Index, const System::Types::TRect &Rect, Winapi::Windows::TOwnerDrawState State);
public:
__fastcall virtual TListBox(System::Classes::TComponent* AOwner);
__fastcall ~TListBox();
void __fastcall Show(void);
void __fastcall Hide(void);
};
}
using namespace CommonListBoxUnit;
#endif
+212
View File
@@ -0,0 +1,212 @@
//---------------------------------------------------------------------------
#pragma hdrstop
#include "CommonUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
String u_strTable[7] = { L"Ⅰ", L"Ⅱ", L"Ⅲ", L"Ⅳ", L"Ⅴ", L"Ⅵ", L"Ⅶ" };
String u_strAlphaTable[7] = { L"C", L"D", L"E", L"F", L"G", L"A", L"B" };
char * GM_INSTRUMENT[] = {
//钢琴组
"三角钢琴"
,"明亮钢琴"
,"电钢琴"
,"酒吧钢琴"
,"柔和钢琴"
,"合唱钢琴"
,"拨弦弦古钢琴"
,"击弦古钢琴"
//打击乐器组
,"钢片琴"
,"钟琴"
,"八音盒"
,"颤音琴"
,"马林巴"
,"木琴"
,"管钟"
,"洋琴"
//风琴组
,"拉杆管风琴"
,"敲击管风琴"
,"摇滚管风琴"
,"教堂管风琴"
,"簧管管风琴"
,"手风琴"
,"口琴"
,"探戈手风琴"
//吉他组
,"木吉他(尼龙弦)"
,"木吉他(金属弦)"
,"电吉他(爵士)"
,"电吉他(清音)"
,"电吉他(闷音)"
,"过激吉他"
,"失真吉他"
,"吉他和音"
//贝司组
,"贝司"
,"电贝司(指弹)"
,"电贝司(拨片)"
,"无品贝司"
,"击弦贝司1"
,"击弦贝司2"
,"合成贝司1"
,"合成贝司2"
//提琴组
,"小提琴"
,"中提琴"
,"大提琴"
,"低音大提琴"
//交响乐组
,"颤音弦乐"
,"拨奏弦乐"
,"竖琴"
,"定音鼓"
,"弦乐合奏1"
,"弦乐合奏2"
,"合成弦乐1"
,"合成弦乐2"
,"合唱(啊)"
,"人声(嘟)"
,"合成人声"
,"管弦乐齐奏"
//铜管乐器组
,"小号"
,"长号"
,"大号"
,"弱音小号"
,"法国号(圆号)"
,"铜管乐合奏"
,"合成铜管乐1"
,"合成铜管乐2"
,"高音萨克斯"
,"中音萨克斯"
,"次中音萨克斯"
,"低音萨克斯"
,"双簧管"
,"英国号"
//木管乐器组
,"巴松(大管)"
,"单簧管(黑管)"
,"短笛"
,"长笛"
,"竖笛"
,"排箫"
,"吹瓶声"
,"日本笛"
,"口哨声"
,"洋埙"
//前导乐组
,"主音(方波)"
,"主音(锯齿波)"
,"主音(汽笛)"
,"主音(夜莺)"
,"主音(精灵)"
,"主音(人声)"
,"主音(平行五度)"
,"主音(贝司+导音)"
//音色垫组
,"背景(新时代)"
,"背景(温暖)"
,"背景(多合成)"
,"背景(合唱)"
,"背景(弓弦)"
,"背景(金属)"
,"背景(光环)"
,"背景(风吹)"
//合成效果组
,"效果(雨滴)"
,"效果(声道)"
,"效果(水晶)"
,"效果(大气)"
,"效果(明亮)"
,"效果(诡异)"
,"效果(回声)"
,"效果(科幻)"
//民族乐器组
,"西塔琴"
,"班卓琴"
,"三昧线"
,"十三弦筝"
,"卡林巴"
,"风笛"
,"提琴"
,"山奈"
//打击乐器组
,"叮当铃"
,"摇摆舞铃"
,"钢鼓"
,"木鱼"
,"太科鼓"
,"旋律鼓"
,"合成鼓"
,"钢钹"
//特殊音效组
,"吉他滑品杂音"
,"呼吸声"
,"海浪声"
,"鸟鸣"
,"电话铃"
,"直升飞机"
,"鼓掌声"
,"枪声"
};
char * LSZ_STYLTYPES[24] =
{
"流行",
"民谣",
"摇滚",
"舞曲",
"爵士",
"蓝调",
"桑巴",
"古典",
"圆舞曲",
"独立",
"乡村",
"R&B",
"电子",
"小夜曲",
"进行曲",
"叙事曲",
"说唱",
"拉丁",
"曼波",
"雷鬼",
"萨尔萨",
"摇摆",
"波萨",
"FUNKY"
} ;
+358
View File
@@ -0,0 +1,358 @@
//---------------------------------------------------------------------------
#ifndef CommonUnitH
#define CommonUnitH
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma once
#define MAX_STYLE_NUM 80
enum EClientType{
e_Ac_Windows,
e_Ac_Android,
e_Ac_iOS,
e_SM_Recreator,
e_SM_Checker,
e_Web,
e_Pro_Windows
};
enum EStyleState{
e_OffLine = -2, //下线
e_CheckFail, //审核未通过
e_Checking, //待审核
e_Distribute, //发布
e_UnDownload, //未下载
e_Downloading, //在下载
e_Downloaded //已下载
};
enum EPaymentOperation{
e_PO_Pay4Basic = 0x01, //基本功能费
e_PO_Pay4Compose = 0x02, //保存编曲
e_PO_Pay4Midi = 0x04, //导出MIDI
e_PO_Pay4Audios = 0x08, //多音轨输出
e_PO_Pay4Fonts = 0x10, //多音色库
e_PO_End
};
enum EMessageType{
e_InvalidMessage,
e_versionRequest = 0x01,
e_versionResponse,
e_connectRequest = 0x11,
e_connectResponse,
e_loginRequest = 0x21,
e_loginResponse,
e_verifyRequest,
e_verifyResponse,
e_purchaseRequest,
e_purchaseResponse,
e_registerRequest,
e_registerResponse,
e_checkPaymentRequest,
e_checkPaymentResponse,
e_payRequest,
e_payResponse,
e_iconRequest,
e_iconResponse,
e_logoffRequest,
e_logoffResponse,
e_dataSendRequest = 0x41,
e_dataSendResponse,
e_dataReceiveRequest,
e_dataReceiveResponse,
e_styleUpdateRequest = 0x61,
e_styleUpdateResponse,
e_styleInfoRequest,
e_styleInfoResponse,
e_styleDataRequest,
e_styleDataResponse,
e_styleCheckRequest,
e_styleCheckResponse,
e_styleRecomRequest,
e_styleRecomResponse,
e_uploadStyleRequest = 0x81,
e_uploadStyleResponse,
e_uploadSongRequest,
e_uploadSongResponse,
e_qnaUpdateRequest = 0x91,
e_qnaUpdateResponse,
e_qnaSubmitRequest,
e_qnaSubmitResponse,
e_noticeUpdateRequest,
e_noticeUpdateResponse,
e_MessgeTypeEnd
};
enum EExtraInfo{
e_RequestSuccess,
e_UpdateNoNeed, //已是最新版本
e_UpdateOptional, //版本可选更新
e_UpdateMandatory, //版本强制更新
e_VerifyInsufficient,
e_RequestFailed = 0x8000,
e_SocketError,
e_WaitTimeout,
e_DatabaseError,
e_ParamError,
e_LoginPasswordError,
e_LoginUserNotExist,
e_InvalidUserID,
e_InvalidStyleID,
e_UserCanceled,
e_NoService,
e_ServiceBusy,
e_InvalidDataID,
e_InvalidPackID,
e_OutOfBound,
e_InvalidData,
e_InvalidAuthority, //无操作权限
e_CheckedAlready, //风格已被审核
e_UsernameExist,
e_OpenFileFailed,
e_NeedRepeat, //需重发消息
e_VipExceeded, //VIP用户设备数超限
e_UserLocked, //账户被冻结
e_UserDeleted, //账户已删除
e_ExtraEnd
};
#pragma pack (2)
/////////////////////////////////////////////////////////
// 通道信息
typedef struct tagChan{
char no; //通道号
char prog; //乐器号
char vol; //音量
tagChan(){
no = prog = vol = -1;
}
}TCHAN, *PTCHAN;
//风格详细信息结构体
typedef struct tagStyleDetail{
int size;
int idAuthor; //作者ID
short iTempo; //原速
short iTimesignature; //节拍 ( 0=4/4, 1=3/4, 2=2/4, 3=6/8 )
char type[4]; //风格分类
char nSegNum[4]; //伴奏/加花/前奏/尾奏个数
//以下部分可变长度传输和存储
char strAuthor[40]; //作者名称 UTF8
char strStyleName[40]; //风格名称 UTF8
char strDescription[120]; //风格描述 UTF8
char aIntroBars[8]; //前奏小节数
char aEndingBars[8]; //尾奏小节数
char chordRecom[8]; //推荐和声进行
TCHAN tracks[4][8][16]; //伴奏/加花/前奏/尾奏轨道信息 (前/尾奏0/2/4/6大调 1/3/5/7小调)
// char progs[4][8][3]; //伴奏/加花/前奏/尾奏主要乐器 (前/尾奏0/2/4/6大调 1/3/5/7小调)
tagStyleDetail(){
size = sizeof(tagStyleDetail);
idAuthor = iTempo = iTimesignature = 0;
memset( type, -1, sizeof(type) );
memset( nSegNum, 0, sizeof(nSegNum) );
memset( strAuthor, 0, sizeof(strAuthor) );
memset( strStyleName, 0, sizeof(strStyleName) );
memset( strDescription, 0, sizeof(strDescription) );
memset( aIntroBars, 0, sizeof(aIntroBars) );
memset( aEndingBars, 0, sizeof(aEndingBars) );
memset( chordRecom, -1, sizeof(chordRecom) );
// memset( progs, -1, sizeof(progs) );
}
}TSTYLEDETAIL, *PTSTYLEDETAIL;
//风格信息结构体
typedef struct tagStyleInfo{
UINT idStyle; //风格ID
WORD cost; //使用消费
WORD score; //评分 (score/100)10分制
int paid; //支付次数
int state; //状态
TSTYLEDETAIL detail; //详细信息
tagStyleInfo(){
idStyle = 0;
cost = 0;
score = 0;
paid = 0;
state = 0;
}
}TSTYLEINFO, *PTSTYLEINFO;
typedef struct tagMyStyleInfo
{
TSTYLEINFO tStyleInfo;
int iStyleDownSate; /* 风格下载状态 */
tagMyStyleInfo(){
iStyleDownSate = 0;
}
}DEFTSTYLEINFO,*LPDEFTSTYLEINFO;
//版本结构体
typedef struct
{
WORD majorVersion; //主版本号
WORD minorVersion; //次版本号(客户端类型0=Windows版, 1=Android版, 2=iOS版, 3=风格合成, 4=风格审核 )
WORD modifyVersion; //修改版本号
WORD buildVersion; //编译版本号
}TVERSION, *PTVERSION;
#define MAX_DESCRIB_LENGTH 1024
//软件信息结构体
typedef struct tSoftwareInfo{
int size;
TVERSION version;
UINT nFileSize;
UINT tIssueDate;
char strDescribe[MAX_DESCRIB_LENGTH];
tSoftwareInfo(){
memset( this, 0, sizeof(tSoftwareInfo) );
size = sizeof(tSoftwareInfo);
};
} TSOFTWAREINFO, *PTSOFTWAREINFO;
#pragma pack (4)
//账户信息结构体
typedef struct tAccountInfo{
int ID; //用户ID
UINT authority; //用户权限
int balance; //帐户余额(唱作音符)
int pops; //魅力值
int fans; //粉丝数
int songs; //歌曲数
int vipPeriod; //VIP时长:-1=终身 0=非VIP 其它=vip剩余秒数
tAccountInfo(){
memset( this, 0, sizeof(tAccountInfo) );
};
}TACCOUNTINFO, *PTACCOUNTINFO;
//用户信息结构体
typedef struct tUserInfo{
char strUserName[32];
char strPassword[80];
char strNickName[32]; //用户昵称
char strIconFile[32]; //用户头像
TACCOUNTINFO accountInfo; //账户信息
int ownStyleNum; //已购买风格数
int arrStyleId[16]; //已购买风格ID数组
tUserInfo(){
memset( strUserName, 0, 32 );
memset( strPassword, 0, 80 );
memset( strNickName, 0, 32 );
memset( strIconFile, 0, 32 );
memset( arrStyleId, 0, 16 );
ownStyleNum = 0;
};
}TUSERINFO,*PTUSERINFO;
//字符串对结构体
typedef struct tStringPair{
char str1[320];
char str2[640];
tStringPair(){
memset( str1, 0, 320 );
memset( str2, 0, 640 );
}
} TSTRINGPAIR, *PTSTRINGPAIR;
//上传歌曲信息结构体
typedef struct tSongInfo{
int size; //结构大小
char strSongName[64]; //歌曲名
int iTempo; //速度
char iTS; //节拍
char iCreation; //创作类型 (1:原创 3:改编)
char iSubmit; //提交审核状态(0:不提交,1:自动提交)
char iSingerType; //演唱人类别 (1:男;2:女;3:组合;4:其他;0:未知)
char strSinger[32]; //演唱
char strOriginal[32]; //原唱
char strLyricist[32]; //作词
char strComposer[32]; //作曲
char strArranger[32]; //编曲
char iMusicStyle[4]; //曲风
UINT aStyleIDs[32]; //使用的风格ID
char strDescription[640];//歌曲描述
char* strLyric; //歌词
char* strMp3Name; //mp3临时文件
char* strIconName; //封面临时文件
//上传工程文件
UINT cpjVersion; //工程版本号
int cpjPrice; //下载收费
char* strCpjName; //工程文件名
tSongInfo(){
memset( this, 0, sizeof(tSongInfo) );
memset( iMusicStyle, -1, 4 );
size = sizeof(tSongInfo);
};
~tSongInfo(){
if( strLyric )
delete[] strLyric;
if( strMp3Name )
delete[] strMp3Name;
if( strIconName )
delete[] strIconName;
if( strCpjName )
delete[] strCpjName;
};
} TSONGINFO, *PTSONGINFO;
//上传歌曲返回分享信息结构
typedef struct tShareInfo{
UINT idSong; //歌曲ID
char strSongURL[256]; //歌曲文件URL
char strCoverURL[256]; //歌曲封面URL
tShareInfo(){
memset( this, 0, sizeof(tShareInfo) );
};
} TSHAREINFO, *PTSHAREINFO;
#pragma pack()
extern String u_strTable[];
extern String u_strAlphaTable[];
extern char * GM_INSTRUMENT[];
extern char * LSZ_STYLTYPES[];
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+160
View File
@@ -0,0 +1,160 @@
//---------------------------------------------------------------------------
#ifndef CompleteFormUnitH
#define CompleteFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include "PNGButton.hpp"
#include "CompletePanelUnit.h"
#include "CommonListboxUnit.h"
#include "SkinHintWindow.h"
#include "BackgroundForm.h"
#include <Vcl.Graphics.hpp>
#include <Vcl.Dialogs.hpp>
//---------------------------------------------------------------------------
class TCompleteForm : public TBackgroundForm
{
__published: // IDE-managed Components
// TImage *m_imgBk;
// TImage *m_imgBottomSide;
// TImage *m_imgLeftBottomConner;
// TImage *m_imgRightSide;
// TImage *m_imgRightBottomConner;
TPNGButton *m_btnPrevStep;
TPNGButton *m_btnBeginPos;
TPNGButton *m_btnEndPos;
TPNGButton *m_btnModify;
TPNGButton *m_btnPause;
TPNGButton *m_btnPlay;
TPNGButton *m_btnRecord;
TPNGButton *m_btnStop;
TPNGButton *m_btnVolMicrophoneSet;
TPNGButton *m_btnVolSpeakerSet;
TImage *m_imgBreakH;
TImage *m_imgBreakI;
TImage *m_imgBreakM;
TImage *m_imgBreakR;
CompletePanelUnit::TPanel *m_panelBarsShow;
Vcl::Extctrls::TPanel *m_panelMusicInfo;
TImage *m_imgMusicInfoBk;
TLabel *m_lblPlayTime;
TLabel *m_lblBeat;
TLabel *m_lblTempo;
TLabel *m_lblKey;
Vcl::Extctrls::TPanel *m_panelSpeakerVolSet;
TImage *m_imgSpeakerVolSet;
TPNGButton *m_btnSpeakerVolPos;
Vcl::Extctrls::TPanel *m_panelVolLevel;
TImage *m_imgVolLevelBk;
TPaintBox *m_pbVolLevel;
TPNGButton *m_btnEmptyRight;
TPNGButton *m_btnSave;
TPNGButton *m_btnKeyChange;
CommonListBoxUnit::TListBox *m_lbKeySelect;
TPNGButton *m_btnAudioEffect;
TPNGButton *m_btnUpload;
Vcl::Extctrls::TPanel *m_panelMicrophoneVolSet;
TImage *m_imgMicVolSet;
TPNGButton *m_btnMicrophoneVolPos;
TPNGButton *m_btnMicSet;
void __fastcall FormActivate(TObject *Sender);
void __fastcall StepClick(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall VolLevelPaint(TObject *Sender);
void __fastcall BtnVolSetClick(TObject *Sender);
void __fastcall ImgVolSetMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BtnVolPosMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BtnVolPosMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
void __fastcall BtnVolPosMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall RecordClick(TObject *Sender);
void __fastcall StopClick(TObject *Sender);
void __fastcall PlayClick(TObject *Sender);
void __fastcall PauseClick(TObject *Sender);
void __fastcall ModifyClick(TObject *Sender);
void __fastcall BeginPosClick(TObject *Sender);
void __fastcall EndPosClick(TObject *Sender);
void __fastcall PlayTimeClick(TObject *Sender);
void __fastcall BarsShowMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BarsShowMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
void __fastcall SaveClick(TObject *Sender);
void __fastcall LBKeySelectMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall KeyChangeMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BarsShowMouseLeave(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall BarsShowMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall FormDeactivate(TObject *Sender);
void __fastcall AuidoEffectClick(TObject *Sender);
void __fastcall UploadClick(TObject *Sender);
void __fastcall MicSetClick(TObject *Sender);
void __fastcall BarsShowDblClick(TObject *Sender);
private: // User declarations
//音量相关
DWORD m_dwLastVol;
int m_nVolLevel,
m_nSpeakerVolPos,
m_nMicrophoneVolPos,
m_yPosDragBegin;
bool m_bPosDraging;
//录音/播放相关
bool m_bFromFile,
m_bModifyRecord;
int m_iStartBar,
m_iLastStartBar,
m_iRecordBar;
double m_dblStartPoint,
m_dblLastStartPoint,
m_dblRecordPoint;
UINT m_tTimer, m_tAccuracy;
BOOL m_bIsBeginSel;
//信息显示相关
int m_iHintStage;
TSkinHintWindow * m_pStageInfoWnd;
TTimer *m_pTimerHint;
//拖动相关
int m_iHitBar,m_iHitPoint;
int m_iBX;
bool m_bDragOrHit;
void InitialBarVols();
void ShowPlayTime();
void ComposeWithNewKey();
void HidePopList(CommonListBoxUnit::TListBox* pList);
void ShowErrorMessage( int errcode );
void __fastcall HintTimerProc(TObject* Sender);
MESSAGE void __fastcall UMMediaTime(TMessage &Message);
MESSAGE void __fastcall UMRecordComplete(TMessage &Message);
MESSAGE void __fastcall UMRecordVolJust(TMessage &Message);
MESSAGE void __fastcall OnPlayOver(TMessage &msg);
MESSAGE void __fastcall UMSetFontPosition(TMessage &msg);
MESSAGE void __fastcall UMHidePopControl(TMessage &msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(MSG_MEDIATIME, TMessage, UMMediaTime)
MESSAGE_HANDLER(MSG_RECORD_COMPLETE, TMessage, UMRecordComplete)
MESSAGE_HANDLER(MSG_RECORD_VOLJUST, TMessage, UMRecordVolJust)
MESSAGE_HANDLER(MSG_PLAY_END, TMessage, OnPlayOver)
MESSAGE_HANDLER(UM_SETFONTPOSITION, TMessage, UMSetFontPosition)
MESSAGE_HANDLER(UM_HIDEPOPCONTROL, TMessage, UMHidePopControl)
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TCompleteForm(TComponent* Owner);
void __fastcall EnableNextStep( bool bEnabled );
};
//---------------------------------------------------------------------------
extern PACKAGE TCompleteForm *CompleteForm;
//---------------------------------------------------------------------------
#endif
+354
View File
@@ -0,0 +1,354 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "CompletePanelUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
__fastcall CompletePanelUnit::TPanel::TPanel(TComponent* AOwner)
: TShowBarsPanel(AOwner)
{
m_iModifyBeginBar = m_iModifyBeginPoint =
m_iModifyEndBar = m_iModifyEndPoint = -1;
m_bShowModifyPos = false;
m_imgBeginPos = m_imgEndPos = NULL;
m_nChordWidth = 40;
m_nChordHeight = 20;
}
//---------------------------------------------------------------------------
__fastcall CompletePanelUnit::TPanel::~TPanel()
{
if( m_imgBeginPos )
delete m_imgBeginPos;
if( m_imgEndPos )
delete m_imgEndPos;
}
//---------------------------------------------------------------------------
void CompletePanelUnit::TPanel::InitialVars()
{
//计算总小节数
int nTotalBarCount = 0;
for( int i=0; i<g_lstComposeStages.size(); i++ ){
COMPOSESTAGE* pCStage = g_lstComposeStages[i];
nTotalBarCount += pCStage->nStageBars;
}
TShowBarsPanel::InitialVars( nTotalBarCount );
}
//---------------------------------------------------------------------------
void __fastcall CompletePanelUnit::TPanel::CreateWnd(void)
{
TShowBarsPanel::CreateWnd();
if( !ParentBackground ){
m_imgBeginPos = new TPngImage();
m_imgBeginPos->LoadFromResourceName(int(HInstance), L"RecordBeginPos");
m_imgEndPos = new TPngImage();
m_imgEndPos->LoadFromResourceName(int(HInstance), L"RecordEndPos");
m_nModifyFlagWidth = m_imgBeginPos->Width;
m_nModifyFlagHeight = m_imgBeginPos->Height;
}
}
//---------------------------------------------------------------------------
void __fastcall CompletePanelUnit::TPanel::SetBarTitle( int iBar, String& strText )
{
//
}
//---------------------------------------------------------------------------
void __fastcall CompletePanelUnit::TPanel::DrawBarOperation( int iBar, int leftDraw, int topDraw )
{
if( m_bShowModifyPos ){
//绘制重录起止标志
if( m_iModifyBeginBar==iBar ){
int X = leftDraw + m_iModifyBeginPoint - m_nModifyFlagWidth/2;
int Y = topDraw + 2;
Canvas->Draw(X, Y, m_imgBeginPos);
}
if( m_iModifyEndBar==iBar ){
int X = leftDraw + m_iModifyEndPoint - m_nModifyFlagWidth/2;
int Y = topDraw + 2;
Canvas->Draw(X, Y, m_imgEndPos);
}
}
}
//---------------------------------------------------------------------------
void __fastcall CompletePanelUnit::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];
COLORREF clrNormal, clrDisable;
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){
clrNormal = g_clrEnding[pStage->iMelodyStage - COMPOSE_ENDING_1];
clrDisable = g_clrEndingDisable[pStage->iMelodyStage - COMPOSE_ENDING_1];
}
else if( pStage->iMelodyStage>=COMPOSE_INTRO_1 ){
clrNormal = g_clrIntro[pStage->iMelodyStage - COMPOSE_INTRO_1];
clrDisable = g_clrIntroDisable[pStage->iMelodyStage - COMPOSE_INTRO_1];
}
else{
clrNormal = g_clrStage[pStage->iVar % STAGE_VAR_NUM];
clrDisable = g_clrStageDisable[pStage->iVar % STAGE_VAR_NUM];
}
if( !m_bShowModifyPos || m_iModifyBeginBar<0 && m_iModifyEndBar<0 ||
( m_iModifyEndBar<0 || iBar<m_iModifyEndBar ) && iBar>m_iModifyBeginBar){
Canvas->Brush->Color = clrNormal;
Canvas->FillRect( rectBar );
}
else if( iBar<m_iModifyBeginBar || m_iModifyEndBar>=0 && iBar>m_iModifyEndBar ){
Canvas->Brush->Color = clrDisable;
Canvas->FillRect( rectBar );
}
else{
if( iBar==m_iModifyBeginBar && iBar==m_iModifyEndBar ){
if( m_iModifyBeginPoint>0 ){
Canvas->Brush->Color = clrDisable;
rectBar.right = leftDraw + m_iModifyBeginPoint;
Canvas->FillRect( rectBar );
}
Canvas->Brush->Color = clrNormal;
rectBar.left = leftDraw + m_iModifyBeginPoint;
rectBar.right = leftDraw + m_iModifyEndPoint;
Canvas->FillRect( rectBar );
if( m_iModifyEndPoint<m_nDataWidth-1 ){
Canvas->Brush->Color = clrDisable;
rectBar.left = leftDraw + m_iModifyEndPoint;
rectBar.right = leftDraw + m_nDataWidth;
Canvas->FillRect( rectBar );
}
}
else if( iBar==m_iModifyBeginBar ){
if( m_iModifyBeginPoint>0 ){
Canvas->Brush->Color = clrDisable;
rectBar.right = leftDraw + m_iModifyBeginPoint;
Canvas->FillRect( rectBar );
}
if( m_iModifyBeginPoint<m_nDataWidth-1 ){
Canvas->Brush->Color = clrNormal;
rectBar.left = leftDraw + m_iModifyBeginPoint;
rectBar.right = leftDraw + m_nDataWidth;
Canvas->FillRect( rectBar );
}
}
else if( iBar==m_iModifyEndBar ){
if( m_iModifyEndPoint>0 ){
Canvas->Brush->Color = clrNormal;
rectBar.right = leftDraw + m_iModifyEndPoint;
Canvas->FillRect( rectBar );
}
if( m_iModifyEndPoint<m_nDataWidth-1 ){
Canvas->Brush->Color = clrDisable;
rectBar.left = leftDraw + m_iModifyEndPoint;
rectBar.right = leftDraw + m_nDataWidth;
Canvas->FillRect( rectBar );
}
}
}
}
//---------------------------------------------------------------------------
#define COLOR_WAVE_NEW RGB(15,229,226)
#define COLOR_WAVE_OLD RGB(75,148,147)
void __fastcall CompletePanelUnit::TPanel::DrawBarContext( int iBar, int leftDraw, int topDraw )
{
//绘制波形
TColor clrOld = Canvas->Pen->Color;
int mid = topDraw + m_nDataHeight/2;
BARVOLS *pBV = g_lstCompleteVols[iBar];
if( iBar>=g_lstCompleteVols.size() || pBV->bInvalid )
return;
if( pBV->bRecording )
Canvas->Pen->Color = COLOR_WAVE_NEW;
else
Canvas->Pen->Color = COLOR_WAVE_OLD;
for( int k=0; k<POINTS_PER_BAR; k++ ){
if( pBV->aVols[k]!=0 && pBV->aVols[k]!=-1 ){
DWORD wLeft = LOWORD(pBV->aVols[k]),
wRight = HIWORD(pBV->aVols[k]);
int yTop = mid - ((14 * wLeft )/0x8000),
yBottom = mid + ((14 * wRight )/0x8000);
if( yBottom>yTop ){
Canvas->MoveTo( leftDraw+k, yTop );
Canvas->LineTo( leftDraw+k, yBottom );
}
}
}
Canvas->Pen->Color = clrOld;
}
//---------------------------------------------------------------------------
void __fastcall CompletePanelUnit::TPanel::BarPosChanged()
{
//
}
//---------------------------------------------------------------------------
bool CompletePanelUnit::TPanel::SetModifyPos( bool bBegin, int iNewBar, int iNewPoint )
{
int iBeginBar, iBeginPoint, iEndBar, iEndPoint;
bool bSet = false;
if( bBegin ){
iBeginBar = iNewBar,
iBeginPoint = iNewPoint;
iEndBar = m_iModifyEndBar;
iEndPoint = m_iModifyEndPoint;
int iBPoints = iBeginBar * m_nDataWidth + iBeginPoint,
iEPoints = iEndBar * m_nDataWidth + iEndPoint;
if( iBPoints<0 )
iBPoints = 0;
if( iEPoints<0 )
iEPoints = m_nBarNum * m_nDataWidth - 1;
if( iEPoints >= iBPoints ){
if( iEPoints < iBPoints + 15 ){
iBPoints = iEPoints - 15;
iBeginBar = iBPoints / m_nDataWidth;
iBeginPoint = iBPoints % m_nDataWidth;
}
m_iModifyBeginBar = iBeginBar;
m_iModifyBeginPoint = iBeginPoint;
bSet = true;
}
}
else{
iBeginBar = m_iModifyBeginBar;
iBeginPoint = m_iModifyBeginPoint;
iEndBar = iNewBar;
iEndPoint = iNewPoint;
int iBPoints = iBeginBar * m_nDataWidth + iBeginPoint,
iEPoints = iEndBar * m_nDataWidth + iEndPoint;
if( iBPoints<0 )
iBPoints = 0;
if( iEPoints<0 )
iEPoints = m_nBarNum * m_nDataWidth - 1;
if( iEPoints >= iBPoints ){
if( iEPoints < iBPoints + 15 ){
iEPoints = iBPoints + 15;
iEndBar = iEPoints / POINTS_PER_BAR;
iEndPoint = iEPoints % POINTS_PER_BAR;
}
m_iModifyEndBar = iEndBar;
m_iModifyEndPoint = iEndPoint;
bSet = true;
}
}
Invalidate();
return bSet;
}
//---------------------------------------------------------------------------
void CompletePanelUnit::TPanel::GetModifyPos( bool bBegin, int& iBar, int& iPoint )
{
if( bBegin ){
iBar = m_iModifyBeginBar;
iPoint = m_iModifyBeginPoint;
}
else{
iBar = m_iModifyEndBar;
iPoint = m_iModifyEndPoint;
}
}
//---------------------------------------------------------------------------
void CompletePanelUnit::TPanel::ShowModifyPos( bool bShow )
{
m_bShowModifyPos = bShow;
if( !bShow ){
m_iModifyBeginBar = m_iModifyBeginPoint =
m_iModifyEndBar = m_iModifyEndPoint = -1;
}
Invalidate();
}
//---------------------------------------------------------------------------
int CompletePanelUnit::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 CompletePanelUnit::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 CompletePanelUnit::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 );
}
}
//---------------------------------------------------------------------------
+64
View File
@@ -0,0 +1,64 @@
//---------------------------------------------------------------------------
#ifndef CompletePanelUnitH
#define CompletePanelUnitH
#include "ShowBarsPanelUnit.h"
//---------------------------------------------------------------------------
namespace CompletePanelUnit
{
//---------------------------------------------------------------------------
class TPanel : public TShowBarsPanel
{
__published:
private:
int m_nChordWidth,
m_nChordHeight;
//重录起止位置图标
TPngImage *m_imgBeginPos,
*m_imgEndPos;
//显示相关
int m_nModifyFlagWidth,
m_nModifyFlagHeight;
//录音/播放相关
bool m_bShowModifyPos;
int m_iModifyBeginBar,
m_iModifyBeginPoint,
m_iModifyEndBar,
m_iModifyEndPoint;
int FirstBar( int iStage );
void InvalidateStage( int iStage, int iArea=BAR_DATA );
protected:
virtual void __fastcall CreateWnd();
virtual void __fastcall SetBarTitle( int iBar, String& strText );
virtual void __fastcall DrawBarBkgnd( int iBar, int left, int top );
virtual void __fastcall DrawBarContext( int iBar, int left, int top );
virtual void __fastcall DrawBarOperation( int iBar, int left, int top );
virtual void __fastcall BarPosChanged();
public:
__fastcall virtual TPanel(System::Classes::TComponent* AOwner);
__fastcall ~TPanel();
void InitialVars();
int ComposeBarCount(){ return m_nBarNum; };
bool SetModifyPos( bool bBegin, int iBar, int iPoint );
void GetModifyPos( bool bBegin, int& iBar, int& iPoint );
void ShowModifyPos( bool bShow=true );
int FindStage( int iBar, int *piFirstBar=NULL );
};
}
using namespace CompletePanelUnit;
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+219
View File
@@ -0,0 +1,219 @@
//---------------------------------------------------------------------------
#ifndef ComposeFormUnitH
#define ComposeFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include "PNGButton.hpp"
#include "ComposePanelUnit.h"
#include <Vcl.Graphics.hpp>
#include "PopMenuUnit.h"
#include "ComposeListBoxUnit.h"
#include "SkinHintWindow.h"
#include "BackgroundForm.h"
//---------------------------------------------------------------------------
class TComposeForm : public TBackgroundForm
{
__published: // IDE-managed Components
// TImage *m_imgBk;
// TImage *m_imgBottomSide;
// TImage *m_imgLeftBottomConner;
// TImage *m_imgRightSide;
// TImage *m_imgRightBottomConner;
TImage *m_imgBreakH;
TImage *m_imgBreakI;
TImage *m_imgBreakR;
TPNGButton *m_btnNextStep;
TPNGButton *m_btnPrevStep;
TPNGButton *m_btnRecord;
TPNGButton *m_btnStop;
TPNGButton *m_btnPlay;
TPNGButton *m_btnPause;
ComposePanelUnit::TPanel *m_panelBarsShow;
TPNGButton *m_btnVolAudioSet;
Vcl::Extctrls::TPanel *m_panelAudioVolSet;
TImage *m_imgAudioVolSet;
TPNGButton *m_btnAudioVolPos;
TPNGButton *m_btnVolMusicSet;
Vcl::Extctrls::TPanel *m_panelMusicVolSet;
TImage *m_imgMusicVolSet;
TPNGButton *m_btnMusicVolPos;
TPNGButton *m_btnStyleChange;
Vcl::Extctrls::TPanel *m_panelStyleName;
TImage *m_imgStyleNameBk;
Vcl::Extctrls::TPanel *m_panelMusicInfo;
TImage *m_imgMusicInfoBk;
TLabel *m_lblPlayTime;
TLabel *m_lblBeat;
TLabel *m_lblTempo;
TLabel *m_lblKey;
TLabel *m_lblDiao;
TLabel *m_lblStyleName;
ComposeListBoxUnit::TListBox *m_lbResource;
ComposeListBoxUnit::TListBox *m_lbCompose;
TImage *m_imgResourceHead;
TImage *m_imgComposeHead;
TImage *m_imgComposeTool;
Vcl::Extctrls::TPanel *m_panelResource;
Vcl::Extctrls::TPanel *m_panelCompose;
TPNGButton *m_btnAdd;
TPNGButton *m_btnMoveUp;
TPNGButton *m_btnMoveDown;
TPNGButton *m_btnComposeMin;
TPNGButton *m_btnResourceMin;
TPNGButton *m_btnResourceClose;
TPNGButton *m_btnComposeClose;
TPNGButton *m_btnComposeMax;
TPNGButton *m_btnResourceMax;
Vcl::Extctrls::TPanel *m_panelComposeBottom;
Vcl::Extctrls::TPanel *m_panelListIcon;
TImage *m_imgResourceIcon;
TImage *m_imgComposeIcon;
TPNGButton *m_btnResourceOpen;
TPNGButton *m_btnComposeOpen;
TImage *m_imgDelete;
TPNGButton *m_btnAudioEffect;
TPNGButton *m_btnMicSet;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall FormActivate(TObject *Sender);
void __fastcall StepClick(TObject *Sender);
void __fastcall PlayClick(TObject *Sender);
void __fastcall StopClick(TObject *Sender);
void __fastcall PauseClick(TObject *Sender);
void __fastcall PlayTimeClick(TObject *Sender);
void __fastcall BtnVolSetClick(TObject *Sender);
void __fastcall ImgVolSetMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BtnVolPosMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BtnVolPosMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
void __fastcall BtnVolPosMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall BarsShowMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall ListBoxMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall StageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
void __fastcall StageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
// void __fastcall LBFontSelectMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall StageMouseLeave(TObject *Sender);
void __fastcall BtnListMinClick(TObject *Sender);
void __fastcall BtnListMaxClick(TObject *Sender);
void __fastcall BtnListCloseClick(TObject *Sender);
void __fastcall BtnListShowClick(TObject *Sender);
void __fastcall BtnAddClick(TObject *Sender);
void __fastcall BtnMoveClick(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall BtnStyleChangeClick(TObject *Sender);
// void __fastcall BtnFontChangeClick(TObject *Sender);
void __fastcall FormDeactivate(TObject *Sender);
void __fastcall AudioEffectClick(TObject *Sender);
void __fastcall MicSetClick(TObject *Sender);
private: // User declarations
//音量相关
int m_nAudioVolPos,
m_nMusicVolPos,
m_yPosDragBegin;
bool m_bPosDraging;
//播放/显示相关
int m_iStartBar,
m_iLastStartBar,
m_nTotalBarNum;
double m_dblStartPoint,
m_dblLastStartPoint;
UINT m_tTimer, m_tAccuracy, m_tMusicLen;
//编曲相关
int m_iLastStyleID;
//菜单操作相关
TPopMenu * m_pPopMenu;
int m_iPopBar, m_iPopPoint;
//拖动操作相关
TImage *m_imgDrag;
bool m_bDraging;
int m_iDragingIndex,
m_xImgDrag,
m_yImgDrag; //透明图片相对于鼠标的位置
TBitmap *m_bmpDeleteNormal,
*m_bmpDeleteHover;
//信息显示相关
int m_iHintStage;
TSkinHintWindow *m_pStageInfoWnd;
TTimer *m_pTimerHint;
TObject *m_pHintObject;
//列表位置相关
int m_iResListTop,
m_nResListHeight,
m_iComListTop,
m_nComListHeight;
// void AutoCompose();
void InitResourceList();
void ResetComposeList();
void CalcListSize();
void CheckOperationState();
void DrawDragImg( TObject* Sender, int iSelIndex );
void AddStage( int iMelodyStage );
void DeleteStage( int iComposeStage );
// bool Compose(bool bCombineSong);
void ShowPlayTime();
void SetFocusStage( int iSelIndex );
void BarsLButtonDown( int iHitType, int iHitBar, int iHitPoint, int X, int Y );
void BarsRButtonDown( int iHitType, int iHitBar, int iHitPoint, int X, int Y );
void __fastcall HintTimerProc(TObject* Sender);
void __fastcall OnSelectStageVar( TObject* Sender );
void __fastcall OnSelectBarFill( TObject* Sender );
void __fastcall OnAddStage( TObject* Sender );
void __fastcall OnDeleteStage( TObject* Sender );
void __fastcall OnSetStageStyle( TObject* Sender );
MESSAGE void __fastcall UMMediaTime(TMessage &Message);
// MESSAGE void __fastcall UMEnableReload(TMessage &Message);
MESSAGE void __fastcall UMSelectStyle(TMessage &msg);
MESSAGE void __fastcall UMReload(TMessage &msg);
MESSAGE void __fastcall UMSetFontPosition(TMessage &msg);
MESSAGE void __fastcall UMHidePopControl(TMessage &msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(MSG_MEDIATIME, TMessage, UMMediaTime)
// MESSAGE_HANDLER(UM_ENABLERELOAD, TMessage, UMEnableReload)
MESSAGE_HANDLER(UM_SELECTSTYLE, TMessage, UMSelectStyle)
MESSAGE_HANDLER(UM_RELOAD, TMessage, UMReload)
MESSAGE_HANDLER(UM_SETFONTPOSITION, TMessage, UMSetFontPosition)
MESSAGE_HANDLER(UM_HIDEPOPCONTROL, TMessage, UMHidePopControl)
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TComposeForm(TComponent* Owner);
void __fastcall ChangeChordMode( bool bAlpha );
};
//---------------------------------------------------------------------------
extern PACKAGE TComposeForm *ComposeForm;
//---------------------------------------------------------------------------
#endif
+605
View File
@@ -0,0 +1,605 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ComposeListBoxUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#define COLOR_BORDER RGB(164,115,70)
//---------------------------------------------------------------------------
__fastcall ComposeListBoxUnit::TListBox::TListBox(System::Classes::TComponent* AOwner)
: TSkinListBox(AOwner)
{
m_imgBackground = new TBitmap();
m_imgBackground->LoadFromResourceName(int(HInstance), L"ListBoxBkgrnd");
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_imgDrag = NULL;
m_xImgDrag = m_yImgDrag = -100;
m_iDragOverPos = m_iDragingStage = -1;
m_bDraging = m_bAddStage = false;
}
//---------------------------------------------------------------------------
__fastcall ComposeListBoxUnit::TListBox::~TListBox()
{
if( m_imgBackground ){
delete m_imgBackground;
}
if( m_pFntText ){
delete m_pFntText;
}
}
//---------------------------------------------------------------------------
void __fastcall ComposeListBoxUnit::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 );
}
if( m_bDraging && m_imgDrag ){
//绘制半透明图片
TBlendFunction Blend;
Blend.BlendOp = AC_SRC_OVER;
Blend.BlendFlags = 0;
Blend.AlphaFormat = 0;
Blend.SourceConstantAlpha =160;
::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 ComposeListBoxUnit::TListBox::DrawItem(int Index, const System::Types::TRect &Rect, Winapi::Windows::TOwnerDrawState State)
{
TRect rcDraw, rcOrig = Rect;
// if( rcOrig.Width()<Width ){ //显示滚动条
// rcOrig.right = Width-19; //减去滚动条宽度
// }
rcDraw = rcOrig;
Canvas->Pen->Color = COLOR_BORDER;
//绘制选中框
if( State.Contains(odSelected) ){//|| State.Contains(odFocused) ){
Canvas->Brush->Color = m_clrSelected;
Canvas->FrameRect( rcDraw );
}
else{
//绘制左边框
Canvas->MoveTo( rcDraw.left, rcDraw.top );
Canvas->LineTo( rcDraw.left, rcDraw.bottom );
//绘制右边框
Canvas->MoveTo( rcDraw.right-1, rcDraw.top );
Canvas->LineTo( rcDraw.right-1, rcDraw.bottom );
if( m_bDraging && m_iDragOverPos==Index ){
//绘制Drop提示
Canvas->Pen->Color = clWhite;
for( int i=0; i<2; i++ ){
Canvas->MoveTo( rcDraw.left+1, rcDraw.top );
Canvas->LineTo( rcDraw.right-1, rcDraw.top );
rcDraw.top++;
}
Canvas->Pen->Color = COLOR_BORDER;
Canvas->MoveTo( rcDraw.left+1, rcDraw.top );
Canvas->LineTo( rcDraw.right-1, rcDraw.top );
}
else{
//绘制上阴影
Canvas->Pen->Color = m_clrBevelRaise;
Canvas->MoveTo( rcDraw.left+1, rcDraw.top );
Canvas->LineTo( rcDraw.right-1, rcDraw.top );
}
if( m_bDraging && m_iDragOverPos==Index+1 ){
//绘制Drop提示
Canvas->Pen->Color = clWhite;
for( int i=0; i<2; i++ ){
Canvas->MoveTo( rcDraw.left+1, rcDraw.bottom-1 );
Canvas->LineTo( rcDraw.right-1, rcDraw.bottom-1 );
rcDraw.bottom--;
}
Canvas->Pen->Color = COLOR_BORDER;
Canvas->MoveTo( rcDraw.left+1, rcDraw.bottom-1 );
Canvas->LineTo( rcDraw.right-1, rcDraw.bottom-1 );
}
else{
//绘制下阴影
Canvas->Pen->Color = COLOR_BORDER;
Canvas->MoveTo( rcDraw.left+1, rcDraw.bottom-1 );
Canvas->LineTo( rcDraw.right-1, rcDraw.bottom-1 );
}
}
rcDraw.left++;
rcDraw.right--;
rcDraw.top++;
rcDraw.bottom--;
//绘制底色
COLORREF rColor;
DWORD dwItemData = DWORD(Items->Objects[Index]);
WORD iVar = HIWORD( dwItemData );
int iInd = LOWORD( dwItemData );
if( iInd>=COMPOSE_ENDING_1 ){
rColor = g_clrEnding[iInd-COMPOSE_ENDING_1];
}
else if( iInd>=COMPOSE_INTRO_1 ){
rColor = g_clrIntro[iInd-COMPOSE_INTRO_1];
}
else{
rColor = g_clrStage[iVar];
}
Canvas->Brush->Color = rColor;
Canvas->FillRect( rcDraw );
//绘制列表项文字
TFont * oldFont= Canvas->Font;
Canvas->Font = m_pFntText;
Canvas->Brush->Style = bsClear;
String strText = Items->Strings[Index];
int nTextWidth = Canvas->TextWidth( strText ),
nTextHeight = Canvas->TextHeight( strText );
if( nTextWidth>rcDraw.Width()-4 ){
strText = strText.SubString(0, 8) + "...";
nTextWidth = Canvas->TextWidth( strText );
}
int x = rcDraw.left + ( rcDraw.Width() - nTextWidth ) / 2,
y = rcOrig.top + ( ItemHeight - nTextHeight ) / 2 + 1;
Canvas->TextOut( x, y, strText );
Canvas->Font = oldFont;
if( Rect.top>Height-ItemHeight ){
//绘制下边框
Canvas->MoveTo( rcDraw.left, Height-1 );
Canvas->LineTo( rcDraw.right, Height-1 );
}
if( Index==Items->Count-1 && Rect.bottom<Height ){ //绘制空白部分
TRect rcBlank( rcOrig.left, rcOrig.bottom, rcOrig.right, Height );
//绘制底图
TBitmap * pTempBMP = new TBitmap();
pTempBMP->Width = rcBlank.Width();
pTempBMP->Height = m_imgBackground->Height;
pTempBMP->Canvas->Draw( 0, 0, m_imgBackground );
int y = rcBlank.top;
for( int i=0; i<rcBlank.Height()/pTempBMP->Height; i++ ){
y += pTempBMP->Height;
}
//Canvas->StretchDraw( rcBlank, pTempBMP );
Canvas->StretchDraw( rcBlank, m_imgBackground );
delete pTempBMP;
//绘制边框
Canvas->Pen->Color = COLOR_BORDER;
Canvas->MoveTo( rcBlank.left, rcBlank.top );
Canvas->LineTo( rcBlank.left, rcBlank.bottom-1 );
Canvas->MoveTo( rcBlank.right-1, rcBlank.top );
Canvas->LineTo( rcBlank.right-1, rcBlank.bottom-1 );
Canvas->MoveTo( rcBlank.left, rcBlank.bottom-1 );
Canvas->LineTo( rcBlank.right, rcBlank.bottom-1 );
//绘制底图
rcBlank.left++;
rcBlank.right--;
rcBlank.bottom--;
}
}
//---------------------------------------------------------------------------
void ComposeListBoxUnit::TListBox::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;
TRect rcLastItem = ItemRect( Items->Count-1 );
if( rcLastItem.bottom <= m_yImgDrag ){
rcDrag.top = rcLastItem.bottom-1;
}
m_xImgDrag = m_yImgDrag = -100;
InvalidateRect( Handle, &rcDrag, false );
UpdateDragOverPos( -1 );
m_iDragOverPos = m_iDragingStage = -1;
m_bAddStage = false;
}
m_bDraging = bDraging;
}
}
//---------------------------------------------------------------------------
void ComposeListBoxUnit::TListBox::SetDragStage( bool bAdd, int iStage )
{
m_bAddStage = bAdd;
m_iDragingStage = iStage;
}
//---------------------------------------------------------------------------
void ComposeListBoxUnit::TListBox::SetDragImgPos( int X, int Y )
{
TPoint ptScreen(X, Y),
ptClient = ScreenToClient( ptScreen );
TRect rcClient = GetClientRect();
RECT rcDrag;
if( m_bDraging && ( 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) ) ){
TRect rcLastItem = ItemRect( Items->Count-1 );
if( rcLastItem.bottom <= m_yImgDrag ){
rcDrag.top = rcLastItem.bottom-1;
}
InvalidateRect( Handle, &rcDrag, false );
}
}
m_xImgDrag = ptClient.x, m_yImgDrag = ptClient.y;
if( m_bDraging ){
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 ComposeListBoxUnit::TListBox::SetDragingPoint( int X, int Y )
{
BOOL bCanDrop = false;
int iNewPos = ItemAtPos( TPoint(X,Y), false );
TRect rcItem;
if( Items->Count==0 ){
return true;
}
if( iNewPos>=0 ){
if( iNewPos<Items->Count ){
rcItem = ItemRect( iNewPos );
if( Y > rcItem.top+rcItem.Height()/2 )
iNewPos++;
}
//检查是否可Drop
bCanDrop = true;
COMPOSESTAGE* pStage = NULL;
if( m_bAddStage ){
if( m_iDragingStage>=COMPOSE_ENDING_1 ){ //拖动的是尾奏
int nStageSize = g_lstComposeStages.size();
if( iNewPos<nStageSize ){
bCanDrop = false;
}
else{
pStage = g_lstComposeStages[nStageSize-1];
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){ //曲式中已有尾奏
bCanDrop = false;
}
}
}
else if( iNewPos>0 ){
pStage = g_lstComposeStages[iNewPos-1];
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){ //放置在尾奏后
bCanDrop = false;
}
}
}
else{
if( m_iDragingStage==iNewPos || m_iDragingStage==iNewPos-1 ){
iNewPos = -1;
}
else{
COMPOSESTAGE* pStage = g_lstComposeStages[m_iDragingStage];
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){
bCanDrop = false;
}
else if( iNewPos==Items->Count ){
pStage = g_lstComposeStages[iNewPos-1];
if( pStage->iMelodyStage>=COMPOSE_ENDING_1 ){
bCanDrop = false;
}
}
}
}
}
//更新Drop提示
if( !bCanDrop )
iNewPos = -1;
UpdateDragOverPos( iNewPos );
return bCanDrop;
}
//---------------------------------------------------------------------------
void ComposeListBoxUnit::TListBox::UpdateDragOverPos( int iNewPos )
{
int iOldPos = m_iDragOverPos;
TRect rcItem;
RECT rcUpdate;
if( iOldPos!=iNewPos ){
m_iDragOverPos = iNewPos;
if( iOldPos!=-1 ){
//清除原提示
if( iOldPos<Items->Count ){
rcItem = ItemRect( iOldPos );
rcUpdate.left = rcItem.Left;
rcUpdate.right = rcItem.right;
rcUpdate.top = rcItem.top;
rcUpdate.bottom = rcItem.bottom;
InvalidateRect( Handle, &rcUpdate, false );
}
if( iOldPos>0 ){
rcItem = ItemRect( iOldPos-1 );
rcUpdate.left = rcItem.Left;
rcUpdate.right = rcItem.right;
rcUpdate.top = rcItem.top;
rcUpdate.bottom = rcItem.bottom;
InvalidateRect( Handle, &rcUpdate, false );
}
}
if( iNewPos!=-1 ){
//显示提示
if( iNewPos<Items->Count ){
rcItem = ItemRect( iNewPos );
rcUpdate.left = rcItem.Left;
rcUpdate.right = rcItem.right;
rcUpdate.top = rcItem.top;
rcUpdate.bottom = rcItem.bottom;
InvalidateRect( Handle, &rcUpdate, false );
}
if( iNewPos>0 ){
rcItem = ItemRect( iNewPos-1 );
rcUpdate.left = rcItem.Left;
rcUpdate.right = rcItem.right;
rcUpdate.top = rcItem.top;
rcUpdate.bottom = rcItem.bottom;
InvalidateRect( Handle, &rcUpdate, false );
}
}
}
}
//---------------------------------------------------------------------------
int ComposeListBoxUnit::TListBox::SetDropPoint( int X, int Y )
{
int iInsertPos = 0;
if( Items->Count>0 ){
iInsertPos = ItemAtPos( TPoint(X,Y), false );
if( iInsertPos>=0 ){
if( iInsertPos<Items->Count ){
TRect rcItem = ItemRect( iInsertPos );
if( Y > rcItem.top+rcItem.Height()/2 )
iInsertPos++;
}
//检查是否可Drop
COMPOSESTAGE* pStage = NULL;
if( m_bAddStage ){
if( m_iDragingStage>=COMPOSE_ENDING_1 ){ //拖动的是尾奏
int nStageSize = g_lstComposeStages.size();
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==Items->Count ){
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 ComposeListBoxUnit::TListBox::InsertStage( int iStage, int iInsertPos )
{
UpdateDragOverPos( -1 );
MELODYSTAGE *pMStage = NULL;
COMPOSESTAGE* pCStage = NULL;
String strText;
DWORD dwItemData;
if( iStage>=COMPOSE_ENDING_1 ){
int iEnding = iStage - COMPOSE_ENDING_1;
strText.printf( L"(%d小节)", g_arrEndingBarNum[iEnding] );
strText = g_strEnding[iEnding] + strText;
dwItemData = iStage;
}
else if( iStage>=COMPOSE_INTRO_1 ){
int iIntro = iStage - COMPOSE_INTRO_1;
strText.printf( L"(%d小节)", g_arrIntroBarNum[iIntro] );
strText = g_strIntro[iIntro] + strText;
dwItemData = iStage;
}
else{
pMStage = g_lstMelodyStages[iStage];
strText = String(GetStageName( iStage ).c_str()) + L"段 " + String(g_strStageVar[pMStage->iVar]);
dwItemData = MAKELONG(iStage, pMStage->iVar);
}
Items->InsertObject( iInsertPos, strText, (TObject*)dwItemData );
Selected[iInsertPos] = true; //重设选中位置
}
//---------------------------------------------------------------------------
void ComposeListBoxUnit::TListBox::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 ComposeListBoxUnit::TListBox::DeleteStage( int iStage )
{
if( iStage>=0 ){
Items->Delete( iStage );
}
}
//---------------------------------------------------------------------------
void ComposeListBoxUnit::TListBox::MoveStage( int iSource, int iDest )
{
UpdateDragOverPos( -1 );
if( iSource<iDest )
iDest--;
Items->Move( iSource,iDest ); //交换位置
Selected[iDest] = true; //重设选中位置
}
//---------------------------------------------------------------------------
+56
View File
@@ -0,0 +1,56 @@
//---------------------------------------------------------------------------
#ifndef ComposeListBoxUnitH
#define ComposeListBoxUnitH
//---------------------------------------------------------------------------
#include "SkinListBoxUnit.h"
namespace ComposeListBoxUnit
{
//---------------------------------------------------------------------------
class TListBox : public TSkinListBox
{
private:
TBitmap *m_imgBackground;
TImage *m_imgDrag;
int m_xImgDrag,
m_yImgDrag,
m_iDragOverPos,
m_iDragingStage;
bool m_bDraging,
m_bAddStage;
TFont * m_pFntText;
COLORREF m_clrSelected,
m_clrBevelRaise,
m_clrBevelLower;
void UpdateDragOverPos( int iNewPos );
protected:
virtual void __fastcall DrawItem(int Index, const System::Types::TRect &Rect, Winapi::Windows::TOwnerDrawState State);
DYNAMIC void __fastcall DragCanceled(void){};
MESSAGE void __fastcall WMPaint(Winapi::Messages::TWMPaint &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_PAINT, TWMPaint, WMPaint)
END_MESSAGE_MAP(TSkinListBox)
public:
__fastcall virtual TListBox(System::Classes::TComponent* AOwner);
__fastcall ~TListBox();
void SetDragImage( TImage* img ){ m_imgDrag=img; };
void SetDragState( bool bDraging );
void SetDragStage( bool bAdd, int iStage );
void SetDragImgPos( int X, int Y );
BOOL SetDragingPoint( int X, int Y );
int SetDropPoint( int X, int Y );
void InsertStage( int iStage, int iInsertPos );
void AddStage( int iStage );
void DeleteStage( int iStage );
void MoveStage( int iSource, int iDest );
};
}
using namespace ComposeListBoxUnit;
#endif
+982
View File
@@ -0,0 +1,982 @@
//---------------------------------------------------------------------------
#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)
{
}
//---------------------------------------------------------------------------
*/
+85
View File
@@ -0,0 +1,85 @@
//---------------------------------------------------------------------------
#ifndef ComposePanelUnitH
#define ComposePanelUnitH
//---------------------------------------------------------------------------
#include "ShowBarsPanelUnit.h"
//#include "BackupUnit.h"
namespace ComposePanelUnit
{
//---------------------------------------------------------------------------
class TPanel : public TShowBarsPanel
{
__published:
void __fastcall StageHeaderMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
private:
TComponentList * m_lstStageHeader;
// TComposeBackup m_bkCompose;
// TMelodyBackup m_bkMelody;
TImage *m_imgDrag;
int m_xImgDrag,
m_yImgDrag,
m_iDragOverPos,
m_iDragingStage;
bool m_bDraging,
m_bAddStage;
int m_nChordWidth,
m_nChordHeight,
m_iFocusStage;
TImage * NewStageHeader( int iStage );
void UpdateStageHeader( int iStage );
void AddStageHeader( int iInsStage, int iShowBar, int iComposeStage );
void RemoveStageHeader( int iDelStage );
void UpdateDragOverPos( int iNewPos );
int FirstBar( int iStage );
void InvalidateStage( int iStage, int iArea=BAR_DATA );
void UpdateHeaders( int iStart=0 );
protected:
virtual void __fastcall CreateWnd();
virtual void __fastcall Paint(void);
virtual void __fastcall SetBarTitle( int iBar, String& strText );
virtual void __fastcall DrawBarBkgnd( int iBar, int left, int top );
virtual void __fastcall DrawBarContext( int iBar, int left, int top );
virtual void __fastcall DrawBarOperation( int iBar, int left, int top );
virtual void __fastcall BarPosChanged();
// DYNAMIC void __fastcall KeyDown(System::Word &Key, System::Classes::TShiftState Shift);
public:
__fastcall virtual TPanel(System::Classes::TComponent* AOwner);
__fastcall ~TPanel();
void InitialVars();
int ComposeBarCount(){ return m_nBarNum; };
// BOOL CheckModify( int iCheckType=CHECK_ALL );
// void BackupModify();
// void RestoreModify();
int FindStage( int iBar, int *piFirstBar=NULL );
void SetFocusStage( int iStage );
void SetBarFill( int iBar, int iFill );
void SetStageVar( int iStage, int iVar );
void SetStageStyle( int iStage, int idStyle );
void SetDragImage( TImage* img ){ m_imgDrag = img; };
void SetDragState( bool bDraging );
void SetDragStage( bool bAdd, int iStage );
void SetDragImgPos( int X, int Y );
BOOL SetDragingPoint( int X, int Y );
int SetDropPoint( int X, int Y );
void InsertStage( int iStage, int iInsertPos );
void AddStage( int iStage );
void DeleteStage( int iStage );
void MoveStage( int iSource, int iDest );
};
}
using namespace ComposePanelUnit;
#endif
+146
View File
@@ -0,0 +1,146 @@
//---------------------------------------------------------------------------
#ifndef ComposeStageUnitH
#define ComposeStageUnitH
//---------------------------------------------------------------------------
#include <vector>
using namespace std;
#define POINTS_PER_BAR 120
#define CHECK_STAGE_LENGTH 1
#define CHECK_STAGE_VAR 2
#define CHECK_STAGE_EVENT 3
#define CHECK_STAGE_ALL 4
/***************************************************************************************/
// 全局类定义
/***************************************************************************************/
/*
class CFill
{
public:
int iPos;
int iType;
CFill( int pos, int type ){
iPos = pos;
iType = type;
}
CFill( CFill* pFill ){
iPos = pFill->iPos;
iType = pFill->iType;
}
};
class CVolumeSet
{
public:
UINT iChannel;
UINT nVolSet;
UINT nVolConfirm;
UINT nVolInit;
CVolumeSet( UINT chan, UINT volSet, UINT volComfirm, UINT volInit ){
iChannel = chan;
nVolSet = volSet;
nVolConfirm = volComfirm;
nVolInit = volInit;
}
CVolumeSet( CVolumeSet* pSet ){
iChannel = pSet->iChannel;
nVolSet = pSet->nVolSet;
nVolConfirm = pSet->nVolConfirm;
nVolInit = pSet->nVolInit;
}
};
class CInstrumentSet
{
public:
UINT iChannel;
UINT nInsSet;
UINT nInsConfirm;
UINT nInsInit;
CInstrumentSet( UINT chan, UINT insSet, UINT insComfirm, UINT insInit ){
iChannel = chan;
nInsSet = insSet;
nInsConfirm = insComfirm;
nInsInit = insInit;
}
CInstrumentSet( CInstrumentSet* pSet ){
iChannel = pSet->iChannel;
nInsSet = pSet->nInsSet;
nInsConfirm = pSet->nInsConfirm;
nInsInit = pSet->nInsInit;
}
};
*/
typedef struct tagBarVols
{
DWORD aVols[POINTS_PER_BAR];
bool bRecording,
bInvalid;
tagBarVols()
{
bRecording = true;
bInvalid = false;
memset( aVols, 0, POINTS_PER_BAR*sizeof(DWORD) );
}
} BARVOLS, *PBARVOLS;
typedef struct tagMelodyBar
{
BARVOLS tBarVol;
char iFill;
char iChords[2];
tagMelodyBar()
{
iFill = -1;
iChords[0] = iChords[1] = -1;
}
} MELODYBAR, *PMELODYBAR;
typedef struct tagMelodyStage //旋律分段信息
{
int iFirstBar;
int iLastBar;
int iVar;
} MELODYSTAGE, *PMELODYSTAGE;
typedef struct tagComposeStage //曲式分段信息
{
int iMelodyStage; //旋律或前间尾奏号
int nStageBars; //该段小节数
int iVar; //伴奏类型
int idStyle; //风格ID
vector<DWORD> aFills; //加花LOWORD=小节数 HIWORD=类型
string strStyleName;
tagComposeStage()
{
iMelodyStage = -1;
nStageBars = 0;
iVar = -1;
idStyle = -1;
}
~tagComposeStage()
{
aFills.clear();
}
} COMPOSESTAGE, *PCOMPOSESTAGE;
typedef vector<PBARVOLS> BARVOLSLIST;
typedef vector<PMELODYBAR> MELODYBARLIST;
typedef vector<PMELODYSTAGE> MELODYSTAGELIST;
typedef vector<PCOMPOSESTAGE> COMPOSESTAGELIST;
#endif
+67
View File
@@ -0,0 +1,67 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CustomerSettingFormUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TCustomerSettingForm *CustomerSettingForm;
//---------------------------------------------------------------------------
#define LEN_BKG_EXTERNAL_ROUND (1)
#define LEN_BKG_EXTERNAL_FRMAE (1)
#define LEN_BKG_INTERNAL_LINE (23)
//---------------------------------------------------------------------------
__fastcall TCustomerSettingForm::TCustomerSettingForm(TComponent* Owner)
: TForm(Owner)
{
int nHeightTmp = m_pTextButtonOK->Top - CSPANEL_START - CSPANEL_HEIGHT;
m_pCSPanel = new TCustmerSettingPanel(this);
m_pCSPanel->Parent = this;
m_pCSPanel->Left = CSPANEL_LEFT;
m_pCSPanel->Top = CSPANEL_START + nHeightTmp/2;
m_pCSPanel->Width = Width - CSPANEL_LEFT - CSPANEL_RIGHT;
m_pCSPanel->Height = CSPANEL_HEIGHT;
//»æÖÆÔ²½Ç´°Ìå
HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+1, 16, 16 );
SetWindowRgn( Handle, hRgn, false );
DeleteObject( hRgn );
SetTransparent( this );
}
//---------------------------------------------------------------------------
__fastcall TCustomerSettingForm::~TCustomerSettingForm()
{
if( m_pCSPanel ){
delete m_pCSPanel;
m_pCSPanel = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TCustomerSettingForm::FormShow(TObject *Sender)
{
m_pCSPanel->SetContent();
}
//---------------------------------------------------------------------------
void __fastcall TCustomerSettingForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if( Msg.Result==HTCLIENT &&
(Msg.YPos<Top+LEN_BKG_INTERNAL_LINE) &&
(Msg.XPos<(Left+ m_PNGButtonClose->Left) ) )
{
Msg.Result = HTCAPTION;
}
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+44
View File
@@ -0,0 +1,44 @@
//---------------------------------------------------------------------------
#ifndef CustomerSettingFormUnitH
#define CustomerSettingFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include "CustomerSettingPanelUnit.h"
#include "PNGButton.hpp"
#include <Vcl.Imaging.jpeg.hpp>
//---------------------------------------------------------------------------
class TCustomerSettingForm : public TForm
{
__published: // IDE-managed Components
TPNGButton *m_pTextButtonOK;
TPNGButton *m_pTextButtonCancel;
TPNGButton *m_PNGButtonClose;
TImage *m_pImageBKG;
TLabel *m_pLabelTitle;
void __fastcall FormShow(TObject *Sender);
private: // User declarations
void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
END_MESSAGE_MAP( TForm )
public: // User declarations
TCustmerSettingPanel *m_pCSPanel;
__fastcall TCustomerSettingForm(TComponent* Owner);
__fastcall ~TCustomerSettingForm();
};
//---------------------------------------------------------------------------
extern PACKAGE TCustomerSettingForm *CustomerSettingForm;
//---------------------------------------------------------------------------
#endif
+453
View File
@@ -0,0 +1,453 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CustomerSettingPanelUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
#define SCOLLBAR_WIDTH (14)
#define TOP_BUTTOM (10)
#define LEFT_RIGHT (SCOLLBAR_WIDTH + 20)
const static COLORREF
CLR_TXT_HOT = RGB(0, 0, 0),
// CLR_BKG_INTERNAL = RGB(207, 163, 124),
CLR_BKG_INTERNAL = RGB(230, 204, 179),
CLR_BKG_INTERNAL_LIGHT = RGB(234, 184, 140),
CLR_CONTENT_DB_LINE_DARK = RGB(192, 148, 109),
CLR_CONTENT_DB_LINE_LIGHT = RGB(237, 193, 154),
COLOR_BORDER = RGB(186,124,83);
//---------------------------------------------------------------------------
__fastcall TCustmerSettingPanel::TCustmerSettingPanel( TComponent* Owner)
: Vcl::Extctrls::TPanel( Owner )
{
m_ScrollBar = NULL;
m_iTopLine =0;
m_iShowLine = 1;
m_iTotalLine= 6;
m_ckInitProject = new TCheckBox(this);
m_ckDownloadStyle = new TCheckBox(this);
m_ckPreBeat = new TCheckBox(this);
m_cbChordMode = new TComboBox(this);
m_cbPreStage = new TComboBox(this);
m_cbPreSortMode = new TComboBox(this);
m_cbPreSortUD = new TComboBox(this);
m_ckInitProject->Parent = this;
m_ckDownloadStyle->Parent = this;
m_ckPreBeat->Parent = this;
m_cbChordMode->Parent = this;
m_cbPreStage->Parent = this;
m_cbPreSortMode->Parent = this;
m_cbPreSortUD->Parent = this;
}
//---------------------------------------------------------------------------
void __fastcall TCustmerSettingPanel::CreateWnd()
{
Vcl::Extctrls::TPanel::CreateWnd();
SetShowLine();
Canvas->Font->Assign(m_ckPreBeat->Font);
}
//---------------------------------------------------------------------------
__fastcall TCustmerSettingPanel::~TCustmerSettingPanel()
{
if( m_ScrollBar ){
delete m_ScrollBar;
m_ScrollBar = NULL;
}
if( m_ckInitProject ){
delete m_ckInitProject;
m_ckInitProject = NULL;
}
if( m_ckDownloadStyle ){
delete m_ckDownloadStyle;
m_ckDownloadStyle = NULL;
}
if( m_ckPreBeat ){
delete m_ckPreBeat;
m_ckPreBeat = NULL;
}
if( m_cbChordMode ){
delete m_cbChordMode;
m_cbChordMode = NULL;
}
if( m_cbPreStage ){
delete m_cbPreStage;
m_cbPreStage = NULL;
}
if( m_cbPreSortMode ){
delete m_cbPreSortMode;
m_cbPreSortMode = NULL;
}
if( m_cbPreSortUD ){
delete m_cbPreSortUD;
m_cbPreSortUD = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TCustmerSettingPanel::WMEraseBkgnd(TWMEraseBkgnd &Message)
{
TRect rect = GetClientRect();
TCanvas* tempCanvas = new TCanvas;
tempCanvas->Handle = Message.DC;
tempCanvas->Brush->Color = CLR_BKG_INTERNAL; //背景颜色
tempCanvas->FillRect( rect );
tempCanvas->Brush->Color = CLR_CONTENT_DB_LINE_DARK;
tempCanvas->FrameRect( rect );
delete tempCanvas;
tempCanvas = NULL;
// DefaultHandler( &Message );
}
//---------------------------------------------------------------------------
void __fastcall TCustmerSettingPanel::WMVScroll(Winapi::Messages::TWMScroll &Message)
{
int minpos, maxpos, page, curpos;
m_ScrollBar->GetScrollRange(&minpos, &maxpos);
page = m_ScrollBar->GetPageSize();
// Get the current position of scroll box.
curpos = m_ScrollBar->GetScrollPos();
// Determine the new position of scroll box.
switch (Message.ScrollCode)
{
case SB_TOP: // Scroll to far top.
curpos = minpos;
break;
case SB_BOTTOM: // Scroll to far bottom.
curpos = maxpos-page+1;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINEUP: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINEDOWN: // Scroll right.
if (curpos < maxpos-page+1)
curpos++;
break;
case SB_PAGEUP: // Scroll one page left.
if (curpos > minpos)
curpos = (minpos > curpos-page) ? minpos : curpos-page;
//max(minpos, curpos-page);
break;
case SB_PAGEDOWN: // Scroll one page right.
if( curpos<maxpos )
curpos = (maxpos-page+1 < curpos+page) ? maxpos-page+1 : curpos+page;
//min(maxpos-page+1, curpos+page);
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = Message.Pos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = Message.Pos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb (scroll box).
if( m_ScrollBar && Message.ScrollBar!=m_ScrollBar->Handle ){
m_ScrollBar->SetPosition(curpos);
// Paint();
}
if( m_iTopLine != curpos ){
m_iTopLine = curpos;
Invalidate();
}
Message.Result = true;
}
//---------------------------------------------------------------------------
void __fastcall TCustmerSettingPanel::WMMouseWheel(TWMMouseWheel &Message)
{
if( m_ScrollBar && m_ScrollBar->Visible ){
UINT nSBCode;
if( Message.WheelDelta>0 ) nSBCode = SB_LINEUP;
else nSBCode = SB_LINEDOWN;
Perform( WM_VSCROLL, MAKELONG(nSBCode,0), NULL );
}
}
//---------------------------------------------------------------------------
void __fastcall TCustmerSettingPanel::SetShowLine()
{
int totalLine = m_iTotalLine;
m_iShowLine = Height/LINE_HEIGHT;
if( totalLine>m_iShowLine ){
m_ScrollBar = new TSkinScrollBar(this);
m_ScrollBar->m_pWndCtrl = this;
m_ScrollBar->Parent = this;
m_ScrollBar->Height = Height-2;
m_ScrollBar->Left = Width - m_ScrollBar->Width - 1;
m_ScrollBar->Top = 1;
m_ScrollBar->Ctl3D = false;
m_ScrollBar->ParentCtl3D = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TCustmerSettingPanel::SetContent()
{
m_ckInitProject->Caption = L"启动时自动打开上次工程";
m_ckDownloadStyle->Caption = L"自动下载风格";
m_ckPreBeat->Caption = L"录音时使用预设风格节拍提示";
m_ckInitProject->Font->Color = CLR_TXT_HOT;
m_ckDownloadStyle->Font->Color = CLR_TXT_HOT;
m_ckPreBeat->Font->Color = CLR_TXT_HOT;
m_ckInitProject->Width = 250;
m_ckDownloadStyle->Width = 250;
m_ckPreBeat->Width = 250;
m_cbChordMode->Ctl3D = false;
m_cbChordMode->ParentCtl3D = false;
m_cbChordMode->Style = csDropDownList;
m_cbChordMode->Items->Add(L"级数");
m_cbChordMode->Items->Add(L"英文");
m_cbChordMode->Height = 24;
m_cbChordMode->Width = 60;
m_cbPreStage->Ctl3D = false;
m_cbPreStage->ParentCtl3D = false;
m_cbPreStage->Style = csDropDownList;
m_cbPreStage->Items->Add(L"M");
m_cbPreStage->Items->Add(L"IME");
m_cbPreStage->Items->Add(L"IMIME");
m_cbPreStage->Height = 24;
m_cbPreStage->Width = 60;
m_cbPreSortMode->Ctl3D = false;
m_cbPreSortMode->ParentCtl3D = false;
m_cbPreSortMode->Style = csDropDownList;
m_cbPreSortMode->Items->Add(L"发布时间");
m_cbPreSortMode->Items->Add(L"价格");
m_cbPreSortMode->Items->Add(L"评分");
m_cbPreSortMode->Height = 24;
m_cbPreSortMode->Width = 75;
m_cbPreSortUD->Ctl3D = false;
m_cbPreSortUD->ParentCtl3D = false;
m_cbPreSortUD->Style = csDropDownList;
m_cbPreSortUD->Items->Add(L"递增");
m_cbPreSortUD->Items->Add(L"递减");
m_cbPreSortUD->Height = 24;
m_cbPreSortUD->Width = 60;
m_ckInitProject->OnClick = CKBoxChange;
m_ckDownloadStyle->OnClick = CKBoxChange;
m_ckPreBeat->OnClick = CKBoxChange;
m_cbChordMode->OnChange = CBChange;
m_cbPreStage->OnChange = CBChange;
m_cbPreSortMode->OnChange = CBChange;
m_cbPreSortUD->OnChange = CBChange;
m_bAutoOpenProject = g_bAutoOpenProject;
m_bDownloadStyle = g_bAutoDownloadStyle;
m_bAlphaKey = g_iShowType;
m_cPreStage = g_iPreStageDefault;
m_iPreStyleSort = g_iPreStyleSort;
m_ckInitProject->Checked = g_bAutoOpenProject;
m_ckDownloadStyle->Checked = g_bAutoDownloadStyle;
m_ckPreBeat->Checked = g_bPrebeat;
m_cbChordMode->ItemIndex = g_iShowType;
m_cbPreStage->ItemIndex = g_iPreStageDefault;
m_cbPreSortMode->ItemIndex = g_iPreStyleSort & 0xffff;
m_cbPreSortUD->ItemIndex = (g_iPreStyleSort & 0xffff0000) >> 16;
if(m_ScrollBar) {
m_ScrollBar->SetRange( 0,m_iTotalLine-1 );
m_ScrollBar->SetPageSize(m_iShowLine);
m_ScrollBar->SetPosition( m_iTopLine );
m_ScrollBar->Visible = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TCustmerSettingPanel::Paint(void)
{
int curX = 0;
int curY = 0;
int contentHeight = LINE_HEIGHT;
int contentStart = -m_iTopLine*LINE_HEIGHT;
TSize sizeFont;
String strText;
TFont *fntOld = new TFont;
fntOld->Assign( Canvas->Font );
Canvas->Font->Color = CLR_TXT_HOT;
Canvas->Brush->Style = bsClear;
/////////////////////////////////////////////////
curX = LEFT_RIGHT;
curY = contentStart;
m_ckInitProject->Left = curX;
m_ckInitProject->Top = curY + (contentHeight - m_ckInitProject->Height)/2;
/////////////////////////////////////////////////
contentStart += LINE_HEIGHT;
curY = contentStart;
m_ckDownloadStyle->Left = curX;
m_ckDownloadStyle->Top = curY + (contentHeight - m_ckDownloadStyle->Height)/2;
/////////////////////////////////////////////////
contentStart += LINE_HEIGHT;
curY = contentStart;
m_ckPreBeat->Left = curX;
m_ckPreBeat->Top = curY + (contentHeight - m_ckPreBeat->Height)/2;
/////////////////////////////////////////////////
contentStart += LINE_HEIGHT;
curX = LEFT_RIGHT + 5;
strText = L"和弦显示方式:";
sizeFont = Canvas->TextExtent(strText);
curY = contentStart + (contentHeight - sizeFont.Height)/2;
Canvas->TextOutW(curX, curY, strText);
curX += sizeFont.Width + 10;
curY = contentStart;
m_cbChordMode->Left = curX;
m_cbChordMode->Top = curY + (contentHeight - m_cbChordMode->Height)/2;
strText = L" * 示例:";
sizeFont = Canvas->TextExtent(strText);
curX += m_cbChordMode->Width + 10;
curY = contentStart + (contentHeight - sizeFont.Height)/2;
Canvas->TextOutW(curX, curY, strText);
if( !m_bAlphaKey ) {
strText = L"VI";
}else{
strText = L"A";
}
Canvas->Font->Name = "Times New Roman";
Canvas->Font->Quality = TFontQuality::fqClearTypeNatural;
Canvas->Font->Color = CLR_TXT_HOT;
Canvas->Font->Style = TFontStyles()<<fsItalic<<fsBold;
Canvas->Font->Size = g_szFont16;
curX += sizeFont.Width;
sizeFont = Canvas->TextExtent(strText);
curY = contentStart + (contentHeight - sizeFont.Height)/2;
Canvas->TextOutW(curX, curY, strText);
strText = L"m";
curX += sizeFont.Width;
curY += 7;
Canvas->Font->Size = g_szFont9;
Canvas->TextOutW(curX, curY, strText);
Canvas->Font->Assign( fntOld );
delete fntOld;
/////////////////////////////////////////////////
contentStart += LINE_HEIGHT;
curX = LEFT_RIGHT + 5;
strText = L"预设段落结构:";
sizeFont = Canvas->TextExtent(strText);
curY = contentStart + (contentHeight - sizeFont.Height)/2;
Canvas->TextOutW(curX, curY, strText);
curX += sizeFont.Width + 10;
curY = contentStart;
m_cbPreStage->Left = curX;
m_cbPreStage->Top = curY + (contentHeight - m_cbPreStage->Height)/2;
strText = L" * I-前奏、M-旋律、E-尾奏";
sizeFont = Canvas->TextExtent(strText);
curX += m_cbPreStage->Width + 10;
curY = contentStart + (contentHeight - sizeFont.Height)/2;
Canvas->TextOutW(curX, curY, strText);
/////////////////////////////////////////////////
curX = LEFT_RIGHT + 5;
contentStart += LINE_HEIGHT;
strText = L"风格列表排序方式:";
sizeFont = Canvas->TextExtent(strText);
curY = contentStart + (contentHeight - sizeFont.Height)/2;
Canvas->TextOutW(curX, curY, strText);
curX += sizeFont.Width + 10;
curY = contentStart;
m_cbPreSortMode->Left = curX;
m_cbPreSortMode->Top = curY + (contentHeight - m_cbPreStage->Height)/2;
curX += m_cbPreSortMode->Width + 30;
curY = contentStart;
m_cbPreSortUD->Left = curX;
m_cbPreSortUD->Top = curY + (contentHeight - m_cbPreStage->Height)/2;
}
//---------------------------------------------------------------------------
void __fastcall TCustmerSettingPanel::CKBoxChange(TObject* Sender)
{
TCheckBox *tmpCK = (TCheckBox *)Sender;
if( tmpCK == m_ckInitProject ) {
m_bAutoOpenProject = tmpCK->Checked;
}else if( tmpCK == m_ckDownloadStyle ){
m_bDownloadStyle = m_ckDownloadStyle->Checked;
}else if( tmpCK == m_ckPreBeat ){
m_bPreBeat = m_ckPreBeat->Checked;
}
}
//---------------------------------------------------------------------------
void __fastcall TCustmerSettingPanel::CBChange(TObject* Sender)
{
TComboBox *tmpCB = (TComboBox *)Sender;
if( tmpCB == m_cbChordMode ) {
m_bAlphaKey = tmpCB->ItemIndex;
this->Invalidate();
}else if( tmpCB == m_cbPreStage ){
m_cPreStage = tmpCB->ItemIndex;
}else if( tmpCB == m_cbPreSortMode ){
m_iPreStyleSort = (m_iPreStyleSort & 0xffff0000) | tmpCB->ItemIndex;
}else if( tmpCB == m_cbPreSortUD ){
m_iPreStyleSort = (m_iPreStyleSort & 0x0000ffff) |
(tmpCB->ItemIndex<<16);
}
if(m_ScrollBar)
m_ScrollBar->SetFocus();
}
//---------------------------------------------------------------------------
+65
View File
@@ -0,0 +1,65 @@
//---------------------------------------------------------------------------
#ifndef CustomerSettingPanelUnitH
#define CustomerSettingPanelUnitH
#include "SkinScrollBarUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#define LINE_HEIGHT (33)
#define CSPANEL_START (26)
#define CSPANEL_LEFT (10)
#define CSPANEL_RIGHT (CSPANEL_LEFT)
#define CSPANEL_HEIGHT (200)
//---------------------------------------------------------------------------
class TCustmerSettingPanel : public Vcl::Extctrls::TPanel
{
private:
int m_iShowLine;
int m_iTopLine;
int m_iTotalLine;
TSkinScrollBar *m_ScrollBar;
TCheckBox *m_ckInitProject;
TCheckBox *m_ckDownloadStyle;
TCheckBox *m_ckPreBeat;
TComboBox *m_cbChordMode;
TComboBox *m_cbPreStage;
TComboBox *m_cbPreSortMode;
TComboBox *m_cbPreSortUD;
void __fastcall CKBoxChange(TObject* Sender);
void __fastcall CBChange(TObject* Sender);
void __fastcall SetShowLine();
virtual void __fastcall CreateWnd();
virtual void __fastcall Paint(void);
MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message);
MESSAGE void __fastcall WMVScroll(Winapi::Messages::TWMScroll &Message);
MESSAGE void __fastcall WMMouseWheel(TWMMouseWheel &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
MESSAGE_HANDLER(WM_VSCROLL, TWMVScroll, WMVScroll)
MESSAGE_HANDLER(WM_MOUSEWHEEL, TWMMouseWheel, WMMouseWheel)
END_MESSAGE_MAP( Vcl::Extctrls::TPanel )
public:
bool m_bAutoOpenProject;
bool m_bDownloadStyle;
bool m_bPreBeat;
bool m_bAlphaKey;
char m_cPreStage;
int m_iPreStyleSort;
void __fastcall SetContent();
__fastcall TCustmerSettingPanel( TComponent* Owner);
__fastcall ~TCustmerSettingPanel();
};
//---------------------------------------------------------------------------
#endif
+3411
View File
File diff suppressed because it is too large Load Diff
+1365
View File
File diff suppressed because it is too large Load Diff
+282
View File
@@ -0,0 +1,282 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "HelpFormUnit.h"
#include "MessageFormUnit.h"
#include "ProgressFormUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
USEFORM("MessageFormUnit.cpp", MessageForm);
THelpForm *HelpForm;
//---------------------------------------------------------------------------
__fastcall THelpForm::THelpForm(TComponent* Owner)
: TBackgroundForm(Owner)
{
m_iPrevPageIndex = 0;
m_nUserNoticeNum = 0;
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::FormCreate(TObject *Sender)
{
SetTransparent( this );
m_arrTabs[TAB_QA] = m_btnQnA;
m_arrTabs[TAB_FB] = m_btnFeedback;
m_arrTabs[TAB_NT] = m_btnUserNT;
m_arrTabs[TAB_CN] = m_btnCoin;
//通知图片
m_pImgNoticeTip = new TPngImage();
m_pImgNoticeTip->LoadFromResourceName(int(HInstance), "ImgNoticeTip");
m_panelShow->SetTextFontSize(m_memMsg->Font->Size);
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::FormActivate(TObject *Sender)
{
if( Sender ){
return;
}
// m_lblUrl->Caption = g_strServerURL;
m_pbUserNoticeNum->Visible = (m_nUserNoticeNum>0);
m_memMsg->Enabled = !g_bUpdateMandatory;
m_panelShow->InitialVars();
m_panelShow->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::FormDeactivate(TObject *Sender)
{
if( Application->ActiveFormHandle!=Application->MainFormHandle ){
return;
}
m_panelShow->SaveFirstRow();
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::PrevStepClick(TObject *Sender)
{
PostMessage(Application->MainFormHandle, UM_JUMP_PAGE, WPARAM(m_iPrevPageIndex),LPARAM(0));
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::TabClick(TObject *Sender)
{
int mode = ((TButton*)Sender)->Tag;
SetPage( mode );
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::FormResize(TObject *Sender)
{
m_btnPrevStep->Top = Height - DPIY( 494 - 460 );
m_imgBreakH->Width = Width - DPIX(28);
m_panelShow->SetBounds( m_panelShow->Left,
m_panelShow->Top,
Width,
Height - DPIY(84) );
int hGap = DPIY(20);
m_memMsg->Width = m_panelShow->Width - DPIX(36);
m_btnSubmit->Left = m_panelShow->Width - DPIX(82);
m_lblGroupLabel->Top = m_panelShow->Height - hGap;
m_lblGroup->Top = m_panelShow->Height - hGap;
m_lblEmailLabel->Top = m_panelShow->Height - hGap;
m_lblVidio->Top = m_panelShow->Height - hGap;
m_lblUrlLabel->Top = m_panelShow->Height - hGap;
m_lblUrl->Top = m_panelShow->Height - hGap;
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::HelpClick(TObject *Sender)
{
PostMessage(Application->MainForm->Handle, UM_OPENMANUAL, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::MoreClick(TObject *Sender)
{
PostMessage(Application->MainForm->Handle, UM_SHOWMORE, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::MemoMsgClick(TObject *Sender)
{
if( m_bMemoHint ){
m_memMsg->Text = "";
m_memMsg->Font->Color = clBlack;
m_bMemoHint = false;
}
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::MemoMsgChange(TObject *Sender)
{
if( !m_bMemoHint && !m_memMsg->Text.Trim().IsEmpty() ){
m_btnSubmit->Enabled = true;
}
else{
m_btnSubmit->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::SubmitClick(TObject *Sender)
{
TProgressForm *frmProgress = new TProgressForm(NULL);
string msg = GBToUTF8(((AnsiString)m_memMsg->Text.Trim()).c_str()).c_str();
int ret = frmProgress->User_SubmitQuestin( msg.c_str() );
int eExtra = frmProgress->GetOpertaionResult();
delete frmProgress;
if( ret==mrOk ){
if( eExtra==0 ){
m_panelShow->AddFeedback( m_memMsg->Text.Trim().c_str() );
m_memMsg->Text = "";
}
else{
MessageForm->ShowMessage( "由于网络故障,信息提交失败。\n请稍后重试!",
MB_ICONERROR|MB_OK );
}
}
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::panelShowClick(TObject *Sender)
{
m_panelShow->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::AboutClick(TObject *Sender)
{
PostMessage(Application->MainForm->Handle, UM_SHOWABOUT, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::UrlClick(TObject *Sender)
{
if( m_lblUrl->Caption.Length()>0 ){
ShellExecute(Handle,NULL, m_lblUrl->Caption.c_str(), NULL,NULL,SW_SHOWNORMAL);
}
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::SetNoticeNum( int num, int iType )
{
if( iType==1 && m_nUserNoticeNum!=num ){
m_nUserNoticeNum = num;
m_pbUserNoticeNum->Visible = (num>0);
if( num>0 ){
m_pbUserNoticeNum->Invalidate();
}
if( m_arrTabs[TAB_NT]->Down ){
m_lblMsgNum->Caption = m_nUserNoticeNum;
m_lblMsgHead->Visible = (num>0);
m_lblMsgMiddle->Visible = (num>0);
m_lblMsgNum->Visible = (num>0);
m_lblMsgURL->Visible = (num>0);
m_lblMsgTail->Visible = (num>0);
m_panelShow->InitialVars();
}
}
}
//---------------------------------------------------------------------------
int __fastcall THelpForm::GetNoticeNum( int iType )
{
if( iType!=0 )
return m_nUserNoticeNum;
return 0;
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::SetPage( int iPage )
{
for( int i=0; i<4; i++ ){
if( i==iPage ){
m_arrTabs[i]->Down = true;
}
else{
m_arrTabs[i]->Down = false;
}
}
if( iPage==2 ){
m_lblMsgNum->Caption = m_nUserNoticeNum;
}
else if( iPage==1 && ( m_memMsg->Text.IsEmpty()
|| m_memMsg->Font->Color==clGray )){
m_bMemoHint = true;
m_memMsg->Text = "请在此处输入您的问题";
m_memMsg->Font->Color = clGray;
}
m_lblMsgHead->Visible = (iPage==2 && m_nUserNoticeNum>0);
m_lblMsgMiddle->Visible = (iPage==2 && m_nUserNoticeNum>0);
m_lblMsgNum->Visible = (iPage==2 && m_nUserNoticeNum>0);
m_lblMsgURL->Visible = (iPage==2 && m_nUserNoticeNum>0);
m_lblMsgTail->Visible = (iPage==2 && m_nUserNoticeNum>0);
m_btnSubmit->Visible = (iPage==1);
m_memMsg->Visible = (iPage==1);
m_panelShow->SetMode( iPage );
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::MsgURLClick(TObject *Sender)
{
char strURL[256];
f_CS_GetWebPageURL( URL_USERNOTICE, strURL );
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::NoticeNumPaint(TObject *Sender)
{
TPaintBox* pPB = (TPaintBox*)Sender;
String strText = m_nUserNoticeNum;
pPB->Canvas->Draw(0, 0, m_pImgNoticeTip);
pPB->Canvas->Brush->Style = bsClear;
pPB->Canvas->Font->Color = clWhite;
int txtWidth = pPB->Canvas->TextWidth( strText );
int txtHeight = pPB->Canvas->TextHeight( strText );
pPB->Canvas->TextOut( (pPB->Width - txtWidth)/2.0+0.5,
(pPB->Height -txtHeight)/2.0,
strText );
}
//---------------------------------------------------------------------------
void __fastcall THelpForm::VidioClick(TObject *Sender)
{
ShellExecute(Handle,NULL, L"http://player.youku.com/player.php/sid/XNDM5MTgxOTQ0/v.swf",
NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
+5481
View File
File diff suppressed because it is too large Load Diff
+101
View File
@@ -0,0 +1,101 @@
//---------------------------------------------------------------------------
#ifndef HelpFormUnitH
#define HelpFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include "PNGButton.hpp"
//#include "TransparentPanelUnit.h"
#include "HelpPanelUnit.h"
#include "BackgroundForm.h"
#define TAB_QA 0
#define TAB_FB 1
#define TAB_NT 2
#define TAB_CN 3
#define TAB_MN 4
#define TAB_SW 5
#define TAB_AB 6
//---------------------------------------------------------------------------
class THelpForm : public TBackgroundForm
{
__published: // IDE-managed Components
// Vcl::Extctrls::TPanel *m_panelShow;
TPaintBox *m_pbUserNoticeNum;
TImage *m_imgBreakH;
TPNGButton *m_btnPrevStep;
// TImage *m_imgRightBottomConner;
// TImage *m_imgRightSide;
// TImage *m_imgLeftBottomConner;
// TImage *m_imgBottomSide;
// TImage *m_imgBk;
TPNGButton *m_btnSubmit;
TPNGButton *m_btnQnA;
TPNGButton *m_btnFeedback;
TPNGButton *m_btnHelp;
TLabel *m_lblGroupLabel;
TLabel *m_lblGroup;
TLabel *m_lblVidio;
TLabel *m_lblEmailLabel;
TMemo *m_memMsg;
HelpPanelUnit::TPanel *m_panelShow;
TPNGButton *m_btnAbout;
TLabel *m_lblUrl;
TLabel *m_lblUrlLabel;
TPNGButton *m_btnUserNT;
TLabel *m_lblMsgHead;
TLabel *m_lblMsgURL;
TLabel *m_lblMsgTail;
TLabel *m_lblMsgNum;
TLabel *m_lblMsgMiddle;
TPNGButton *m_btnCoin;
TPNGButton *m_btnMore;
void __fastcall FormActivate(TObject *Sender);
void __fastcall FormDeactivate(TObject *Sender);
void __fastcall PrevStepClick(TObject *Sender);
void __fastcall TabClick(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall MoreClick(TObject *Sender);
void __fastcall MemoMsgClick(TObject *Sender);
void __fastcall MemoMsgChange(TObject *Sender);
void __fastcall SubmitClick(TObject *Sender);
void __fastcall panelShowClick(TObject *Sender);
void __fastcall AboutClick(TObject *Sender);
void __fastcall UrlClick(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall MsgURLClick(TObject *Sender);
void __fastcall NoticeNumPaint(TObject *Sender);
void __fastcall HelpClick(TObject *Sender);
void __fastcall VidioClick(TObject *Sender);
private: // User declarations
bool m_bMemoHint;
int m_nUserNoticeNum;
TPNGButton* m_arrTabs[5];
TPngImage * m_pImgNoticeTip;
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
END_MESSAGE_MAP(TForm)
public: // User declarations
int m_iPrevPageIndex;
void __fastcall SetNoticeNum( int num, int iType ); //iTyp: 0=public, 1=user
int __fastcall GetNoticeNum( int iType ); //iTyp: -1=all, 0=public, 1=user
void __fastcall SetPage( int iPage );
__fastcall THelpForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE THelpForm *HelpForm;
//---------------------------------------------------------------------------
#endif
+631
View File
@@ -0,0 +1,631 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "HelpPanelUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
const static COLORREF clrEnter = clHighlight,//RGB( 100,180,236 ),
clrLeave = clBlue;//RGB( 67,117,233 );
//---------------------------------------------------------------------------
__fastcall HelpPanelUnit::TPanel::TPanel(TComponent* AOwner)
: Vcl::Extctrls::TPanel(AOwner)
{
m_sbVert = NULL;
m_nLeftBound = 15;
m_nRightBound = 48;
m_nTopBound = 15;
m_nBottomBound = 45;
m_nRowWidth = 0;
m_nRowHight = 22;
m_iMode = 0;
m_nBeginShowRow = 0;
for( int i=0; i<MODE_NUM; i++ ){
m_aFirstRow[i] = m_aFirstTitle[i] = 0;
}
m_lblCoinPage = NULL;
}
//---------------------------------------------------------------------------
void __fastcall HelpPanelUnit::TPanel::CreateWnd(void)
{
Vcl::Extctrls::TPanel::CreateWnd();
if( !ParentBackground ){
if( m_imgBackground ) return;
m_sbVert = new TSkinScrollBar(this);
m_sbVert->Parent = this;
m_sbVert->m_pWndCtrl = this;
m_sbVert->Visible = false;
m_sbVert->Left = ClientWidth - m_sbVert->Width - 1;
m_sbVert->Top = 1;
m_sbVert->Height = ClientHeight-2;
CalcViewArea();
m_imgBackground = new TBitmap();
m_imgBackground->LoadFromResourceName(int(HInstance), L"CustomPanelBackground");
m_lblCoinPage = new TLabel( NULL );
m_lblCoinPage->Visible = false;
m_lblCoinPage->Transparent = true;
m_lblCoinPage->Parent = this;
m_lblCoinPage->Font->Name = "Tahoma";
// m_lblCoinPage->Font->Size = int(11 * 96.0 / g_yDpi + 0.5);
m_lblCoinPage->Font->Style = TFontStyles()<<fsUnderline;
m_lblCoinPage->Font->Color = clrLeave;
m_lblCoinPage->Caption = "官网详细说明";
m_lblCoinPage->OnClick = LinkClick;
m_lblCoinPage->OnMouseEnter = LinkMouseEnter;
m_lblCoinPage->OnMouseLeave = LinkMouseLeave;
m_lblCoinPage->Left = m_nLeftBound + 20;
}
else{
m_imgBackground = NULL;
m_imgBarTitle = NULL;
}
}
//---------------------------------------------------------------------------
__fastcall HelpPanelUnit::TPanel::~TPanel()
{
if( m_imgBackground )
delete m_imgBackground;
if( m_sbVert )
delete m_sbVert;
while( !m_lstLines.empty() ){
delete m_lstLines[0];
m_lstLines.erase(m_lstLines.begin());
}
}
//---------------------------------------------------------------------------
void HelpPanelUnit::TPanel::InitialVars()
{
RefreshTextLines();
CalcViewArea();
Invalidate();
}
//---------------------------------------------------------------------------
void HelpPanelUnit::TPanel::SetTextFontSize(int size)
{
if( m_lblCoinPage )
m_lblCoinPage->Font->Size = size;
Canvas->Font->Size = size;// int(11 * 96.0 / g_yDpi + 0.5); //字母字体大小
Canvas->Font->Quality = TFontQuality::fqClearTypeNatural;
}
//---------------------------------------------------------------------------
void HelpPanelUnit::TPanel::ScrollView( int nPos, bool bRedraw )
{
if( m_nBeginShowRow!=nPos ){
m_nBeginShowRow = nPos;
Invalidate();
}
if( bRedraw ){
m_sbVert->SetPosition( nPos );
}
}
//---------------------------------------------------------------------------
void HelpPanelUnit::TPanel::CalcViewArea()
{
if( !m_sbVert )
return;
m_nRowNum = m_lstLines.size();
if( m_nRowNum>0 ){
int iFirstRow = m_aFirstRow[m_iMode];
if( iFirstRow<0 ){
int iFirstTitle = m_aFirstTitle[m_iMode];
for( iFirstRow=0; iFirstRow<m_nRowNum && iFirstTitle>0; iFirstRow++ ){
if( m_lstLines[iFirstRow]->strText.empty() ){
iFirstTitle--;
}
}
}
m_nBeginShowRow = iFirstRow;
}
if( m_nRowNum>m_nRowShow ){ //显示滚动条
m_sbVert->Visible = true;
m_sbVert->SetRange( 0, m_nRowNum-1 );
m_sbVert->SetPageSize( m_nRowShow );
m_sbVert->SetPosition( 0 );
//计算显示的第一行
int iRowScroll = 0;
if( m_nBeginShowRow>0 ){
iRowScroll = min( m_nBeginShowRow, m_nRowNum-m_nRowShow );
if( iRowScroll<0 ){
iRowScroll = 0;
}
}
ScrollView( iRowScroll );
}
else{
m_nBeginShowRow = 0;
m_sbVert->Visible = false;
}
}
//---------------------------------------------------------------------------
void __fastcall HelpPanelUnit::TPanel::Paint()
{
if( !ParentBackground && !m_lstLines.empty() ){
int xPos = m_nLeftBound,
yPos = m_nTopBound;
TColor clrOld = Canvas->Font->Color;
Canvas->Brush->Style = bsClear;
int flag = 0;
for( int i=0; i<m_lstLines.size(); i++ ){
TLineString* pLine = m_lstLines[i];
if( pLine->flag>0 && pLine->flag!=flag ){
flag = pLine->flag;
if( flag==1 ){
Canvas->Font->Color = COLOR_QUESTION;
if( m_iMode<2 )
Canvas->Font->Style = TFontStyles()<<fsBold;
}
else{
Canvas->Font->Color = COLOR_ANSWER;
Canvas->Font->Style = TFontStyles();
}
}
if( i>=m_nBeginShowRow ){
char strFlag[10];
if( pLine->flag==1 ){
if( m_iMode<2 )
strcpy( strFlag, "Q:" );
else{
strcpy( strFlag, "△" );
}
Canvas->TextOut( xPos, yPos, strFlag );
}
else if( pLine->flag==2 ){
if( m_iMode<2 )
strcpy( strFlag, "A:" );
else{
strcpy( strFlag, " " );
}
Canvas->TextOut( xPos, yPos, strFlag );
}
else if(pLine->flag == 3)
{
strcpy( strFlag, "●" );
Canvas->Font->Color = RGB(255, 0, 0);
Canvas->Font->Style = TFontStyles() << fsBold;
Canvas->TextOut( xPos, yPos, strFlag );
//Canvas->Font->Color = RGB(0, 0, 255);
}
Canvas->TextOut( xPos+20, yPos, pLine->strText.c_str() );
yPos += m_nRowHight;
}
if( i-m_nBeginShowRow >= m_nRowShow ){
break;
}
}
Canvas->Font->Color = clrOld;
Canvas->Font->Style = TFontStyles();
}
}
//---------------------------------------------------------------------------
void __fastcall HelpPanelUnit::TPanel::WMEraseBkgnd(Winapi::Messages::TWMEraseBkgnd &Message)
{
if( m_imgBackground ){
TCanvas* tempCanvas = new TCanvas;
tempCanvas->Handle = Message.DC;
//绘制底图
int cx = ClientWidth/m_imgBackground->Width + 1;
int cy = ClientHeight/m_imgBackground->Height + 1;
for (int i=0; i<cx; i++)
for (int j=0; j<cy; j++)
tempCanvas->Draw(i*m_imgBackground->Width,
j*m_imgBackground->Height,
m_imgBackground);
//绘制外边框
tempCanvas->Brush->Color = COLOR_BORDER;
TRect rect = GetClientRect();
tempCanvas->FrameRect(rect);
delete tempCanvas;
Message.Result = true;
}
else{
DefaultHandler( &Message );
}
}
//---------------------------------------------------------------------------
void __fastcall HelpPanelUnit::TPanel::WMSize(Winapi::Messages::TWMSize &Message)
{
DefaultHandler( &Message );
if( ParentBackground )
return;
if( m_sbVert ){
m_sbVert->Left = ClientWidth - m_sbVert->Width - 1;
m_sbVert->Top = 1;
m_sbVert->Height = ClientHeight - 2;
}
m_nRowWidth = ClientWidth - m_nLeftBound - m_nRightBound;
m_nRowShow = (ClientHeight - m_nTopBound - m_nBottomBound) / m_nRowHight;
SaveFirstRow();
for(int i=0; i<MODE_NUM; i++ ){
m_aFirstRow[i] = -1; //第一行无效
}
// m_iFirstRowMode0 = m_iFirstRowMode1 = -1;
RefreshTextLines();
CalcViewArea();
}
//---------------------------------------------------------------------------
void __fastcall HelpPanelUnit::TPanel::WMVScroll(Winapi::Messages::TWMScroll &Message)
{
int minpos, maxpos, page, curpos;
m_sbVert->GetScrollRange(&minpos, &maxpos);
page = m_sbVert->GetPageSize();
// Get the current position of scroll box.
curpos = m_sbVert->GetScrollPos();
// Determine the new position of scroll box.
switch (Message.ScrollCode)
{
case SB_TOP: // Scroll to far top.
curpos = minpos;
break;
case SB_BOTTOM: // Scroll to far bottom.
curpos = maxpos-page+1;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINEUP: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINEDOWN: // Scroll right.
if (curpos < maxpos-page+1)
curpos++;
break;
case SB_PAGEUP: // Scroll one page left.
if (curpos > minpos)
curpos = (minpos > curpos-page) ? minpos : curpos-page;
//max(minpos, curpos-page);
break;
case SB_PAGEDOWN: // Scroll one page right.
if( curpos<maxpos )
curpos = (maxpos-page+1 < curpos+page) ? maxpos-page+1 : curpos+page;
//min(maxpos-page+1, curpos+page);
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = Message.Pos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = Message.Pos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb (scroll box).
if( Message.ScrollBar!=m_sbVert->Handle )
m_sbVert->SetPosition(curpos);
ScrollView(curpos, FALSE);
Message.Result = true;
}
//---------------------------------------------------------------------------
void __fastcall HelpPanelUnit::TPanel::WMMouseWheel(TWMMouseWheel &Message)
{
if( m_sbVert->Visible ){
UINT nSBCode;
if( Message.WheelDelta>0 ) nSBCode = SB_LINEUP;
else nSBCode = SB_LINEDOWN;
Perform( WM_VSCROLL, MAKELONG(nSBCode,0), NULL );
}
}
//---------------------------------------------------------------------------
void HelpPanelUnit::TPanel::SetMode( int iMode )
{
if( m_iMode != iMode ){
SaveFirstRow();
if( iMode==0 || iMode==3){
m_nTopBound = 15;
}
else if( iMode==2 ){
m_nTopBound = 60;
}
else{
m_nTopBound = 160;
}
m_nRowShow = (ClientHeight - m_nTopBound - m_nBottomBound) / m_nRowHight;
m_iMode = iMode;
RefreshTextLines();
CalcViewArea();
Invalidate();
}
m_lblCoinPage->Visible = m_iMode==3;
}
//---------------------------------------------------------------------------
void HelpPanelUnit::TPanel::RefreshTextLines()
{
int i;
//清空列表
for( i=0; i<m_lstLines.size(); i++ ){
delete m_lstLines[i];
}
m_lstLines.clear();
//读取字符串
int idUser = g_bLogon ? g_infoUser.accountInfo.ID : 0;
int num = 0;
if( m_iMode==0 )
f_CS_GetQnA( num, NULL, false, 0 );
else if( m_iMode==1 )
f_CS_GetQnA( num, NULL, true, idUser );
// else if( m_iMode==2 )
// f_CS_GetNotice( num, NULL, 0 );
else if( m_iMode==2 && idUser )
f_CS_GetNotice( num, NULL, idUser );
else if(m_iMode == 3)
ReadData();
if( num>0 ){
TSTRINGPAIR* arrString = new TSTRINGPAIR[num];
bool bRevert = true;
if( m_iMode==0 ){
f_CS_GetQnA( num, arrString, false, 0 );
bRevert = false;
}
else if( m_iMode==1 )
f_CS_GetQnA( num, arrString, true, idUser );
// else if( m_iMode==2 )
// f_CS_GetNotice( num, arrString, 0 );
else if( m_iMode==2 )
f_CS_GetNotice( num, arrString, idUser );
for( i=(bRevert?num-1:0); bRevert?i>=0:i<num; bRevert?i--:i++ ){
//处理提问
wstring strQ = str2wstr( UTF8ToMBCS( arrString[i].str1 ) );
TLineString * pLine = new TLineString;
pLine->flag = 1; //question
int nWidth = 0;
int iStart = 0;
for(int j=0; j<strQ.size(); j++ ){
nWidth += Canvas->TextWidth( strQ[j] );
if( nWidth>=m_nRowWidth || strQ[j]=='\n' ){
pLine->strText = strQ.substr( iStart, j-iStart );
if( strQ[j]=='\n' ) j++;
iStart = j;
nWidth = 0;
m_lstLines.push_back( pLine );
if( iStart<strQ.size() ){
pLine = new TLineString;
}
}
}
if( iStart<strQ.size() ){
pLine->strText = strQ.substr( iStart, strQ.size()-iStart );
m_lstLines.push_back( pLine );
}
wstring strA;
if( m_iMode==2 ){
AnsiString strSpace= L"&nbsp;";
AnsiString anStr = arrString[i].str2;
int pos = 0;
while( pos = anStr.Pos( strSpace ) ){
anStr.Delete( pos, strSpace.Length() );
anStr.Insert( L" ", pos );
}
strA = str2wstr( UTF8ToMBCS( anStr.c_str() ) );
}
else{
strA = str2wstr( UTF8ToMBCS( arrString[i].str2 ) );
}
pLine = new TLineString;
pLine->flag = 2; //answer
if( strA.size()>0 ){
nWidth = 0;
iStart = 0;
for(int j=0; j<strA.size(); j++ ){
nWidth += Canvas->TextWidth( strA[j] );
if( nWidth>=m_nRowWidth || strA[j]=='\n' ){
pLine->strText = strA.substr( iStart, j-iStart );
if( strA[j]=='\n' ) j++;
iStart = j;
nWidth = 0;
m_lstLines.push_back( pLine );
if( iStart<strA.size() ){
pLine = new TLineString;
}
}
}
if( iStart<strA.size() ){
pLine->strText = strA.substr( iStart, strA.size()-iStart );
m_lstLines.push_back( pLine );
}
}
else{
pLine->strText = L"暂时还没有答复";
m_lstLines.push_back( pLine );
}
if( bRevert ? i>0 : i<num-1 ){ //break
pLine = new TLineString;
m_lstLines.push_back( pLine );
}
}
delete[] arrString;
}
}
//---------------------------------------------------------------------------
void HelpPanelUnit::TPanel::AddFeedback( wstring str )
{
RefreshTextLines();
m_nBeginShowRow = 0;
CalcViewArea();
Invalidate();
}
//---------------------------------------------------------------------------
void HelpPanelUnit::TPanel::SaveFirstRow()
{
int iFirstRow = m_nBeginShowRow;
int iFirstTitle = 0;
for( int i=0; i<m_lstLines.size() && i<=iFirstRow; i++ ){
if( m_lstLines[i]->strText.empty() ){
iFirstTitle++;
}
}
m_aFirstRow[m_iMode] = iFirstRow;
m_aFirstTitle[m_iMode] = iFirstTitle;
}
void HelpPanelUnit::TPanel::ReadData()
{
String str = L"@说明:\n 唱作音符是唱作网的虚拟货币,在唱作魔方软件使用中会\
用到唱作音符。\n@获取途径:\n 唱作音符主要来源于充值兑换,在唱作网的\
活动中也可获取。\n 另外,注册用户时也会赠予一定音符。\n";
wchar_t *data = str.c_str();
TLineString *pLine = new TLineString;
int nWidth = 0;
int iStart = 0;
for(int i = 0; i < str.Length(); i++)
{
nWidth += Canvas->TextWidth(String(data[i]));
if(nWidth >= m_nRowWidth || data[i] == '\n')
{
if(data[iStart] == L'@')
{
pLine->strText = (str.SubString(iStart + 2, i - iStart + 1)).c_str();
pLine->flag = 3;
}
else
{
pLine->flag = 4;
pLine->strText = (str.SubString(iStart, i - iStart + 1)).c_str();
}
if(data[i] == '\n')
{
i++;
}
iStart = i;
nWidth = 0;
m_lstLines.push_back(pLine);
pLine = new TLineString;
}
}
pLine->strText = (str.SubString(iStart, str.Length() - iStart + 1)).c_str();
pLine->flag = 4;
m_lstLines.push_back(pLine);
m_lblCoinPage->Top = m_nTopBound + ( m_lstLines.size() + 1 ) * m_nRowHight;
}
//---------------------------------------------------------------------------
void __fastcall HelpPanelUnit::TPanel::LinkClick(TObject *Sender)
{
char strURL[256];
f_CS_GetWebPageURL( URL_COINSPEC, strURL );
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall HelpPanelUnit::TPanel::LinkMouseEnter(TObject *Sender)
{
((TLabel*)Sender)->Font->Color = clrEnter;
Screen->Cursor = crHandPoint;
}
//---------------------------------------------------------------------------
void __fastcall HelpPanelUnit::TPanel::LinkMouseLeave(TObject *Sender)
{
((TLabel*)Sender)->Font->Color = clrLeave;
Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
+122
View File
@@ -0,0 +1,122 @@
//---------------------------------------------------------------------------
#ifndef HelpPanelUnitH
#define HelpPanelUnitH
#include "SkinScrollBarUnit.h"
#include <Vcl.Imaging.pngimage.hpp>
#define COLOR_BORDER RGB(164,115,70)
#define COLOR_QUESTION RGB(255,0,0)
#define COLOR_ANSWER RGB(0,0,255)
#include <vector>
using namespace std;
#define MODE_NUM 5
typedef struct{
wstring str1;
wstring str2;
} TWSPAIR;
typedef vector< TWSPAIR* > TWSPAIRLIST;
typedef struct tagLineString{
int flag;
wstring strText;
tagLineString(){
flag = 0;
}
} TLineString;
typedef vector< TLineString* > TTEXTLINE;
namespace HelpPanelUnit
{
//---------------------------------------------------------------------------
class TPanel : public Extctrls::TPanel
{
private:
//背景及小节栏图片
TBitmap *m_imgBackground,
*m_imgBarTitle;
// TWSPAIRLIST m_lstWStrPair[MODE_NUM];
// TWSPAIRLIST m_lstFeedback;
TTEXTLINE m_lstLines;
TLabel *m_lblCoinPage;
int m_iMode; //显示模式 0=常见问题,1=我要提问,2=网站公告,3=空间消息
int m_iLastMode; //上次显示模式
char m_CharBuf[2048];
void CalcViewArea();
void ReadData();
void __fastcall LinkClick(TObject *Sender);
void __fastcall LinkMouseEnter(TObject *Sender);
void __fastcall LinkMouseLeave(TObject *Sender);
MESSAGE void __fastcall WMEraseBkgnd(Winapi::Messages::TWMEraseBkgnd &Message);
MESSAGE void __fastcall WMSize(Winapi::Messages::TWMSize &Message);
MESSAGE void __fastcall WMVScroll(Winapi::Messages::TWMScroll &Message);
MESSAGE void __fastcall WMMouseWheel(TWMMouseWheel &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
MESSAGE_HANDLER(WM_SIZE, TWMSize, WMSize)
MESSAGE_HANDLER(WM_VSCROLL, TWMVScroll, WMVScroll)
MESSAGE_HANDLER(WM_MOUSEWHEEL, TWMMouseWheel, WMMouseWheel)
END_MESSAGE_MAP(Vcl::Extctrls::TPanel)
//protected:
//显示相关
int m_nRowShow,
m_nBeginShowRow,
m_nRowNum,
m_nPosFlag,
m_nPosText,
/* m_iFirstRowMode0,
m_iFirstRowMode1,
m_iFirstQAMode0,
m_iFirstQAMode1,
*/
m_aFirstRow[MODE_NUM],
m_aFirstTitle[MODE_NUM],
m_nRowWidth,
m_nRowHight,
m_nLeftBound,
m_nRightBound,
m_nTopBound,
m_nBottomBound;
TSkinScrollBar *m_sbVert;
virtual void __fastcall CreateWnd();
virtual void __fastcall Paint(void);
void RefreshTextLines();
public:
void ScrollView( int nPos, bool bRedraw=true );
void SetMode( int iMode );
void AddFeedback( wstring str );
void SaveFirstRow();
void InitialVars();
void SetTextFontSize(int size);
__fastcall virtual TPanel(System::Classes::TComponent* AOwner);
__fastcall ~TPanel();
};
}
using namespace HelpPanelUnit;
#endif
+373
View File
@@ -0,0 +1,373 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <IdHTTP.hpp>
//#include <IdTCPClient.hpp>
//#include <IdTCPConnection.hpp>
//#include <IdHTTPServer.hpp>
//#include <IdTCPServer.hpp>
//#include <IdBaseComponent.hpp>
//#include <IdComponent.hpp>
//#include <IdMultipartFormData.hpp>
#include "ImgCopperExUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
bool GetPicType(String &name, TMemoryStream *tmpMemoryStream, bool bBac)
{
bool bReturn = true;
tmpMemoryStream->Position = 0;
WORD wType = 0;
tmpMemoryStream->ReadBuffer(&wType, 2);
String tmpName = name;
if( wType==0x4D42 ){ //bmp
if( bBac )
name = ChangeFileExt(name, L".bmp");
}else if( wType==0x5089 ){ //png
if( bBac )
name = ChangeFileExt(name, L".png");
}else if( wType==0xD8FF ) { //jpg
if( bBac )
name = ChangeFileExt(name, L".jpg");
}else bReturn = false;
if( bReturn && bBac )
CopyFile(tmpName.c_str(), name.c_str(), false);
return bReturn;
}
//---------------------------------------------------------------------------
VCBMPEDGE g_VCBMPEDGE;
TBitmap* resizableImage(TBitmap *imgDest, TRect rectDest,
int tagSrc, String resourceNameSrc,
UIEdgeInsets insetsSrc,
System::Uitypes::TColor TransparentColor)
{
// ------judge the image is handled
bool bFindBMPEDGE = false;
BMPEDGE *pBMPEDGE = NULL;
for( VCBMPEDGE::iterator vc_pFindVCBMPEDGE = g_VCBMPEDGE.begin();
vc_pFindVCBMPEDGE != g_VCBMPEDGE.end();
vc_pFindVCBMPEDGE++ )
{
if( tagSrc==(*vc_pFindVCBMPEDGE)->iTag ) {
pBMPEDGE = *vc_pFindVCBMPEDGE;
bFindBMPEDGE = true;
break;
}
}
// ------l r t b cl cr ct cb c cn get bitmap
if( NULL==pBMPEDGE ) {
pBMPEDGE = new BMPEDGE(tagSrc, resourceNameSrc);
pBMPEDGE->pImgLeftT = new TBitmap();
pBMPEDGE->pImgLeftB = new TBitmap();
pBMPEDGE->pImgRightT = new TBitmap();
pBMPEDGE->pImgRightB = new TBitmap();
pBMPEDGE->pImgCenterL = new TBitmap();
pBMPEDGE->pImgCenterR = new TBitmap();
pBMPEDGE->pImgCenterT = new TBitmap();
pBMPEDGE->pImgCenterB = new TBitmap();
pBMPEDGE->pImgCenter = new TBitmap();
pBMPEDGE->pImgBMPSrc = new TBitmap();
pBMPEDGE->pImgBMPSrc->LoadFromResourceName(int(HInstance), resourceNameSrc);
}
TBitmap *imgSrc = pBMPEDGE->pImgBMPSrc;
// ------ l r t b cl cr ct cb c cn rect
int iLeft, iTop, iWidth, iHeight;
int iLeftNew, iTopNew, iWidthNew, iHeightNew;
iLeft = 0;
iTop = 0;
iWidth = imgSrc->Width;
iHeight = imgSrc->Height;
TRect rectSrc = TRect(0, 0, iWidth, iHeight);
iLeftNew = 0;
iTopNew = 0;
iWidthNew = rectDest.Width();
iHeightNew = rectDest.Height();
UIEdgeInsets insets;
if( !bFindBMPEDGE ) {
pBMPEDGE->insetsDest.left = insetsSrc.left;
pBMPEDGE->insetsDest.right = insetsSrc.right;
pBMPEDGE->insetsDest.top = insetsSrc.top;
pBMPEDGE->insetsDest.bottom = insetsSrc.bottom;
insets = insetsSrc;
}else{
insets = pBMPEDGE->insetsDest;
}
int LEFTT_WIDTH = insets.left;
int LEFTT_HEIGHT = insets.top;
int LEFTB_WIDTH = insets.left;
int LEFTB_HEIGHT = insets.bottom;
int RIGHTT_WIDTH = insets.right;
int RIGHTT_HEIGHT = insets.top;
int RIGHTB_WIDTH = insets.right;
int RIGHTB_HEIGHT = insets.bottom;
int CENTERL_WIDTH = insets.left;
int CENTERL_HEIGHT = rectSrc.Height() - (LEFTT_HEIGHT+LEFTB_HEIGHT);
int CENTERR_WIDTH = insets.right;
int CENTERR_HEIGHT = iHeight - (RIGHTT_HEIGHT+RIGHTB_HEIGHT);
int CENTERT_WIDTH = iWidth - (LEFTT_WIDTH+RIGHTT_WIDTH);
int CENTERT_HEIGHT = insets.top;
int CENTERB_WIDTH = iWidth - (LEFTB_WIDTH+RIGHTB_WIDTH);
int CENTERB_HEIGHT = insets.bottom;
int CENTER_WIDTH = CENTERT_WIDTH;
int CENTER_HEIGHT = iHeight - (CENTERT_HEIGHT+CENTERB_HEIGHT);
int CENTERL_NEW_WIDTH = insets.left;
int CENTERL_NEW_HEIGHT = iHeightNew - (LEFTT_HEIGHT+LEFTB_HEIGHT);
int CENTERR_NEW_WIDTH = insets.right;
int CENTERR_NEW_HEIGHT = CENTERL_NEW_HEIGHT;
int CENTERT_NEW_WIDTH = iWidthNew - (LEFTT_WIDTH+RIGHTT_WIDTH);
int CENTERT_NEW_HEIGHT = insets.top;
int CENTERB_NEW_WIDTH = CENTERT_NEW_WIDTH;
int CENTERB_NEW_HEIGHT = insets.bottom;
int CENTER_NEW_WIDTH = CENTERT_NEW_WIDTH;
int CENTER_NEW_HEIGHT = CENTERL_NEW_HEIGHT;
// ------ size transparent
TBitmap *pImgLeftT = pBMPEDGE->pImgLeftT;
TBitmap *pImgLeftB = pBMPEDGE->pImgLeftB;
TBitmap *pImgRightT = pBMPEDGE->pImgRightT;
TBitmap *pImgRightB = pBMPEDGE->pImgRightB;
TBitmap *pImgCenterL = pBMPEDGE->pImgCenterL;
TBitmap *pImgCenterR = pBMPEDGE->pImgCenterR;
TBitmap *pImgCenterT = pBMPEDGE->pImgCenterT;
TBitmap *pImgCenterB = pBMPEDGE->pImgCenterB;
TBitmap *pImgCenter = pBMPEDGE->pImgCenter;
if( !bFindBMPEDGE ) {
pImgLeftT->SetSize( LEFTT_WIDTH, LEFTT_HEIGHT );
pImgLeftB->SetSize( LEFTB_WIDTH, LEFTB_HEIGHT );
pImgRightT->SetSize( RIGHTT_WIDTH, RIGHTT_HEIGHT );
pImgRightB->SetSize( RIGHTB_WIDTH, RIGHTB_HEIGHT );
pImgCenterL->SetSize( CENTERL_WIDTH, CENTERL_HEIGHT);
pImgCenterR->SetSize( CENTERR_WIDTH, CENTERR_HEIGHT);
pImgCenterT->SetSize( CENTERT_WIDTH, CENTERT_HEIGHT);
pImgCenterB->SetSize( CENTERB_WIDTH, CENTERB_HEIGHT);
pImgCenter->SetSize( CENTER_WIDTH, CENTER_HEIGHT );
pBMPEDGE->SetTransparent(TransparentColor);
}
if( NULL==imgDest ) {
imgDest = new TBitmap();
imgDest->SetSize(iWidthNew, iHeightNew);
}
imgDest->Transparent = true;
imgDest->TransparentColor = clWhite;
// ------new bitmap
if( !bFindBMPEDGE ) {
// -----
StretchBlt(pImgLeftT->Canvas->Handle, 0, 0, LEFTT_WIDTH, LEFTT_HEIGHT,
imgSrc->Canvas->Handle, 0, 0, LEFTT_WIDTH, LEFTT_HEIGHT,
SRCCOPY);
StretchBlt(pImgLeftB->Canvas->Handle, 0, 0, LEFTB_WIDTH, LEFTB_HEIGHT,
imgSrc->Canvas->Handle, 0, iHeight-LEFTB_HEIGHT, LEFTB_WIDTH, LEFTB_HEIGHT,
SRCCOPY);
StretchBlt(pImgRightT->Canvas->Handle, 0, 0, RIGHTT_WIDTH, RIGHTT_HEIGHT,
imgSrc->Canvas->Handle, iWidth-RIGHTT_WIDTH, 0, RIGHTT_WIDTH, RIGHTT_HEIGHT,
SRCCOPY);
StretchBlt(pImgRightB->Canvas->Handle, 0, 0, RIGHTB_WIDTH, RIGHTB_HEIGHT,
imgSrc->Canvas->Handle, iWidth-RIGHTB_WIDTH, iHeight-RIGHTB_HEIGHT, RIGHTB_WIDTH, RIGHTB_HEIGHT,
SRCCOPY);
StretchBlt(pImgCenterL->Canvas->Handle, 0, 0, CENTERL_WIDTH, CENTERL_HEIGHT,
imgSrc->Canvas->Handle, 0, LEFTT_HEIGHT, CENTERL_WIDTH, CENTERL_HEIGHT,
SRCCOPY);
StretchBlt(pImgCenterR->Canvas->Handle, 0, 0, CENTERR_WIDTH, CENTERR_HEIGHT,
imgSrc->Canvas->Handle, iWidth-RIGHTT_WIDTH, RIGHTT_HEIGHT, CENTERR_WIDTH, CENTERR_HEIGHT,
SRCCOPY);
StretchBlt(pImgCenterT->Canvas->Handle, 0, 0, CENTERT_WIDTH, CENTERT_HEIGHT,
imgSrc->Canvas->Handle, LEFTT_WIDTH, 0, CENTERT_WIDTH, CENTERT_HEIGHT,
SRCCOPY);
StretchBlt(pImgCenterB->Canvas->Handle, 0, 0, CENTERB_WIDTH, CENTERB_HEIGHT,
imgSrc->Canvas->Handle, LEFTB_WIDTH, iHeight-LEFTB_HEIGHT, CENTERB_WIDTH, CENTERB_HEIGHT,
SRCCOPY);
StretchBlt(pImgCenter->Canvas->Handle, 0, 0, CENTER_WIDTH, CENTER_HEIGHT,
imgSrc->Canvas->Handle, LEFTT_WIDTH, LEFTT_HEIGHT, CENTER_WIDTH, CENTER_HEIGHT,
SRCCOPY);
}
// -----
StretchBlt(imgDest->Canvas->Handle, 0, 0, LEFTT_WIDTH, LEFTT_HEIGHT,
pImgLeftT->Canvas->Handle, 0, 0, LEFTT_WIDTH, LEFTT_HEIGHT,
SRCCOPY);
StretchBlt(imgDest->Canvas->Handle, 0, iHeightNew-LEFTB_HEIGHT, LEFTB_WIDTH, LEFTB_HEIGHT,
pImgLeftB->Canvas->Handle, 0, 0, LEFTB_WIDTH, LEFTB_HEIGHT,
SRCCOPY);
StretchBlt(imgDest->Canvas->Handle, iWidthNew-RIGHTT_WIDTH, 0, RIGHTT_WIDTH, RIGHTT_HEIGHT,
pImgRightT->Canvas->Handle, 0, 0, RIGHTT_WIDTH, RIGHTT_HEIGHT,
SRCCOPY);
StretchBlt(imgDest->Canvas->Handle, iWidthNew-RIGHTB_WIDTH, iHeightNew-RIGHTB_HEIGHT, RIGHTB_WIDTH, RIGHTB_HEIGHT,
pImgRightB->Canvas->Handle, 0, 0, RIGHTB_WIDTH, RIGHTB_HEIGHT,
SRCCOPY);
StretchBlt(imgDest->Canvas->Handle, 0, LEFTT_HEIGHT, CENTERL_NEW_WIDTH, CENTERL_NEW_HEIGHT,
pImgCenterL->Canvas->Handle,0, 0, CENTERL_WIDTH, CENTERL_HEIGHT,
SRCCOPY);
StretchBlt(imgDest->Canvas->Handle, iWidthNew-RIGHTT_WIDTH, RIGHTT_HEIGHT, CENTERR_NEW_WIDTH, CENTERR_NEW_HEIGHT,
pImgCenterR->Canvas->Handle,0, 0, CENTERR_WIDTH, CENTERR_HEIGHT,
SRCCOPY);
StretchBlt(imgDest->Canvas->Handle, LEFTT_WIDTH, 0, CENTERT_NEW_WIDTH, CENTERT_NEW_HEIGHT,
pImgCenterT->Canvas->Handle,0, 0, CENTERT_WIDTH, CENTERT_HEIGHT,
SRCCOPY);
StretchBlt(imgDest->Canvas->Handle, LEFTT_WIDTH, iHeightNew-LEFTB_HEIGHT, CENTERB_NEW_WIDTH, CENTERB_NEW_HEIGHT,
pImgCenterB->Canvas->Handle,0, 0, CENTERB_WIDTH, CENTERB_HEIGHT,
SRCCOPY);
StretchBlt(imgDest->Canvas->Handle, LEFTT_WIDTH, LEFTT_HEIGHT, CENTER_NEW_WIDTH, CENTER_NEW_HEIGHT,
pImgCenter->Canvas->Handle, 0, 0, CENTER_WIDTH, CENTER_HEIGHT,
SRCCOPY);
if( !bFindBMPEDGE ) {
g_VCBMPEDGE.push_back(pBMPEDGE);
}
return imgDest;
}
//---------------------------------------------------------------------------
TThreadMusciCover *g_pTThreadMusciCover = NULL;
__fastcall TThreadMusciCover::TThreadMusciCover(bool CreateSuspended, TForm *Form)
: TThread(CreateSuspended)
{
m_pForm = Form;
}
//---------------------------------------------------------------------------
void __fastcall TThreadMusciCover::Execute()
{
TStringStream *strStream = new TStringStream(NULL, 65001);
String strUrl = g_strServerURL;
strUrl += L"/index.php/Client/getUserMusicCover/userId/";
strUrl += IntToStr(g_infoUser.accountInfo.ID);
String dir = MUSIC_COVER_DIR;
String file = L"tmp";
HRESULT result = GetUrlData(strUrl, dir, file, strStream, true, UrlDown_ImageCover);
strUrl = strStream->DataString;
delete strStream;
if( !(result==S_OK && strUrl.Length() > 1) ){
return;
}
file = MUSIC_COVER_FILE;
if( S_OK==GetUrlData(strUrl, dir, file, NULL, false, UrlDown_ImageCover) ) {
PostMessage(m_pForm->Handle, UM_MUSICCOVER, 0, 0 );
}
}
//---------------------------------------------------------------------------
TThreadHttpPostUsrIcon *g_pTThreadHttpPostUsrIcon = NULL;
__fastcall TThreadHttpPostUsrIcon::TThreadHttpPostUsrIcon(bool CreateSuspended, TWinControl *pWnCtrl, String strPath)
: TThread(CreateSuspended)
{
m_pWnCtrl = pWnCtrl;
m_strPath = strPath;
}
//---------------------------------------------------------------------------
void __fastcall TThreadHttpPostUsrIcon::Execute()
{
String strFileName = L"";
bool bSucess = true;
String strUrl = g_strServerURL;
strUrl += L"/index.php/Client/uploadUserPortrait";
String struserId = IntToStr(g_infoUser.accountInfo.ID);
String strusername = g_infoUser.strUserName;
String strpassword = g_infoUser.strPassword;
String strCopperPath = m_strPath;
TIdMultiPartFormDataStream *stream = new TIdMultiPartFormDataStream();
stream->AddFormField(L"userId", struserId);
stream->AddFormField(L"username", strusername, L"UTF-8")->ContentTransfer = L"8bit";
stream->AddFormField(L"password", strpassword, L"UTF-8")->ContentTransfer = L"8bit";
stream->AddFile(L"Filedata", strCopperPath, L"image/jpg");
String strResJson;
TIdHTTP *httpPost = NULL;
try{
httpPost = new TIdHTTP();
httpPost->Request->ContentType = L"multipart/form-data;";
strResJson = httpPost->Post(strUrl, stream);
}catch(Exception &e) {
SAFE_DELETE(httpPost);
SAFE_DELETE(stream);
return;
}
TJSONObject *jsonOri = NULL;
int nState = -1;
try
{
jsonOri = GetJsonContext(strResJson);
if( jsonOri!=NULL ) {
TJSONObject *ValueState = GetJsonValue(jsonOri, 0);
if( ValueState!=NULL ) {
nState = StrToInt(ValueState->Value());
if( 1==nState ) {
TJSONObject *ValueFileName = GetJsonValue(jsonOri, 1);
if( ValueFileName!=NULL )
strFileName = ValueFileName->Value();
}
}
}
SAFE_DELETE(jsonOri);
}catch(Exception &e){
SAFE_DELETE(jsonOri);
SAFE_DELETE(httpPost);
SAFE_DELETE(stream);
return;
}
SAFE_DELETE(httpPost);
SAFE_DELETE(stream);
m_strFileName = strFileName;
PostMessage(m_pWnCtrl->Handle, UM_UPLOADUSRICON, 0, 0 );
}
//---------------------------------------------------------------------------
+126
View File
@@ -0,0 +1,126 @@
//---------------------------------------------------------------------------
#ifndef ImgCopperExUnitH
#define ImgCopperExUnitH
#include "NotificationExUnit.h"
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define MUSIC_COVER_DIR L"MusicCover\\"
#define MUSIC_COVER_FILE L"MusicCover"
#define MUSIC_COVER_COPPER L"MusicCoverCopper.jpg"
//---------------------------------------------------------------------------
bool GetPicType(String &name, TMemoryStream *tmpMemoryStream, bool bBac);
//---------------------------------------------------------------------------
typedef struct UIEdgeInsets {
int left, right, top, bottom;
UIEdgeInsets(int ileft, int iright, int itop, int ibottom) {
left = ileft;
right = iright;
top = itop;
bottom = ibottom;
}
UIEdgeInsets(){
left = -1;
right = -1;
top = -1;
bottom = -1;
}
} UIEdgeInsets;
typedef struct tagUIEdgeInsetsBMP{
TBitmap *pImgLeftT,*pImgLeftB,*pImgRightT,*pImgRightB;
TBitmap *pImgCenterL, *pImgCenterR, *pImgCenterT, *pImgCenterB, *pImgCenter;
TBitmap *pImgBMPSrc;
UIEdgeInsets insetsDest;
int iTag;
String strResourceName;
tagUIEdgeInsetsBMP(int tag, String resourceName) {
iTag = tag;
strResourceName = resourceName;
pImgLeftT = pImgLeftB = pImgRightT = pImgRightB = NULL;
pImgCenterL = pImgCenterR = pImgCenterT = pImgCenterB = pImgCenter = NULL;
pImgBMPSrc = NULL;
}
~tagUIEdgeInsetsBMP() {
SAFE_DELETE(pImgLeftT)
SAFE_DELETE(pImgLeftB)
SAFE_DELETE(pImgRightT)
SAFE_DELETE(pImgRightB)
SAFE_DELETE(pImgCenterL)
SAFE_DELETE(pImgCenterR)
SAFE_DELETE(pImgCenterT)
SAFE_DELETE(pImgCenterB)
SAFE_DELETE(pImgCenter)
SAFE_DELETE(pImgBMPSrc)
}
void SetTransparent(System::Uitypes::TColor TransparentColor) {
pImgLeftT->Transparent = true;
pImgLeftT->TransparentColor = TransparentColor;
pImgLeftB->Transparent = true;
pImgLeftB->TransparentColor = TransparentColor;
pImgRightT->Transparent = true;
pImgRightT->TransparentColor = TransparentColor;
pImgRightB->Transparent = true;
pImgRightB->TransparentColor = TransparentColor;
pImgCenterL->Transparent = true;
pImgCenterL->TransparentColor = TransparentColor;
pImgCenterR->Transparent = true;
pImgCenterR->TransparentColor = TransparentColor;
pImgCenterT->Transparent = true;
pImgCenterT->TransparentColor = TransparentColor;
pImgCenterB->Transparent = true;
pImgCenterB->TransparentColor = TransparentColor;
pImgCenter->Transparent = true;
pImgCenter->TransparentColor = TransparentColor;
}
}BMPEDGE;
typedef vector<BMPEDGE*> VCBMPEDGE;
TBitmap* resizableImage(TBitmap *imgDest, TRect rectDest,
int tagSrc, String resourceNameSrc,
UIEdgeInsets insetsSrc,
System::Uitypes::TColor TransparentColor=clWhite);
//---------------------------------------------------------------------------
class TThreadMusciCover : public TThread
{
private:
TForm *m_pForm;
protected:
void __fastcall Execute();
public:
__fastcall TThreadMusciCover(bool CreateSuspended, TForm *Form);
};
extern TThreadMusciCover *g_pTThreadMusciCover;
//---------------------------------------------------------------------------
class TThreadHttpPostUsrIcon : public TThread
{
private:
TWinControl *m_pWnCtrl;
String m_strPath;
protected:
void __fastcall Execute();
public:
String m_strFileName;
__fastcall TThreadHttpPostUsrIcon(bool CreateSuspended, TWinControl *pWnCtrl, String strPath);
};
extern TThreadHttpPostUsrIcon *g_pTThreadHttpPostUsrIcon;
//---------------------------------------------------------------------------
#endif
+585
View File
@@ -0,0 +1,585 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ImgCopperFormUnit.h"
#include "GlobalUnit.h"
#include <System.IOUtils.hpp>
//---------------------------------------------------------------------------
static const COLORREF CLR_LINE_D = RGB( 18, 19, 21 ),
CLR_LINE_L = RGB( 140, 141, 145 );
#define TOP_LEFT 0
#define TOP_RIGHT 1
#define BOTTOM_LEFT 2
#define BOTTOM_RIGHT 3
#define TOP 4
#define BOTTOM 5
#define LEFT 6
#define RIGHT 7
#define CENTER 8
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TImgCopperForm *ImgCopperForm;
//---------------------------------------------------------------------------
__fastcall TImgCopperForm::TImgCopperForm(TComponent* Owner, TRect rtCopper, TPicture *pPicSrc)
: TForm(Owner)
{
m_rtCopper = rtCopper;
m_pPicSrc = new TPicture();
if(pPicSrc && pPicSrc->Graphic->Width && pPicSrc->Graphic->Height ) {
m_pPicSrc->Assign(pPicSrc);
}
m_pTBitmapLine = new TBitmap();
m_pTBitmapLine->SetSize(4, 4);
m_pTBitmapLine->Canvas->Brush->Style = bsClear;
for( int indexY=0; indexY<4; indexY++ )
{
bool bLine = (indexY%2==0)?true:false;
for( int indexX=0; indexX<4; indexX++ )
{
bool bEven = (indexX%2==0)?true:false;
if(bLine) bEven = !bEven;
m_pTBitmapLine->Canvas->Pixels[indexX][indexY] =
(bEven==true)?CLR_LINE_D:CLR_LINE_L;
}
}
// -----
m_bPicDown = false;
m_nResize = 1;
DragAcceptFiles(this->Handle, true);
m_pTransSkinScollBar = new TTransSkinScollBar(this);
m_pTransSkinScollBar->Parent = this;
m_pTransSkinScollBar->SetBounds(0, 0, 14, 100);
m_pTransSkinScollBar->Vertial = false;
m_pTransSkinScollBar->ThumbWidth = 12;
m_pTransSkinScollBar->OnChangePos = SizeChange;
m_pTransSkinScollBar->BringToFront();
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::FormCreate(TObject *Sender)
{
//绘制圆角窗体
FormResize(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::FormClose(TObject *Sender, TCloseAction &Action)
{
SAFE_DELETE(m_pTBitmapLine)
SAFE_DELETE(m_pPicSrc)
SAFE_DELETE(m_pTransSkinScollBar)
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if( Msg.Result==HTCLIENT && Msg.YPos<Top+24 && Msg.XPos<Left+m_btnClose->Left)
Msg.Result = HTCAPTION;
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::FormResize(TObject *Sender)
{
// -----
HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+1, 16, 16 );
SetWindowRgn( Handle, hRgn, false );
DeleteObject( hRgn );
TBitmap *pBmpBkg = new TBitmap();
pBmpBkg->SetSize(Width, Height);
resizableImage(pBmpBkg, TRect(0, 0, Width, Height),
0, L"copperDialog", UIEdgeInsets(20, 20, 30, 20) );
TPicture *pPicBkg = new TPicture();
pPicBkg->Assign(pBmpBkg);
m_pImageBKG->Picture = pPicBkg;
m_pImageBKG->Width = Width;
m_pImageBKG->Height = Height;
SAFE_DELETE(pBmpBkg)
SAFE_DELETE(pPicBkg)
m_pLbTittle->Left = (Width-m_pLbTittle->Width)/2;
m_btnClose->Left = Width-m_btnClose->Width-10;
// -----
TRect rtBKG = TRect(1, 24, Width-1, 24+(Height-68));
m_rtBKG = rtBKG;
m_pPaintBoxSrc->Left = 1;
m_pPaintBoxSrc->Top = rtBKG.Top;
m_pPaintBoxSrc->Width = Width-2;
m_pPaintBoxSrc->Height = rtBKG.Height();
m_rtCopperEdge.Left = rtBKG.Left+(rtBKG.Width()-m_rtCopper.Width())/2-4;
m_rtCopperEdge.Top = rtBKG.Top+(rtBKG.Height()-m_rtCopper.Height())/2-4;
m_rtCopperEdge.Right = m_rtCopperEdge.Left+m_rtCopper.Width()+8;
m_rtCopperEdge.Bottom = m_rtCopperEdge.Top+m_rtCopper.Height()+8;
m_pTransSkinScollBar->Width = Width/3;
m_pTransSkinScollBar->Left
= m_pPaintBoxSrc->Left+(m_pPaintBoxSrc->Width-m_pTransSkinScollBar->Width)/2;
m_pTransSkinScollBar->Top
= m_pPaintBoxSrc->Top+m_pPaintBoxSrc->Height -
m_pTransSkinScollBar->Height-8;
HRGN hRgnSize =
CreateRoundRectRgn( 0, 0,
m_pTransSkinScollBar->Width+1,
m_pTransSkinScollBar->Height+1,
3, 3 );
SetWindowRgn( m_pTransSkinScollBar->Handle, hRgnSize, false );
DeleteObject( hRgnSize );
m_pBtnCancel->Left = Width-m_pBtnCancel->Width-10;
m_pBtnCancel->Top = Height-m_pBtnCancel->Height-10;
m_pBtnOk->Left = m_pBtnCancel->Left-m_pBtnOk->Width-10;
m_pBtnOk->Top = m_pBtnCancel->Top;
m_btnChoose->Left = 10;
m_btnChoose->Top =
m_pBtnCancel->Top+(m_pBtnCancel->Height-m_btnChoose->Height)/2;
m_pLbTittle->Caption = this->Caption;
SetSrcPicRect();
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::SetCaption(String strCaption)
{
m_pLbTittle->Caption = strCaption;
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::m_pPaintBoxSrcPaint(TObject *Sender)
{
int nWidth = m_pPaintBoxSrc->Width;
int nHeight = m_pPaintBoxSrc->Height;
// 创建一个与显示设备兼容的内存设备
HDC BufDC = CreateCompatibleDC(m_pPaintBoxSrc->Canvas->Handle);
// 创建一个与显示设备兼容的位图
HBITMAP BufBitmap = CreateCompatibleBitmap(m_pPaintBoxSrc->Canvas->Handle, nWidth, nHeight);
// 将设备与位图关联
SelectObject(BufDC, BufBitmap);
// CreateCompatibleBitmap创建位图后数据初始化为0,而RGB(0,0,0)则表示是黑色
// 这里需要清除其黑色背景,使其变为透明
PerformEraseBackground(this, BufDC);
// 临时的Canvas,用来画图用,但它并不是必须的,可以直接使用GDI函数来画图
TCanvas *CanvasDraw = new TCanvas();
// 关联到内存设备
CanvasDraw->Handle = BufDC;
//--------------------------------------
CanvasDraw->Brush->Color = RGB(221, 193, 169);
CanvasDraw->FillRect(TRect(0, 0, nWidth, nHeight));
CanvasDraw->StretchDraw(m_rtSrc, m_pPicSrc->Graphic);
int iLeft, iTop, iWidth, iHeight;
CanvasDraw->Brush->Bitmap = m_pTBitmapLine;
//left
iLeft = m_rtCopperEdge.Left-m_rtBKG.Left;
iTop = m_rtCopperEdge.Top-m_rtBKG.Top;
iWidth = 4;
iHeight = m_rtCopperEdge.Height();
CanvasDraw->FillRect( TRect(iLeft, iTop, iLeft+iWidth, iTop+iHeight) );
//right
iLeft = m_rtCopperEdge.Left+m_rtCopperEdge.Width()-4-m_rtBKG.Left;
iTop = m_rtCopperEdge.Top-m_rtBKG.Top;
iWidth = 4;
iHeight = m_rtCopperEdge.Height();
CanvasDraw->FillRect( TRect(iLeft, iTop, iLeft+iWidth, iTop+iHeight) );
//top
iLeft = m_rtCopperEdge.Left-m_rtBKG.Left;
iTop = m_rtCopperEdge.Top-m_rtBKG.Top;
iWidth = m_rtCopperEdge.Width();
iHeight = 4;
CanvasDraw->FillRect( TRect(iLeft, iTop, iLeft+iWidth, iTop+iHeight) );
//bottom
iLeft = m_rtCopperEdge.Left-m_rtBKG.Left;
iTop = m_rtCopperEdge.Top+m_rtCopperEdge.Height()-4-m_rtBKG.Top;
iWidth = m_rtCopperEdge.Width();
iHeight = 4;
CanvasDraw->FillRect( TRect(iLeft, iTop, iLeft+iWidth, iTop+iHeight) );
// 一次性将内存图像数据覆盖过去,因为跳过了擦除背景过程,所以避免了闪烁的问题
BitBlt(m_pPaintBoxSrc->Canvas->Handle, 0, 0, nWidth, nHeight,
CanvasDraw->Handle, 0, 0, SRCCOPY);
// 释放资源
DeleteDC(BufDC);
DeleteObject(BufBitmap);
SAFE_DELETE(CanvasDraw)
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::m_pPaintBoxSrcMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
m_bPicDown = true;
m_ptDown = TPoint(X, Y);
m_rtSrcMove = m_rtSrc;
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::m_pPaintBoxSrcMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if( m_bPicDown ) {
int nLeft, nTop, nWidth, nHeight;
nWidth = m_rtSrcMove.Width();
nHeight = m_rtSrcMove.Height();
nLeft = m_rtSrcMove.Left+X-m_ptDown.X;
nTop = m_rtSrcMove.Top+Y-m_ptDown.Y;
m_rtSrc.Left = nLeft;
m_rtSrc.Top = nTop;
m_rtSrc.Right = m_rtSrc.Left+nWidth;
m_rtSrc.Bottom = m_rtSrc.Top+nHeight;
m_pPaintBoxSrcPaint(NULL);
}
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::m_pPaintBoxSrcMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
m_bPicDown = false;
m_rtSrcMove = m_rtSrc;
m_pTransSkinScollBar->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::SizeChange(TObject *Sender)
{
int nSize = m_pTransSkinScollBar->SBTop + 1;
if(m_nResize==nSize) return;
m_nResize = nSize;
int nLMove, nTMove, nWMove, nHMove;
nLMove = m_rtSrcMove.Left;
nTMove = m_rtSrcMove.Top;
nWMove = m_rtSrcMove.Width();
nHMove = m_rtSrcMove.Height();
int nLBac, nTBac, nWBac, nHBac;
nLBac = m_rtSrcBac.Left;
nTBac = m_rtSrcBac.Top;
nWBac = m_rtSrcBac.Width();
nHBac = m_rtSrcBac.Height();
//方向
int nStatusLoc;
TPoint ptCenterSrcMove = TPoint(nLMove+nWMove/2, nTMove+nHMove/2);
if( ptCenterSrcMove.X>m_rtSrcBac.Right &&
ptCenterSrcMove.Y<m_rtSrcBac.Top )
{
nStatusLoc = TOP_RIGHT;
}else if( ptCenterSrcMove.X>m_rtSrcBac.Right &&
ptCenterSrcMove.Y>m_rtSrcBac.Bottom )
{
nStatusLoc = BOTTOM_RIGHT;
}else if( ptCenterSrcMove.X<m_rtSrcBac.Left &&
ptCenterSrcMove.Y>m_rtSrcBac.Bottom )
{
nStatusLoc = BOTTOM_LEFT;
}else if( ptCenterSrcMove.X<m_rtSrcBac.Left &&
ptCenterSrcMove.Y<m_rtSrcBac.Top )
{
nStatusLoc = TOP_LEFT;
}else if( ptCenterSrcMove.X>m_rtSrcBac.Right &&
ptCenterSrcMove.Y>m_rtSrcBac.Top &&
ptCenterSrcMove.Y<m_rtSrcBac.Bottom )
{
nStatusLoc = RIGHT;
}else if( ptCenterSrcMove.X<m_rtSrcBac.Left &&
ptCenterSrcMove.Y>m_rtSrcBac.Top &&
ptCenterSrcMove.Y<m_rtSrcBac.Bottom )
{
nStatusLoc = LEFT;
}else if( ptCenterSrcMove.Y>m_rtSrcBac.Bottom &&
ptCenterSrcMove.X>m_rtSrcBac.Left &&
ptCenterSrcMove.X<m_rtSrcBac.Right )
{
nStatusLoc = BOTTOM;
}else if( ptCenterSrcMove.Y<m_rtSrcBac.Top &&
ptCenterSrcMove.X>m_rtSrcBac.Left &&
ptCenterSrcMove.X<m_rtSrcBac.Right )
{
nStatusLoc = TOP;
}else{
nStatusLoc = CENTER;
}
//得到缩放焦点
TPoint ptFocus;
if( CENTER==nStatusLoc ) {
ptFocus = ptCenterSrcMove;
}else if( TOP_RIGHT==nStatusLoc ) {
ptFocus = TPoint(nLMove+nWMove/4, nTMove+nHMove*3/4);
}else if( BOTTOM_RIGHT==nStatusLoc ) {
ptFocus = TPoint(nLMove+nWMove/4, nTMove+nHMove/4);
}else if( BOTTOM_LEFT==nStatusLoc ) {
ptFocus = TPoint(nLMove+nWMove*3/4, nTMove+nHMove/4);
}else if( TOP_LEFT==nStatusLoc ) {
ptFocus = TPoint(nLMove+nWMove*3/4, nTMove+nHMove*3/4);
}else if( RIGHT==nStatusLoc ) {
ptFocus = TPoint(nLMove+nWMove/4, nTMove+nHMove/2);
}else if( LEFT==nStatusLoc ) {
ptFocus = TPoint(nLMove+nWMove*3/4, nTMove+nHMove/2);
}else if( BOTTOM==nStatusLoc ) {
ptFocus = TPoint(nLMove+nWMove/2, nTMove+nHMove/4);
}else if( TOP==nStatusLoc ) {
ptFocus = TPoint(nLMove+nWMove/2, nTMove+nHMove*3/4);
}
//进行缩放处理
int nLSrc, nTSrc, nWSrc, nHSrc;
nWSrc = nWBac*nSize;
nHSrc = nHBac*nSize;
if( CENTER==nStatusLoc ) {
nLSrc = ptFocus.X - nWSrc/2;
nTSrc = ptFocus.Y - nHSrc/2;
}else if( TOP_RIGHT==nStatusLoc ) {
nLSrc = ptFocus.X - nWSrc/4;
nTSrc = ptFocus.Y - nHSrc*3/4;
}else if( BOTTOM_RIGHT==nStatusLoc ) {
nLSrc = ptFocus.X - nWSrc/4;
nTSrc = ptFocus.Y - nHSrc/4;
}else if( BOTTOM_LEFT==nStatusLoc ) {
nLSrc = ptFocus.X - nWSrc*3/4;
nTSrc = ptFocus.Y - nHSrc/4;
}else if( TOP_LEFT==nStatusLoc ) {
nLSrc = ptFocus.X - nWSrc*3/4;
nTSrc = ptFocus.Y - nHSrc*3/4;
}else if( RIGHT==nStatusLoc ) {
nLSrc = ptFocus.X - nWSrc/4;
nTSrc = ptFocus.Y - nHSrc/2;
}else if( LEFT==nStatusLoc ) {
nLSrc = ptFocus.X - nWSrc*3/4;
nTSrc = ptFocus.Y - nHSrc/2;
}else if( BOTTOM==nStatusLoc ) {
nLSrc = ptFocus.X - nWSrc/2;
nTSrc = ptFocus.Y - nHSrc/4;
}else if( TOP==nStatusLoc ) {
nLSrc = ptFocus.X - nWSrc/2;
nTSrc = ptFocus.Y - nHSrc*3/4;
}
m_rtSrc.Left = nLSrc;
m_rtSrc.Top = nTSrc;
m_rtSrc.Right = m_rtSrc.Left+nWSrc;
m_rtSrc.Bottom = m_rtSrc.Top+nHSrc;
m_pPaintBoxSrcPaint(NULL);
m_pTransSkinScollBar->Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::SetSrcPicRect()
{
int nLeft, nTop, nWidth, nHeight;
if( m_pPicSrc ) {
int nWidthLarge = -1;
int nWidthCopper = m_rtCopper.Width();
int nHeightCopper = m_rtCopper.Height();
nWidth = m_pPicSrc->Width;
nHeight = m_pPicSrc->Height;
if( nWidth<m_rtCopper.Width() ) {
nLeft = (nWidthCopper-nWidth)/2;
}else{
nWidthLarge = nWidth;
nLeft = 0;
nWidth = nWidthCopper;
}
if( -1!=nWidthLarge ) {
nHeight = nHeight*nWidth/nWidthLarge;
}
nTop = (nHeightCopper-nHeight)/2;
m_rtSrc.Left = nLeft+(m_rtCopperEdge.Left-m_pPaintBoxSrc->Left)+4;
m_rtSrc.Top = nTop+(m_rtCopperEdge.Top-m_pPaintBoxSrc->Top)+4;
m_rtSrc.Right = m_rtSrc.Left+nWidth;
m_rtSrc.Bottom = m_rtSrc.Top+nHeight;
m_rtSrcBac = m_rtSrc;
m_rtSrcMove = m_rtSrc;
if( -1!=nWidthLarge )
m_pTransSkinScollBar->SBTotal = m_pPicSrc->Width*5/m_rtSrc.Width();
else
m_pTransSkinScollBar->SBTotal = 5;
m_pTransSkinScollBar->SBShow = 2;
m_pTransSkinScollBar->SBTop = 0;
m_nResize = 1;
}
}
//---------------------------------------------------------------------------
bool __fastcall TImgCopperForm::SetSrcPic(String fileName)
{
TMemoryStream *memoryStream = new TMemoryStream();
memoryStream->Position = 0;
memoryStream->LoadFromFile(fileName);
if( !GetPicType(fileName, memoryStream, true) ){
SAFE_DELETE(memoryStream)
return false;
}else {
TPicture *pTPicture = new TPicture();
try{
pTPicture->LoadFromFile(fileName);
}catch(Exception &e){
SAFE_DELETE(pTPicture)
SAFE_DELETE(memoryStream)
return false;
}
if( m_pPicSrc ) {
m_pPicSrc->Assign(pTPicture);
SetSrcPicRect();
m_pPaintBoxSrcPaint(NULL);
m_pTransSkinScollBar->Invalidate();
SAFE_DELETE(pTPicture)
}
}
SAFE_DELETE(memoryStream)
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::WMDRopFiles (TMessage& Msg)
{
wchar_t wcFileName[256];
int iCount = DragQueryFile((HDROP)Msg.WParam, 0xffffffff, wcFileName , 256);
for (int index=0; index<iCount; index++)
{
DragQueryFile((HDROP )Msg.WParam, index, wcFileName , 256);
String fileName = wstr2str(wcFileName).c_str();
if( SetSrcPic(fileName) ) break;
}
DragFinish((HDROP)Msg.WParam);
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::m_btnChooseClick(TObject *Sender)
{
String strPicPath;
// -----
TOpenDialog *pDlg = new TOpenDialog(NULL);
pDlg->Title = "打开图片";
pDlg->Options << ofFileMustExist;
// pDlg->FileName = ExtractFileName(L"");
// pDlg->InitialDir = ExtractFilePath(L"");
pDlg->Filter = "jpg文件 (*.jpg)|*.JPG|png文件 (*.png)|*.PNG|bmp文件 (*.bmp)|*.BMP";
pDlg->DefaultExt = "jpg";
if ( pDlg->Execute(Handle) ) {
strPicPath = pDlg->FileName.c_str();
}
SAFE_DELETE(pDlg);
if( !strPicPath.IsEmpty() ){
SetSrcPic(strPicPath);
}
}
//---------------------------------------------------------------------------
void __fastcall TImgCopperForm::m_pBtnOkClick(TObject *Sender)
{
int iLeft, iTop, iWidth, iHeight;
iLeft = 0;
iTop = 0;
iWidth = m_rtCopper.Width();
iHeight = m_rtCopper.Height();
TBitmap *pTBitmapCopper = new TBitmap();
pTBitmapCopper->SetSize(iWidth, iHeight);
pTBitmapCopper->Canvas->Brush->Color = RGB(0, 0, 0);
pTBitmapCopper->Canvas->FillRect(TRect(iLeft, iTop, iLeft+iWidth, iTop+iHeight));
iWidth = m_rtSrc.Width();
iHeight = m_rtSrc.Height();
m_rtSrc.Left -= m_rtCopperEdge.Left-m_pPaintBoxSrc->Left+4;
m_rtSrc.Top -= m_rtCopperEdge.Top-m_pPaintBoxSrc->Top+4;
m_rtSrc.Right = m_rtSrc.Left+iWidth;
m_rtSrc.Bottom = m_rtSrc.Top+iHeight;
pTBitmapCopper->Canvas->StretchDraw(m_rtSrc, m_pPicSrc->Graphic);
m_strCopperPath = g_strUserPath.c_str();
m_strCopperPath += L"temp\\";
if(!DirectoryExists(m_strCopperPath, false))
ForceDirectories(m_strCopperPath);
m_strCopperPath += L"copper.jpg";
TJPEGImage *pTJPEGImage = new TJPEGImage();
pTJPEGImage->Assign(pTBitmapCopper);
pTJPEGImage->SaveToFile( m_strCopperPath );
SAFE_DELETE(pTJPEGImage);
SAFE_DELETE(pTBitmapCopper);
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+80
View File
@@ -0,0 +1,80 @@
//---------------------------------------------------------------------------
#ifndef ImgCopperFormUnitH
#define ImgCopperFormUnitH
//---------------------------------------------------------------------------
#include "ImgCopperExUnit.h"
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include <Vcl.Graphics.hpp>
#include "PNGButton.hpp"
#include "TransSkinScrollBar.h"
//---------------------------------------------------------------------------
class TImgCopperForm : public TForm
{
__published: // IDE-managed Components
TPNGButton *m_btnClose;
TPNGButton *m_pBtnOk;
TPNGButton *m_pBtnCancel;
TLabel *m_pLbTittle;
TImage *m_pImageBKG;
TPaintBox *m_pPaintBoxSrc;
TPNGButton *m_btnChoose;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall m_pPaintBoxSrcMouseMove(TObject *Sender, TShiftState Shift, int X,
int Y);
void __fastcall m_pPaintBoxSrcMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall m_pPaintBoxSrcMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall m_pPaintBoxSrcPaint(TObject *Sender);
void __fastcall m_pBtnOkClick(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall m_btnChooseClick(TObject *Sender);
private: // User declarations
TRect m_rtBKG;
TRect m_rtCopper;
TRect m_rtCopperEdge;
TBitmap *m_pTBitmapLine;
TPicture *m_pPicSrc;
TRect m_rtSrc;
TRect m_rtSrcBac;
TRect m_rtSrcMove;
bool m_bPicDown;
TPoint m_ptDown;
int m_nResize;
TTransSkinScollBar *m_pTransSkinScollBar;
void __fastcall SizeChange(TObject *Sender);
bool __fastcall SetSrcPic(String fileName);
void __fastcall SetSrcPicRect();
MESSAGE void __fastcall WMDRopFiles (TMessage& Msg);
void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
MESSAGE_HANDLER(WM_DROPFILES, TMessage, WMDRopFiles)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TImgCopperForm(TComponent* Owner, TRect rtCopper, TPicture *pPicSrc);
String m_strCopperPath;
void __fastcall SetCaption(String strCaption);
};
//---------------------------------------------------------------------------
extern PACKAGE TImgCopperForm *ImgCopperForm;
//---------------------------------------------------------------------------
#endif
+558
View File
@@ -0,0 +1,558 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#include <pcre.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "LoginFormUnit.h"
#include "MessageFormUnit.h"
#include "VerifyCodeFormUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TLoginForm *LoginForm;
const char * g_pPattern[5] = { "^[_a-zA-Z0-9\\xA1-\\xFE\\.-]{3,16}$",
"^[_a-zA-Z0-9\\.-]+@([_a-zA-Z0-9]+\\.)+[a-zA-Z0-9]{2,3}$",
"^[\\x21-\\x7E]{3,16}$",
"^[\\x21-\\x7E]{6,16}$",
"^$|^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$"
};
//---------------------------------------------------------------------------
__fastcall TLoginForm::TLoginForm(TComponent* Owner)
: TForm(Owner)
{
m_bRegister = false;
m_bAgree = true;
isEmailOrMobile = 0;
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::FormCreate(TObject *Sender)
{
m_pImgCheck = new TBitmap();
m_pImgCheck->LoadFromResourceName(int(HInstance), L"AutoLoginCheck");
//绘制圆角窗体
HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+2, 10, 10 );
SetWindowRgn( Handle, hRgn, false );
DeleteObject( hRgn );
char strURL[256];
f_CS_GetWebPageURL( URL_REGCODE, strURL );
RESTClient->BaseURL = String(strURL);
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::FormDestroy(TObject *Sender)
{
if( m_pImgCheck )
delete m_pImgCheck;
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::AutoCheckPaint(TObject *Sender)
{
//绘制Check状态
int x = 0;
if( !m_bRegister && !m_bAutoLog ){
x = -m_pImgCheck->Width/2;
}
m_pbAutoCheck->Canvas->Draw(x, 0, m_pImgCheck);
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::AutoCheckClick(TObject *Sender)
{
//切换Check状态
if( !m_bRegister ){
g_bAutoLogin = m_bAutoLog = !m_bAutoLog;
m_pbAutoCheck->Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::GoClick(TObject *Sender)
{
if( !m_bRegister ){
//检查输入
m_editLogUsername->Text = m_editLogUsername->Text.Trim();
m_editLogPassword->Text = m_editLogPassword->Text.Trim();
if( m_editLogUsername->Text.IsEmpty() ){
m_editLogUsername->SetFocus();
}
else if( m_editLogPassword->Text.IsEmpty() ){
m_editLogPassword->SetFocus();
}
else{
bool bCheckOk = true;
AnsiString astrUN = m_editLogUsername->Text;
if( !CheckInput( astrUN.c_str(), 0 ) && !CheckInput( astrUN.c_str(), 1 ) ){
m_editLogUsername->Text = "";
m_editLogUsername->SetFocus();
bCheckOk = false;
}
else{
AnsiString astrPW = m_editLogPassword->Text;
if( !CheckInput( astrPW.c_str(), 2 ) ){
m_editLogPassword->Text = "";
m_editLogPassword->SetFocus();
bCheckOk = false;
}
}
if( bCheckOk ){
m_strUsername = m_editLogUsername->Text;
m_strPassword = m_editLogPassword->Text;
ModalResult = mrOk;
string strUN = AnsiString( m_strUsername ).c_str();
string strPW = AnsiString( m_strPassword ).c_str();
SetAutoLogin( m_bAutoLog, strUN.c_str(), strPW.c_str() );
}
}
}
else{
//检查输入
m_editRegUsername->Text = m_editRegUsername->Text.Trim();
m_editRegPassword->Text = m_editRegPassword->Text.Trim();
m_editVerify->Text = m_editVerify->Text.Trim();
m_editConfirm->Text = m_editConfirm->Text.Trim();
if( m_editRegUsername->Text.IsEmpty() ){
m_editRegUsername->SetFocus();
}
else if( m_editVerify->Text.IsEmpty() ){
m_editVerify->SetFocus();
}
else if( m_editRegPassword->Text.IsEmpty() ){
m_editRegPassword->SetFocus();
}
else if( m_editConfirm->Text.IsEmpty() ){
m_editConfirm->SetFocus();
}
else{
AnsiString astrPW = m_editRegPassword->Text;
if(!CheckInput(astrPW.c_str(), 3)){
m_editRegPassword->Text = "";
m_editRegPassword->SetFocus();
return;
}
if(m_editRegPassword->Text.Compare(m_editConfirm->Text)){
m_editConfirm->Text = "";
m_editConfirm->SetFocus();
return;
}
AnsiString astrUN = m_editRegUsername->Text;
if( CheckInput(astrUN.c_str(), 1) ){
isEmailOrMobile = 1;
}
else if( CheckInput(astrUN.c_str(), 4) ){
isEmailOrMobile = 2;
}
else{
m_editRegUsername->Text = "";
m_editRegUsername->SetFocus();
return;
}
this->Enabled = false;
Screen->Cursor = crHourGlass;
AnsiString strVerify = m_editVerify->Text;
RESTRequest->Resource = "verifyRegCode";
RESTRequest->Params->Clear();
RESTRequest->Params->AddItem("username", astrUN);
RESTRequest->Params->AddItem("verifyCode", strVerify);
try{
RESTRequest->Execute();
}
catch (Exception &exception){
DebugPrint("exception: %s", exception.Message );
}
Screen->Cursor = crDefault;
this->Enabled = true;
if(RESTResponse->StatusCode==200){
TJSONValue *jValue = RESTResponse->JSONValue;
if(jValue==NULL)
return;
TJSONValue *jCode = jValue->FindValue("code");
if( jCode==NULL )
return;
String code = ((TJSONString*)jCode)->Value();
if(code!="00000"){
String msg;
if(code=="A0213")
msg = "注册验证码已过期";
else if(code=="A0214")
msg = "注册验证码错误";
else
msg = ((TJSONString*)jValue->FindValue("msg"))->Value();
MessageForm->ShowMessage( msg, MB_ICONERROR | MB_OK );
return;
}
}
else{
MessageForm->ShowMessage( RESTResponse->StatusText, MB_ICONERROR | MB_OK );
return;
}
m_strUsername = m_editRegUsername->Text;
m_strPassword = m_editRegPassword->Text;
ModalResult = mrOk;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::FormShow(TObject *Sender)
{
if( !m_bRegister ){
Height = 173;
m_editLogUsername->Text = m_strUsername;
m_editLogPassword->Text = m_strPassword;
if( m_editLogUsername->Text.IsEmpty() ){
m_editLogUsername->SetFocus();
}
else{
m_editLogPassword->SetFocus();
}
}
else{
Height = 219;
m_editRegUsername->Text = "";
m_editRegPassword->Text = "";
m_editConfirm->Text = "";
m_editVerify->Text = "";
if( m_editRegUsername->Text.IsEmpty() ){
m_editRegUsername->SetFocus();
}
else if(m_editVerify->Text.IsEmpty()){
m_editVerify->SetFocus();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
switch( Key ){
case VK_RETURN:
if( !m_bRegister && m_btnLogGo->Enabled
|| m_bRegister && m_btnRegGo->Enabled )
GoClick( NULL );
break;
case VK_ESCAPE:
ModalResult = mrCancel;
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::SwitchClick(TObject *Sender)
{
if(Sender==(TObject*)m_btnRegister){
m_bRegister = true;
m_panLogin->Visible = false;
m_panRegister->Visible = true;
Height = 219;
if( m_editRegUsername->Text.IsEmpty() ){
m_editRegUsername->SetFocus();
}
else if( m_editVerify->Text.IsEmpty() ){
m_editVerify->SetFocus();
}
else if(m_editRegPassword->Text.IsEmpty() ){
m_editRegPassword->SetFocus();
}
else{
m_editConfirm->SetFocus();
}
}
else{
m_bRegister = false;
m_panLogin->Visible = true;
m_panRegister->Visible = false;
Height = 173;
if( m_editLogUsername->Text.IsEmpty() ){
m_editLogUsername->SetFocus();
}
else{
m_editLogPassword->SetFocus();
}
}
Invalidate();
}
//---------------------------------------------------------------------------
bool TLoginForm::CheckInput( const char * pText, int type )
{
bool bRet = false;
pcre * pPcre = NULL;
int nOffset = -1;
const char * pPattern = g_pPattern[type];
const char * pErrMsg = NULL;
if( NULL == (pPcre = pcre_compile(pPattern, 0, &pErrMsg, &nOffset, NULL)) ){
printf("pcre_compile ErrMsg=%s\n", pErrMsg);
}
else{
if( pcre_exec(pPcre, NULL, pText, strlen(pText), 0, NULL, 0) < 0 ){
printf("%s doesn't match %s\n", pText, pPattern);
}
else{
printf("%s matches %s\n", pText, pPattern);
bRet = true;
}
pcre_free(pPcre);
}
return bRet;
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::UsernameChange(TObject *Sender)
{
TransparentEditUnit::TEdit* pEdit = (TransparentEditUnit::TEdit*)Sender;
AnsiString strName = pEdit->Text.Trim();
string strTmp = GBToUTF8(strName.c_str());
pEdit->OnChange = NULL;
while( strTmp.length()>pEdit->MaxLength ){
pEdit->Text = pEdit->Text.SubString( 0, pEdit->Text.Length()-1 );
strName = pEdit->Text.Trim();
strTmp = GBToUTF8(strName.c_str());
}
pEdit->SelStart = pEdit->Text.Length();
pEdit->OnChange = UsernameChange;
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::UrlLinkMouseEnter(TObject *Sender)
{
TLabel* pL = (TLabel*)Sender;
pL->Font->Color = clHighlight;
pL->Font->Style = pL->Font->Style<<fsUnderline;
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::UrlLinkMouseLeave(TObject *Sender)
{
TLabel* pL = (TLabel*)Sender;
pL->Font->Color = clBlue;
pL->Font->Style = pL->Font->Style>>fsUnderline;
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::UrlLinkClick(TObject *Sender)
{
TLabel* pL = (TLabel*)Sender;
char strURL[256];
f_CS_GetWebPageURL( pL->Tag, strURL );
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::LogHideClick(TObject *Sender)
{
AutoCheckClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::RegCheckClick(TObject *Sender)
{
//切换Check状态
if( m_bRegister ){
m_bAgree = !m_bAgree;
m_btnRegGo->Enabled = m_bAgree;
m_pbRegCheck->Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::RegChcekPaint(TObject *Sender)
{
//绘制Check状态
int x = 0;
if( m_bRegister && !m_bAgree ){
x = -m_pImgCheck->Width/2;
}
m_pbRegCheck->Canvas->Draw(x, 0, m_pImgCheck);
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::OnCDTimer(int countDown)
{
if( countDown==0 ){
m_lblSendTip->Caption = "重新发送";
m_lblSendTip->Enabled = true;
m_btnSend->Enabled = true;
}
else{
m_lblSendTip->Caption = String(countDown) + "秒";
m_lblSendTip->Enabled = false;
m_btnSend->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::SendClick(TObject *Sender)
{
m_editRegUsername->Text = m_editRegUsername->Text.Trim();
if(m_editRegUsername->Text.IsEmpty()){
m_editRegUsername->SetFocus();
return;
}
AnsiString astrUN = m_editRegUsername->Text;
if( !CheckInput(astrUN.c_str(), 1) && !CheckInput(astrUN.c_str(), 4 )){
m_editRegUsername->Text = "";
m_editRegUsername->SetFocus();
return;
}
String sKey, sCode;
TVerifyCodeForm* pForm = new TVerifyCodeForm(NULL, RESTClient->BaseURL);
if( pForm->ShowModal() == mrOk){
sKey = pForm->GetKey();
sCode = pForm->GetCode();
}
delete pForm;
if(sKey.Length()==0 || sCode.Length()==0)
return;
this->Enabled = false;
Screen->Cursor = crHourGlass;
RESTRequest->Resource = "sendRegCode";
RESTRequest->Params->Clear();
RESTRequest->Params->AddItem("contact", astrUN);
RESTRequest->Params->AddItem("captchaKey", sKey);
RESTRequest->Params->AddItem("captchaCode", sCode);
try{
RESTRequest->Execute();
}
catch (Exception &exception){
DebugPrint("exception: %s", exception.Message );
}
Screen->Cursor = crDefault;
this->Enabled = true;
if(RESTResponse->StatusCode==200){
TJSONValue *jValue = RESTResponse->JSONValue;
if(jValue==NULL)
return;
TJSONValue *jCode = jValue->FindValue("code");
if( jCode==NULL )
return;
String code = ((TJSONString*)jCode)->Value();
if(code=="00000"){
m_lblSendTip->Caption = String(CODE_INTERVAL) + "秒";
// m_lblSendTip->Font->Color = 0x009DA7B0;//"$001E394F";
m_lblSendTip->Enabled = false;
m_btnSend->Enabled = false;
PostMessage(Application->MainFormHandle, UM_STARTCDTIMER, 0, 0);
MessageForm->ShowMessage("已向 " + astrUN + " 发送注册验证码\n(15分钟内有效,请勿重复提交!)", MB_OK | MB_ICONINFORMATION);
}
else{
String msg;
if(code=="A0213")
msg = "人机验证码已过期";
else if(code=="A0214")
msg = "人机验证码错误";
else
msg = ((TJSONString*)jValue->FindValue("msg"))->Value();
MessageForm->ShowMessage( msg, MB_ICONERROR | MB_OK );
}
}
else{
MessageForm->ShowMessage( RESTResponse->StatusText, MB_ICONERROR | MB_OK );
}
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::ResetPassClick(TObject *Sender)
{
char strURL[256];
f_CS_GetWebPageURL( URL_RESETPASS, strURL );
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::RegHideClick(TObject *Sender)
{
RegCheckClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::SendTipClick(TObject *Sender)
{
SendClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::SendTipMouseEnter(TObject *Sender)
{
m_btnSend->Up = true;;
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::SendMouseLeave(TObject *Sender)
{
m_btnSend->Up = false;
}
//---------------------------------------------------------------------------
void __fastcall TLoginForm::BkgdMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
//点击顶部拖动
if (X > 10 && X < Width - 24 && Y < 22){
ReleaseCapture();
Perform(WM_NCLBUTTONDOWN,HTCAPTION, 0);
}
else{
MouseDown(Button, Shift, X, Y);
}
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+99
View File
@@ -0,0 +1,99 @@
//---------------------------------------------------------------------------
#ifndef LoginFormUnitH
#define LoginFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include "PNGButton.hpp"
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Graphics.hpp>
#include "TransparentEditUnit.h"
#include <Vcl.Imaging.jpeg.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include <Data.Bind.Components.hpp>
#include <Data.Bind.ObjectScope.hpp>
#include <REST.Client.hpp>
#include <REST.Types.hpp>
#define CODE_INTERVAL 120
//---------------------------------------------------------------------------
class TLoginForm : public TForm
{
__published: // IDE-managed Components
Extctrls::TPanel *m_panLogin;
TImage *m_imgLogBackground;
TPNGButton *m_btnLogGo;
TPNGButton *m_btnLogClose;
TPNGButton *m_btnRegister;
TransparentEditUnit::TEdit *m_editLogUsername;
TransparentEditUnit::TEdit *m_editLogPassword;
TPaintBox *m_pbAutoCheck;
Extctrls::TPanel *m_panRegister;
TImage *m_imgRegBackground;
TPNGButton *m_btnRegClose;
TPNGButton *m_btnRegGo;
TPNGButton *m_btnLogin;
TPNGButton *m_btnSend;
TransparentEditUnit::TEdit *m_editRegPassword;
TransparentEditUnit::TEdit *m_editRegUsername;
TransparentEditUnit::TEdit *m_editConfirm;
TransparentEditUnit::TEdit *m_editVerify;
TLabel *m_lblAgreement;
TLabel *m_lblSendTip;
TLabel *m_lblLogHide;
TLabel *m_lblRegHide;
TLabel *m_lblResetPass;
TPaintBox *m_pbRegCheck;
TRESTClient *RESTClient;
TRESTRequest *RESTRequest;
TRESTResponse *RESTResponse;
void __fastcall AutoCheckPaint(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall AutoCheckClick(TObject *Sender);
void __fastcall GoClick(TObject *Sender);
void __fastcall FormShow(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall SwitchClick(TObject *Sender);
void __fastcall UsernameChange(TObject *Sender);
void __fastcall UrlLinkMouseEnter(TObject *Sender);
void __fastcall UrlLinkMouseLeave(TObject *Sender);
void __fastcall UrlLinkClick(TObject *Sender);
void __fastcall LogHideClick(TObject *Sender);
void __fastcall RegCheckClick(TObject *Sender);
void __fastcall RegChcekPaint(TObject *Sender);
void __fastcall SendClick(TObject *Sender);
void __fastcall ResetPassClick(TObject *Sender);
void __fastcall RegHideClick(TObject *Sender);
void __fastcall SendTipClick(TObject *Sender);
void __fastcall SendTipMouseEnter(TObject *Sender);
void __fastcall SendMouseLeave(TObject *Sender);
void __fastcall BkgdMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
private: // User declarations
TBitmap * m_pImgCheck;
bool CheckInput( const char * pText, int type );
public: // User declarations
bool m_bAutoLog,
m_bRegister,
m_bAgree;
int isEmailOrMobile; // 捆绑邮箱或手机号 1=邮箱 2=手机号
String m_strUsername;
String m_strPassword;
void __fastcall OnCDTimer(int countDown);
__fastcall TLoginForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TLoginForm *LoginForm;
//---------------------------------------------------------------------------
#endif
+3080
View File
File diff suppressed because it is too large Load Diff
+6420
View File
File diff suppressed because it is too large Load Diff
+232
View File
@@ -0,0 +1,232 @@
//---------------------------------------------------------------------------
#ifndef MainFormH
#define MainFormH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include "SystemMenuUnit.h"
#include "PNGButton.hpp"
#include "TransparentPanelUnit.h"
#include "SkinHintWindow.h"
#include "NotificationFormUnit.h"
#include <Vcl.Graphics.hpp>
#include "CommonListboxUnit.h"
#define MENU_NEW 0
#define MENU_OPEN 1
#define MENU_OPENRECENT 2
#define MENU_SAVE 3
#define MENU_SAVEAS 4
#define MENU_IOSETTING 5
#define MENU_PERFERENCE 6
#define MENU_HELP 7
#define MENU_FORUM 8
#define TABSHEET_NUM 6
//---------------------------------------------------------------------------
class TMainForm : public TForm
{
__published: // IDE-managed Components
TImage *m_pImageStep;
TPNGButton *m_btnSysMenu;
TPNGButton *m_btnLogin;
TPNGButton *m_btnMinBox;
TPNGButton *m_btnMaxBox;
TPNGButton *m_btnCloseBox;
TPNGButton *m_btnRestBox;
TPageControl *m_pPgCtrl_Work;
TLabel *m_labCaption;
TransparentPanelUnit::TPanel *m_panelUserInfo;
TImage *m_imgUserFrame;
TImage *m_imgUserIcon;
TPNGButton *m_btnLogoff;
TLabel *m_lblUsername;
TPNGButton *m_btnCancelLog;
TLabel *m_lblLoging;
TPNGButton *m_btnThrdStep;
TPNGButton *m_btnFrthStep;
TPNGButton *m_btnFifthStep;
TPNGButton *m_btnSecStep;
TPNGButton *m_btnFirstStep;
TPNGButton *m_btnHelpBox;
TPaintBox *m_pbUserNoticeNum;
TransparentPanelUnit::TPanel *m_panelNoticeNum;
TImage *m_imgVip;
CommonListBoxUnit::TListBox *m_lbFontSelect;
Vcl::Extctrls::TPanel *m_panelFontName;
TImage *m_imgFontNameBk;
TLabel *m_lblFontName;
TPNGButton *m_btnFontChange;
TLabel *m_lblExtFont;
void __fastcall FormCreate(TObject *Sender);
void __fastcall OnBtnSysMenuClick(TObject *Sender);
void __fastcall CloseBoxClick(TObject *Sender);
void __fastcall MinBoxClick(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall MaxBoxClick(TObject *Sender);
void __fastcall RestBoxClick(TObject *Sender);
void __fastcall LoginClick(TObject *Sender);
void __fastcall LogoffClick(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
void __fastcall UsernameMouseEnter(TObject *Sender);
void __fastcall UsernameMouseLeave(TObject *Sender);
void __fastcall UsernameMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall OnSelectPageStep(TObject *Sender);
void __fastcall HelpBoxClick(TObject *Sender);
void __fastcall UserNoticeNumPaint(TObject *Sender);
void __fastcall UserNoticeNumClick(TObject *Sender);
void __fastcall UserNoticeNumMouseEnter(TObject *Sender);
void __fastcall UserNoticeNumMouseLeave(TObject *Sender);
void __fastcall OnCustomerSetting(TObject *Sender);
void __fastcall UserIconClick(TObject *Sender);
void __fastcall VipClick(TObject *Sender);
void __fastcall FontSelectMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall DownloadExtFontClick(TObject *Sender);
void __fastcall ExtFontMouseEnter(TObject *Sender);
void __fastcall ExtFontMouseLeave(TObject *Sender);
void __fastcall FontChangeMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y); //add by tj 2014/05/15
private: // User declarations
// TJPEGImage *m_pPicTabBk;
TPngImage *m_pImgNoticeNum,
*m_pImgTopLeft,
*m_pImgTopRight,
*m_pImgTopTile,
*m_pImgHorTile,
*m_pImgVerTile,
*m_pImgBottomLeft,
*m_pImgBottomRight;
TTabSheet *m_paTabSheets[TABSHEET_NUM];
TSystemMenu *m_pSysMenu;
String m_strLoadProjectName;
TPNGButton *m_btnStep[5];
//用户信息提示相关
TSkinHintWindow * m_pStyleInfoWnd;
bool m_bShowHint, m_bUNHot;
TTimer *m_pTimerHint;
void __fastcall HintTimerProc(TObject* Sender);
//动态 //add by tj 2014/04/17
TTimer *m_pNotificationGetTimer;
void __fastcall NotificationTimerProc(TObject* Sender);
TNotificationForm *m_pNotificationForm;
//倒计时定时器
TTimer * m_pCDTimer;
void __fastcall CDTimerProc(TObject* Sender);
void __fastcall ClearCDTimer();
String m_strUsrIconPath;
void InitFontList();
bool SetSelectFont();
void UpdateProjectMenuItems();
void SetActivePage( int iActiveIndex );
void LoadProject( LPCTSTR strName );
void NewProject();
void LoadNewcomerMission();
// bool CheckPayment( int iOperation );
int SaveMedia( int iOperation, int iSaveOption, int iFileType, String strFileName, bool bUpload=false );
void ShowErrorMessage( int err, String strOperation );
void __fastcall OnCreateNewProject(TObject * Sender = NULL);
void __fastcall OnPredefineProject(TObject * Sender = NULL);
void __fastcall CreateParams(TCreateParams &Params);
void __fastcall OnSaveProject(TObject *Sender=NULL);
void __fastcall OnLoadProject(TObject *Sender=NULL);
void __fastcall OnUserHelp(TObject *Sender=NULL);
void __fastcall OnForumVist(TObject *Sender=NULL);
void __fastcall OnAbout(TObject *Sender=NULL);
void __fastcall OnSoftwares(TObject *Sender=NULL);
void __fastcall OnNotification(TObject *Sender=NULL);
void __fastcall OnIOSetting(TObject *Sender=NULL);
void __fastcall OnUserManual(TObject *Sender=NULL);
//消息处理
MESSAGE void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
MESSAGE void __fastcall WMNCLButtonDblClk(TWMNCLButtonDblClk &Msg);
MESSAGE void __fastcall OnRestoreWindow(TMessage &msg);
MESSAGE void __fastcall OnShowNextPage(TMessage &msg);
MESSAGE void __fastcall OnShowSysMenu(TMessage &msg);
MESSAGE void __fastcall OnLogin(TMessage &msg);
MESSAGE void __fastcall OnNetworkError(TMessage &msg);
MESSAGE void __fastcall OnNetworkMessage(TMessage &msg);
MESSAGE void __fastcall OnLoadProjectMessage(TMessage &msg);
MESSAGE void __fastcall OnSaveProjectMessage(TMessage &msg);
MESSAGE void __fastcall OnNewProjectMessage(TMessage &msg);
MESSAGE void __fastcall AcceptFiles (TMessage& Msg);
MESSAGE void __fastcall OnRefreshStepPageState(TMessage & Msg);
MESSAGE void __fastcall OnJumpPage(TMessage & Msg);
MESSAGE void __fastcall OnShowAbout(TMessage & Msg);
MESSAGE void __fastcall OnShowMore(TMessage & Msg);
MESSAGE void __fastcall OnOpenManual(TMessage & Msg);
MESSAGE void __fastcall OnAudioEffect(TMessage & Msg);
MESSAGE void __fastcall OnSaveMusic(TMessage & Msg);
MESSAGE void __fastcall OnUploadMusic(TMessage & Msg);
MESSAGE void __fastcall OnMicSetting(TMessage & Msg);
MESSAGE void __fastcall OnOpenAutoProj(TMessage & Msg);//add by tj 2013/1/2
// MESSAGE void __fastcall OnHandleAutoProj(TMessage & Msg);
MESSAGE void __fastcall UMNotification(TMessage & Msg); //add by tj 2014/04/17
MESSAGE void __fastcall OnUploadUsrIcon(TMessage & Msg);
MESSAGE void __fastcall WMEraseBkgnd(Winapi::Messages::TWMEraseBkgnd &Message);
MESSAGE void __fastcall WMDpiChanged(TMessage &Message);
MESSAGE void __fastcall UMStartCDTimer(TMessage &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(UM_REFRESH_PAGE_STATE, TMessage, OnRefreshStepPageState)
MESSAGE_HANDLER(UM_RESTORE, TMessage, OnRestoreWindow)
MESSAGE_HANDLER(UM_SHOWNEXTPAGE, TMessage, OnShowNextPage)
MESSAGE_HANDLER(UM_SHOWSYSMENU, TMessage, OnShowSysMenu)
MESSAGE_HANDLER(UM_LOGIN, TMessage, OnLogin)
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
MESSAGE_HANDLER(WM_NCLBUTTONDBLCLK, TWMNCLButtonDblClk, WMNCLButtonDblClk)
MESSAGE_HANDLER(MSG_NETWORKERROR, TMessage, OnNetworkError)
MESSAGE_HANDLER(MSG_NETWORKMESSAGE, TMessage, OnNetworkMessage)
MESSAGE_HANDLER(UM_LOADPROJECT, TMessage, OnLoadProjectMessage)
MESSAGE_HANDLER(UM_SAVEPROJECT, TMessage, OnSaveProjectMessage)
MESSAGE_HANDLER(UM_NEWPROJECT, TMessage, OnNewProjectMessage)
MESSAGE_HANDLER(WM_DROPFILES,TMessage, AcceptFiles)
MESSAGE_HANDLER(UM_JUMP_PAGE,TMessage,OnJumpPage)
MESSAGE_HANDLER(UM_SHOWABOUT,TMessage,OnShowAbout)
MESSAGE_HANDLER(UM_SHOWMORE,TMessage,OnShowMore)
MESSAGE_HANDLER(UM_OPENMANUAL,TMessage,OnOpenManual)
MESSAGE_HANDLER(UM_AUDIOEFFECT,TMessage,OnAudioEffect)
MESSAGE_HANDLER(UM_SAVEMUSIC,TMessage,OnSaveMusic)
MESSAGE_HANDLER(UM_UPLOADMUSIC,TMessage,OnUploadMusic)
MESSAGE_HANDLER(UM_MICSETTING,TMessage,OnMicSetting)
MESSAGE_HANDLER(UM_OPENAUTOPROJ,TMessage,OnOpenAutoProj) //add by tj 2013/1/2
MESSAGE_HANDLER(UM_NOTIFICATION, TMessage, UMNotification) //add by tj 2014/04/17
MESSAGE_HANDLER(UM_UPLOADUSRICON,TMessage, OnUploadUsrIcon)
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
MESSAGE_HANDLER(WM_DPICHANGED, TMessage, WMDpiChanged)
MESSAGE_HANDLER(UM_STARTCDTIMER, TMessage, UMStartCDTimer)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
__fastcall ~TMainForm();
public:
void SetSysMenuState(int iMenuIndex,bool bIsEnable);
int GetActivePageIndex();
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
+134
View File
@@ -0,0 +1,134 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "ManageSongFormUnit.h"
#include "QRcodePanel.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TManageSongForm *ManageSongForm;
TQRcodePanel * QRPanel = NULL;
//---------------------------------------------------------------------------
__fastcall TManageSongForm::TManageSongForm(TComponent* Owner, bool bUpload, UINT idSong )
: TForm(Owner)
{
m_pQRdata = NULL;
char strURL[1024];
if( bUpload ){
if( idSong>0 ){
String strMsg = L"歌曲上传成功\n\n请进入网站";
if( f_QR_Encode && f_CS_GetWebPageURL ){
char strURL[256], strID[20];
f_CS_GetWebPageURL( URL_SHAREPLAY, strURL );
sprintf( strID, "%d", idSong );
strcat( strURL, strID );
m_pQRdata = new unsigned char[100*100];
int qrWidth = f_QR_Encode( strURL, m_pQRdata );
QRPanel = new TQRcodePanel( NULL );
if( QRPanel ){
m_lbMsg->Width = 150;
m_lbGoManage->Left = 72;
QRPanel->Parent = this;
QRPanel->SetBounds( 192, 26, 100, 100 );
QRPanel->SetQRData( qrWidth, m_pQRdata );
QRPanel->Show();
}
}
strMsg += L"试听和分享";
f_CS_GetWebPageURL( URL_SONGPLAY, strURL );
m_strGo = strURL;
m_strGo += "&musicId=" + IntToStr( (int)idSong );
m_lbMsg->Caption = strMsg;
}
}
else{
m_lbMsg->Caption = L"您上传的未发布歌曲数量已达上限,\n\n请进入网站处理。";
f_CS_GetWebPageURL( URL_SONGMANAGE, strURL );
m_strGo = strURL;
}
Font->Color = RGB(60,43,23);
}
//---------------------------------------------------------------------------
void __fastcall TManageSongForm::FormCreate(TObject *Sender)
{
SetTransparent( this );
Left = Screen->Width / 2 - Width / 2;
Top = Screen->Height / 2 - Height / 2;
HRGN hRgn = CreateRoundRectRgn(0, 0, Width + 1, Height + 1, 20, 20);
SetWindowRgn(Handle, hRgn, TRUE);
DeleteObject(hRgn);
}
//---------------------------------------------------------------------------
void __fastcall TManageSongForm::WMNCHitTest(TWMNCHitTest &Msg) {
TForm::Dispatch(&Msg);
if (Msg.Result == HTCLIENT && Msg.XPos > Left + 10 && Msg.XPos <
Left + Width - 20 && Msg.YPos < Top + 24)
Msg.Result = HTCAPTION;
}
//---------------------------------------------------------------------------
void __fastcall TManageSongForm::GoManageMouseEnter(TObject *Sender)
{
Screen->Cursor = crHandPoint;
}
//---------------------------------------------------------------------------
void __fastcall TManageSongForm::GoManageMouseLeave(TObject *Sender)
{
Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
void __fastcall TManageSongForm::GoManageClick(TObject *Sender)
{
// char strURL[256];
// f_CS_GetWebPageURL( URL_SONGMANAGE, strURL );
// ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
ShellExecute(Handle, NULL, m_strGo.c_str(), NULL, NULL, SW_SHOWNORMAL);
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TManageSongForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
switch( Key ){
case VK_RETURN:
return GoManageClick(NULL);
break;
case VK_ESCAPE:
ModalResult = mrCancel;
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TManageSongForm::FormDestroy(TObject *Sender)
{
if( QRPanel ){
delete QRPanel;
QRPanel = NULL;
}
if( m_pQRdata ){
delete[] m_pQRdata;
m_pQRdata = NULL;
}
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+45
View File
@@ -0,0 +1,45 @@
//---------------------------------------------------------------------------
#ifndef ManageSongFormUnitH
#define ManageSongFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include "PNGButton.hpp"
//---------------------------------------------------------------------------
class TManageSongForm : public TForm
{
__published: // IDE-managed Components
TImage *m_ImgBkg;
TImage *m_ImgFlag;
TLabel *m_lbMsg;
TLabel *m_lbTitle;
TPNGButton *m_btnClose;
TLabel *m_lbGoManage;
void __fastcall GoManageMouseEnter(TObject *Sender);
void __fastcall GoManageMouseLeave(TObject *Sender);
void __fastcall GoManageClick(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall FormDestroy(TObject *Sender);
private: // User declarations
unsigned char * m_pQRdata;
String m_strGo;
void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TManageSongForm(TComponent* Owner, bool bUpload, UINT idSong=0 );
void SetMessage(String strMsg);
};
//---------------------------------------------------------------------------
extern PACKAGE TManageSongForm *ManageSongForm;
//---------------------------------------------------------------------------
#endif
+80
View File
@@ -0,0 +1,80 @@
//---------------------------------------------------------------------------
#pragma hdrstop
#include <tchar.h>
#include "MenuHookUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
WNDPROC MenuOldWndProc;
LRESULT CALLBACK MenuWndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
LRESULT ret;
switch( Msg ){
case WM_CREATE:
ret = CallWindowProc( MenuOldWndProc, hWnd, Msg, wParam, lParam );
{
//去除边界
DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
dwStyle &= ~( WS_BORDER | WS_DLGFRAME );
SetWindowLong(hWnd, GWL_STYLE, dwStyle );
//去除框架
DWORD dwStyleEx = GetWindowLong(hWnd, GWL_EXSTYLE);
dwStyleEx &= ~( WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE );
SetWindowLong(hWnd, GWL_EXSTYLE, dwStyleEx);
}
return ret;
case WM_PRINT:
return CallWindowProc( MenuOldWndProc, hWnd, WM_PRINTCLIENT, wParam, lParam );
case WM_WINDOWPOSCHANGING:
{
//将菜单大小改小
PWINDOWPOS lpPos = PWINDOWPOS(lParam);
int deltaX = GetSystemMetrics(SM_CXEDGE) + GetSystemMetrics(SM_CXFOCUSBORDER);
int deltaY = GetSystemMetrics(SM_CYEDGE) + GetSystemMetrics(SM_CYFOCUSBORDER);
lpPos->cx -= 2 * deltaX;
lpPos->cy -= 2 * deltaY;
}
return CallWindowProc( MenuOldWndProc, hWnd, Msg, wParam, lParam );
case WM_GETICON:
return 0;
case WM_NCPAINT:
return CallWindowProc( MenuOldWndProc, hWnd, WM_PRINT, wParam, lParam );
default:
return CallWindowProc( MenuOldWndProc, hWnd, Msg, wParam, lParam );
}
}
LRESULT CALLBACK WindowsHook( int Code, UINT wParam, long lParam)
{
PCWPSTRUCT pStruct;
WNDPROC lastWndProc;
TCHAR strClassName[64];
pStruct = (PCWPSTRUCT)lParam;
//捕捉菜单创建WM_CREATE和0x01E2消息,检查是否菜单窗口
if( Code==HC_ACTION && ( pStruct->message==WM_CREATE || pStruct->message==0x01E2 ) &&
GetClassName(pStruct->hwnd, strClassName, sizeof(strClassName))==6 &&
_tcscmp(strClassName, L"#32768")==0 ){
lastWndProc = (WNDPROC)GetWindowLong( pStruct->hwnd, GWL_WNDPROC );
if( lastWndProc!=MenuWndProc ){
//替换菜单窗口过程函数
SetWindowLong( pStruct->hwnd, GWL_WNDPROC, (long)MenuWndProc );
//保留旧的窗口过程
MenuOldWndProc = lastWndProc;
}
}
return CallNextHookEx( (HHOOK)WH_CALLWNDPROC, Code, wParam, lParam );
}
+11
View File
@@ -0,0 +1,11 @@
//---------------------------------------------------------------------------
#ifndef MenuHookUnitH
#define MenuHookUnitH
#include <windows.h>
LRESULT CALLBACK MenuWndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
LRESULT CALLBACK WindowsHook( int Code, UINT wParam, long lParam);
//---------------------------------------------------------------------------
#endif
+195
View File
@@ -0,0 +1,195 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MessageFormUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TMessageForm *MessageForm;
//---------------------------------------------------------------------------
__fastcall TMessageForm::TMessageForm(TComponent* Owner)
: TForm(Owner)
{
m_pImgCheck = new TBitmap();
m_pImgCheck->LoadFromResourceName(int(HInstance), L"AutoLoginCheck");
m_iCheck = -1;
Font->Color = RGB(60,43,23);
SetTransparent( this );
}
//---------------------------------------------------------------------------
__fastcall TMessageForm::~TMessageForm()
{
delete m_pImgCheck;
}
//---------------------------------------------------------------------------
void __fastcall TMessageForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if( Msg.Result==HTCLIENT && Msg.YPos<Top+24 )
Msg.Result = HTCAPTION;
}
//---------------------------------------------------------------------------
int __fastcall TMessageForm::ShowMessage( const String AMessage, int AType )
{
if( Visible )
return -1;
m_iconInformation->Visible = false;
m_iconError->Visible = false;
m_iconQuestion->Visible = false;
m_btnYes->Visible = false;
m_btnNo->Visible = false;
m_btnOk->Visible = false;
m_btnCancel->Visible = false;
int iIconType = AType & 0x0F0;
if( iIconType==MB_ICONERROR ){
m_iconError->Visible = true;
}
else if( iIconType==MB_ICONQUESTION ) {
m_iconQuestion->Visible = true;
}
else if( iIconType==MB_ICONINFORMATION ) {
m_iconInformation->Visible = true;
}
int iButtonType = AType & 0x0F;
if( iButtonType==MB_OK ){
m_btnOk->Visible = true;
m_btnOk->Left = (Width - m_btnOk->Width)/2 + 6;
}
else if( iButtonType==MB_OKCANCEL ){
m_btnOk->Visible = true;
m_btnCancel->Visible = true;
m_btnOk->Left = (Width - (m_btnOk->Width+6)*2 )/2 + 6;
m_btnCancel->Left = m_btnOk->Left + m_btnOk->Width + 6;
}
else if( iButtonType==MB_YESNO ){
m_btnYes->Visible = true;
m_btnNo->Visible = true;
m_btnYes->Left = (Width - (m_btnYes->Width+6)*2 )/2 + 6;
m_btnNo->Left = m_btnYes->Left + m_btnYes->Width + 6;
}
else if( iButtonType==MB_YESNOCANCEL ){
m_btnYes->Visible = true;
m_btnNo->Visible = true;
m_btnCancel->Visible = true;
m_btnYes->Left = (Width - (m_btnYes->Width+6)*3 )/2 + 6;
m_btnNo->Left = m_btnYes->Left + m_btnYes->Width + 6;
m_btnCancel->Left = m_btnNo->Left + m_btnNo->Width + 6;
}
int iCheckType = AType & 0xF00;
if( iCheckType ){
if( iCheckType==MB_CHECKED ){
m_iCheck = 1;
}
else if( iCheckType==MB_UNCHECKED ){
m_iCheck = 0;
}
m_pbCheck->Show();
m_lblCheckMessage->Show();
}
else{
m_pbCheck->Hide();
m_lblCheckMessage->Hide();
}
m_lblMessage->Caption = AMessage;
HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+2, 20, 20 );
SetWindowRgn( Handle, hRgn, false );
DeleteObject( hRgn );
return ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TMessageForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
switch( Key ){
case VK_RETURN:
case ' ':
if( m_btnYes->Visible )
ModalResult = mrYes;
else if( m_btnOk->Visible )
ModalResult = mrOk;
break;
case VK_ESCAPE:
if( m_btnCancel->Visible )
ModalResult = mrCancel;
break;
case 'Y':
if( m_btnYes->Visible )
ModalResult = mrYes;
break;
case 'N':
if( m_btnNo->Visible )
ModalResult = mrNo;
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TMessageForm::CheckPaint(TObject *Sender)
{
//绘制Check状态
if( m_iCheck>=0 ){
int x = 0;
if( m_iCheck==0 ){
x = -m_pImgCheck->Width/2;
}
m_pbCheck->Canvas->Draw(x, 0, m_pImgCheck);
}
}
//---------------------------------------------------------------------------
void _fastcall TMessageForm::SetCheckMessage( String strMessage )
{
if( strMessage.IsEmpty() ){
m_lblCheckMessage->Caption = L"不再提示";
}
else{
m_lblCheckMessage->Caption = strMessage;
}
}
//---------------------------------------------------------------------------
void __fastcall TMessageForm::CheckClick(TObject *Sender)
{
//切换Check状态
if( m_iCheck==0 ){
m_iCheck = 1;
}
else{
m_iCheck = 0;
}
m_pbCheck->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TMessageForm::CheckMessageClick(TObject *Sender)
{
CheckClick( NULL );
}
//---------------------------------------------------------------------------
bool TMessageForm::GetCheckState()
{
return (m_iCheck==1)?true:false;
}
File diff suppressed because it is too large Load Diff
+60
View File
@@ -0,0 +1,60 @@
//---------------------------------------------------------------------------
#ifndef MessageFormUnitH
#define MessageFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include "PNGButton.hpp"
#include <Vcl.Imaging.jpeg.hpp>
#include <Vcl.Graphics.hpp>
//---------------------------------------------------------------------------
#define MB_CHECKED 0x100
#define MB_UNCHECKED 0x200
class TMessageForm : public TForm
{
__published: // IDE-managed Components
TImage *m_imgBk;
TImage *m_iconError;
TImage *m_iconInformation;
TImage *m_iconQuestion;
TPNGButton *m_btnYes;
TPNGButton *m_btnOk;
TPNGButton *m_btnNo;
TPNGButton *m_btnCancel;
TLabel *m_lblMessage;
TPaintBox *m_pbCheck;
TLabel *m_lblCheckMessage;
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall CheckPaint(TObject *Sender);
void __fastcall CheckClick(TObject *Sender);
void __fastcall CheckMessageClick(TObject *Sender);
private: // User declarations
TBitmap * m_pImgCheck;
int m_iCheck;
void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TMessageForm(TComponent* Owner);
__fastcall ~TMessageForm();
void _fastcall SetCheckMessage( String strMessage );
bool GetCheckState();
int __fastcall ShowMessage( const String AMessage, int AType=MB_ICONINFORMATION|MB_OK );
};
//---------------------------------------------------------------------------
extern PACKAGE TMessageForm *MessageForm;
//---------------------------------------------------------------------------
#endif
+789
View File
@@ -0,0 +1,789 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "MessageFormUnit.h"
#include "MicSetFormUnit.h"
#define IO_DEVICE_WASAPI 0x10000
#define IO_DEVICE_ASIO 0x20000
#define IO_DEVICE_MIDI 0x40000
#define DEVICE_DEFAULT 0x02
#define REC_INPUT_OFF 0x10000
// source info structure
typedef struct {
char name[256];
DWORD flags;
} IO_CHANNEL_INFO;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
USEFORM("MessageFormUnit.cpp", MessageForm);
TMicSetForm *MicSetForm;
//---------------------------------------------------------------------------
__fastcall TMicSetForm::TMicSetForm(TComponent* Owner)
: TForm(Owner)
{
m_pImgCheck = new TBitmap();
m_pImgCheck->LoadFromResourceName(int(HInstance), L"AutoLoginCheck");
Font->Color = RGB(60,43,23);
m_iCurrPlaybackDevice = m_iCurrRecordDevice = -1;
m_iCurrOutput = m_iCurrInput = -1;
m_PopupMenu = NULL;
}
//---------------------------------------------------------------------------
__fastcall TMicSetForm::~TMicSetForm()
{
if( m_pImgCheck ){
delete m_pImgCheck;
m_pImgCheck = NULL;
}
if( m_PopupMenu ){
delete m_PopupMenu;
m_PopupMenu = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::FormCreate(TObject *Sender)
{
m_tbVolume->ControlStyle>>csOpaque;
Font->Color = RGB(60,43,23);
//绘制圆角窗体
HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+1, 16, 16 );
SetWindowRgn( Handle, hRgn, false );
DeleteObject( hRgn );
m_bAutoAdjust = g_bRecordAutoAdjust;
m_bMoniter = g_bRecordMoniter;
m_iCurrPlaybackDevice = g_iPlaybackDevice;
m_iCurrOutput = g_iPlaybackOutput;
m_iCurrRecordDevice = g_iRecordDevice;
m_iCurrInput = g_iRecordInput;
IO_DEVICE_INFO aPbDevs[20], //播放设备
aRcDevs[20]; //录音设备
int nPbDev = f_MM_GetPlaybackDeviceInfo( 20, aPbDevs );
int nRcDev = f_MM_GetRecordDeviceInfo( 20, aRcDevs );
for( int i=0; i<nPbDev; i++ ){
IO_DEVICE_INFO * pDev = new IO_DEVICE_INFO(aPbDevs[i]);
if( pDev->iDevice & IO_DEVICE_WASAPI )
m_aWasapiPb.push_back( pDev );
else if( pDev->iDevice & IO_DEVICE_ASIO )
m_aAsioPb.push_back( pDev );
else
m_aCommonPb.push_back( pDev );
}
for( int i=0; i<nRcDev; i++ ){
IO_DEVICE_INFO * pDev = new IO_DEVICE_INFO(aRcDevs[i]);
if( pDev->iDevice & IO_DEVICE_WASAPI )
m_aWasapiRc.push_back( pDev );
else if( pDev->iDevice & IO_DEVICE_MIDI )
m_aMidiRc.push_back( pDev );
else
m_aCommonRc.push_back( pDev );
}
m_rbCommon->Enabled = !m_aCommonPb.empty();// && !m_aCommonRc.empty();
m_rbASIO->Enabled = !m_aAsioPb.empty();
m_rbWASAPI->Enabled = !m_aWasapiPb.empty();// && !m_aWasapiPb.empty();
int iType = m_iCurrPlaybackDevice>=0 ? (m_iCurrPlaybackDevice & 0xF0000) : -1;
if( m_iCurrPlaybackDevice<0 && !m_aCommonPb.empty()
|| m_iCurrRecordDevice<0 && ( iType==0 && !m_aCommonRc.empty()
|| iType==IO_DEVICE_WASAPI && !m_aWasapiRc.empty() ) )
f_MM_SetIODevice( m_iCurrPlaybackDevice, m_iCurrOutput,
m_iCurrRecordDevice, m_iCurrInput );
if( iType<0 )
iType = m_iCurrPlaybackDevice>=0 ? (m_iCurrPlaybackDevice & 0xF0000) : -1;
m_rbCommon->Checked = iType==0;
m_rbASIO->Checked = iType==IO_DEVICE_ASIO;
m_rbWASAPI->Checked = iType==IO_DEVICE_WASAPI;
ReloadPlayDev();
ReloadOutput();
ReloadRecDev();
ReloadInput();
m_pTimerLatency = new TTimer(this);
m_pTimerLatency->Enabled = false;
m_pTimerLatency->Interval = 250;
m_pTimerLatency->OnTimer = LatencyTimerProc;
m_tbVolume->Position = g_fRecordVolume * 100;
m_tbVolume->Hint = IntToStr(m_tbVolume->Position);
if( m_iCurrPlaybackDevice>=0 && m_iCurrRecordDevice>=0 )
BeginRecordTest();
else
m_tbVolume->Enabled = false;
SetTransparent( this );
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::FormClose(TObject *Sender, TCloseAction &Action)
{
BeginRecordTest( false );
if( m_pTimerLatency ){
delete m_pTimerLatency;
m_pTimerLatency = NULL;
}
if( m_PopupMenu ){
delete m_PopupMenu;
m_PopupMenu = NULL;
}
while( !m_aCommonPb.empty() ){
delete m_aCommonPb.back();
m_aCommonPb.pop_back();
}
while( !m_aCommonRc.empty() ){
delete m_aCommonRc.back();
m_aCommonRc.pop_back();
}
while( !m_aWasapiPb.empty() ){
delete m_aWasapiPb.back();
m_aWasapiPb.pop_back();
}
while( !m_aWasapiRc.empty() ){
delete m_aWasapiRc.back();
m_aWasapiRc.pop_back();
}
while( !m_aAsioPb.empty() ){
delete m_aAsioPb.back();
m_aAsioPb.pop_back();
}
while( !m_aMidiRc.empty() ){
delete m_aMidiRc.back();
m_aMidiRc.pop_back();
}
if( ModalResult!=mrOk ){
if( !(g_iPlaybackDevice==m_iCurrPlaybackDevice
&& g_iRecordDevice==m_iCurrRecordDevice
&& g_iPlaybackOutput==m_iCurrOutput
&& g_iRecordInput==m_iCurrInput) ){
f_MM_SetIODevice( g_iPlaybackDevice, g_iPlaybackOutput,
g_iRecordDevice, g_iRecordInput );
}
if( m_bAutoAdjust!=g_bRecordAutoAdjust )
f_MM_SetRecordAutoAdjust( g_bRecordAutoAdjust );
if( m_bMoniter!=g_bRecordMoniter )
f_MM_SetRecordMoniter( g_bRecordMoniter );
f_MM_SetStreamVolume( 1, g_fRecordVolume );
}
}
//---------------------------------------------------------------------------
void TMicSetForm::ReloadPlayDev()
{
m_cbPlayDev->Clear();
int iDevice = -1;
if( m_iCurrPlaybackDevice>0 ){
int iType = m_iCurrPlaybackDevice & 0xF0000;
vector<IO_DEVICE_INFO*>& rDevs = iType==IO_DEVICE_WASAPI ? m_aWasapiPb
: iType==IO_DEVICE_ASIO ? m_aAsioPb
: m_aCommonPb;
for( int i=0; i<rDevs.size(); i++ ){
if( rDevs[i]->iDevice==m_iCurrPlaybackDevice )
iDevice = m_cbPlayDev->Items->Count;
if( iType==0 && !strcmp( rDevs[i]->name, "Default" ))
m_cbPlayDev->AddItem( "系统默认设备", (TObject*)rDevs[i]->iDevice );
else
m_cbPlayDev->AddItem( rDevs[i]->name, (TObject*)rDevs[i]->iDevice );
}
}
m_cbPlayDev->ItemIndex = iDevice;
m_cbPlayDev->Enabled = m_cbPlayDev->Items->Count > 0;
}
//---------------------------------------------------------------------------
void TMicSetForm::ReloadRecDev()
{
if( !m_rbASIO->Checked ){
m_cbRecDevOrOutput->Clear();
int iDevice = -1;
if( m_iCurrRecordDevice>=0 ){
int iType = m_iCurrRecordDevice & 0xF0000;
m_lblRecDevOrOutput->Caption = "录音设备";
m_cbRecDevOrOutput->Width = m_cbPlayDev->Width;
m_lblASIO->Visible = false;
vector<IO_DEVICE_INFO*>& rDevs = iType==IO_DEVICE_WASAPI ? m_aWasapiRc
: iType==IO_DEVICE_MIDI ? m_aMidiRc
: m_aCommonRc;
for( int i=0; i<rDevs.size(); i++ ){
if( rDevs[i]->iDevice==m_iCurrRecordDevice )
iDevice = m_cbRecDevOrOutput->Items->Count;
if( iType==0 && !strcmp( rDevs[i]->name, "Default" ))
m_cbRecDevOrOutput->AddItem( "系统默认设备", (TObject*)rDevs[i]->iDevice );
else
m_cbRecDevOrOutput->AddItem( rDevs[i]->name, (TObject*)rDevs[i]->iDevice );
}
}
m_cbRecDevOrOutput->ItemIndex = iDevice;
m_cbRecDevOrOutput->Enabled = m_cbRecDevOrOutput->Items->Count > 0;
}
}
//---------------------------------------------------------------------------
void TMicSetForm::ReloadOutput()
{
if( m_rbASIO->Checked ){
int iDevice = -1;
m_cbRecDevOrOutput->Clear();
m_lblRecDevOrOutput->Caption = "播放输出";
m_cbRecDevOrOutput->Width = m_cbInput->Width;
m_lblASIO->Visible = true;
IO_CHANNEL_INFO chanInfo[20];
int nSize = f_MM_GetPlaybackOutputInfo( 20, chanInfo );
int iChannel = -1;
if( m_iCurrOutput>=0 && m_iCurrOutput<nSize)
iChannel = m_iCurrOutput;
else if( nSize>0 )
iChannel = 0;
for( int i=0; i<nSize; i+=2 ){
m_cbRecDevOrOutput->AddItem( chanInfo[i].name, (TObject*)i );
}
if( iChannel>=0 )
m_cbRecDevOrOutput->ItemIndex = iChannel/2;
m_iCurrOutput = iChannel;
m_lblASIO->Enabled = iChannel>=0;
m_cbRecDevOrOutput->Enabled = m_cbRecDevOrOutput->Items->Count > 0;
}
}
//---------------------------------------------------------------------------
void TMicSetForm::ReloadInput()
{
m_cbInput->Clear();
if( !m_cbRecDevOrOutput->Enabled ){
m_cbInput->Enabled = false;
return;
}
IO_CHANNEL_INFO chanInfo[20];
int iChannel = -1;
int nSize = f_MM_GetRecordInputInfo( 20, chanInfo );
if( m_iCurrInput>=0 && m_iCurrInput<nSize){
iChannel = m_iCurrInput;
}
if( nSize>0 ){
for( int i=0; i<nSize; i++ ){
m_cbInput->AddItem( chanInfo[i].name, (TObject*)i );
if( iChannel<0 ){
iChannel = i;
}
}
if( iChannel<0 ){
iChannel = 0;
}
m_cbInput->ItemIndex = iChannel;
}
else if( (m_iCurrPlaybackDevice & 0xF0000)!=IO_DEVICE_ASIO ){
m_cbInput->AddItem( "默认输入", (TObject*)0 );
m_cbInput->ItemIndex = 0;
}
m_cbInput->Enabled = m_cbInput->Items->Count > 0;
m_iCurrInput = iChannel;
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if( Msg.Result==HTCLIENT && Msg.YPos<Top+24
&& Msg.XPos>Left+35 && Msg.XPos<Left+275 )
Msg.Result = HTCAPTION;
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
switch( Key ){
case VK_RETURN:
case ' ':
if( m_btnOk->Visible ){
OkClick( NULL );
ModalResult = mrOk;
}
break;
case VK_ESCAPE:
if( m_btnCancel->Visible )
ModalResult = mrCancel;
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::CheckPaint(TObject *Sender)
{
TPaintBox* pPB = (TPaintBox*)Sender;
//绘制Check状态
int x = 0;
if( pPB==m_pbAutoCheck && !m_bAutoAdjust
|| pPB==m_pbMoniter && !m_bMoniter ){
x = -m_pImgCheck->Width/2;
}
pPB->Canvas->Draw(x, 0, m_pImgCheck);
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::CheckClick(TObject *Sender)
{
TPaintBox* pPB = (TPaintBox*)Sender;
//切换Check状态
if( pPB==m_pbAutoCheck ){
m_bAutoAdjust = !m_bAutoAdjust;
f_MM_SetRecordAutoAdjust( m_bAutoAdjust );
}
else{
m_bMoniter = !m_bMoniter;
f_MM_SetRecordMoniter( m_bMoniter );
}
pPB->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::OkClick(TObject *Sender)
{
g_iPlaybackDevice = m_iCurrPlaybackDevice;
g_iRecordDevice = m_iCurrRecordDevice;
g_iPlaybackOutput = m_iCurrOutput;
g_iRecordInput = m_iCurrInput;
int iType = m_iCurrPlaybackDevice & 0xF0000;
vector<IO_DEVICE_INFO*>& rDevsPb = iType==IO_DEVICE_WASAPI ? m_aWasapiPb
: iType==IO_DEVICE_ASIO ? m_aAsioPb
: m_aCommonPb;
for( int i=0; i<rDevsPb.size(); i++ ){
if( rDevsPb[i]->iDevice==m_iCurrPlaybackDevice ){
strcpy( g_strPlaybackDevice, rDevsPb[i]->name );
break;
}
}
iType = m_iCurrRecordDevice & 0xF0000;
if( iType==IO_DEVICE_ASIO ){
strcpy( g_strRecordDevice, g_strPlaybackDevice );
}
else{
vector<IO_DEVICE_INFO*>& rDevsRc = iType==IO_DEVICE_WASAPI ? m_aWasapiRc
: iType==IO_DEVICE_MIDI ? m_aMidiRc
: m_aCommonRc;
for( int i=0; i<rDevsRc.size(); i++ ){
if( rDevsRc[i]->iDevice==m_iCurrRecordDevice ){
strcpy( g_strRecordDevice, rDevsRc[i]->name );
break;
}
}
}
//保存所有状态
g_fRecordVolume = m_tbVolume->Position / 100.0;
// g_fRecordVolume = f_MM_GetStreamVolume( 1 ) / 100.0;
g_bRecordAutoAdjust = m_bAutoAdjust;
g_bRecordMoniter = m_bMoniter;
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::PlayDevChange(TObject *Sender)
{
int iNewDev = (int)(m_cbPlayDev->Items->Objects[m_cbPlayDev->ItemIndex]);
if( iNewDev==m_iCurrPlaybackDevice )
return;
BeginRecordTest( false );
int iType = (m_iCurrPlaybackDevice & 0xF0000);
int iPlayDev = iNewDev, iOutput = -1,
iRecDev = m_iCurrRecordDevice,
iInput = m_iCurrInput;
if( iType==IO_DEVICE_ASIO ){
iRecDev = iNewDev;
iInput = -1;
}
Screen->Cursor = crHourGlass;
HRESULT hr = f_MM_SetIODevice( iPlayDev, iOutput, iRecDev, iInput );
m_iCurrPlaybackDevice = iPlayDev;
m_iCurrOutput = iOutput;
m_iCurrRecordDevice = iRecDev;
m_iCurrInput = iInput;
if( iType==IO_DEVICE_ASIO ){
ReloadOutput();
ReloadInput();
}
if( hr==S_OK ){
if( m_iCurrRecordDevice>=0 )
BeginRecordTest();
}
else
ShowErrorMessage( hr );
m_tbVolume->Enabled = hr==S_OK && m_iCurrRecordDevice>=0;
Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::RecDevOrOutputChange(TObject *Sender)
{
int iIndex = (int)(m_cbRecDevOrOutput->Items->Objects[m_cbRecDevOrOutput->ItemIndex]);
int iPlayDev = m_iCurrPlaybackDevice,
iOutput = m_iCurrOutput,
iRecDev = m_iCurrRecordDevice,
iInput = m_iCurrInput;
if( m_rbASIO->Checked ){
if( iIndex==m_iCurrOutput )
return;
else
iOutput = iIndex;
}
else{
if( iIndex==m_iCurrRecordDevice )
return;
else
iRecDev = iIndex;
}
BeginRecordTest( false );
Screen->Cursor = crHourGlass;
HRESULT hr = f_MM_SetIODevice( iPlayDev, iOutput, iRecDev, iInput );
m_iCurrPlaybackDevice = iPlayDev;
m_iCurrOutput = iOutput;
m_iCurrRecordDevice = iRecDev;
m_iCurrInput = iInput;
if( !m_rbASIO->Checked )
ReloadInput();
if( hr==S_OK ){
if( m_iCurrRecordDevice>=0 )
BeginRecordTest();
}
else
ShowErrorMessage( hr );
m_tbVolume->Enabled = hr==S_OK && m_iCurrRecordDevice>=0;
Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::InputChange(TObject *Sender)
{
int iInput = m_cbInput->ItemIndex;
if( iInput==m_iCurrInput )
return;
BeginRecordTest( false );
int iPlayDev = m_iCurrPlaybackDevice,
iOutput = m_iCurrOutput,
iRecDev = m_iCurrRecordDevice;
Screen->Cursor = crHourGlass;
HRESULT hr = f_MM_SetIODevice( iPlayDev, iOutput, iRecDev, iInput );
m_iCurrInput = iInput;
if( hr==S_OK )
BeginRecordTest();
else
ShowErrorMessage( hr );
m_tbVolume->Enabled = hr==S_OK;
Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::VolumeChange(TObject *Sender)
{
int nVol = m_tbVolume->Position;
m_tbVolume->Hint = IntToStr(nVol);
f_MM_SetStreamVolume( 1, nVol/100.0 );
if( m_bAutoAdjust ){
m_bAutoAdjust = false;
m_pbAutoCheck->Invalidate();
f_MM_SetRecordAutoAdjust( m_bAutoAdjust );
}
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::UMRecordVolJust(TMessage &Message)
{
m_tbVolume->OnChange = NULL;
m_tbVolume->Position = (int)Message.WParam;
m_tbVolume->Hint = IntToStr((int)Message.WParam);
m_tbVolume->OnChange = VolumeChange;
}
// ---------------------------------------------------------------------------
void TMicSetForm::BeginRecordTest(bool bStart)
{
if( bStart ){
HRESULT hr = f_MM_RecordTest( Handle );
if( hr==S_OK ){
if( m_bAutoAdjust ){
m_tbVolume->OnChange = NULL;
m_tbVolume->Position = 100;
m_tbVolume->Hint = IntToStr(100);
f_MM_SetStreamVolume( 1, 1 );
}
m_tbVolume->Enabled = true;
m_tbVolume->OnChange = VolumeChange;
m_pTimerLatency->Enabled = true;
m_lblLatencyTime->Caption = "0.0 ms";
}
else{
m_pTimerLatency->Enabled = false;
m_tbVolume->Enabled = false;
m_lblLatencyTime->Caption = "---- ms";
ShowErrorMessage( hr );
}
}
else{
m_pTimerLatency->Enabled = false;
f_MM_Stop();
m_tbVolume->Enabled = false;
m_lblLatencyTime->Caption = "---- ms";
}
}
// ---------------------------------------------------------------------------
void __fastcall TMicSetForm::LatencyTimerProc(TObject* Sender)
{
float fLatency = f_MM_GetLatency( true );
char str[16];
sprintf( str, "%.1f ms", fLatency );
m_lblLatencyTime->Caption = str;
}
// ---------------------------------------------------------------------------
void TMicSetForm::ShowErrorMessage( int errcode )
{
String msg;
int errRec = LOWORD( errcode ),
errPlay = HIWORD( errcode ),
err = errRec>0 ? errRec : errPlay;
if( err==1 ){
msg += L"内存空间不足。";
}
else{
if(errRec>1 && m_cbInput->Enabled)
msg += "输入";
if(errPlay>1 && m_cbRecDevOrOutput->Enabled)
msg += "输出";
}
if( msg.Length()==0 )
return;
if( err==46 ){
msg += L"设备被其它程序独占。";
}
else if( err==37 ){
msg += L"设备无法打开。";
}
else if( err==3 || err==23 ){
msg += L"设备无效。";
}
else{
msg += L"设备启动失败。";
}
MessageForm->ShowMessage( msg, MB_ICONERROR|MB_OK );
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::ASIOMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if( Button==mbLeft ){
if( m_PopupMenu ){
delete m_PopupMenu;
m_PopupMenu = NULL;
}
m_PopupMenu = new TPopMenu(NULL);
m_PopupMenu->CreateCustomMenuItem( "显示面板", DoShowPanel );
m_PopupMenu->CreateCustomMenuItem( "重启设备", DoRestart );
TPoint point( m_lblASIO->Left, m_lblASIO->Top+m_lblASIO->Height );
point = ClientToScreen(point);
m_PopupMenu->Popup( point.X, point.Y );
}
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::DoShowPanel(TObject* Sender)
{
if( m_iCurrPlaybackDevice & IO_DEVICE_ASIO )
f_MM_ShowAsioPanel();
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::DoRestart(TObject* Sender)
{
if( m_iCurrPlaybackDevice & IO_DEVICE_ASIO ){
if( f_MM_RestartAsioDevice()==S_OK ){
ReloadOutput();
ReloadInput();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMicSetForm::DeviceTypeClick(TObject *Sender)
{
int iTypeOld = m_iCurrPlaybackDevice & 0xF0000;
int iType = m_rbASIO->Checked ? IO_DEVICE_ASIO
: m_rbWASAPI->Checked ? IO_DEVICE_WASAPI
: 0;
if( iType==iTypeOld )
return;
BeginRecordTest( false );
int iPlayDev = -1, iOutput = -1,
iRecDev = -1, iInput = -1;
if( iType==IO_DEVICE_ASIO ){
iPlayDev = m_aAsioPb[0]->iDevice;
if( iRecDev<0 )
iRecDev = iPlayDev;
}
else{
vector<IO_DEVICE_INFO*>& rDevsPb = iType==IO_DEVICE_WASAPI ? m_aWasapiPb
: iType==IO_DEVICE_ASIO ? m_aAsioPb
: m_aCommonPb;
for( int i=0; i<rDevsPb.size(); i++ ){
if( rDevsPb[i]->flags & DEVICE_DEFAULT ){
iPlayDev = rDevsPb[i]->iDevice;
break;
}
}
if( iRecDev<0 ){
vector<IO_DEVICE_INFO*>& rDevsRc = iType==IO_DEVICE_WASAPI ? m_aWasapiRc
: m_aCommonRc;
for( int i=0; i<rDevsRc.size(); i++ ){
if( rDevsRc[i]->flags & DEVICE_DEFAULT ){
iRecDev = rDevsRc[i]->iDevice;
break;
}
}
}
}
Screen->Cursor = crHourGlass;
m_iCurrPlaybackDevice = iPlayDev;
m_iCurrOutput = iOutput;
HRESULT hr = f_MM_SetIODevice( iPlayDev, iOutput, iRecDev, iInput );
if( iPlayDev>=0 ){
m_iCurrPlaybackDevice = iPlayDev;
m_iCurrOutput = iOutput;
}
m_iCurrRecordDevice = iRecDev;
m_iCurrInput = iInput;
ReloadPlayDev();
ReloadOutput();
ReloadRecDev();
ReloadInput();
if( hr==S_OK ){
if( m_cbInput->Enabled )
BeginRecordTest();
}
else
ShowErrorMessage( hr );
Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+129
View File
@@ -0,0 +1,129 @@
//---------------------------------------------------------------------------
#ifndef MicSetFormUnitH
#define MicSetFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include "PNGButton.hpp"
#include <Vcl.Imaging.jpeg.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.ComCtrls.hpp>
#include "PopMenuUnit.h"
//---------------------------------------------------------------------------
#define MB_CHECKED 0x100
#define MB_UNCHECKED 0x200
typedef struct tagDeviceInfo{
int iDevice;
char name[256]; // description
DWORD flags;
tagDeviceInfo(){
memset( this, 0, sizeof(tagDeviceInfo) );
}
tagDeviceInfo( tagDeviceInfo* src ){
memcpy( this, src, sizeof(tagDeviceInfo) );
}
} IO_DEVICE_INFO;
class TMicSetForm : public TForm
{
__published: // IDE-managed Components
TImage *m_imgBk;
TPNGButton *m_btnOk;
TPNGButton *m_btnCancel;
TLabel *m_lblRecDevOrOutput;
TComboBox *m_cbRecDevOrOutput;
TLabel *m_lblVolume;
TTrackBar *m_tbVolume;
TPaintBox *m_pbAutoCheck;
TLabel *m_lblAutoAdjust;
TLabel *m_lblHintMsg;
TLabel *m_lblCaption;
TImage *m_imgLog;
TPNGButton *m_btnClose;
TComboBox *m_cbInput;
TLabel *m_lblInput;
TLabel *m_lblHint;
TLabel *m_lblLatency;
TLabel *m_lblLatencyTime;
TLabel *m_lblMoniter;
TPaintBox *m_pbMoniter;
TLabel *m_lblOutput;
TComboBox *m_cbPlayDev;
TLabel *m_lblASIO;
TLabel *m_lblType;
TRadioButton *m_rbCommon;
TRadioButton *m_rbWASAPI;
TRadioButton *m_rbASIO;
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall CheckPaint(TObject *Sender);
void __fastcall CheckClick(TObject *Sender);
// void __fastcall CheckMessageClick(TObject *Sender);
// void __fastcall CancelClick(TObject *Sender);
void __fastcall OkClick(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall RecDevOrOutputChange(TObject *Sender);
void __fastcall VolumeChange(TObject *Sender);
void __fastcall InputChange(TObject *Sender);
void __fastcall PlayDevChange(TObject *Sender);
// void __fastcall ASIOClick(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall ASIOMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall DeviceTypeClick(TObject *Sender);
private: // User declarations
TBitmap * m_pImgCheck;
TTimer *m_pTimerLatency;
bool m_bAutoAdjust,
m_bMoniter;
/* int m_iCurrPlaybackDevice, m_iCurrOutput,
m_iCurrRecordDevice, m_iCurrInput;
int m_iASIOStart;
bool m_bASIO;
*/
TPopMenu *m_PopupMenu; //µ¯³ö²Ëµ¥
IO_DEVICE_INFO m_aPbDevs[20], m_aRcDevs[20];
int m_iCurrPlaybackDevice, m_iCurrOutput,
m_iCurrRecordDevice, m_iCurrInput;
vector<IO_DEVICE_INFO*> m_aCommonPb, m_aCommonRc,
m_aWasapiPb, m_aWasapiRc,
m_aAsioPb, m_aMidiRc;
void ReloadPlayDev();
void ReloadRecDev();
void ReloadOutput();
void ReloadInput();
void BeginRecordTest( bool bStart=true );
void ShowErrorMessage( int err );
void __fastcall DoShowPanel(TObject* Sender);
void __fastcall DoRestart(TObject* Sender);
void __fastcall LatencyTimerProc(TObject* Sender);
MESSAGE void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
MESSAGE void __fastcall UMRecordVolJust(TMessage &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
MESSAGE_HANDLER(MSG_RECORD_VOLJUST, TMessage, UMRecordVolJust)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TMicSetForm(TComponent* Owner);
__fastcall ~TMicSetForm();
// void _fastcall SetCheckMessage( String strMessage );
int __fastcall ShowMessage( const String AMessage, int AType=MB_ICONINFORMATION|MB_OK );
};
//---------------------------------------------------------------------------
extern PACKAGE TMicSetForm *MicSetForm;
//---------------------------------------------------------------------------
#endif
+270
View File
@@ -0,0 +1,270 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "NotificationADPanelUnit.h"
#define PERIOD_AD ( 3*1000 )
#define AD_SHOW_NUMBER 1
#define AD_CHANGE_WIDTH 10
#define AD_CHANGE_HEIGHT 6
#define AD_CHANGE_HEIGHT_TO_BOTTOM 5
#define AD_CHANGE_PIC2PIC 5
#define AD_PIC_LEFT 0
#define AD_PIC_TOP 0
#define AD_PIC_WIDTH Width
#define AD_PIC_HEIGHT (Height - AD_CHANGE_HEIGHT - 2*AD_CHANGE_HEIGHT_TO_BOTTOM)
const static COLORREF
CLR_BKG = RGB(39, 42, 47);
//---------------------------------------------------------------------------
#pragma package(smart_init)
__fastcall TNotiADPanel::TNotiADPanel( TComponent* Owner, VCTJSON *VCJsonAD)
: Vcl::Extctrls::TPanel( Owner )
{
m_VCJsonAD = VCJsonAD;
m_iIndex = 0;
m_pADTimer = new TTimer(this);
m_pADTimer->Enabled = false;
m_pADTimer->Interval = PERIOD_AD;
m_pADTimer->OnTimer = NotificationTimerProc;
this->BevelOuter = bvNone;
ParentColor = true;
}
//---------------------------------------------------------------------------
__fastcall TNotiADPanel::~TNotiADPanel()
{
if( m_pPaintBoxAD ) { delete m_pPaintBoxAD; m_pPaintBoxAD = NULL; }
vector<TUrlPaintBox *>::iterator vc_pFindADChange;
for( vc_pFindADChange = m_pPBADChange.begin();
vc_pFindADChange != m_pPBADChange.end();
vc_pFindADChange++ )
{
if( *vc_pFindADChange ) {
delete *vc_pFindADChange;
*vc_pFindADChange = NULL;
}
}
vector<TPicture *>::iterator vc_pFindPIC;
for( vc_pFindPIC = m_vcPIC.begin();
vc_pFindPIC != m_vcPIC.end();
vc_pFindPIC++ )
{
if( *vc_pFindPIC ) {
delete *vc_pFindPIC;
*vc_pFindPIC = NULL;
}
}
if( m_pADTimer ) { delete m_pADTimer; m_pADTimer = NULL; }
}
//---------------------------------------------------------------------------
void __fastcall TNotiADPanel::CreateWnd()
{
Vcl::Extctrls::TPanel::CreateWnd();
SetAD();
}
//---------------------------------------------------------------------------
void __fastcall TNotiADPanel::WMEraseBkgnd(TWMEraseBkgnd &Message)
{
TRect rect = GetClientRect();
TCanvas* tempCanvas = new TCanvas;
tempCanvas->Handle = Message.DC;
tempCanvas->Brush->Color = CLR_BKG; //±³¾°ÑÕÉ«
tempCanvas->FillRect( rect );
delete tempCanvas;
tempCanvas = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TNotiADPanel::NotificationTimerProc(TObject* Sender)
{
TTimer *NotiTimer = (TTimer *)Sender;
int index = 0;
int size = (*m_VCJsonAD).size();
if( size>AD_SHOW_NUMBER )
{
if( NotiTimer == m_pADTimer ) {
m_iIndex = ( (m_iIndex+1)==size )? 0: (m_iIndex+1);
}
vector<TUrlPaintBox *>::iterator vc_pFindADChange;
bool bFind = false;
VCTJSON::iterator vc_pFindAD;
for( vc_pFindAD = (*m_VCJsonAD).begin(),
vc_pFindADChange = m_pPBADChange.begin();
vc_pFindAD != (*m_VCJsonAD).end(),
vc_pFindADChange != m_pPBADChange.end();
vc_pFindADChange++ )
{
if( index==m_iIndex ) {
(*vc_pFindADChange)->State = 1;
bFind = true;
}else{
(*vc_pFindADChange)->State = 0;
if( !bFind ) {
vc_pFindAD++;
}
}
(*vc_pFindADChange)->Invalidate();
index++;
}
vector<TPicture *>::iterator vc_pFindPIC = m_vcPIC.begin() + m_iIndex;
m_pPaintBoxAD->GraphicImg = *vc_pFindPIC;
m_pPaintBoxAD->StrUrl = (*vc_pFindAD).strUrl;
m_pPaintBoxAD->Invalidate();
}else {
m_pADTimer->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TNotiADPanel::SetAD()
{
int adSize = (*m_VCJsonAD).size();
if( adSize )
{
int startLoc = Width - adSize*(AD_CHANGE_WIDTH+AD_CHANGE_PIC2PIC)
+ AD_CHANGE_PIC2PIC;
TUrlPaintBox *tmpPB;
TPicture *picImg;
VCTJSON::iterator vc_pFindAD;
for( vc_pFindAD = (*m_VCJsonAD).begin();
vc_pFindAD != (*m_VCJsonAD).end();
vc_pFindAD++ )
{
picImg = new TPicture();
String name = (*vc_pFindAD).strNamePic;
picImg->LoadFromFile( (*vc_pFindAD).strNamePic );
m_vcPIC.push_back(picImg);
if( adSize>1 )
{
tmpPB = new TUrlPaintBox(this);
tmpPB->Parent = this;
tmpPB->Width = AD_CHANGE_WIDTH;
tmpPB->Height = AD_CHANGE_HEIGHT;
tmpPB->Left = startLoc;
tmpPB->Top = Height - AD_CHANGE_HEIGHT - AD_CHANGE_HEIGHT_TO_BOTTOM;
tmpPB->StateCount = 2;
tmpPB->OnMouseEnter = ADChangeMouseEnter;
tmpPB->OnMouseLeave = ADChangeMouseLeave;
if( vc_pFindAD == (*m_VCJsonAD).begin() ) {
tmpPB->State = 1;
}
tmpPB->BringToFront();
tmpPB->Visible = true;
startLoc += AD_CHANGE_WIDTH + AD_CHANGE_PIC2PIC;
m_pPBADChange.push_back(tmpPB);
}
}
vc_pFindAD = (*m_VCJsonAD).begin();
m_pPaintBoxAD = new TUrlPaintBox(this);
m_pPaintBoxAD->Parent = this;
m_pPaintBoxAD->Width = AD_PIC_WIDTH;
m_pPaintBoxAD->Height = AD_PIC_HEIGHT;
m_pPaintBoxAD->Left = AD_PIC_LEFT;
m_pPaintBoxAD->Top = AD_PIC_TOP;
m_pPaintBoxAD->OnMouseEnter = PaintBoxMouseEnter;
m_pPaintBoxAD->OnMouseLeave = PaintBoxMouseLeave;
m_pPaintBoxAD->GraphicImg = *( m_vcPIC.begin() );
m_pPaintBoxAD->StrUrl = (*vc_pFindAD).strUrl;
m_pPaintBoxAD->Visible = true;
}
m_pADTimer->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TNotiADPanel::PaintBoxMouseLeave(TObject *Sender)
{
int adSize = (*m_VCJsonAD).size();
if( adSize<=1 ){
return;
}
TPoint clientPos = ScreenToClient(Mouse->CursorPos);
TUrlPaintBox *tmpPB = (TUrlPaintBox *)Sender;
if( tmpPB==m_pPaintBoxAD ) {
m_pADTimer->Enabled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TNotiADPanel::PaintBoxMouseEnter(TObject *Sender)
{
int adSize = (*m_VCJsonAD).size();
if( adSize<=1 ){
return;
}
TUrlPaintBox *tmpPB = (TUrlPaintBox *)Sender;
if( tmpPB==m_pPaintBoxAD ) {
m_pADTimer->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TNotiADPanel::ADChangeMouseEnter(TObject *Sender)
{
m_pADTimer->Enabled = false;
TUrlPaintBox *tmpPB = (TUrlPaintBox *)Sender;
int index = 0;
vector<TUrlPaintBox *>::iterator vc_pFindADChange;
for( vc_pFindADChange = m_pPBADChange.begin();
vc_pFindADChange != m_pPBADChange.end();
vc_pFindADChange++ )
{
if( tmpPB==*vc_pFindADChange ) {
break;
}
index++;
}
if( m_iIndex != index ) {
m_iIndex = index;
NotificationTimerProc(NULL);
}
}
//---------------------------------------------------------------------------
void __fastcall TNotiADPanel::ADChangeMouseLeave(TObject *Sender)
{
m_pADTimer->Enabled = true;
}
//---------------------------------------------------------------------------
+48
View File
@@ -0,0 +1,48 @@
//---------------------------------------------------------------------------
#ifndef NotificationADPanelUnitH
#define NotificationADPanelUnitH
//---------------------------------------------------------------------------
#include "NotificationExUnit.h"
#include <Vcl.Imaging.pngimage.hpp>
#include <Vcl.Imaging.pnglang.hpp>
#include <Vcl.Graphics.hpp>
#include "PNGButton.hpp"
//---------------------------------------------------------------------------
typedef vector<TUrlLabel*> VCURLLABEL;
class TNotiADPanel : public Vcl::Extctrls::TPanel
{
private:
VCTJSON *m_VCJsonAD;
void __fastcall SetAD();
int m_iIndex;
vector<TPicture *> m_vcPIC;
TUrlPaintBox *m_pPaintBoxAD;
void __fastcall PaintBoxMouseEnter(TObject *Sender);
void __fastcall PaintBoxMouseLeave(TObject *Sender);
vector<TUrlPaintBox *> m_pPBADChange;
void __fastcall ADChangeMouseEnter(TObject *Sender);
void __fastcall ADChangeMouseLeave(TObject *Sender);
TTimer *m_pADTimer;
void __fastcall NotificationTimerProc(TObject* Sender);
virtual void __fastcall CreateWnd();
MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
END_MESSAGE_MAP( Vcl::Extctrls::TPanel )
public:
__fastcall TNotiADPanel( TComponent* Owner, VCTJSON *VCJsonAD);
__fastcall ~TNotiADPanel();
};
//---------------------------------------------------------------------------
#endif
+535
View File
@@ -0,0 +1,535 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "NotificationContentPanelUnit.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
#define SCOLLBAR_WIDTH (14)
#define TOP_BUTTOM (10)
#define LEFT_RIGHT (SCOLLBAR_WIDTH + 20)
#define LINE_HEIGHT (25)
#define DB_NAME_LINE (2)
#define DB_NAME_HEIGHT (DB_NAME_LINE*LINE_HEIGHT)
#define DB_NAME_RECT_LEFT (10)
#define DB_NAME_RECT_HEIGHT (20)
#define DB_NAME_TEXT_LEFT (5)
#define DB_NAME_TEXT_WIDTH (10)
#define PIC_TO_LEFT (LEFT_RIGHT)
#define PIC_HEIGHT (45)
#define PIC_WIDTH (45)
#define PIC_LEFT (LEFT_RIGHT)
#define PIC_RIGHT (PIC_LEFT + PIC_WIDTH + LEFT_RIGHT)
#define LABEL_TO_LEFT (PIC_LEFT)
#define LABEL_MAX_WIDTH_PIC (Width - PIC_RIGHT - LEFT_RIGHT)
#define LABEL_MAX_WIDTH (Width - LABEL_TO_LEFT - LEFT_RIGHT)
#define LABEL_HEIGHT (PIC_HEIGHT/2)
const static COLORREF
CLR_TXT_HOT = RGB(171, 186, 207),
CLR_CONTENT_BKG = RGB(56, 61, 67),
CLR_CONTENT_DB_NAME_BKG = RGB(47, 50, 56),
CLR_CONTENT_DB_NAME_FRAME = RGB(32, 35, 39),
CLR_CONTENT_DB_LINE_DARK = RGB(32, 35, 39),
CLR_CONTENT_DB_LINE_LIGHT = RGB(76, 81, 87);
//---------------------------------------------------------------------------
__fastcall TNotiContenPanel::TNotiContenPanel( TComponent* Owner, VCTJSONDB *VCJsonContent)
: Vcl::Extctrls::TPanel( Owner )
{
ParentColor = true;
m_VCJsonContent = VCJsonContent;
m_ScrollBar = NULL;
m_iTopLine =0;
m_iShowLine = 1;
SetContent();
}
//---------------------------------------------------------------------------
void __fastcall TNotiContenPanel::CreateWnd()
{
Vcl::Extctrls::TPanel::CreateWnd();
SetShowLine();
}
//---------------------------------------------------------------------------
__fastcall TNotiContenPanel::~TNotiContenPanel()
{
if( m_ScrollBar ){
delete m_ScrollBar;
m_ScrollBar = NULL;
}
vector<TPicture *>::iterator vc_pFindPIC;
for( vc_pFindPIC = ItemPIC.begin();
vc_pFindPIC != ItemPIC.end();
vc_pFindPIC++ )
{
if( *vc_pFindPIC ) {
delete *vc_pFindPIC;
*vc_pFindPIC = NULL;
}
}
vector<VCURLLABEL*>::iterator vc_pFindItemLabel;
for( vc_pFindItemLabel = ItemLabel.begin();
(vc_pFindItemLabel != ItemLabel.end());
vc_pFindItemLabel++ )
{
vector<TUrlLabel*>::iterator vc_pFindLabel;
VCURLLABEL* vcLabel = *vc_pFindItemLabel;
for( vc_pFindLabel = (*vcLabel).begin();
vc_pFindLabel!= (*vcLabel).end();
vc_pFindLabel++ )
{
if( *vc_pFindLabel ) {
delete *vc_pFindLabel;
*vc_pFindLabel = NULL;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TNotiContenPanel::WMEraseBkgnd(TWMEraseBkgnd &Message)
{
TRect rect = GetClientRect();
TCanvas* tempCanvas = new TCanvas;
tempCanvas->Handle = Message.DC;
tempCanvas->Brush->Color = CLR_CONTENT_BKG; //背景颜色
tempCanvas->FillRect( rect );
delete tempCanvas;
tempCanvas = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TNotiContenPanel::WMVScroll(Winapi::Messages::TWMScroll &Message)
{
int minpos, maxpos, page, curpos;
m_ScrollBar->GetScrollRange(&minpos, &maxpos);
page = m_ScrollBar->GetPageSize();
// Get the current position of scroll box.
curpos = m_ScrollBar->GetScrollPos();
// Determine the new position of scroll box.
switch (Message.ScrollCode)
{
case SB_TOP: // Scroll to far top.
curpos = minpos;
break;
case SB_BOTTOM: // Scroll to far bottom.
curpos = maxpos-page+1;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINEUP: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINEDOWN: // Scroll right.
if (curpos < maxpos-page+1)
curpos++;
break;
case SB_PAGEUP: // Scroll one page left.
if (curpos > minpos)
curpos = (minpos > curpos-page) ? minpos : curpos-page;
//max(minpos, curpos-page);
break;
case SB_PAGEDOWN: // Scroll one page right.
if( curpos<maxpos )
curpos = (maxpos-page+1 < curpos+page) ? maxpos-page+1 : curpos+page;
//min(maxpos-page+1, curpos+page);
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = Message.Pos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = Message.Pos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb (scroll box).
if( Message.ScrollBar!=m_ScrollBar->Handle ){
m_ScrollBar->SetPosition(curpos);
// Paint();
}
if( m_iTopLine != curpos ){
m_iTopLine = curpos;
Invalidate();
}
Message.Result = true;
}
//---------------------------------------------------------------------------
void __fastcall TNotiContenPanel::WMMouseWheel(TWMMouseWheel &Message)
{
if( m_ScrollBar->Visible ){
UINT nSBCode;
if( Message.WheelDelta>0 ) nSBCode = SB_LINEUP;
else nSBCode = SB_LINEDOWN;
Perform( WM_VSCROLL, MAKELONG(nSBCode,0), NULL );
}
}
//---------------------------------------------------------------------------
void __fastcall TNotiContenPanel::SetContent()
{
bool bPicExist, bLabelExist;
VCTJSONDB::iterator vc_pFindContent;
for( vc_pFindContent = (*m_VCJsonContent).begin();
vc_pFindContent != (*m_VCJsonContent).end();
vc_pFindContent++)
{
int dbNum = 0;
VCTJSON::iterator vc_pFindContentPIC;
for( vc_pFindContentPIC = (*vc_pFindContent).vcContent.begin();
vc_pFindContentPIC != (*vc_pFindContent).vcContent.end();
vc_pFindContentPIC++)
{
bPicExist = bLabelExist = false;
//===========图片信息
TPicture *picImg = NULL;
TUrlPaintBox *tmpPicDraw = NULL;
String strExit = (*vc_pFindContentPIC).strNamePic;
if( strExit.Length() ) {
picImg = new TPicture();
picImg->LoadFromFile( strExit );
bPicExist = true;
if( bPicExist ) {
tmpPicDraw = new TUrlPaintBox(this);
tmpPicDraw->Parent = this;
tmpPicDraw->GraphicImg = picImg;
tmpPicDraw->StrUrl = (*vc_pFindContentPIC).strUrl;
tmpPicDraw->Visible = true;
}
}
ItemPIC.push_back( picImg );
ItemPICDraw.push_back( tmpPicDraw );
//===========文字信息
VCURLLABEL *tmpVCUrlLabel = new VCURLLABEL();
//链接信息
TUrlLabel *tmpLabel = CreateLabel((*vc_pFindContentPIC).strName,
(*vc_pFindContentPIC).strUrl);
if( tmpLabel!=NULL ) {
tmpVCUrlLabel->push_back(tmpLabel);
bLabelExist = true;
}
//说明信息
tmpLabel = CreateLabel((*vc_pFindContentPIC).strAuthor, L"");
if( tmpLabel!=NULL ) {
tmpVCUrlLabel->push_back(tmpLabel);
bLabelExist = true;
}
if( !bLabelExist) { //如果说明不存在
ItemPIC.pop_back();
ItemPICDraw.pop_back();
if( picImg ) { delete picImg; picImg=NULL;};
if( tmpPicDraw ) { delete tmpPicDraw; tmpPicDraw=NULL;};
if( tmpVCUrlLabel ) { delete tmpVCUrlLabel; tmpVCUrlLabel=NULL;};
}else {
ItemLabel.push_back(tmpVCUrlLabel);
dbNum++;
}
}
//===========类型信息
if( bLabelExist ) {
ItemDBName.push_back((*vc_pFindContent).strDbName);
ItemDBNameNum.push_back(dbNum);
}
}
}
//---------------------------------------------------------------------------
TUrlLabel* __fastcall TNotiContenPanel::CreateLabel(String caption, String url)
{
TUrlLabel *tmpUrlLabel;
if( caption.Length() ) {
tmpUrlLabel = new TUrlLabel(this);
tmpUrlLabel->Parent = this;
tmpUrlLabel->Caption = caption;
tmpUrlLabel->StrUrl = url;
}else { tmpUrlLabel=NULL; }
return tmpUrlLabel;
}
//---------------------------------------------------------------------------
void __fastcall TNotiContenPanel::CutOffLabelString()
{
int maxPicExsit = LABEL_MAX_WIDTH_PIC;
int maxPicNo = LABEL_MAX_WIDTH;
int maxLabelLen;
vector<TPicture*>::iterator vc_pFindItemPIC;
vector<VCURLLABEL*>::iterator vc_pFindLBItem = ItemLabel.begin();
for( vc_pFindLBItem = ItemLabel.begin(),
vc_pFindItemPIC = ItemPIC.begin();
vc_pFindLBItem != ItemLabel.end(),
vc_pFindItemPIC != ItemPIC.end();
vc_pFindLBItem++,
vc_pFindItemPIC++)
{
if( (*vc_pFindItemPIC) == NULL ){
maxLabelLen = maxPicNo;
}else{
maxLabelLen = maxPicExsit;
}
vector<TUrlLabel*>::iterator vc_pFindLabel;
VCURLLABEL* vcLabel = *vc_pFindLBItem;
for( vc_pFindLabel = (*vcLabel).begin();
vc_pFindLabel!= (*vcLabel).end();
vc_pFindLabel++)
{
String caption = (*vc_pFindLabel)->Caption;
TSize size = Canvas->TextExtent( caption );
int nLen = caption.Length();
if( size.Width >= maxLabelLen )
{
nLen = nLen*(maxLabelLen)/size.Width;
nLen -= 1;
if(nLen <= 0){
caption = caption.SubString(0, 1);
}else{
caption = caption.SubString(0, nLen);
caption += "..";
}
(*vc_pFindLabel)->Caption = caption;
}
}
}
}
//---------------------------------------------------------------------------
int __fastcall TNotiContenPanel::GetLineNumber()
{
int linePIC;
int linePICExist = (PIC_HEIGHT%LINE_HEIGHT==0)?(PIC_HEIGHT/LINE_HEIGHT):
((PIC_HEIGHT/LINE_HEIGHT)+1);
int lineLabel = 0;
int lineNumber = 0;
vector<TPicture*>::iterator vc_pFindItemPIC;
vector<VCURLLABEL*>::iterator vc_pFindItemLabel;
for( vc_pFindItemLabel =ItemLabel.begin(),
vc_pFindItemPIC = ItemPIC.begin();
vc_pFindItemLabel != ItemLabel.end()&&
vc_pFindItemPIC != ItemPIC.end();
vc_pFindItemLabel++,
vc_pFindItemPIC++)
{
if( (*vc_pFindItemPIC) == NULL ) {
linePIC = 0;
}else{
linePIC = linePICExist;
}
VCURLLABEL* vcLabel = *vc_pFindItemLabel;
lineLabel = (*vcLabel).size();
int lineNumberTmp = lineNumber;
// if( linePIC>lineLabel ) {
// lineNumber += linePIC;
// }else {
// lineNumber += lineLabel;
// }
lineNumber += linePICExist;
ItemLine.push_back(lineNumber - lineNumberTmp);
}
lineNumber += ItemDBName.size()*DB_NAME_LINE;
return lineNumber;
}
//---------------------------------------------------------------------------
void __fastcall TNotiContenPanel::SetShowLine()
{
CutOffLabelString();
int totalLine = GetLineNumber();
// m_iShowLine = (Height - 2*TOP_BUTTOM)/LINE_HEIGHT;
m_iShowLine = Height/LINE_HEIGHT;
if( totalLine>m_iShowLine ){
m_ScrollBar = new CDTSkinScrollBar(this);
m_ScrollBar->m_pWndCtrl = this;
m_ScrollBar->Parent = this;
m_ScrollBar->Height = Height-2;
// m_ScrollBar->Width = SCOLLBAR_WIDTH;
m_ScrollBar->Left = Width - m_ScrollBar->Width - 1;
m_ScrollBar->Top = 1;
m_ScrollBar->SetRange( 0,totalLine-1 );
m_ScrollBar->SetPageSize(m_iShowLine);
m_ScrollBar->SetPosition( m_iTopLine );
m_ScrollBar->Visible = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TNotiContenPanel::Paint(void)
{
int contentHeight = 0;
int curX = 0;
int curY = 0;
int curWidth = 0;
int curHeight = 0;
int contentStart = -m_iTopLine*LINE_HEIGHT;
int dbNum = 0;
bool dbNameShow = true;
vector<int>::iterator vc_pFindItemDBNameNum = ItemDBNameNum.begin();
vector<String>::iterator vc_pFindItemDBName = ItemDBName.begin();
vector<int>::iterator vc_pFindItemLine;
vector<TPicture*>::iterator vc_pFindItemPIC;
vector<TUrlPaintBox*>::iterator vc_pFindItemPICDraw;
vector<VCURLLABEL*>::iterator vc_pFindItemLabel;
if( vc_pFindItemDBNameNum == ItemDBNameNum.end()
|| vc_pFindItemDBName == ItemDBName.end() )
return;
for( vc_pFindItemLine = ItemLine.begin(),
vc_pFindItemPIC = ItemPIC.begin(),
vc_pFindItemPICDraw = ItemPICDraw.begin(),
vc_pFindItemLabel = ItemLabel.begin();
(vc_pFindItemLine != ItemLine.end())&&
(vc_pFindItemPIC != ItemPIC.end()) &&
(vc_pFindItemPICDraw != ItemPICDraw.end()),
(vc_pFindItemLabel != ItemLabel.end());
vc_pFindItemLine++,
vc_pFindItemPIC++,
vc_pFindItemPICDraw++,
vc_pFindItemLabel++ )
{
if( dbNameShow && dbNum == 0 )
{
contentHeight = DB_NAME_HEIGHT;
//类型信息
dbNum = (*vc_pFindItemDBNameNum) - 1;
TSize sizeFont = Canvas->TextExtent((*vc_pFindItemDBName));
curX = DB_NAME_RECT_LEFT;
curY = contentStart + contentHeight/2 - DB_NAME_RECT_HEIGHT/2;
curWidth = sizeFont.Width;
curHeight = DB_NAME_RECT_HEIGHT;
Canvas->Brush->Color = CLR_CONTENT_DB_NAME_BKG;
Canvas->FillRect(TRect(curX, curY, curX+curWidth+DB_NAME_TEXT_WIDTH, curY+curHeight));
Canvas->Brush->Color = CLR_CONTENT_DB_NAME_FRAME;
Canvas->FrameRect(TRect(curX, curY,curX+curWidth+DB_NAME_TEXT_WIDTH, curY+curHeight));
curX = DB_NAME_RECT_LEFT + DB_NAME_TEXT_LEFT;
curY = curY + (DB_NAME_RECT_HEIGHT - sizeFont.Height)/2;
Canvas->Font->Color = CLR_TXT_HOT;
Canvas->Brush->Style = bsClear;
Canvas->TextOutW(curX, curY, (*vc_pFindItemDBName));
if( vc_pFindItemDBName != ItemDBName.end() &&
vc_pFindItemDBNameNum != ItemDBNameNum.end())
{
vc_pFindItemDBName++;
vc_pFindItemDBNameNum++;
}
if( vc_pFindItemDBName == ItemDBName.end() ){
dbNameShow = false;
}
contentStart += contentHeight;
}else {
dbNum--;
}
//图片
contentHeight = (*vc_pFindItemLine)*LINE_HEIGHT;
curY = contentStart + (contentHeight - PIC_HEIGHT)/2;
bool bPicExsit = true;
if( (*vc_pFindItemPIC) != NULL ) {
curX = PIC_LEFT;
curWidth = PIC_HEIGHT;
curHeight = PIC_WIDTH;
(*vc_pFindItemPICDraw)->SetBounds(curX, curY, curWidth, curHeight);
// Canvas->StretchDraw( TRect(curX, curY, curX+curWidth, curY+curHeight),
// (*vc_pFindItemPIC)->Graphic );
}else{
bPicExsit = false;
}
//文字说明
vector<TUrlLabel*>::iterator vc_pFindLabel;
VCURLLABEL* vcLabel = *vc_pFindItemLabel;
// int labelStart = contentStart + (contentHeight - (*vcLabel).size()*LINE_HEIGHT)/2;
int labelStart,lineStart;
labelStart = lineStart = curY;
for( vc_pFindLabel = (*vcLabel).begin();
vc_pFindLabel!= (*vcLabel).end();
vc_pFindLabel++ )
{
// if( bPicExsit ) {
curX = PIC_RIGHT + (LABEL_MAX_WIDTH_PIC - (*vc_pFindLabel)->Width)/2;
// }else{
// curX = LABEL_TO_LEFT + (LABEL_MAX_WIDTH - (*vc_pFindLabel)->Width)/2;
// }
curY = labelStart + (LABEL_HEIGHT - (*vc_pFindLabel)->Height)/2;
(*vc_pFindLabel)->Left = curX;
(*vc_pFindLabel)->Top = curY;
labelStart += LABEL_HEIGHT;
}
lineStart += PIC_HEIGHT;
Canvas->Pen->Color = CLR_CONTENT_DB_LINE_DARK;
Canvas->MoveTo( PIC_RIGHT, lineStart-1 );
Canvas->LineTo( Width-LEFT_RIGHT, lineStart-1 );
Canvas->Pen->Color = CLR_CONTENT_DB_LINE_LIGHT;
Canvas->MoveTo( PIC_RIGHT, lineStart );
Canvas->LineTo( Width-LEFT_RIGHT, lineStart );
contentStart += contentHeight;
}
}
//---------------------------------------------------------------------------
+56
View File
@@ -0,0 +1,56 @@
//---------------------------------------------------------------------------
#ifndef NotificationContentPanelUnitH
#define NotificationContentPanelUnitH
#include "CDSkinScrollBarUnit.h"
#include "NotificationExUnit.h"
#include "NotificationThreadUnit.h"
//---------------------------------------------------------------------------
typedef vector<TUrlLabel*> VCURLLABEL;
class TNotiContenPanel : public Vcl::Extctrls::TPanel
{
private:
VCTJSONDB *m_VCJsonContent;
vector<int> ItemDBNameNum; //一个名字对应的相应个数
vector<String> ItemDBName; //类型名字说明
vector<int> ItemLine; //一个item图片和文字占用的行数
vector<TPicture*> ItemPIC;
vector<TUrlPaintBox*> ItemPICDraw;
vector<VCURLLABEL*> ItemLabel; //一张图片可能对应n个文字说明
int m_iShowLine;
int m_iTopLine;
CDTSkinScrollBar *m_ScrollBar;
TUrlLabel* __fastcall CreateLabel(String caption, String url);
void __fastcall CutOffLabelString();
int __fastcall GetLineNumber();
void __fastcall SetShowLine();
void __fastcall SetContent();
virtual void __fastcall CreateWnd();
virtual void __fastcall Paint(void);
MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message);
MESSAGE void __fastcall WMVScroll(Winapi::Messages::TWMScroll &Message);
MESSAGE void __fastcall WMMouseWheel(TWMMouseWheel &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
MESSAGE_HANDLER(WM_VSCROLL, TWMVScroll, WMVScroll)
MESSAGE_HANDLER(WM_MOUSEWHEEL, TWMMouseWheel, WMMouseWheel)
END_MESSAGE_MAP( Vcl::Extctrls::TPanel )
public:
__fastcall TNotiContenPanel( TComponent* Owner, VCTJSONDB *VCJsonContent);
__fastcall ~TNotiContenPanel();
};
//---------------------------------------------------------------------------
#endif
+356
View File
@@ -0,0 +1,356 @@
//---------------------------------------------------------------------------
#pragma hdrstop
#include <vcl.h>
#include "NotificationExUnit.h"
#include <System.IOUtils.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
extern wstring g_strUserPath;
TJSONObject* __fastcall GetJsonContext(String strContextNoti)
{
TJSONObject *jsonTmp = new TJSONObject();
TBytes StringBytesTmp = TEncoding::UTF8->GetBytes(strContextNoti);
jsonTmp = (TJSONObject *)jsonTmp->ParseJSONValue(StringBytesTmp, 0);
return jsonTmp;
}
//---------------------------------------------------------------------------
TJSONObject* __fastcall GetJsonValue(TJSONObject *json, int index)
{
if( json->Count > index ){
String strkey = json->Get(index)->JsonString->Value();
return (TJSONObject *)json->GetValue(strkey);
}
return NULL;
}
//---------------------------------------------------------------------------
typedef struct tagBingdingWhere{
IBinding *bind;
int iWhereIs;
}BingdingWhere;
typedef vector<BingdingWhere *> VCBingding;
VCBingding vc_Bingding;
void __fastcall StopURLDownload(int iWhereIs)
{
for(int i=0; i<vc_Bingding.size(); i++) {
BingdingWhere *pTmp = vc_Bingding[i];
if( iWhereIs==pTmp->iWhereIs ) {
if( pTmp->bind ){
pTmp->bind->Abort();
}
break;
}
}
}
HRESULT STDMETHODCALLTYPE CBindCBHttpCallback::OnStartBinding(DWORD dwReserved, IBinding __RPC_FAR *pib)
{
pib->AddRef();
for(int i=0; i<vc_Bingding.size(); i++) {
BingdingWhere *pTmp = vc_Bingding[i];
if(pTmp->iWhereIs==iWhereIs){
pTmp->bind->Release();
pTmp->bind = pib;
return S_OK;
}
}
BingdingWhere *pWhere = new BingdingWhere();
pWhere->bind = pib;
pWhere->iWhereIs = iWhereIs;
vc_Bingding.push_back(pWhere);
return S_OK;
}
HRESULT STDMETHODCALLTYPE CBindCBHttpCallback::OnStopBinding(HRESULT hresult, LPCWSTR szError)
{
for(int i=0; i<vc_Bingding.size(); i++) {
BingdingWhere *pTmp = vc_Bingding[i];
if( iWhereIs==pTmp->iWhereIs ) {
if( pTmp->bind ){
pTmp->bind->Release();
pTmp->bind = NULL;
}
delete pTmp;
vc_Bingding.erase(vc_Bingding.begin()+i);
break;
}
}
return S_OK;
}
//**********************************************************************
//***************************************TUrlLabel
//**********************************************************************
//---------------------------------------------------------------------------
__fastcall TUrlLabel::TUrlLabel( TComponent* Owner):
Vcl::Stdctrls::TLabel( Owner )
{
FCloseForm = false;
Transparent = true;
ControlStyle>>csOpaque;
FColorNor = CLR_TEXT_NORMAL;
FColorEnt = CLR_TEXT_ENTER;
FColorLea = CLR_TEXT_LEAVE;
Font->Color = FColorNor;
}
//---------------------------------------------------------------------------
__fastcall TUrlLabel::~TUrlLabel()
{
}
//---------------------------------------------------------------------------
void __fastcall TUrlLabel::CMMouseLeave(Winapi::Messages::TMessage &Msg)
{
if( FStrUrl.Length() ) {
Screen->Cursor = crDefault;
Font->Color = FColorLea;
}
if( FOnMouseLeave )
FOnMouseLeave(this);
}
//---------------------------------------------------------------------------
void __fastcall TUrlLabel::CMMouseEnter(Winapi::Messages::TMessage &Msg)
{
if( FStrUrl.Length() ) {
Screen->Cursor = crHandPoint;
Font->Color = FColorEnt;
}else
Font->Color = FColorNor;
if( FOnMouseEnter ) {
FOnMouseEnter(this);
}
}
//---------------------------------------------------------------------------
void __fastcall TUrlLabel::Click()
{
if( StrUrl.Length() ) {
ShellExecute(Parent->Handle, NULL, StrUrl.c_str(), NULL, NULL, SW_SHOWNORMAL);
if(FCloseForm) {
TCustomForm * parentForm = GetParentForm( this );
parentForm->Close();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TUrlLabel::SetStrUrl(String url)
{
FStrUrl = url;
if( FStrUrl.Length() ) {
Font->Color = FColorLea;
}
}
//---------------------------------------------------------------------------
//**********************************************************************
//***************************************TUrlPaintBox
//**********************************************************************
//---------------------------------------------------------------------------
const COLORREF
CLR_AD_CHANGE_NOR = RGB(63, 68, 76),
CLR_AD_CHANGE_ENTER = RGB(94, 101, 112);
#define STATE_NORMAL 0
#define STATE_ENTER 1
__fastcall TUrlPaintBox::TUrlPaintBox( TComponent* Owner, TPicture * graphicImg):
Vcl::Extctrls::TPaintBox( Owner )
{
FCloseForm = false;
FState = 0;
FStateCount = 1;
FIndex = 0;
FGraphicImg = graphicImg;
}
//---------------------------------------------------------------------------
__fastcall TUrlPaintBox::~TUrlPaintBox()
{
}
//---------------------------------------------------------------------------
void __fastcall TUrlPaintBox::Click()
{
if( FStrUrl.Length() ) {
ShellExecute(Parent->Handle, NULL, FStrUrl.c_str(), NULL, NULL, SW_SHOWNORMAL);
if(FCloseForm) {
TCustomForm * parentForm = GetParentForm( this );
parentForm->Close();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TUrlPaintBox::CMMouseEnter(Winapi::Messages::TMessage &Msg)
{
if( FStrUrl.Length() )
Screen->Cursor = crHandPoint;
if( FOnMouseEnter )
FOnMouseEnter(this);
}
//---------------------------------------------------------------------------
void __fastcall TUrlPaintBox::CMMouseLeave(Winapi::Messages::TMessage &Msg)
{
if( FStrUrl.Length() )
Screen->Cursor = crDefault;
if( FOnMouseLeave )
FOnMouseLeave(this);
}
//---------------------------------------------------------------------------
void __fastcall TUrlPaintBox::SetGraphicImg(TPicture *GraphicImg)
{
FGraphicImg = GraphicImg;
this->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TUrlPaintBox::SetStrUrl(String strUrl)
{
FStrUrl = strUrl;
}
//---------------------------------------------------------------------------
void __fastcall TUrlPaintBox::SetStateCount(int stateCount)
{
FStateCount = stateCount;
}
//---------------------------------------------------------------------------
void __fastcall TUrlPaintBox::Paint()
{
if( GraphicImg ){
if( 1< FStateCount )
Canvas->Draw((-(FGraphicImg->Width/FStateCount))*FState, 0, FGraphicImg->Graphic);
else
Canvas->StretchDraw( TRect(0, 0, Width, Height), FGraphicImg->Graphic);
}else{
if( FState==STATE_NORMAL ){
Canvas->Brush->Color = CLR_AD_CHANGE_NOR;
}else if( FState==STATE_ENTER ){
Canvas->Brush->Color = CLR_AD_CHANGE_ENTER;
}
Canvas->FillRect(TRect(0, 0, Width, Height));
}
}
//---------------------------------------------------------------------------
//**********************************************************************
//***************************************GetUrlData
//**********************************************************************
//---------------------------------------------------------------------------
HRESULT GetUrlData(String url, String fileDirect, String &fileName, TStringStream *fileToSteam, bool bfileToStream, int iWhereIs)
{
String BasePath = g_strUserPath.c_str();
BasePath += fileDirect;
fileName = BasePath + fileName;
if(!DirectoryExists(BasePath, false))
ForceDirectories(BasePath);
DeleteUrlCacheEntry(url.c_str());
CBindCBHttpCallback callBack;
callBack.iWhereIs = iWhereIs;
HRESULT result = URLDownloadToFile(NULL, url.c_str(), fileName.c_str(), 0, &callBack);
if( result==S_OK )
{
bool bfileExsit = true;
if( !FileExists(fileName) ){
result = S_FALSE;
fileName = L"";
bfileExsit = false;
}
if( bfileToStream )
{
if( bfileExsit )
{
if( fileToSteam == NULL ){
fileToSteam = new TStringStream(NULL, 65001);
}
fileToSteam->LoadFromFile(fileName);
fileToSteam->Position = 0;
DeleteFile(fileName);
}
}
}
return result;
}
//---------------------------------------------------------------------------
bool __fastcall GetPic(String &name, bool bCopy)
{
bool bReturn = true;
TMemoryStream *tmpMemoryStream = new TMemoryStream();
tmpMemoryStream->LoadFromFile(name);
tmpMemoryStream->Position = 0;
WORD wType = 0;
tmpMemoryStream->ReadBuffer(&wType, 2);
String tmpName = name;
if( wType==0x5089 ){ //png
name = ChangeFileExt(name, L".png");
RenameFile(tmpName, name);
}else if( wType==0xD8FF ) { //jpg
name = ChangeFileExt(name, L".jpg");
RenameFile(tmpName, name);
}else if( wType==0x4947 ){
name = ChangeFileExt(name, L".gif");
RenameFile(tmpName, name);
}else{
bReturn = false;
}
if( tmpMemoryStream )
delete tmpMemoryStream;
if( bReturn && bCopy)
CopyFile(name.c_str(), tmpName.c_str(), true);
return bReturn;
}
+175
View File
@@ -0,0 +1,175 @@
//---------------------------------------------------------------------------
#ifndef NotificationExUnitH
#define NotificationExUnitH
//---------------------------------------------------------------------------
#include <Data.DBXJSON.hpp>
#include <vector>
using namespace std;
#include <System.IOUtils.hpp>
#include <Urlmon.h>
#include <wininet.h>
#pragma comment(lib, "urlmon.lib")
#pragma comment(lib, "wininet.lib")
//---------------------------------------------------------------------------
#define JSON_PIC_DERICTORY L"temp\\JSON\\"
#define JSON_PIC_DERICTORY_AD L"AD\\"
#define JSON_PIC_DERICTORY_CONTENT L"CONTENT\\"
#define JSON_PIC_DERICTORY_TEXT L"TEXT\\"
typedef struct tagJson{
String strName;
String strNamePic;
String strFileUrl;
String strUrl;
String strAuthor;
}TJSON, *PTJSON;
typedef vector<TJSON> VCTJSON;
typedef vector<PTJSON> VCPTJSON;
//extern VCTJSON::iterator vc_pFindAD;
//extern VCTJSON::iterator vc_pFindNoti;
typedef struct tagJsonDB{ //ͬÀàÐ͵Ä
String strDbName;
VCTJSON vcContent;
}TJSONDB, *PTJSONDB;
typedef vector<TJSONDB> VCTJSONDB;
typedef vector<PTJSONDB> VCPTJSONDB;
//extern VCTJSONDB::iterator vc_pFindContent;
//extern VCTJSON::iterator vc_pFindContentPIC;
TJSONObject* __fastcall GetJsonContext(String strContextNoti);
TJSONObject* __fastcall GetJsonValue(TJSONObject *json, int index);
//---------------------------------------------------------------------------
static const COLORREF
CLR_TEXT_NORMAL = RGB( 156, 170, 189 ),
CLR_TEXT_ENTER = RGB( 100, 180, 236 ),
CLR_TEXT_LEAVE = RGB( 67, 117, 233 );
//---------------------------------------------------------------------------
#define UrlDown_Notification 0
#define UrlDown_ImageCover 1
void __fastcall StopURLDownload(int iWhereIs=UrlDown_Notification);
class CBindCBHttpCallback : public IBindStatusCallback
{
public:
CBindCBHttpCallback(){};
~CBindCBHttpCallback(){};
STDMETHOD(OnStartBinding)(DWORD dwReserved, IBinding __RPC_FAR *pib);
STDMETHOD(OnStopBinding)(HRESULT hresult, LPCWSTR szError);
STDMETHOD(OnProgress)(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode,
LPCWSTR wszStatusText)
{ return E_NOTIMPL; }
STDMETHOD(GetPriority)(LONG __RPC_FAR *pnPriority)
{ return E_NOTIMPL; }
STDMETHOD(OnLowResource)(DWORD reserved)
{ return E_NOTIMPL; }
STDMETHOD(GetBindInfo)(DWORD __RPC_FAR *grfBINDF, BINDINFO __RPC_FAR *pbindinfo)
{ return E_NOTIMPL; }
STDMETHOD(OnDataAvailable)(DWORD grfBSCF, DWORD dwSize, FORMATETC __RPC_FAR *pformatetc,
STGMEDIUM __RPC_FAR *pstgmed)
{ return E_NOTIMPL; }
STDMETHOD(OnObjectAvailable)(REFIID riid, IUnknown __RPC_FAR *punk)
{ return E_NOTIMPL; }
STDMETHOD_(ULONG,AddRef)()
{ return 0; }
STDMETHOD_(ULONG,Release)()
{ return 0; }
STDMETHOD(QueryInterface)(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
{ return E_NOTIMPL; }
int iWhereIs;
};
//---------------------------------------------------------------------------
class TUrlLabel : public Vcl::Stdctrls::TLabel{
private:
TColor FColorNor;
TColor FColorEnt;
TColor FColorLea;
bool FCloseForm;
String FStrUrl;
void __fastcall SetStrUrl(String url);
TNotifyEvent FOnMouseEnter;//on mouse enter notify event
TNotifyEvent FOnMouseLeave;//on mouse leave notify event
DYNAMIC void __fastcall Click(void);
MESSAGE void __fastcall CMMouseEnter(Winapi::Messages::TMessage &Msg); // to know when mouse is entered
MESSAGE void __fastcall CMMouseLeave(Winapi::Messages::TMessage &Msg); // to know when mouse is leaved
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
END_MESSAGE_MAP(TLabel)
public:
__fastcall TUrlLabel( TComponent* Owner);
__fastcall ~TUrlLabel();
__published:
__property bool CloseForm = {read=FCloseForm, write=FCloseForm, default=false};
__property String StrUrl = {read=FStrUrl, write=SetStrUrl};
__property System::Classes::TNotifyEvent OnMouseEnter = {read=FOnMouseEnter, write=FOnMouseEnter};
__property System::Classes::TNotifyEvent OnMouseLeave = {read=FOnMouseLeave, write=FOnMouseLeave};
__property TColor ColorNor = {read=FColorNor, write=FColorNor, default=CLR_TEXT_NORMAL};
__property TColor ColorEnt = {read=FColorEnt, write=FColorEnt, default=CLR_TEXT_NORMAL};
__property TColor ColorLea = {read=FColorLea, write=FColorLea, default=CLR_TEXT_NORMAL};
};
//---------------------------------------------------------------------------
class TUrlPaintBox : public Vcl::Extctrls::TPaintBox{
private:
String FStrUrl;
TPicture *FGraphicImg;
bool FCloseForm;
int FState;
int FStateCount;
int FIndex;
void __fastcall SetStrGraphicName(String strGraphicName);
void __fastcall SetGraphicImg(TPicture *GraphicImg);
void __fastcall SetStrUrl(String strUrl);
void __fastcall SetStateCount(int stateCount);
TNotifyEvent FOnMouseEnter;//on mouse enter notify event
TNotifyEvent FOnMouseLeave;//on mouse leave notify event
DYNAMIC void __fastcall Click(void);
MESSAGE void __fastcall CMMouseEnter(Winapi::Messages::TMessage &Msg); // to know when mouse is entered
MESSAGE void __fastcall CMMouseLeave(Winapi::Messages::TMessage &Msg); // to know when mouse is leaved
virtual void __fastcall Paint(void);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
END_MESSAGE_MAP(TPaintBox)
public:
__fastcall TUrlPaintBox( TComponent* Owner, TPicture * graphicImg=NULL);
__fastcall ~TUrlPaintBox();
__published:
__property bool CloseForm = {read=FCloseForm, write=FCloseForm, default=false};
__property int State = {read=FState, write=FState, default=0};
__property int StateCount = {read=FStateCount, write=SetStateCount, default=1};
__property int Index = {read=FIndex, write=FIndex, default=0};
__property TPicture *GraphicImg = {read=FGraphicImg, write=SetGraphicImg};
__property String StrUrl = {read=FStrUrl, write=SetStrUrl};
__property System::Classes::TNotifyEvent OnMouseEnter = {read=FOnMouseEnter, write=FOnMouseEnter};
__property System::Classes::TNotifyEvent OnMouseLeave = {read=FOnMouseLeave, write=FOnMouseLeave};
};
//---------------------------------------------------------------------------
bool __fastcall GetPic(String &name, bool bCopy=false);
HRESULT GetUrlData(String url, String fileDirect, String &fileName, TStringStream *fileToSteam=NULL, bool bfileToStream=false, int iWhereIs=UrlDown_Notification);
//---------------------------------------------------------------------------
#endif
+566
View File
@@ -0,0 +1,566 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "NotificationFormUnit.h"
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TNotificationForm *NotificationForm;
//---------------------------------------------------------------------------
#define PERIOD_SHUTDOW ( 2*60*1000 )
#define PERIOD_TEXT ( 3*1000 )
//---------------------------------------------------------------------------
#define LEN_BKG_EXTERNAL_ROUND (1)
#define LEN_BKG_EXTERNAL_FRMAE (1)
#define LEN_BKG_INTERNAL_LINE (23)
//---------------------------------------------------------------------------
#define AD_PANEL_TOP (LEN_BKG_INTERNAL_LINE + 3)
#define AD_PANEL_LEFT (8)
#define AD_PANEL_WIDTH (Width - 2*AD_PANEL_LEFT)
#define AD_PANEL_HEIGHT (75)
#define TEXT_HEIGHT (LEN_BKG_INTERNAL_LINE + 1)
//---------------------------------------------------------------------------
#define JSON_ID_TYPE 0
#define JSON_ID_NAME 1
#define JSON_ID_COUNT 2
#define JSON_ID_DB 3
#define JSON_TYPE_PIC 1
#define JSON_TYPE_TEXT 2
#define JSON_TYPE_CONTENT 3
//---------------------------------------------------------------------------
const static COLORREF
CLR_TXT_HOT = RGB(171, 186, 207),
CLR_BKG_EXTERNAL_ROUND = RGB(60, 62, 70),
CLR_BKG_EXTERNAL_FRMAE = RGB(98, 106, 114),
CLR_BKG_INTERNAL = RGB(39, 42, 47),
CLR_BKG_INTERNAL_LINE_HIG = RGB(71, 73, 78),
CLR_BKG_INTERNAL_LINE_BLACK = RGB(22, 24, 26);
//---------------------------------------------------------------------------
__fastcall TNotificationForm::TNotificationForm(TComponent* Owner)
: TForm(Owner)
{
Color = CLR_BKG_INTERNAL;
this->Left = Screen->Width - this->Width - 14;
this->Top = Screen->WorkAreaHeight - this->Height;
//公告区
m_pTextNotiTimer = new TTimer(this);
m_pTextNotiTimer->Enabled = false;
m_pTextNotiTimer->Interval = PERIOD_TEXT;
m_pTextNotiTimer->OnTimer = NotificationTimerProc;
//自动关闭
m_pNotiShutDownTimer = new TTimer(this);
m_pNotiShutDownTimer->Enabled = false;
m_pNotiShutDownTimer->Interval = PERIOD_SHUTDOW;
m_pNotiShutDownTimer->OnTimer = NotificationTimerProc;
m_pNotificationThread = new TNotificationThread(true, this);
m_pNotificationThread->Start();
SetTransparent( this );
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::setPANEL()
{
bool bSuccess = true;
int tmp = m_VCJsonAD.size();
if( m_VCJsonAD.size() ) {
m_pNotiADPanel = new TNotiADPanel(this, &m_VCJsonAD);
m_pNotiADPanel->Parent = this;
m_pNotiADPanel->Top = AD_PANEL_TOP;
m_pNotiADPanel->Left = AD_PANEL_LEFT;
m_pNotiADPanel->Width = AD_PANEL_WIDTH;
m_pNotiADPanel->Height = AD_PANEL_HEIGHT;
}else { bSuccess = false;}
if( m_VCJsonContent.size() ) {
m_pNotiContenPanel = new TNotiContenPanel(this, &m_VCJsonContent);
m_pNotiContenPanel->Parent = this;
if( bSuccess ) {
m_pNotiContenPanel->Top = AD_PANEL_TOP + AD_PANEL_HEIGHT;
m_pNotiContenPanel->Left = AD_PANEL_LEFT;
m_pNotiContenPanel->Width = this->Width - 2*AD_PANEL_LEFT;
m_pNotiContenPanel->Height = this->Height - TEXT_HEIGHT - m_pNotiContenPanel->Top;
}else{
m_pNotiContenPanel->Top = AD_PANEL_TOP;
m_pNotiContenPanel->Left = 0;
m_pNotiContenPanel->Width = this->Width;
m_pNotiContenPanel->Height = this->Height - TEXT_HEIGHT - m_pNotiContenPanel->Top;
}
bSuccess = true;
}else { bSuccess = false;}
if( m_VCJonNoti.size() ) {
m_pNotiUrl = new TUrlLabel(this);
m_pNotiUrl->Parent = this;
m_pNotiUrl->Caption = (*m_VCJonNoti.begin()).strName;
String url = (*m_VCJonNoti.begin()).strUrl;
if( url.Length() ) {
m_pNotiUrl->StrUrl = url;
}else{
char strURL[256];
f_CS_GetWebPageURL( URL_HOMEPAGE, strURL );
m_pNotiUrl->StrUrl = (String)strURL;
}
m_pNotiUrl->Top = this->Height - TEXT_HEIGHT + (TEXT_HEIGHT - m_pNotiUrl->Height)/2;
m_pNotiUrl->Left = (this->Width - m_pNotiUrl->Width)/2;
if( m_VCJonNoti.size() > 1) {
m_pNotiUrl->OnMouseEnter = NotiChangeMouseEnter;
m_pNotiUrl->OnMouseLeave = NotiChangeMouseLeave;
m_pTextNotiTimer->Enabled = true;
}
}
if( bSuccess ){
m_pNotiShutDownTimer->Enabled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::CreateParams(Vcl::Controls::TCreateParams &Params)
{
TForm::CreateParams(Params);
Params.WndParent = GetDesktopWindow();
Params.ExStyle |= WS_EX_TOOLWINDOW;
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::FormShow(TObject *Sender)
{
this->Left = Screen->Width - this->Width - 14;
this->Top = Screen->WorkAreaHeight - this->Height;
// AnimateWindow(Handle, 1000, AW_BLEND);
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::FormClose(TObject *Sender, TCloseAction &Action)
{
/* AnimateWindow(Handle,1000,AW_BLEND+AW_HIDE);
if( m_pNotiADPanel ) { delete m_pNotiADPanel; m_pNotiADPanel = NULL; }
if( m_pTextNotiTimer ){ delete m_pTextNotiTimer; m_pTextNotiTimer = NULL; }
if( m_pNotiShutDownTimer ){ delete m_pNotiShutDownTimer; m_pNotiShutDownTimer = NULL; }
if( m_pNotiUrl ) { delete m_pNotiUrl; m_pNotiUrl = NULL;}
if( m_pNotiContenPanel ) { delete m_pNotiContenPanel; m_pNotiContenPanel = NULL; }
if( m_pNotificationThread ) { delete m_pNotificationThread; m_pNotificationThread = NULL; }
ClearJsonDirect();
m_VCJsonAD.clear();
m_VCJonNoti.clear();
m_VCJsonContent.clear();
*/
PostMessage(Application->MainForm->Handle, UM_NOTIFICATION,
NOTIFICATION_SHOW_CLOSED, 0 );
}
//---------------------------------------------------------------------------
__fastcall TNotificationForm::~TNotificationForm()
{
if( m_pNotiADPanel ) { delete m_pNotiADPanel; m_pNotiADPanel = NULL; }
if( m_pTextNotiTimer ){ delete m_pTextNotiTimer; m_pTextNotiTimer = NULL; }
if( m_pNotiShutDownTimer ){ delete m_pNotiShutDownTimer; m_pNotiShutDownTimer = NULL; }
if( m_pNotiUrl ) { delete m_pNotiUrl; m_pNotiUrl = NULL;}
if( m_pNotiContenPanel ) { delete m_pNotiContenPanel; m_pNotiContenPanel = NULL; }
if( m_pNotificationThread ) {
StopURLDownload();
m_pNotificationThread->WaitFor();
delete m_pNotificationThread;
m_pNotificationThread = NULL;
}
ClearJsonDirect();
m_VCJsonAD.clear();
m_VCJonNoti.clear();
m_VCJsonContent.clear();
}
bool __fastcall TNotificationForm::ParseJson()
{
ClearJsonDirect();
char strURL[256];
if( S_OK != f_CS_GetWebPageURL( URL_JASONQUERY, strURL ) )
return false;
String urlJson = strURL;
String strJson;
String picDirect = JSON_PIC_DERICTORY;
String picName = L"json.tmp";
TStringStream *strStream = new TStringStream(NULL, 65001);
HRESULT resultJson = GetUrlData(urlJson, picDirect, picName, strStream, true);
strJson= strStream->DataString;
delete strStream;
// HRESULT resultJson = S_OK;
// strJson = L"{\"1\":{\"type\":1,\"name\":\"活动\",\"count\":3,\"db\":{\"1\":{\"name\":\"改编达人\",\"picture\":\"http://www.ichangzuo.com/ichangzuo/File/Music/Cover/201307/414_1374757039.png\",\"file\":\"\",\"url\":\"http://composemusic.xicp.net:81/index.php/Activity?tpl=show\",\"author\":\"\"},\"2\":{\"name\":\"改编达人\",\"picture\":\"http://www.ichangzuo.com/ichangzuo/File/Music/Cover/201403/414_1396202466.png\",\"file\":\"\",\"url\":\"http://composemusic.xicp.net:81/index.php/Activity?tpl=show\",\"author\":\"\"},\"3\":{\"name\":\"改编达人\",\"picture\":\"http://www.ichangzuo.com/ichangzuo/File/User/Photo/414_1374202747.jpg\",\"file\":\"\",\"url\":\"http://composemusic.xicp.net:81/index.php/Activity?tpl=show\",\"author\":\"\"}}},\"2\":{\"type\":1,\"name\":\"广告\",\"count\":0},\"3\":{\"type\":1,\"name\":\"软件\",\"count\":0},\"4\":{\"type\":3,\"name\":\"推荐音乐\",\"count\":3,\"db\":{\"1\":{\"name\":\"跟着感觉走\",\"picture\":\"http://composemusic.xicp.net:81/ichangzuo/File/Web/Default/music_cover_default.jpg\",\"file\":\"http://composemusic.xicp.net:81/ichangzuo/File/Music/Music/201307/867_1374396650.MP3\",\"url\":\"http://composemusic.xicp.net:81/index.php/Music?tpl=play&i=22\",\"author\":\"木木\"},\"2\":{\"name\":\"墨西歌舞\",\"picture\":\"http://composemusic.xicp.net:81/ichangzuo/File/User/Default/Music_cover/10475_1380381900.jpg\",\"file\":\"http://composemusic.xicp.net:81/ichangzuo/File/Music/Music/201309/10475_1378453592.mp3\",\"url\":\"http://composemusic.xicp.net:81/index.php/Music?tpl=play&i=549\",\"author\":\"下雨了\"},\"3\":{\"name\":\"123的\",\"picture\":\"http://composemusic.xicp.net:81/ichangzuo/File/Web/Default/music_cover_default.jpg\",\"file\":\"http://composemusic.xicp.net:81/ichangzuo/File/Music/Music/201403/23599_1395305792.mp3\",\"url\":\"http://composemusic.xicp.net:81/index.php/Music?tpl=play&i=2457\",\"author\":\"小花花\"}}},\"5\":{\"type\":3,\"name\":\"推荐歌词\",\"count\":1,\"db\":{\"1\":{\"name\":\"你会\",\"picture\":\"http://composemusic.xicp.net:81/ichangzuo/File/User/Portrait/default.jpg\",\"file\":\"\",\"url\":\"http://composemusic.xicp.net:81/index.php/Lyric?tpl=show&i=33\",\"author\":\"小花花\"}}},\"6\":{\"type\":2,\"name\":\"公告\",\"count\":3,\"db\":{\"1\":{\"name\":\"333\",\"picture\":\"\",\"file\":\"\",\"url\":\"\",\"author\":\"0\"},\"2\":{\"name\":\"这是一个测试的标题\",\"picture\":\"\",\"file\":\"\",\"url\":\"\",\"author\":\"0\"},\"3\":{\"name\":\"这是一个测试\",\"picture\":\"\",\"file\":\"\",\"url\":\"\",\"author\":\"0\"}}}}";
if( !m_pNotiShutDownTimer || !(resultJson==S_OK && strJson.Length() > 1) ){
return false;
}
String jsonPath = JSON_PIC_DERICTORY;
bool bSuccess = false;
int indexPic = 0;
TJSONObject *jsonOri = GetJsonContext(strJson);
if( jsonOri==NULL ) {
return false;
}
try
{
for( int i=0; i<jsonOri->Size(); i++ )
{
TJSONObject *ValueID = GetJsonValue(jsonOri, i);
if( ValueID==NULL ) {continue;}
TJSONObject *ValueCount = GetJsonValue(ValueID, JSON_ID_COUNT);
if( ValueCount==NULL ) { continue; }
if( StrToInt(ValueCount->Value())==0 ) { continue; }
TJSONObject *ValueDB = GetJsonValue(ValueID, JSON_ID_DB);
if( ValueDB==NULL) {continue;}
bool bTypeContent = false;
TJSONDB jsonContent;
for(int i=0; i<ValueDB->Size(); i++)
{
TJSONObject *ValueDBID = GetJsonValue(ValueDB, i);
if( ValueDBID==NULL ) {continue;}
TJSONObject *ValueType = GetJsonValue(ValueID, JSON_ID_TYPE);
if( ValueType==NULL ) { continue;}
TJSON jsonAdd;
jsonAdd.strName = ValueDBID->GetValue(L"name")->Value();
jsonAdd.strFileUrl = ValueDBID->GetValue(L"file")->Value();
jsonAdd.strUrl = ValueDBID->GetValue(L"url")->Value();
jsonAdd.strAuthor = ValueDBID->GetValue(L"author")->Value();
String strPicDirect;
String strType = ValueType->Value();
if( StrToInt(strType)==JSON_TYPE_PIC ){
strPicDirect = JSON_PIC_DERICTORY_AD;
}else if( StrToInt(strType)==JSON_TYPE_TEXT ) {
strPicDirect = JSON_PIC_DERICTORY_TEXT;
}else if( StrToInt(strType)==JSON_TYPE_CONTENT ){
strPicDirect = JSON_PIC_DERICTORY_CONTENT;
}
String strPicUrl = ValueDBID->GetValue(L"picture")->Value();
// String strPicUrl = L"http://www.ichangzuo.com/ichangzuo/File/Software/Content/Ac/137784127986.jpg";
if( strPicUrl.Length() ) {
strPicDirect = jsonPath + strPicDirect;
String strPicName = IntToStr(indexPic) + ExtractFileExt(strPicUrl);
resultJson = GetUrlData(strPicUrl, strPicDirect, strPicName);
if( !m_pNotiShutDownTimer ){
delete jsonOri;
return false;
}
if( resultJson == S_OK ){
jsonAdd.strNamePic = strPicName;
indexPic++;
}
}
if( StrToInt(strType)==JSON_TYPE_PIC && jsonAdd.strNamePic.Length() ){
m_VCJsonAD.push_back(jsonAdd);
}else if( StrToInt(strType)==JSON_TYPE_TEXT ) {
m_VCJonNoti.push_back(jsonAdd);
}else if( StrToInt(strType)==JSON_TYPE_CONTENT ){
jsonContent.vcContent.push_back(jsonAdd);
bTypeContent = true;
}
}
if( bTypeContent && jsonContent.vcContent.size() ) {
TJSONObject *ValueName = GetJsonValue(ValueID, JSON_ID_NAME);
if( ValueName == NULL ){
jsonContent.strDbName = L"";
}else {
jsonContent.strDbName = ValueName->Value();
}
m_VCJsonContent.push_back(jsonContent);
}
}
}catch(Exception &e){
delete jsonOri;
return false;
}
if( jsonOri ){
delete jsonOri;
jsonOri = NULL;
}
if( m_VCJsonAD.size() ) {
bSuccess = true;
}
if( m_VCJsonContent.size() ){
bSuccess = true;
}else { bSuccess = false;}
return bSuccess;
}
//---------------------------------------------------------------------------
bool __fastcall TNotificationForm::LoadImg()
{
TPicture *picImg = NULL;
int adSize = m_VCJsonAD.size();
if( adSize )
{
VCTJSON::iterator vc_pFindAD;
for( vc_pFindAD = m_VCJsonAD.begin();
vc_pFindAD != m_VCJsonAD.end();
vc_pFindAD++ )
{
if( (*vc_pFindAD).strNamePic.Length() ) {
if( GetPic(vc_pFindAD->strNamePic) )
{
try{
picImg = new TPicture();
picImg->LoadFromFile( (*vc_pFindAD).strNamePic );
delete picImg;
}catch(Exception &e){
return false;
}
}else{
return false;
}
}else{
return false;
}
}
}
adSize = m_VCJsonContent.size();
if( adSize ){
VCTJSONDB::iterator vc_pFindContent;
for( vc_pFindContent = m_VCJsonContent.begin();
vc_pFindContent != m_VCJsonContent.end();
vc_pFindContent++)
{
VCTJSON::iterator vc_pFindContentPIC;
for( vc_pFindContentPIC = (*vc_pFindContent).vcContent.begin();
vc_pFindContentPIC != (*vc_pFindContent).vcContent.end();
vc_pFindContentPIC++)
{
if( (*vc_pFindContentPIC).strNamePic.Length() )
{
if( GetPic(vc_pFindContentPIC->strNamePic) ) {
try{
picImg = new TPicture();
picImg->LoadFromFile( (*vc_pFindContentPIC).strNamePic );
delete picImg;
}catch(Exception &e){
return false;
}
}else{
return false;
}
}
}
}
}
return true;
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::NotificationTimerProc(TObject* Sender)
{
TTimer *NotiTimer = (TTimer *)Sender;
int index = -1;
int size = 0;
if( NotiTimer== m_pTextNotiTimer) { //公告切换
index = -1;
size = m_VCJonNoti.size();
if( size>1 ) {
index = (m_iTextNotiIndex+1<size)?(m_iTextNotiIndex+1):0;
}else {
m_pTextNotiTimer->Enabled = false;
return;
}
if( m_iTextNotiIndex != index )
{
m_iTextNotiIndex = index;
VCTJSON::iterator vc_pFindNoti = m_VCJonNoti.begin() + index;
String url = (*vc_pFindNoti).strUrl;
if( url.Length() ) {
m_pNotiUrl->StrUrl = url;
}else{
m_pNotiUrl->StrUrl = L"http://www.ichangzuo.com/";
}
m_pNotiUrl->Caption = (*vc_pFindNoti).strName;
m_pNotiUrl->Left = (this->Width - m_pNotiUrl->Width)/2;
}
}else if( NotiTimer == m_pNotiShutDownTimer ) {
m_pNotiShutDownTimer->Enabled = false;
this->Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::WMEraseBkgnd(Winapi::Messages::TWMEraseBkgnd &Message)
{
TRect rect = GetClientRect();
TRect rectFill = rect;
TCanvas* tempCanvas = new TCanvas;
tempCanvas->Handle = Message.DC;
rectFill.Top = rectFill.Top + LEN_BKG_EXTERNAL_ROUND;
rectFill.Left = rectFill.Left + LEN_BKG_EXTERNAL_ROUND;
rectFill.Right = rectFill.Right - LEN_BKG_EXTERNAL_ROUND;
rectFill.Bottom = rectFill.Bottom - LEN_BKG_EXTERNAL_ROUND;
tempCanvas->Brush->Color = CLR_BKG_INTERNAL;
tempCanvas->FillRect( rectFill );
// //==========画圆角
tempCanvas->Pen->Color = CLR_BKG_EXTERNAL_ROUND;
int X,Y;
//上面的
Y = 0;
X = 0;
tempCanvas->Pixels[X][Y] = tempCanvas->Pen->Color;
X = Width - LEN_BKG_EXTERNAL_ROUND;
tempCanvas->Pixels[X][Y] = tempCanvas->Pen->Color;
//下面的
Y = Height - LEN_BKG_EXTERNAL_ROUND;
X = 0;
tempCanvas->Pixels[X][Y] = tempCanvas->Pen->Color;
X = Width - LEN_BKG_EXTERNAL_ROUND;
tempCanvas->Pixels[X][Y] = tempCanvas->Pen->Color;
//===========画边框
tempCanvas->Pen->Color = CLR_BKG_EXTERNAL_FRMAE;
tempCanvas->MoveTo( LEN_BKG_EXTERNAL_FRMAE, 0 );
tempCanvas->LineTo( Width-LEN_BKG_EXTERNAL_FRMAE, 0 );
tempCanvas->MoveTo( LEN_BKG_EXTERNAL_FRMAE, Height-LEN_BKG_EXTERNAL_FRMAE );
tempCanvas->LineTo( Width-LEN_BKG_EXTERNAL_FRMAE, Height-LEN_BKG_EXTERNAL_FRMAE );
tempCanvas->MoveTo( 0, LEN_BKG_EXTERNAL_FRMAE );
tempCanvas->LineTo( 0, Height-LEN_BKG_EXTERNAL_FRMAE );
tempCanvas->MoveTo( Width-LEN_BKG_EXTERNAL_FRMAE, LEN_BKG_EXTERNAL_FRMAE );
tempCanvas->LineTo( Width-LEN_BKG_EXTERNAL_FRMAE, Height-LEN_BKG_EXTERNAL_FRMAE );
//===========画分割线
int iLineHeight = LEN_BKG_INTERNAL_LINE;
tempCanvas->Pen->Color = CLR_BKG_INTERNAL_LINE_HIG;
tempCanvas->MoveTo( LEN_BKG_EXTERNAL_FRMAE, iLineHeight );
tempCanvas->LineTo( Width-LEN_BKG_EXTERNAL_FRMAE, iLineHeight );
tempCanvas->MoveTo( LEN_BKG_EXTERNAL_FRMAE, iLineHeight+2 );
tempCanvas->LineTo( Width-LEN_BKG_EXTERNAL_FRMAE, iLineHeight+2 );
tempCanvas->Pen->Color = CLR_BKG_INTERNAL_LINE_BLACK;
tempCanvas->MoveTo( LEN_BKG_EXTERNAL_FRMAE, iLineHeight+1 );
tempCanvas->LineTo( Width-LEN_BKG_EXTERNAL_FRMAE, iLineHeight+1 );
//画标题
tempCanvas->Font->Color = CLR_TXT_HOT;
tempCanvas->Brush->Style = bsClear;
TSize size = tempCanvas->TextExtent( Caption );
X = LEN_BKG_EXTERNAL_FRMAE + ( Width - size.Width )/2,
Y = LEN_BKG_EXTERNAL_FRMAE + ( LEN_BKG_INTERNAL_LINE-size.Height )/2;
X = ( Width - size.Width )/2;
Y = ( LEN_BKG_INTERNAL_LINE-size.Height )/2;
tempCanvas->TextOut( X, Y, Caption );
delete tempCanvas;
Message.Result = true;
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if( Msg.Result==HTCLIENT &&
(Msg.YPos<Top+LEN_BKG_INTERNAL_LINE) &&
(Msg.XPos<(Left+ m_PNGButtonClose->Left) ) )
{
Msg.Result = HTCAPTION;
}
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::m_PNGButtonCloseClick(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::NotiChangeMouseEnter(TObject *Sender)
{
m_pTextNotiTimer->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::NotiChangeMouseLeave(TObject *Sender)
{
m_pTextNotiTimer->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TNotificationForm::ClearJsonDirect()
{
String fileDirect = g_strUserPath.c_str();
fileDirect += JSON_PIC_DERICTORY;
if( DirectoryExists(fileDirect) ) {
TDirectory *clearDirect = new TDirectory();
clearDirect->Delete(fileDirect, true);
delete clearDirect;
}
}
//---------------------------------------------------------------------------
+168
View File
@@ -0,0 +1,168 @@
object NotificationForm: TNotificationForm
Left = 0
Top = 0
BorderStyle = bsNone
Caption = #21809#20316#32593#21160#24577
ClientHeight = 330
ClientWidth = 268
Color = clBtnFace
DoubleBuffered = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
FormStyle = fsStayOnTop
Scaled = False
OnClose = FormClose
OnShow = FormShow
TextHeight = 13
object m_PNGButtonClose: TPNGButton
Left = 240
Top = 4
Width = 23
Height = 18
ImgStates = 3
PngImg.Data = {
89504E470D0A1A0A0000000D49484452000000450000001208060000000D0613
66000000097048597300000B1300000B1301009A9C1800000A4D694343505068
6F746F73686F70204943432070726F66696C65000078DA9D53775893F7163EDF
F7650F5642D8F0B1976C81002223AC08C81059A21092006184101240C585880A
561415119C4855C482D50A489D88E2A028B867418A885A8B555C38EE1FDCA7B5
7D7AEFEDEDFBD7FBBCE79CE7FCCE79CF0F8011122691E6A26A003952853C3AD8
1F8F4F48C4C9BD80021548E0042010E6CBC26705C50000F00379787E74B03FFC
01AF6F00020070D52E2412C7E1FF83BA50265700209100E02212E70B01905200
C82E54C81400C81800B053B3640A009400006C797C422200AA0D00ECF4493E05
00D8A993DC1700D8A21CA908008D0100992847240240BB00605581522C02C0C2
00A0AC40222E04C0AE018059B632470280BD0500768E58900F4060008099422C
CC0020380200431E13CD03204C03A030D2BFE0A95F7085B8480100C0CB95CD97
4BD23314B895D01A77F2F0E0E221E2C26CB142611729106609E4229C979B2313
48E7034CCE0C00001AF9D1C1FE383F90E7E6E4E1E666E76CEFF4C5A2FE6BF06F
223E21F1DFFEBC8C020400104ECFEFDA5FE5E5D60370C701B075BF6BA95B00DA
560068DFF95D33DB09A05A0AD07AF98B7938FC401E9EA150C83C1D1C0A0B0BED
2562A1BD30E38B3EFF33E16FE08B7EF6FC401EFEDB7AF000719A4099ADC0A383
FD71616E76AE528EE7CB0442316EF7E723FEC7857FFD8E29D1E234B15C2C158A
F15889B850224DC779B952914421C995E212E97F32F11F96FD0993770D00AC86
4FC04EB607B5CB6CC07EEE01028B0E58D27600407EF32D8C1A0B910010673432
79F7000093BFF98F402B0100CD97A4E30000BCE8185CA894174CC608000044A0
812AB041070CC114ACC00E9CC11DBCC01702610644400C24C03C104206E4801C
0AA11896411954C03AD804B5B0031AA0119AE110B4C131380DE7E0125C81EB70
170660189EC218BC86090441C8081361213A8811628ED822CE0817998E042261
48349280A420E988145122C5C872A402A9426A915D4823F22D7214398D5C40FA
90DBC820328AFC8ABC47319481B25103D4027540B9A81F1A8AC6A073D174340F
5D8096A26BD11AB41E3D80B6A2A7D14BE87574007D8A8E6380D1310E668CD961
5C8C87456089581A26C71663E55835568F35631D583776151BC09E61EF082402
8B8013EC085E8410C26C82909047584C5843A825EC23B412BA085709838431C2
272293A84FB4257A12F9C478623AB1905846AC26EE211E219E255E270E135F93
48240EC992E44E0A21259032490B496B48DB482DA453A43ED210699C4C26EB90
6DC9DEE408B280AC209791B7900F904F92FBC9C3E4B7143AC588E24C09A22452
A494124A35653FE504A59F324299A0AA51CDA99ED408AA883A9F5A496DA07650
2F5387A91334759A25CD9B1643CBA42DA3D5D09A696769F7682FE974BA09DD83
1E4597D097D26BE807E9E7E983F4770C0D860D83C7486228196B197B19A718B7
192F994CA605D39799C85430D7321B9967980F986F55582AF62A7C1591CA1295
3A9556957E95E7AA545573553FD579AA0B54AB550FAB5E567DA64655B350E3A9
09D416ABD5A91D55BBA936AECE5277528F50CF515FA3BE5FFD82FA630DB28685
46A08648A35463B7C6198D2116C63265F15842D6725603EB2C6B984D625BB2F9
EC4C7605FB1B762F7B4C534373AA66AC6691669DE671CD010EC6B1E0F039D99C
4ACE21CE0DCE7B2D032D3F2DB1D66AAD66AD7EAD37DA7ADABEDA62ED72ED16ED
EBDAEF75709D409D2C9DF53A6D3AF77509BA36BA51BA85BADB75CFEA3ED363EB
79E909F5CAF50EE9DDD147F56DF4A3F517EAEFD6EFD11F373034083690196C31
3863F0CC9063E86B9869B8D1F084E1A811CB68BA91C468A3D149A327B826EE87
67E33578173E66AC6F1C62AC34DE65DC6B3C61626932DBA4C4A4C5E4BE29CD94
6B9A66BAD1B4D374CCCCC82CDCACD8ACC9EC8E39D59C6B9E61BED9BCDBFC8D85
A5459CC54A8B368BC796DA967CCB05964D96F7AC98563E567956F556D7AC49D6
5CEB2CEB6DD6576C501B579B0C9B3A9BCBB6A8AD9BADC4769B6DDF14E2148F29
D229F5536EDA31ECFCEC0AEC9AEC06ED39F661F625F66DF6CF1DCC1C121DD63B
743B7C727475CC766C70BCEBA4E134C3A9C4A9C3E957671B67A1739DF33517A6
4B90CB1297769717536DA78AA76E9F7ACB95E51AEEBAD2B5D3F5A39BBB9BDCAD
D96DD4DDCC3DC57DABFB4D2E9B1BC95DC33DEF41F4F0F758E271CCE39DA79BA7
C2F390E72F5E765E595EFBBD1E4FB39C269ED6306DC8DBC45BE0BDCB7B603A3E
3D65FACEE9033EC63E029F7A9F87BEA6BE22DF3DBE237ED67E997E07FC9EFB3B
FACBFD8FF8BFE179F216F14E056001C101E501BD811A81B3036B031F049904A5
0735058D05BB062F0C3E15420C090D591F72936FC017F21BF96333DC672C9AD1
15CA089D155A1BFA30CC264C1ED6118E86CF08DF107E6FA6F94CE9CCB60888E0
476C88B81F69199917F97D14292A32AA2EEA51B453747174F72CD6ACE459FB67
BD8EF18FA98CB93BDB6AB6727667AC6A6C526C63EC9BB880B8AAB8817887F845
F1971274132409ED89E4C4D8C43D89E37302E76C9A339CE49A54967463AEE5DC
A2B917E6E9CECB9E773C593559907C3885981297B23FE5832042502F184FE5A7
6E4D1D13F2849B854F45BEA28DA251B1B7B84A3C92E69D5695F638DD3B7D43FA
68864F4675C633094F522B79911992B923F34D5644D6DEACCFD971D92D39949C
949CA3520D6996B42BD730B728B74F662B2B930DE479E66DCA1B9387CAF7E423
F973F3DB156C854CD1A3B452AE500E164C2FA82B785B185B78B848BD485AD433
DF66FEEAF9230B82167CBD90B050B8B0B3D8B87859F1E022BF45BB16238B5317
772E315D52BA647869F0D27DCB68CBB296FD50E2585255F26A79DCF28E5283D2
A5A5432B82573495A994C9CB6EAEF45AB9631561956455EF6A97D55B567F2A17
955FAC70ACA8AEF8B046B8E6E2574E5FD57CF5796DDADADE4AB7CAEDEB48EBA4
EB6EACF759BFAF4ABD6A41D5D086F00DAD1BF18DE51B5F6D4ADE74A17A6AF58E
CDB4CDCACD03356135ED5BCCB6ACDBF2A136A3F67A9D7F5DCB56FDADABB7BED9
26DAD6BFDD777BF30E831D153BDEEF94ECBCB52B78576BBD457DF56ED2EE82DD
8F1A621BBABFE67EDDB847774FC59E8F7BA57B07F645EFEB6A746F6CDCAFBFBF
B2096D52368D1E483A70E59B806FDA9BED9A77B5705A2A0EC241E5C127DFA67C
7BE350E8A1CEC3DCC3CDDF997FB7F508EB48792BD23ABF75AC2DA36DA03DA1BD
EFE88CA39D1D5E1D47BEB7FF7EEF31E36375C7358F579EA09D283DF1F9E48293
E3A764A79E9D4E3F3DD499DC79F74CFC996B5D515DBD6743CF9E3F1774EE4CB7
5FF7C9F3DEE78F5DF0BC70F422F762DB25B74BAD3DAE3D477E70FDE148AF5B6F
EB65F7CBED573CAE74F44DEB3BD1EFD37FFA6AC0D573D7F8D72E5D9F79BDEFC6
EC1BB76E26DD1CB825BAF5F876F6ED17770AEE4CDC5D7A8F78AFFCBEDAFDEA07
FA0FEA7FB4FEB165C06DE0F860C060CFC3590FEF0E09879EFE94FFD387E1D247
CC47D52346238D8F9D1F1F1B0D1ABDF264CE93E1A7B2A713CFCA7E56FF79EB73
ABE7DFFDE2FB4BCF58FCD8F00BF98BCFBFAE79A9F372EFABA9AF3AC723C71FBC
CE793DF1A6FCADCEDB7DEFB8EFBADFC7BD1F9928FC40FE50F3D1FA63C7A7D04F
F73EE77CFEFC2FF784F3FB25D29F33000006B94944415478DABD58094C544718
9EDDE5580159451456B45AAF6A6BAB8918B0948A495B540E8F2A8A8AA0A82508
08222851ACF5880222A055A15A5CD4A25851118CA890D818164CDA7A8416E3D1
5691E241E53E97DDED3FEC0CFBEF6337D0A4F2922FEFBD7933DFFBE79B7FFEF9
67445AAD96BC8D4BAD56F3471182984184AA6A1984F5F1770D8356505F64E41F
FF955BC8A91561515047FECF8B8A20019801CC19CC58393746CDEE58386E7427
40C5D0C9EA6A5027C5E81F1C22D4490DE2168AA246E816FE6D8BC28DA6425802
AC00D600292BC31DD7B0FA58305ADE066806B400DA9938BCA358700B04EE8DC6
04E7A2508E0E846EC185A250C31D0072C000647423E039A016600B180190A111
6D05BC00BC649DC0A2489820D6AC8D1DBB0F609DD12283C4AC4C8404A907BC61
F766260CEF2817DC82F159B33B17064F3D6E0B1744C5EC6E66F70E56D6C3536C
97FA2F4F529696ADC3C32D9148D4DFECD8FEF5CA8015B94545C59F844544A6B5
B4B458E13AAE2E2E8A7339D991CC782C8A19335436D7DB37AABCFCB72821775A
EA81745F1FEF67BFDEB963E7BF2C20ACB5B5D51AD7797FD2A46F0BAF162431EE
16261841A258797ACE897A5E55B50DB7138BC59D911B22360607AF7E58545CEC
B06953EC41954A25C375E4727942D18D6B894818A39EF291E76CAF53150F1EBC
871B0F1C38B0F1DCD9EC63EB4242FD2A2B2B47E06FE3C78F7B5C7CE3DA0A78BC
67C453B82883008E6EEE1E87A1BD735FB99D860FBF5BAABC15C23CB19619DFC9
BC40C245A1A2BBBBCF54BCA9ADFD14B7975A5AFE939696BA694B5CDCE6DADABA
89F89B4C26532A4B6EAD4062AB8C89426FB6F7EEDD9FB33C2030A3A1A1C14055
7373F30E50DA0297D9DADAD62B328FAF77769E960FAF0DC4F0E22E2B65A2C87F
AFA8F870B19F7F726363E3A0DEB841ACBA1F4E67C54C9D32E53EBCFE0DA863A2
0BA74F97284AA5724C7844E4D9B6B6B6A1026F6C83BE490DC4924A5FEF4F4A5C
3E6B96C7A3BE88423BE2704271327CE7AEDD9BA14C424C5CE09EDA6D5BE312D7
04AF4E85D75744BF2A18D8447431850A4C63D598F3B9173E8F89DD12DC1BF7BE
BD7B8E2F5DE2771D5EFF005433E3794C21441F8306307EFBC3478E7AA4A76724
68341A3353DC229148F3D5BAB55BC2C3C38AE1B586F1720FD4985A7D28E1071B
A3639268074C912FFA72E18D03C949B1F0584EF4F3BC47FF882EF051A31DA928
8049C0EDD107EE9BF0F800F084E8A60F35BE83182EC95C14BA00500F9107AF59
BBB8ACEC7690296E575717C5F7C78FFDC8847E4D741EDE3D2D4D89423B3175C9
D265474ACB6E4F33453EC3D5E5979CB3D9A1F07897196B4A144B6634F594B180
89C0BDA00FDC97E0B1828952CD8C6F37218A8C89E2386FFE8288C78F9F789AE2
1E376EECB5BC4B170F2151B0A7181585BAF4C81D3B77EDC9CC542C23BD5C3075
4E6D8FDF1A4F744BB630D1E1B9018F29C30163F6EE4BF03B9AFEDDC2DEB8C3D6
87E6C6C644D311A5D307C7149CA75051AC18BF3DAC30FE570B0B37F6C6EDE535
777F62C2BE1CA29B3E9497AF6A3DA60FED845D7EC195C0C8A8E8BDC2C067636D
DDD4D4DC6C83CB68804C4D498EF3F1F6CA22BA7C429856F3911C4C452928B8E2
B6212A7A4F5FB9D35292B77A7B7B953051F0EA43883ED076E54027140AE79494
B42C6150B5B0B0A8EDE8E8188CCB68F08D8ADA10B82A28E867A2CF818C065AEB
AAAAAA993EF3162A6A6A6A0C22F8E8D1A39E9EC93E9DE9E3BB204CF8CDDEDEFE
757EDE85202727A79F18391685AF0E764F9F3E1BEDED3BFF647D7DBD93903BE7
4CF6192F9F79C1426E5836AB0A2E5F5A396AD43B7F31D1F92AC145E9CA94CBCB
CB1D028356E7C3CAF32E6E3F64C89072881FBB030256263536358DC4DF6005FA
334B91E93379F2E497449F31F71065E8675FCC3EF7F0E1230FDC98E611B0EC86
4C9FEE5C065E341B82E481F6F6764B5C67C284F1378BAE17FA11DD1C25C8E86E
F77699E176A8BAFA85B78187D8D834E45DCC4D855CA7B1A444392C705570388C
AAC148CBE58E05B74B4BC289A19BF33CA52B9BFDD8CD3D1DC45E64D069C85132
32D243215DA8CBBB9C3F223E7EFB413AF002D1CF43AE1242F4C99B5A280A359E
CEFB61EC67F4D230632A892EDDA77397A7F97C1F41C95E31176F11780A1545CA
5C9CB6A569BE2D2B13337E9EE6F3644CCCDE69FC68601E52C7BCB08DF49C3E16
A4E7BE8AEF7D789ACFF74922A24FF3F1BE8AA7F99AFED810F28E4A99E156EC99
E7116AA2DF10F2CD9D187D6B6546B7B04EA8883EA0637EBE19342786BB6C9CE8
8905DC2AA2DF1072DE7ED92573C3F94E961F1DE091C43B590931DCE5F2A303BC
93D5929E470D6646DA727E7E89914DF8DF7C50FAE5E8000B830F984C1DF4080F
8BF037E14113216FE990E95FF02F3670DC3FF48F0000000049454E44AE426082}
OnClick = m_PNGButtonCloseClick
end
end
+70
View File
@@ -0,0 +1,70 @@
//---------------------------------------------------------------------------
#ifndef NotificationFormUnitH
#define NotificationFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include <Vcl.Imaging.pnglang.hpp>
#include <Vcl.Graphics.hpp>
#include "NotificationContentPanelUnit.h"
#include "NotificationADPanelUnit.h"
#include "PNGButton.hpp"
#include "NotificationThreadUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
class TNotificationForm : public TForm
{
__published: // IDE-managed Components
TPNGButton *m_PNGButtonClose;
void __fastcall FormShow(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall m_PNGButtonCloseClick(TObject *Sender);
private: // User declarations
int m_ModalResult;
TTimer *m_pNotiShutDownTimer;
VCTJSON m_VCJsonAD;
VCTJSON m_VCJonNoti;
VCTJSONDB m_VCJsonContent;
void __fastcall ClearJsonDirect();
TNotiADPanel *m_pNotiADPanel;
void __fastcall NotificationTimerProc(TObject* Sender);
TTimer *m_pTextNotiTimer;
int m_iTextNotiIndex;
TUrlLabel *m_pNotiUrl;
void __fastcall NotiChangeMouseEnter(TObject *Sender);
void __fastcall NotiChangeMouseLeave(TObject *Sender);
TNotiContenPanel *m_pNotiContenPanel;
TNotificationThread *m_pNotificationThread;
void __fastcall CreateParams(Vcl::Controls::TCreateParams &Params);
void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
END_MESSAGE_MAP( TForm )
public: // User declarations
bool __fastcall ParseJson();
bool __fastcall LoadImg();
void __fastcall setPANEL();
__fastcall TNotificationForm(TComponent* Owner);
__fastcall ~TNotificationForm();
};
//---------------------------------------------------------------------------
extern PACKAGE TNotificationForm *NotificationForm;
#endif
+33
View File
@@ -0,0 +1,33 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "NotificationThreadUnit.h"
#include "NotificationFormUnit.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall TNotificationThread::TNotificationThread(bool CreateSuspended, TForm* pForm)
: TThread(CreateSuspended)
{
m_pForm = pForm;
}
//---------------------------------------------------------------------------
void __fastcall TNotificationThread::Execute()
{
if( ((TNotificationForm *)m_pForm)->ParseJson() &&
((TNotificationForm *)m_pForm)->LoadImg() )
{
PostMessage(Application->MainForm->Handle, UM_NOTIFICATION,
NOTIFICATION_SHOW_FORM , 0 );
}else{
PostMessage(Application->MainForm->Handle, UM_NOTIFICATION,
NOTIFICATION_NO_JSONDATA, 0 );
}
}
//---------------------------------------------------------------------------
+25
View File
@@ -0,0 +1,25 @@
//---------------------------------------------------------------------------
#ifndef NotificationThreadUnitH
#define NotificationThreadUnitH
#include <Data.DBXJSON.hpp>
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#define NOTIFICATION_GETNOTI_PERIOD ( 5*1000 )
#define NOTIFICATION_CUSNOTI_PERIOD ( 5*1000 )
#define NOTIFICATION_SHOW_CLOSED 0
#define NOTIFICATION_NO_JSONDATA 1
#define NOTIFICATION_MENU_JSONDATA 2
#define NOTIFICATION_SHOW_FORM 3
//---------------------------------------------------------------------------
class TNotificationThread : public TThread
{
private:
TForm * m_pForm;
protected:
void __fastcall Execute();
public:
__fastcall TNotificationThread(bool CreateSuspended, TForm* pForm);
};
//---------------------------------------------------------------------------
#endif
+103
View File
@@ -0,0 +1,103 @@
// CodeGear C++Builder
// Copyright (c) 1995, 2024 by Embarcadero Technologies, Inc.
// All rights reserved
// (DO NOT EDIT: machine generated header) 'PNGButton.pas' rev: 36.00 (Windows)
#ifndef PngbuttonHPP
#define PngbuttonHPP
#pragma delphiheader begin
#pragma option push
#if defined(__BORLANDC__) && !defined(__clang__)
#pragma option -w- // All warnings off
#pragma option -Vx // Zero-length empty class member
#endif
#pragma pack(push,8)
#include <System.hpp>
#include <SysInit.hpp>
#include <System.SysUtils.hpp>
#include <Winapi.Messages.hpp>
#include <System.Classes.hpp>
#include <System.Types.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include <System.UITypes.hpp>
#include <Vcl.Menus.hpp>
//-- user supplied -----------------------------------------------------------
namespace Pngbutton
{
//-- forward type declarations -----------------------------------------------
class DELPHICLASS TPNGButton;
//-- type declarations -------------------------------------------------------
class PASCALIMPLEMENTATION TPNGButton : public Vcl::Controls::TGraphicControl
{
typedef Vcl::Controls::TGraphicControl inherited;
private:
System::Classes::TNotifyEvent FOnMouseEnter;
System::Classes::TNotifyEvent FOnMouseLeave;
System::Uitypes::TModalResult FModalResult;
protected:
int EtatBtn;
bool FDown;
bool FUp;
int FStateCount;
Vcl::Imaging::Pngimage::TPngImage* FPngImg;
bool FVisible;
DYNAMIC void __fastcall MouseDown(System::Uitypes::TMouseButton Button, System::Classes::TShiftState Shift, int X, int Y);
DYNAMIC void __fastcall MouseUp(System::Uitypes::TMouseButton Button, System::Classes::TShiftState Shift, int X, int Y);
MESSAGE void __fastcall MouseEnter(Winapi::Messages::TMessage &Msg);
MESSAGE void __fastcall MouseLeave(Winapi::Messages::TMessage &Msg);
virtual void __fastcall SetEnabled(bool Value);
public:
__fastcall virtual TPNGButton(System::Classes::TComponent* AOwner);
__fastcall virtual ~TPNGButton();
void __fastcall SetStateCount(int value);
void __fastcall SetPngImg(Vcl::Imaging::Pngimage::TPngImage* value);
void __fastcall SetDown(bool value);
void __fastcall SetUp(bool value);
virtual void __fastcall Paint();
DYNAMIC void __fastcall Click();
__published:
__property Action;
__property Anchors = {default=3};
__property bool Down = {read=FDown, write=SetDown, default=0};
__property bool Up = {read=FUp, write=SetUp, default=0};
__property Enabled = {default=1};
__property int ImgStates = {read=FStateCount, write=SetStateCount, default=4};
__property System::Uitypes::TModalResult ModalResult = {read=FModalResult, write=FModalResult, default=0};
__property ParentShowHint = {default=1};
__property Vcl::Imaging::Pngimage::TPngImage* PngImg = {read=FPngImg, write=SetPngImg};
__property PopupMenu;
__property ShowHint;
__property Visible = {default=1};
__property OnClick;
__property OnContextPopup;
__property OnMouseDown;
__property OnMouseUp;
__property OnMouseMove;
__property System::Classes::TNotifyEvent OnMouseEnter = {read=FOnMouseEnter, write=FOnMouseEnter};
__property System::Classes::TNotifyEvent OnMouseLeave = {read=FOnMouseLeave, write=FOnMouseLeave};
};
//-- var, const, procedure ---------------------------------------------------
extern DELPHI_PACKAGE void __fastcall Register(void);
} /* namespace Pngbutton */
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_PNGBUTTON)
using namespace Pngbutton;
#endif
#pragma pack(pop)
#pragma option pop
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // PngbuttonHPP
+154
View File
@@ -0,0 +1,154 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "PayMentFormUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "GeneralDialogPanel"
#pragma link "TextButton"
#pragma link "PNGButton"
#pragma resource "*.dfm"
TPayMentForm *PayMentForm;
#define PANEL_LEFT 20
#define PANEL_TOP 42
#define PANEL_BOTTOM 15
//---------------------------------------------------------------------------
#define LEN_BKG_EXTERNAL_ROUND (1)
#define LEN_BKG_EXTERNAL_FRMAE (1)
#define LEN_BKG_INTERNAL_LINE (23)
//---------------------------------------------------------------------------
__fastcall TPayMentForm::TPayMentForm(TComponent* Owner, int iOperation, int nIdCount,
UINT *aIdStyle, int *aStyleCost,
int nCost, int nBalance)
: TForm(Owner)
{
int nLbHeight = (m_pTextButtonOK->Top - 23 - PANEL_HEIGHT)/2;
char bufBalance[200];
sprintf( bufBalance, "当前账户现有 %d 唱作音符", nBalance );
m_pLabelBlance->Caption = bufBalance;
m_pPayMentPanel = new TPayMentPanel(this);
m_pPayMentPanel->Parent = this;
m_pPayMentPanel->Font->Size = m_pLabelBlance->Font->Size;
m_pPayMentPanel->Left = PANEL_LEFT;
m_pPayMentPanel->Top = 23 + nLbHeight;
m_pPayMentPanel->Width = Width - 2*PANEL_LEFT;
m_pPayMentPanel->Height = 120;
m_pPayMentPanel->SetContent(iOperation, nIdCount, aIdStyle,
aStyleCost, nCost, nBalance);
m_pLabelMessage = NULL;
m_lbVip = NULL;
char bufCost[200];
if( nBalance<nCost ){
m_pTextButtonOK->Visible = false;
sprintf( bufCost, "账户余额不足,请登录网站充值兑换");
m_pLabelMessage = new TUrlLabel(this);
m_pLabelMessage->Parent = this;
m_pLabelMessage->ColorNor = CLR_TEXT_LEAVE;
m_pLabelMessage->ColorEnt = CLR_TEXT_ENTER;
m_pLabelMessage->ColorLea = CLR_TEXT_LEAVE;
m_pLabelMessage->Caption = bufCost;
char strURLMsg[256];
f_CS_GetWebPageURL( URL_RECHARGE, strURLMsg );
String StrUrl = (String)strURLMsg;
StrUrl += L"&coin=" + IntToStr(nCost - nBalance);
m_pLabelMessage->StrUrl = StrUrl;
m_pLabelMessage->Font->Name = m_pLabelBlance->Font->Name;
m_pLabelMessage->Font->Size = m_pLabelBlance->Font->Size;// int(8 * 96.0 / g_yDpi + 0.5);
m_pLabelMessage->Font->Style = TFontStyles()<<fsUnderline;
}
if(0==g_infoUser.accountInfo.vipPeriod){
m_lbVip = new TUrlLabel(this);
m_lbVip->Parent = this;
m_lbVip->ColorNor = CLR_TEXT_LEAVE;
m_lbVip->ColorEnt = CLR_TEXT_ENTER;
m_lbVip->ColorLea = CLR_TEXT_LEAVE;
m_lbVip->Caption = L"成为VIP:免功能费,风格八折";
char strURL[256];
f_CS_GetWebPageURL( URL_VIPMEMBER, strURL );
m_lbVip->StrUrl = strURL;
m_lbVip->Font->Name = m_pLabelBlance->Font->Name;
m_lbVip->Font->Size = m_pLabelBlance->Font->Size;//int(8 * 96.0 / g_yDpi + 0.5);
m_lbVip->Font->Style = TFontStyles()<<fsUnderline;
}
SetTransparent( this );
}
//---------------------------------------------------------------------------
__fastcall TPayMentForm::~TPayMentForm()
{
if( m_pPayMentPanel ){
delete m_pPayMentPanel;
m_pPayMentPanel = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TPayMentForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if( Msg.Result==HTCLIENT &&
(Msg.YPos<Top+LEN_BKG_INTERNAL_LINE) &&
(Msg.XPos<(Left+ m_PNGButtonClose->Left) ) )
{
Msg.Result = HTCAPTION;
}
}
//---------------------------------------------------------------------------
void __fastcall TPayMentForm::FormShow(TObject *Sender)
{
//绘制圆角窗体
HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+1, 16, 16 );
SetWindowRgn( Handle, hRgn, false );
DeleteObject( hRgn );
int nLbHeight = (m_pTextButtonOK->Top - 23 - PANEL_HEIGHT)/2;
m_pLabelBlance->Left = (Width - m_pLabelBlance->Width)/2;
m_pLabelBlance->Top = 23 + (nLbHeight - m_pLabelBlance->Height)/2;
nLbHeight = Height - (m_pPayMentPanel->Top + m_pPayMentPanel->Height);
if( m_pLabelMessage ) {
m_pLabelMessage->Left = m_pPayMentPanel->Left;
if(m_lbVip) {
m_pLabelMessage->Top = m_pPayMentPanel->Top + m_pPayMentPanel->Height
+ (nLbHeight/2 - m_pLabelMessage->Height)/2 + 5;
}
else {
m_pLabelMessage->Top = m_pPayMentPanel->Top + m_pPayMentPanel->Height
+ (nLbHeight - m_pLabelMessage->Height)/2;
}
}
if( m_lbVip ) {
m_lbVip->Left = m_pPayMentPanel->Left;
if( m_pLabelMessage ) {
m_lbVip->Top = m_pPayMentPanel->Top + m_pPayMentPanel->Height + nLbHeight/2 +
(nLbHeight/2 - m_lbVip->Height)/2 - 5;
}
else {
m_lbVip->Top = m_pPayMentPanel->Top + m_pPayMentPanel->Height +
(nLbHeight - m_lbVip->Height)/2;
}
}
m_pTextButtonCancel->Top = m_pPayMentPanel->Top + m_pPayMentPanel->Height
+ (nLbHeight - m_pTextButtonCancel->Height)/2;
m_pTextButtonOK->Top = m_pPayMentPanel->Top + m_pPayMentPanel->Height
+ (nLbHeight - m_pTextButtonOK->Height)/2;
m_pPayMentPanel->SetSB();
m_pPayMentPanel->SetFocus();
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+45
View File
@@ -0,0 +1,45 @@
//---------------------------------------------------------------------------
#ifndef PayMentFormUnitH
#define PayMentFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include "PayMentPanelUnit.h"
#include "PNGButton.hpp"
#include <Vcl.Imaging.jpeg.hpp>
//---------------------------------------------------------------------------
class TPayMentForm : public TForm
{
__published: // IDE-managed Components
TPNGButton *m_pTextButtonOK;
TPNGButton *m_pTextButtonCancel;
TPNGButton *m_PNGButtonClose;
TImage *m_pImageBKG;
TLabel *m_pLabelTittle;
TLabel *m_pLabelBlance;
void __fastcall FormShow(TObject *Sender);
private: // User declarations
TPayMentPanel *m_pPayMentPanel;
TUrlLabel *m_lbVip;
TUrlLabel *m_pLabelMessage;
void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
END_MESSAGE_MAP( TForm )
public: // User declarations
__fastcall TPayMentForm(TComponent* Owner, int iOperation, int nIdCount,
UINT *aIdStyle, int *aStyleCost,
int nCost, int nBalance);
__fastcall ~TPayMentForm();
};
//---------------------------------------------------------------------------
extern PACKAGE TPayMentForm *PayMentForm;
//---------------------------------------------------------------------------
#endif
+400
View File
@@ -0,0 +1,400 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "PayMentPanelUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
#define LINE_HEIGHT (20)
#define SCOLLBAR_WIDTH (14)
#define STYLE_NAME_WIDTH (Width/2)
#define STYLE_PAY_WIDTH (Width - STYLE_NAME_WIDTH - SCOLLBAR_WIDTH)
const static COLORREF
CLR_TXT_HOT = RGB(0, 0, 0),
CLR_BKG_INTERNAL = RGB(207, 163, 124),
CLR_BKG_INTERNAL_LIGHT = RGB(234, 184, 140),
CLR_CONTENT_DB_LINE_DARK = RGB(192, 148, 109),
CLR_CONTENT_DB_LINE_LIGHT = RGB(237, 193, 154),
COLOR_BORDER = RGB(186,124,83);
//---------------------------------------------------------------------------
__fastcall TPayMentPanel::TPayMentPanel( TComponent* Owner)
: Vcl::Extctrls::TPanel( Owner )
{
m_ScrollBar = NULL;
m_iTopLine = 0;
m_iShowLine = 1;
bStylePayShow = true;
DoubleBuffered = true;
ParentCtl3D = false;
Ctl3D = false;
}
//---------------------------------------------------------------------------
void __fastcall TPayMentPanel::CreateWnd()
{
Vcl::Extctrls::TPanel::CreateWnd();
Canvas->Font->Size = Font->Size;//int(8 * 96.0 / g_yDpi + 0.5);
SetShowLine();
}
//---------------------------------------------------------------------------
__fastcall TPayMentPanel::~TPayMentPanel()
{
if( m_ScrollBar ){
delete m_ScrollBar;
m_ScrollBar = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TPayMentPanel::WMEraseBkgnd(TWMEraseBkgnd &Message)
{
TRect rect = GetClientRect();
TCanvas* tempCanvas = new TCanvas;
tempCanvas->Handle = Message.DC;
tempCanvas->Brush->Color = CLR_BKG_INTERNAL; //背景颜色
tempCanvas->FillRect( rect );
tempCanvas->Brush->Color = CLR_CONTENT_DB_LINE_DARK;
tempCanvas->FrameRect( rect );
delete tempCanvas;
tempCanvas = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TPayMentPanel::WMVScroll(Winapi::Messages::TWMScroll &Message)
{
int minpos, maxpos, page, curpos;
m_ScrollBar->GetScrollRange(&minpos, &maxpos);
page = m_ScrollBar->GetPageSize();
// Get the current position of scroll box.
curpos = m_ScrollBar->GetScrollPos();
// Determine the new position of scroll box.
switch (Message.ScrollCode)
{
case SB_TOP: // Scroll to far top.
curpos = minpos;
break;
case SB_BOTTOM: // Scroll to far bottom.
curpos = maxpos-page+1;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINEUP: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINEDOWN: // Scroll right.
if (curpos < maxpos-page+1)
curpos++;
break;
case SB_PAGEUP: // Scroll one page left.
if (curpos > minpos)
curpos = (minpos > curpos-page) ? minpos : curpos-page;
//max(minpos, curpos-page);
break;
case SB_PAGEDOWN: // Scroll one page right.
if( curpos<maxpos )
curpos = (maxpos-page+1 < curpos+page) ? maxpos-page+1 : curpos+page;
//min(maxpos-page+1, curpos+page);
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = Message.Pos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = Message.Pos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb (scroll box).
if( Message.ScrollBar!=m_ScrollBar->Handle ){
m_ScrollBar->SetPosition(curpos);
// Paint();
}
if( m_iTopLine != curpos ){
m_iTopLine = curpos;
// Invalidate();
if( m_nAddCost>0 ) {
InvalidateRect(this->Handle,
&TRect(0, LINE_HEIGHT, Width, Height-2*LINE_HEIGHT),
false);
}else{
InvalidateRect(this->Handle,
&TRect(0, LINE_HEIGHT, Width, Height-LINE_HEIGHT),
false);
}
}
Message.Result = true;
}
//---------------------------------------------------------------------------
void __fastcall TPayMentPanel::WMMouseWheel(TWMMouseWheel &Message)
{
if( m_ScrollBar && m_ScrollBar->Visible ){
UINT nSBCode;
if( Message.WheelDelta>0 ) nSBCode = SB_LINEUP;
else nSBCode = SB_LINEDOWN;
Perform( WM_VSCROLL, MAKELONG(nSBCode,0), NULL );
}
}
//---------------------------------------------------------------------------
void __fastcall TPayMentPanel::SetContent(int iOperation, int nIdCount,
UINT *aIdStyle, int *aStyleCost,
int nCost, int nBalance)
{
int nCostTotal = 0;
TSTYLEINFO *tStyle = new TSTYLEINFO;
STYLEPAY stylePayName;
stylePayName.strStyleName = L"风格";
stylePayName.strStyleCost = L"唱作音符";
m_VCStylePay.push_back(stylePayName);
if( iOperation==e_PO_Pay4Basic ||
(iOperation == (e_PO_Pay4Basic|e_PO_Pay4Midi) ) )
{
bStylePayShow = false;
}else{
for(int i=0; i<nIdCount; i++)
{
f_SM_GetStyleInfo(aIdStyle[i], tStyle);
STYLEPAY stylePayStyle;
stylePayStyle.strStyleName = UTF8ToMBCS(tStyle->detail.strStyleName).c_str();
if( aStyleCost[i]==0 )
stylePayStyle.strStyleCost = "免费";
else if( aStyleCost[i]==-2 )
stylePayStyle.strStyleCost = "已支付";
else{
stylePayStyle.strStyleCost = IntToStr(aStyleCost[i]);
nCostTotal += aStyleCost[i];
}
m_VCStylePay.push_back(stylePayStyle);
}
if(tStyle){
delete tStyle;
tStyle=NULL;
}
}
m_nAddCost = nCost - nCostTotal;
if( m_nAddCost>0 ) {
STYLEPAY stylePayDefault;
stylePayDefault.strStyleName = L"功能费";
stylePayDefault.strStyleCost = IntToStr(m_nAddCost);
m_VCStylePay.push_back(stylePayDefault);
}
STYLEPAY stylePayTotal;
stylePayTotal.strStyleName = L"合计:";
stylePayTotal.strStyleCost = IntToStr(nCost);
m_VCStylePay.push_back(stylePayTotal);
if( m_nAddCost>0 )
m_nStyleNum = m_VCStylePay.size()-3;
else
m_nStyleNum = m_VCStylePay.size()-2;
}
//---------------------------------------------------------------------------
void __fastcall TPayMentPanel::CutOffString(String &cutOffStr)
{
String strTmp = cutOffStr;
TSize size = Canvas->TextExtent( strTmp );
int nLen = strTmp.Length();
if( size.Width >= STYLE_NAME_WIDTH )
{
nLen = nLen*(STYLE_NAME_WIDTH)/size.Width;
nLen -= 1;
if(nLen <= 0){
strTmp = strTmp.SubString(0, 1);
}else{
strTmp = strTmp.SubString(0, nLen);
strTmp += "..";
}
cutOffStr = strTmp;
}
}
//---------------------------------------------------------------------------
int __fastcall TPayMentPanel::GetLineNumber()
{
return m_nStyleNum;
}
//---------------------------------------------------------------------------
void __fastcall TPayMentPanel::SetShowLine()
{
if( bStylePayShow ) {
if( m_nAddCost>0 )
m_iShowLine = Height/LINE_HEIGHT - 3;
else
m_iShowLine = Height/LINE_HEIGHT - 2;
int totalLine = GetLineNumber();
if( totalLine>m_iShowLine ){
m_ScrollBar = new TSkinScrollBar(this);
m_ScrollBar->m_pWndCtrl = this;
m_ScrollBar->Parent = this;
if( m_nAddCost>0 )
m_ScrollBar->Height = Height-3*LINE_HEIGHT-2;
else
m_ScrollBar->Height = Height-2*LINE_HEIGHT-2;
m_ScrollBar->Left = Width - m_ScrollBar->Width - 1;
m_ScrollBar->Top = LINE_HEIGHT+1;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TPayMentPanel::SetSB()
{
vector<STYLEPAY>::iterator vc_pFind;
for(vc_pFind = m_VCStylePay.begin(); vc_pFind != m_VCStylePay.end(); vc_pFind++){
CutOffString(vc_pFind->strStyleName);
}
if( m_ScrollBar ){
int totalLine = GetLineNumber();
m_ScrollBar->SetRange( 0, totalLine-1 );
m_ScrollBar->SetPageSize( m_iShowLine );
m_ScrollBar->SetPosition( m_iTopLine );
m_ScrollBar->Visible = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TPayMentPanel::Paint(void)
{
vector<STYLEPAY>::iterator vc_pFind = m_VCStylePay.begin();
TSize sizeFont;
Canvas->Font->Color = CLR_TXT_HOT;
Canvas->Brush->Style = bsClear;
int curX, curY;
///////////////////////////////
sizeFont = Canvas->TextExtent(vc_pFind->strStyleName);
curX = (STYLE_NAME_WIDTH - sizeFont.Width)/2;
curY = (LINE_HEIGHT - sizeFont.Height)/2 ;
Canvas->TextOutW( curX, curY, vc_pFind->strStyleName );
sizeFont = Canvas->TextExtent(vc_pFind->strStyleCost);
curX = STYLE_NAME_WIDTH + (STYLE_PAY_WIDTH - sizeFont.Width)/2;
Canvas->TextOutW( curX, curY, vc_pFind->strStyleCost );
curY = LINE_HEIGHT;
/////////////////////////////////
if( m_nAddCost>0 )
curY = Height - 2*LINE_HEIGHT;
else
curY = Height - LINE_HEIGHT;
Canvas->Brush->Color = CLR_BKG_INTERNAL_LIGHT; //背景颜色
Canvas->FillRect( TRect(1, LINE_HEIGHT,
Width-1, curY ) );
/////////////////////////////////
Canvas->Font->Color = CLR_TXT_HOT;
Canvas->Brush->Style = bsClear;
if( bStylePayShow ){
vc_pFind++;
vc_pFind = vc_pFind + m_iTopLine;
sizeFont = Canvas->TextExtent(vc_pFind->strStyleName);
curY = LINE_HEIGHT + (LINE_HEIGHT - sizeFont.Height)/2;
int nShowAdd = 1;
if( m_nAddCost>0 ) nShowAdd = 2;
for( int i=m_iTopLine;
(m_nStyleNum > 0) &&
(i < m_nStyleNum ) &&
(vc_pFind != m_VCStylePay.end()-nShowAdd) &&
(i <= m_iTopLine + m_iShowLine -1);
i++, vc_pFind++ )
{
sizeFont = Canvas->TextExtent(vc_pFind->strStyleName);
curX = (STYLE_NAME_WIDTH - sizeFont.Width)/2;
Canvas->TextOutW( curX, curY, vc_pFind->strStyleName );
sizeFont = Canvas->TextExtent(vc_pFind->strStyleCost);
curX = STYLE_NAME_WIDTH + (STYLE_PAY_WIDTH - sizeFont.Width)/2;
Canvas->TextOutW( curX, curY, vc_pFind->strStyleCost);
curY += LINE_HEIGHT;
}
/////////////////////////////////
curY = Height - nShowAdd*LINE_HEIGHT;
Canvas->Pen->Color = CLR_CONTENT_DB_LINE_DARK;
Canvas->MoveTo( 0, curY-1 );
Canvas->LineTo( Width, curY-1 );
Canvas->Pen->Color = CLR_CONTENT_DB_LINE_LIGHT;
Canvas->MoveTo( 0, curY );
Canvas->LineTo( Width, curY );
}
if( m_nAddCost>0 ) {
vc_pFind = m_VCStylePay.end() -2;
sizeFont = Canvas->TextExtent(vc_pFind->strStyleName);
curX = (STYLE_NAME_WIDTH - sizeFont.Width)/2;
curY += (LINE_HEIGHT - sizeFont.Height)/2 ;
Canvas->TextOutW( curX, curY, vc_pFind->strStyleName );
sizeFont = Canvas->TextExtent(vc_pFind->strStyleCost);
curX = STYLE_NAME_WIDTH + (STYLE_PAY_WIDTH - sizeFont.Width)/2;
Canvas->TextOutW( curX, curY, vc_pFind->strStyleCost );
}
/////////////////////////////
vc_pFind = m_VCStylePay.end()-1;
sizeFont = Canvas->TextExtent(vc_pFind->strStyleName);
curX = (STYLE_NAME_WIDTH - sizeFont.Width)/2;
curY = Height - LINE_HEIGHT +
(LINE_HEIGHT - sizeFont.Height)/2 ;
Canvas->TextOutW( curX, curY, vc_pFind->strStyleName );
sizeFont = Canvas->TextExtent(vc_pFind->strStyleCost);
curX = STYLE_NAME_WIDTH + (STYLE_PAY_WIDTH - sizeFont.Width)/2;
Canvas->TextOutW( curX, curY, vc_pFind->strStyleCost );
curY = Height - LINE_HEIGHT;
Canvas->Pen->Color = CLR_CONTENT_DB_LINE_DARK;
Canvas->MoveTo( 0, curY-1 );
Canvas->LineTo( Width, curY-1 );
Canvas->Pen->Color = CLR_CONTENT_DB_LINE_LIGHT;
Canvas->MoveTo( 0, curY );
Canvas->LineTo( Width, curY );
}
//---------------------------------------------------------------------------
+56
View File
@@ -0,0 +1,56 @@
//---------------------------------------------------------------------------
#ifndef PayMentPanelUnitH
#define PayMentPanelUnitH
#include "NotificationExUnit.h"
#include "SkinScrollBarUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
typedef struct tagStylePay{
String strStyleName;
String strStyleCost;
}STYLEPAY, *PSTYLEPAY;
#define PANEL_HEIGHT 120
//---------------------------------------------------------------------------
class TPayMentPanel : public Vcl::Extctrls::TPanel
{
private:
vector<STYLEPAY> m_VCStylePay;
bool bStylePayShow;
int m_iShowLine;
int m_iTopLine;
int m_nAddCost;
int m_nStyleNum;
TSkinScrollBar *m_ScrollBar;
void __fastcall CutOffString(String &cutOffStr);
int __fastcall GetLineNumber();
void __fastcall SetShowLine();
virtual void __fastcall CreateWnd();
virtual void __fastcall Paint(void);
MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message);
MESSAGE void __fastcall WMVScroll(Winapi::Messages::TWMScroll &Message);
MESSAGE void __fastcall WMMouseWheel(TWMMouseWheel &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
MESSAGE_HANDLER(WM_VSCROLL, TWMVScroll, WMVScroll)
MESSAGE_HANDLER(WM_MOUSEWHEEL, TWMMouseWheel, WMMouseWheel)
END_MESSAGE_MAP( Vcl::Extctrls::TPanel )
public:
void __fastcall SetContent(int iOperation=1, int nIdCount=0,
UINT *aIdStyle=NULL, int *aStyleCost=NULL,
int nCost=0, int nBalance=0);
void __fastcall SetSB();
__fastcall TPayMentPanel( TComponent* Owner);
__fastcall ~TPayMentPanel();
};
//---------------------------------------------------------------------------
#endif
+235
View File
@@ -0,0 +1,235 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "PopMenuUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#define POPMENU_MINWIDTH 60
#define BREAK_HEIGHT 5
#define CLR_DISABLE RGB(163,153,143)
__fastcall TPopMenu::TPopMenu(TComponent* Owner)
: TPopupMenu( Owner )
{
m_pPicChecked = m_pPicNormal = m_pPicHover = NULL;
OwnerDraw = TRUE;
AutoHotkeys = maManual;
m_pFntText = new TFont();
m_pFntText->Name = "黑体";
m_pFntText->Size = int(10 * 96.0 / g_yDpi + 0.5);
m_clrNormal = RGB(60,43,23);
m_clrHover = RGB(232,212,191);
m_clrBreak = RGB(150,118,80);
m_clrFrame = RGB(206,162,126);
m_pPicNormal = new TBitmap;
m_pPicNormal->LoadFromResourceName(int(HInstance), "MenuNormalBar");
m_pPicHover = new TBitmap;
m_pPicHover->LoadFromResourceName(int(HInstance), "MenuHoverBar");
m_pPicChecked = new TBitmap;
m_pPicChecked->LoadFromResourceName(int(HInstance), "MenuChecked");
}
__fastcall TPopMenu::~TPopMenu()
{
if( m_pPicNormal )
delete m_pPicNormal;
if( m_pPicHover )
delete m_pPicHover;
if( m_pPicChecked )
delete m_pPicChecked;
if( m_pFntText )
delete m_pFntText;
ClearMenuItem();
}
void TPopMenu::CreateCustomMenuItem( String strCaption, TNotifyEvent aClickEvent,
int subIndex, bool bEnabled, bool bChecked, int iTag )
{
TMenuItem * pItem = new TMenuItem( this );
pItem->Caption = strCaption;
pItem->OnAdvancedDrawItem = OwnerDrawItem;
pItem->OnMeasureItem = OwnerMeasureItem;
pItem->OnClick = aClickEvent;
pItem->Checked = bChecked;
pItem->Enabled = bEnabled;
pItem->Tag = iTag;
if( subIndex==-1 )
Items->Add( pItem );
else
Items->Items[subIndex]->Add( pItem );
}
void TPopMenu::ClearMenuItem()
{
for( int i=Items->Count-1; i>=0; i-- ){
Items->Delete(i);
}
}
void __fastcall TPopMenu::OwnerDrawItem(TObject* Sender, TCanvas* ACanvas, const TRect &ARect, TOwnerDrawState State)
{
TMenuItem *pItem = (TMenuItem*)Sender;
TRect rectDraw(ARect.left , ARect.top, ARect.right, ARect.bottom);
if( pItem->MenuIndex==0 ){ //第一个菜单项
ACanvas->Pen->Color = m_clrBreak;
ACanvas->MoveTo( ARect.left, ARect.top );
ACanvas->LineTo( ARect.right, ARect.top );
ACanvas->Pen->Color = m_clrFrame;
ACanvas->MoveTo( ARect.left+1, ARect.top+1 );
ACanvas->LineTo( ARect.right-1, ARect.top+1 );
ACanvas->Pen->Color = m_clrBreak;
ACanvas->MoveTo( ARect.left+2, ARect.top+2 );
ACanvas->LineTo( ARect.right-2, ARect.top+2 );
ACanvas->Pixels[ARect.left][ARect.top+1] = m_clrBreak;
ACanvas->Pixels[ARect.left][ARect.top+2] = m_clrBreak;
ACanvas->Pixels[ARect.right-1][ARect.top+1] = m_clrBreak;
ACanvas->Pixels[ARect.right-1][ARect.top+2] = m_clrBreak;
ACanvas->Pixels[ARect.left+1][ARect.top+2] = m_clrFrame;
ACanvas->Pixels[ARect.right-2][ARect.top+2] = m_clrFrame;
rectDraw.top += 3;
}
TMenuItem * pItemParent = pItem->Parent;
if( pItem->MenuIndex==pItemParent->Count-1 ){ //最后一个菜单项
ACanvas->Pen->Color = m_clrBreak;
ACanvas->MoveTo( ARect.left, ARect.bottom-1 );
ACanvas->LineTo( ARect.right, ARect.bottom-1 );
ACanvas->Pen->Color = m_clrFrame;
ACanvas->MoveTo( ARect.left+1, ARect.bottom-2 );
ACanvas->LineTo( ARect.right-1, ARect.bottom-2 );
ACanvas->Pen->Color = m_clrBreak;
ACanvas->MoveTo( ARect.left+2, ARect.bottom-3 );
ACanvas->LineTo( ARect.right-2, ARect.bottom-3 );
ACanvas->Pixels[ARect.left][ARect.bottom-2] = m_clrBreak;
ACanvas->Pixels[ARect.left][ARect.bottom-3] = m_clrBreak;
ACanvas->Pixels[ARect.right-1][ARect.bottom-2] = m_clrBreak;
ACanvas->Pixels[ARect.right-1][ARect.bottom-3] = m_clrBreak;
ACanvas->Pixels[ARect.left+1][ARect.bottom-3] = m_clrFrame;
ACanvas->Pixels[ARect.right-2][ARect.bottom-3] = m_clrFrame;
rectDraw.bottom -= 3;
}
//绘制左边框
ACanvas->Pen->Color = m_clrBreak;
ACanvas->MoveTo( rectDraw.left, rectDraw.top );
ACanvas->LineTo( rectDraw.left, rectDraw.bottom );
ACanvas->Pen->Color = m_clrFrame;
ACanvas->MoveTo( rectDraw.left+1, rectDraw.top );
ACanvas->LineTo( rectDraw.left+1, rectDraw.bottom );
ACanvas->Pen->Color = m_clrBreak;
ACanvas->MoveTo( rectDraw.left+2, rectDraw.top );
ACanvas->LineTo( rectDraw.left+2, rectDraw.bottom );
rectDraw.left += 3;
//绘制右边框
ACanvas->Pen->Color = m_clrBreak;
ACanvas->MoveTo( rectDraw.right-1, rectDraw.top );
ACanvas->LineTo( rectDraw.right-1, rectDraw.bottom );
ACanvas->Pen->Color = m_clrFrame;
ACanvas->MoveTo( rectDraw.right-2, rectDraw.top );
ACanvas->LineTo( rectDraw.right-2, rectDraw.bottom );
ACanvas->Pen->Color = m_clrBreak;
ACanvas->MoveTo( rectDraw.right-3, rectDraw.top );
ACanvas->LineTo( rectDraw.right-3, rectDraw.bottom );
rectDraw.right -= 3;
//绘制背景
if( State.Contains(odSelected) && !State.Contains(odDisabled) ){
//高亮项
m_pFntText->Color = m_clrHover;
ACanvas->StretchDraw( rectDraw, m_pPicHover );
}
else{
if( State.Contains(odDisabled) ){
//禁用项
m_pFntText->Color = CLR_DISABLE;
}
else{
//常规项
m_pFntText->Color = m_clrNormal;
}
ACanvas->StretchDraw( rectDraw, m_pPicNormal );
}
//绘制Check框
if( State.Contains(odChecked) ){
TRect rectCheck( rectDraw.left+4, rectDraw.top+4, rectDraw.left+20, rectDraw.top+20 );
ACanvas->StretchDraw( rectCheck, m_pPicChecked );
}
//绘制伴奏类型颜色
if( pItem->Tag>0 && (pItem->Tag & SHOW_STAGE_VAR) ){
TRect rectVar( rectDraw.right-28, rectDraw.top+4, rectDraw.right-4, rectDraw.top+20 );
ACanvas->Pen->Color = m_clrFrame;
ACanvas->Brush->Color = g_clrStage[pItem->Tag & 0xFFFF];
ACanvas->Rectangle( rectVar );
}
if( pItem->IsLine() ){
ACanvas->Pen->Color = m_clrFrame;
ACanvas->MoveTo( rectDraw.left+6, rectDraw.top+2 );
ACanvas->LineTo( rectDraw.right-6, rectDraw.top+2 );
}
else{
TFont *oldFont = ACanvas->Font;
ACanvas->Font = m_pFntText;
ACanvas->Brush->Style = bsClear;
ACanvas->TextRect( ARect, rectDraw.left+24, rectDraw.top+6, pItem->Caption ); //输出菜单文字
ACanvas->Font = oldFont;
}
}
void __fastcall TPopMenu::OwnerMeasureItem(TObject* Sender, TCanvas* ACanvas, int &Width, int &Height)
{
TMenuItem *pItem = (TMenuItem*)Sender;
// if( pItem->Tag>=0 )
Width += 36;
// if( pItem->Checked )
Width += 24;
if( pItem->IsLine() )
Height = BREAK_HEIGHT;
else{
Height = m_pPicNormal->Height;
if( pItem->MenuIndex==0 ) //第一个菜单项
Height += 3;
TMenuItem * pItemParent = pItem->Parent;
if( pItem->MenuIndex==pItemParent->Count-1) //最后一个菜单项
Height += 3;
}
}
+25
View File
@@ -0,0 +1,25 @@
//---------------------------------------------------------------------------
#ifndef PopMenuUnitH
#define PopMenuUnitH
#define SHOW_STAGE_VAR 0x10000
class TPopMenu : public TPopupMenu
{
private:
TBitmap *m_pPicNormal, *m_pPicHover, *m_pPicChecked;
TFont *m_pFntText;
COLORREF m_clrNormal, m_clrHover, m_clrBreak, m_clrFrame;
public:
__fastcall TPopMenu(TComponent* Owner);
__fastcall ~TPopMenu();
void CreateCustomMenuItem( String strCaption, TNotifyEvent aClickEvent=NULL,
int subIndex=-1, bool bEnbaled=true, bool bChecked=false, int iTag=-1 );
void ClearMenuItem();
void __fastcall OwnerDrawItem(TObject* Sender, TCanvas* ACanvas, const TRect &ARect, TOwnerDrawState State);
void __fastcall OwnerMeasureItem(TObject* Sender, TCanvas* ACanvas, int &Width, int &Height);
};
//---------------------------------------------------------------------------
#endif
+453
View File
@@ -0,0 +1,453 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "PredefineProjectFormUnit.h"
#include "GlobalUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TPredefineProjectForm *PredefineProjectForm;
const BYTE u_arrPredefChords[3][2][8][8] = { //预设和弦
//主歌
{ { { 0, 37, 20, 28, 0, 37, 20, 30 }, // 1 6 4 5 1 6 4 5
{ 0, 17, 37, 28, 0, 17, 37, 30 }, // 1 3 6 5 1 3 6 5
{ 0, 37, 20, 17, 37, 20, 28, 0 }, // 1 6 4 3 6 4 5 1
{ 0, 17, 37, 28, 20, 17, 9, 30 }, // 1 3 6 5 4 3 2 5
{ 0, 28, 37, 28, 0, 28, 37, 30 }, // 1 5 6 5 1 5 6 5
{ 0, 37, 28, 20, 17, 9, 28, 0 }, // 1 6 5 4 3 2 5 1
{ 0, 9, 28, 0, 0, 9, 28, 0 }, // 1 2 5 1 1 2 5 1
{ 0, 20, 28, 0, 0, 20, 28, 0 } // 1 4 5 1 1 4 5 1
},
{ {37, 9, 17, 37, 37, 9, 17, 37 }, // 6 2 3 6 6 2 3 6
{37, 28, 20, 17, 37, 28, 20, 19 }, // 6 5 4 3 6 5 4 3
{37, 28, 17, 37, 37, 28, 17, 37 }, // 6 5 3 6 6 5 3 6
{37, 20, 9, 17, 37, 20, 9, 19 }, // 6 4 2 3 6 4 2 3
{37, 17, 37, 28, 37, 17, 37, 30 }, // 6 3 6 5 6 3 6 5
{37, 9, 20, 28, 37, 9, 20, 30 }, // 6 2 4 5 6 2 4 5
{37, 9, 28, 37, 37, 9, 28, 37 }, // 6 2 5 6 6 2 5 6
{37, 20, 9, 37, 37, 20, 9, 37 } // 6 4 2 6 6 4 2 6
}
},
//副歌
{ { { 0, 37, 20, 17, 37, 20, 28, 0 }, // 1 6 4 3 6 4 5 1
{ 0, 37, 28, 20, 17, 9, 28, 0 }, // 1 6 5 4 3 2 5 1
{ 0, 9, 28, 0, 0, 9, 28, 0 }, // 1 2 5 1 1 2 5 1
{ 0, 20, 28, 0, 0, 20, 28, 0 }, // 1 4 5 1 1 4 5 1
{20, 28, 37, 37, 20, 28, 0, 0 }, // 4 5 6 6 4 5 1 1
{ 9, 28, 0, 28, 37, 9, 28, 0 }, // 2 5 1 5 6 2 5 1
{20, 28, 17, 37, 20, 9, 28, 0 }, // 4 5 3 6 4 2 5 1
{ 9, 28, 20, 28, 0, 20, 28, 0 } // 2 5 4 5 1 4 5 1
},
{ {37, 9, 17, 37, 37, 9, 17, 37 }, // 6 2 3 6 6 2 3 6
{37, 28, 17, 37, 37, 28, 17, 37 }, // 6 5 3 6 6 5 3 6
{37, 9, 28, 37, 37, 9, 28, 37 }, // 6 2 5 6 6 2 5 6
{37, 20, 9, 37, 37, 20, 9, 37 }, // 6 4 2 6 6 4 2 6
{ 9, 17, 28, 37, 9, 17, 28, 37 }, // 2 3 5 6 2 3 5 6
{37, 9, 28, 17, 37, 9, 28, 37 }, // 6 2 5 3 6 2 5 6
{20, 28, 0, 0, 20, 28, 37, 37 }, // 4 5 1 1 4 5 6 6
{17, 37, 9, 28, 17, 37, 17, 37 } // 3 6 2 5 3 6 3 6
}
},
//桥
{ { { 9, 20, 28, 17, 9, 20, 28, 0 }, // 2 4 5 3 2 4 5 1
{ 9, 28, 0, 28, 37, 28, 0, 30 }, // 2 5 1 5 6 5 1 5
{20, 17, 9, 28, 0, 17, 9, 30 }, // 4 3 2 5 1 3 2 5
{17, 9, 37, 17, 9, 28, 0, 30 }, // 3 2 6 3 2 5 1 5
{20, 0, 20, 0, 20, 0, 20, 30 }, // 4 1 4 1 4 1 4 5
{20, 28, 0, 0, 20, 28, 0, 0 }, // 4 5 1 1 4 5 1 1
{20, 17, 9, 0, 20, 17, 9, 0 }, // 4 3 2 1 4 3 2 1
{28, 20, 28, 20, 0, 28, 20, 30 } // 5 4 5 4 1 5 4 5
},
{ { 9, 17, 28, 37, 9, 17, 28, 37 }, // 2 3 5 6 2 3 5 6
{17, 37, 28, 37, 9, 17, 20, 19 }, // 3 6 5 6 2 3 4 3
{20, 0, 28, 37, 20, 0, 37, 19 }, // 4 1 5 6 4 1 6 3
{20, 28, 0, 28, 20, 28, 0, 30 }, // 4 5 1 5 4 5 1 5
{ 9, 17, 37, 17, 20, 37, 0, 37 }, // 2 3 6 3 4 6 1 6
{ 9, 37, 9, 37, 9, 37, 9, 19 }, // 2 6 2 6 2 6 2 3
{ 9, 37, 9, 17, 9, 37, 20, 30 }, // 2 6 2 3 2 6 4 5
{17, 9, 17, 37, 20, 9, 17, 37 } // 3 2 3 6 4 2 3 6
}
}
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
__fastcall TPredefineProjectForm::TPredefineProjectForm(TComponent* Owner)
: TForm(Owner)
{
m_Ts = g_iMelodyTimeSignature;
m_Tempo = g_nMelodyTempo;
m_Key = 0;
m_KeyType = 0;
m_RavStage = 2;
mLordSong = rand() % 8;
mBridge = rand() % 8;
mRefrain = rand() % 8;
mPaintBoxFlag = true;
mIsPreSetShow = false;
}
//---------------------------------------------------------------------------
__fastcall TPredefineProjectForm::~TPredefineProjectForm()
{
if(mPreChordSet) {
delete mPreChordSet;
mPreChordSet = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::WMNCHitTest(TWMNCHitTest &Message)
{
TForm::Dispatch(&Message);
if( Message.Result==HTCLIENT && Message.YPos<Top+30 && Message.XPos<Left+520) {
if(!mCloseBtn->BoundsRect.Contains(TPoint(Message.XPos - Left, Message.YPos - Top))) {
Message.Result = HTCAPTION;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoFormCreate(TObject *Sender)
{
HRGN hRgn = CreateRoundRectRgn(0, 0, Width+1, Height+1, 16, 16);
SetWindowRgn(Handle, hRgn, false);
DeleteObject(hRgn);
int ChordWidth = mChordsBox->Width / 8;
int ChordLeft;
int ChordTop = 1;
int ChordRight;
int ChordBottom = 27;
for(int i = 0; i < 8; i++) {
ChordLeft = i * ChordWidth;
ChordRight = ChordLeft + ChordWidth;
mChordRect[i] = TRect(ChordLeft, ChordTop, ChordRight, ChordBottom);
}
mChordRect[0].Left++;
mChordRect[7].Right--;
mTSComboBox->ItemIndex = m_Ts;
mTempoSpinEdit->Value = m_Tempo;
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoChordPaint(TObject *Sender)
{
TPaintBox *PaintBox = (TPaintBox *)Sender;
TRect cRect = PaintBox->ClientRect;
cRect.Right--;
cRect.Left++;
cRect.Top++;
cRect.Bottom--;
PaintBox->Canvas->Brush->Color = TColor(0xC8F0FF);
PaintBox->Canvas->Pen->Color = TColor(0x4673A4);
PaintBox->Canvas->RoundRect(cRect, 5, 5);
int Preset = 0;
int Stage = mStageSetComboBox->ItemIndex;
if(mStageComboBox->ItemIndex == 2) {
if(mStageSetComboBox->ItemIndex == 0) {
Preset = mLordSong;
}
else if(mStageSetComboBox->ItemIndex == 1) {
Preset = mBridge;
Stage = 2;
}
else if(mStageSetComboBox->ItemIndex == 2){
Preset = mRefrain;
Stage = 1;
}
}
else {
if(mStageSetComboBox->ItemIndex == 0) {
Preset = mLordSong;
}
else if(mStageSetComboBox->ItemIndex == 1) {
Preset = mRefrain;
}
}
BYTE *Chord = (BYTE *)u_arrPredefChords[Stage][m_KeyType][Preset];
for(int i = 0; i < 8; i++) {
TRect Rect = mChordRect[i];
int ch = Chord[i];
int type = ch & 0x03;
int key = (ch >> 2) + m_Key;
if( key>11 ) key -= 12;
DrawChord(PaintBox->Canvas, Rect, key, type);
if(i != 7) {
PaintBox->Canvas->MoveTo(Rect.Right - 1, Rect.Top);
PaintBox->Canvas->LineTo(Rect.Right - 1, Rect.Bottom);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoPaintBoxMouseLeave(TObject *Sender)
{
mPresetMouseOver = false;
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoPaintBoxMouseEnter(TObject *Sender)
{
mPresetMouseOver = true;
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoPresetChordShow(TObject *Sender)
{
mIsPreSetShow = true;
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoPresetChordHide(TObject *Sender)
{
if(mStageComboBox->ItemIndex == 2) {
if(mStageSetComboBox->ItemIndex == 0) {
mLordSong = mPreChordSet->SelectedIndex;
}
else if(mStageSetComboBox->ItemIndex == 1) {
mBridge = mPreChordSet->SelectedIndex;
}
else if(mStageSetComboBox->ItemIndex == 2){
mRefrain = mPreChordSet->SelectedIndex;
}
}
else {
if(mStageSetComboBox->ItemIndex == 0) {
mLordSong = mPreChordSet->SelectedIndex;
}
else if(mStageSetComboBox->ItemIndex == 1) {
mRefrain = mPreChordSet->SelectedIndex;
}
}
if(GetActiveWindow() != Handle) {
mPaintBoxFlag = true;
}
if(!mPresetMouseOver)
mPaintBoxFlag = true;
mIsPreSetShow = false;
mChordsBox->Repaint();
}
//---------------------------------------------------------------------------
void TPredefineProjectForm::DrawChord(TCanvas *Canvas, TRect Rect, int iKey, int iType)
{
int iMainKey, iAjustKey; //调级数、升降
TPrefineProjectSet::GetChordDisplayKey(iKey, m_Key, iMainKey, iAjustKey);
UniDrawChord(Canvas, Rect, iMainKey, iAjustKey, iType);
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoStageCountChange(TObject *Sender)
{
mStageSetComboBox->Clear();
for(int i = 0; i <= mStageComboBox->ItemIndex; i++) {
mStageSetComboBox->AddItem(IntToStr(i + 1), NULL);
}
mStageSetComboBox->ItemIndex = 0;
DoStageSetChange(NULL);
m_RavStage = mStageComboBox->ItemIndex + 1;
mChordsBox->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoStageSetChange(TObject *Sender)
{
// if(m_RavStage == 3 && mStageSetComboBox->ItemIndex == 1)
// mSelectedStage = 2;
// else if(m_RavStage == 3 && mStageSetComboBox->ItemIndex == 2)
// mSelectedStage = 1;
// else
// mSelectedStage = mStageSetComboBox->ItemIndex;
//
mChordsBox->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoKeyChange(TObject *Sender)
{
TComboBox *Combo = (TComboBox *)Sender;
m_Key = Combo->ItemIndex;
mChordsBox->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoKeyTypeChange(TObject *Sender)
{
TComboBox *Combo = (TComboBox *)Sender;
m_KeyType = Combo->ItemIndex;
mChordsBox->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoTsChange(TObject *Sender)
{
TComboBox *Combo = (TComboBox *)Sender;
m_Ts = Combo->ItemIndex;
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoPaintBoxMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if(mPaintBoxFlag) {
if(mPreChordSet) {
delete mPreChordSet;
mPreChordSet = NULL;
}
mPreChordSet = new TPrefineProjectSet(NULL);
mPreChordSet->Parent = this;
int Preset = 0;
int Stage = mStageSetComboBox->ItemIndex;
if(mStageComboBox->ItemIndex == 2) {
if(mStageSetComboBox->ItemIndex == 0) {
Preset = mLordSong;
}
else if(mStageSetComboBox->ItemIndex == 1) {
Preset = mBridge;
Stage = 2;
}
else if(mStageSetComboBox->ItemIndex == 2){
Preset = mRefrain;
Stage = 1;
}
}
else {
if(mStageSetComboBox->ItemIndex == 0) {
Preset = mLordSong;
}
else if(mStageSetComboBox->ItemIndex == 1) {
Preset = mRefrain;
}
}
for(int i = 0; i < 8; i++) {
BYTE *Chord = (BYTE *)u_arrPredefChords[Stage][m_KeyType][i];
TPrefineProjectSetItem *Item = new TPrefineProjectSetItem(mPreChordSet);
Item->Key = m_Key;
Item->Index = i;
memcpy(Item->PredefChord, Chord, 8 * sizeof(BYTE));
mPreChordSet->AddItem(Item);
}
mPreChordSet->SelectedIndex = Preset;
TPoint posClient(0, mChordsBox->Height);
mPreChordSet->OnShow = DoPresetChordShow;
mPreChordSet->OnHide = DoPresetChordHide;
TPoint pos = mChordsBox->ClientToScreen(posClient);
mPreChordSet->Top = pos.Y;
mPreChordSet->Left = pos.X + 1;
mPreChordSet->Width = mChordsBox->Width - 2;
mPreChordSet->Height = 200;
mPreChordSet->Show();
}
mPaintBoxFlag = !mPaintBoxFlag;
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::OnTempoEditChange(TObject *Sender)
{
TSpinEdit *Edit = (TSpinEdit *)Sender;
if(Edit->Value == 55) {
mTempoComboBox->ItemIndex = 0;
}
else if(Edit->Value == 65){
mTempoComboBox->ItemIndex = 1;
}
else if(Edit->Value == 80) {
mTempoComboBox->ItemIndex = 2;
}
else if(Edit->Value == 110) {
mTempoComboBox->ItemIndex = 3;
}
else if(Edit->Value == 120) {
mTempoComboBox->ItemIndex = 4;
}
else {
mTempoComboBox->ItemIndex = 5;
}
m_Tempo = Edit->Value;
}
//---------------------------------------------------------------------------
void __fastcall TPredefineProjectForm::DoTempoComboChange(TObject *Sender)
{
TComboBox *Combo = (TComboBox *)Sender;
if(Combo->ItemIndex == 0) {
mTempoSpinEdit->Value = 55;
}
else if(Combo->ItemIndex == 1){
mTempoSpinEdit->Value = 65;
}
else if(Combo->ItemIndex == 2) {
mTempoSpinEdit->Value = 80;
}
else if(Combo->ItemIndex == 3) {
mTempoSpinEdit->Value = 110;
}
else if(Combo->ItemIndex == 4) {
mTempoSpinEdit->Value = 120;
}
}
//---------------------------------------------------------------------------
int __fastcall TPredefineProjectForm::ShowModal()
{
int ret = TForm::ShowModal();
m_Preset[0] = mLordSong;
if(mStageComboBox->ItemIndex == 2) {
m_Preset[1] = mBridge;
m_Preset[2] = mRefrain;
}
else {
m_Preset[1] = mRefrain;
m_Preset[2] = 0;
}
return ret;
}
void __fastcall TPredefineProjectForm::DoFormActivate(TObject *Sender)
{
if(mStageComboBox->ItemIndex != (mStageSetComboBox->Items->Count - 1)) {
DoStageCountChange(NULL);
}
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+86
View File
@@ -0,0 +1,86 @@
//---------------------------------------------------------------------------
#ifndef PredefineProjectFormUnitH
#define PredefineProjectFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.Samples.Spin.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include "PNGButton.hpp"
#include "GlobalUnit.h"
#include "PredefineProjectSetUnit.h"
//---------------------------------------------------------------------------
class TPredefineProjectForm : public TForm
{
__published: // IDE-managed Components
TComboBox *mKeyComboBox;
TComboBox *mKeyTypeComboBox;
TComboBox *mTempoComboBox;
TComboBox *mStageComboBox;
TComboBox *mStageSetComboBox;
TComboBox *mTSComboBox;
TSpinEdit *mTempoSpinEdit;
TPaintBox *mChordsBox;
TImage *mBackGround;
TPNGButton *mOkButton;
TPNGButton *mCancelButton;
TPNGButton *mCloseBtn;
void __fastcall DoFormCreate(TObject *Sender);
void __fastcall DoChordPaint(TObject *Sender);
void __fastcall DoPaintBoxMouseLeave(TObject *Sender);
void __fastcall DoPaintBoxMouseEnter(TObject *Sender);
void __fastcall DoStageCountChange(TObject *Sender);
void __fastcall DoStageSetChange(TObject *Sender);
void __fastcall DoKeyChange(TObject *Sender);
void __fastcall DoKeyTypeChange(TObject *Sender);
void __fastcall DoTsChange(TObject *Sender);
void __fastcall DoPaintBoxMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall OnTempoEditChange(TObject *Sender);
void __fastcall DoTempoComboChange(TObject *Sender);
void __fastcall DoFormActivate(TObject *Sender);
private: // User declarations
TRect mChordRect[8];
TPrefineProjectSet *mPreChordSet;
bool mPaintBoxFlag;
bool mPresetMouseOver;
bool mIsPreSetShow;
int mLordSong; // Ö÷¸è
int mRefrain; // ¸±¸è
int mBridge; // ÇÅ
void DrawChord(TCanvas *Canvas, TRect Rect, int iKey, int iType);
void __fastcall DoPresetChordShow(TObject *Sender);
void __fastcall DoPresetChordHide(TObject *Sender);
void __fastcall WMNCHitTest(TWMNCHitTest &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
END_MESSAGE_MAP(TForm)
public: // User declarations
int m_Ts;
int m_Tempo;
int m_Key;
int m_KeyType;
int m_RavStage;
int m_Preset[3];
__fastcall TPredefineProjectForm(TComponent* Owner);
__fastcall ~TPredefineProjectForm();
virtual int __fastcall ShowModal();
};
//---------------------------------------------------------------------------
extern PACKAGE TPredefineProjectForm *PredefineProjectForm;
extern const BYTE u_arrPredefChords[3][2][8][8];
//---------------------------------------------------------------------------
#endif
+299
View File
@@ -0,0 +1,299 @@
//---------------------------------------------------------------------------
#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;
}
}
//---------------------------------------------------------------------------
+97
View File
@@ -0,0 +1,97 @@
//---------------------------------------------------------------------------
#ifndef PredefineProjectSetUnitH
#define PredefineProjectSetUnitH
#include <vcl.h>
class TPrefineProjectSet;
class TPrefineProjectSetItem;
//---------------------------------------------------------------------------
class TPrefineProjectSetItem : public TGraphicControl
{
private:
bool FIsSelected;
bool FIsFocus;
void __fastcall SetSelected(bool Value);
MESSAGE void __fastcall CMMouseEnter(TMessage &Message);
MESSAGE void __fastcall CMMouseLeave(TMessage &Message);
MESSAGE void __fastcall WMLButtonDown(TWMLButtonDown &Message);
protected:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
MESSAGE_HANDLER(WM_LBUTTONDOWN, TWMLButtonDown, WMLButtonDown)
END_MESSAGE_MAP(TGraphicControl)
virtual void __fastcall Paint();
public:
int Key;
BYTE PredefChord[8];
int Index;
TPrefineProjectSet *CtrlParent;
virtual __fastcall TPrefineProjectSetItem(TWinControl *Parent);
void DrawChord(TCanvas *Canvas, TRect Rect, int iKey, int iType);
__property bool IsSelected = {read = FIsSelected, write = SetSelected};
};
class TPrefineProjectSet : public TCustomControl
{
private:
TWinControl *mContentArea;
HWND mActiveWndBak;
int mItemWidth;
int mItemHeight;
int mSelectedIndex;
TList *mItemList;
TPrefineProjectSetItem *mCurrentItem;
void __fastcall SetSelectedIndex(int Value);
MESSAGE void __fastcall WMKillFocus(TMessage &Message);
MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message);
MESSAGE void __fastcall WMSize(TWMSize &Message);
protected:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_KILLFOCUS, TMessage, WMKillFocus)
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
MESSAGE_HANDLER(WM_SIZE, TWMSize, WMSize)
END_MESSAGE_MAP(TCustomControl)
void __fastcall CreateParams(TCreateParams &Params);
void __fastcall CreateWnd();
public:
TNotifyEvent OnHide;
TNotifyEvent OnShow;
__fastcall TPrefineProjectSet(TComponent *Owner);
__fastcall ~TPrefineProjectSet();
void __fastcall DoItemClick(TPrefineProjectSetItem *Item, int Index);
void __fastcall Hide();
void __fastcall Show();
void __fastcall AddItem(TPrefineProjectSetItem *Item);
static void __fastcall GetChordDisplayKey(int iKey, int iBaseKey, int& iMainKey, int& iAjustKey);
__property int SelectedIndex = {read = mSelectedIndex, write = SetSelectedIndex};
};
#endif
+735
View File
@@ -0,0 +1,735 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "ProgressThreadUnit.h";
#include "ProgressFormUnit.h"
#define OPERATION_MM_SAVE 1
#define OPERATION_MM_LOAD 2
#define OPERATION_PROJ_LOAD 3
#define OPERATION_PROJ_SAVE 4
#define OPERATION_USER_LOGIN 5
#define OPERATION_USER_CHECKPAYMENT 6
#define OPERATION_USER_CONFIRMPAYMENT 7
#define OPERATION_USER_SUBMITQA 8
#define OPERATION_USER_REGISTER 9
#define OPERATION_USER_UPLOADSONG 10
#define OPERATION_USER_SUBMITSCORE 11
#define OPERATION_MM_SAVEMEDIA 14
#define STATE_IDLE 0x00
#define STATE_SAVING 0x01
#define STATE_SAVE_SUCCESS 0x02
#define STATE_SAVE_FAILED 0x04
#define STATE_CONFIRMING 0x10
#define STATE_CONFIRM_SUCCESS 0x20
#define STATE_CONFIRM_FAILED 0x40
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TProgressForm *ProgressForm;
//---------------------------------------------------------------------------
__fastcall TProgressForm::TProgressForm(TComponent* Owner)
: TForm(Owner)
{
m_lblCaption->Font->Color = RGB(60,43,23);
m_nMaxPos = m_pbProgress->Width;
m_nPos = 0;
m_nParam1 = m_nParam2 = m_nParam3 = m_nParam4 = 0;
m_pParam1 = m_pParam2 = NULL;
memset( m_strParam1, 0, sizeof(m_strParam1) );
memset( m_strBuff, 0, sizeof(m_strBuff) );
m_pIntParam1 = m_pIntParam2 = NULL;
m_bmpTileLeft = new TBitmap();
m_bmpTileLeft->LoadFromResourceName(int(HInstance), L"ProgressLeft");
m_bmpTileRight = new TBitmap();
m_bmpTileRight->LoadFromResourceName(int(HInstance), L"ProgressRight");
m_nTileWidth = m_bmpTileLeft->Width;
m_nTileHeight = m_bmpTileLeft->Height;
m_nNextMinPos = 0;
m_nNextMaxPos = m_nMaxPos;
m_iOperation = m_iOperationResult = 0;
m_pConfirmThread = NULL;
m_iSaveState = STATE_IDLE;
m_iConfirmResult = m_iFileHandle = 0;
m_pTimer = new TTimer(this);
m_pTimer->Enabled = false;
m_pTimer->Interval = 200;
m_pTimer->OnTimer = TimerProc;
m_pThread = new TProgressThread( true, this );
SetTransparent( this );
}
//---------------------------------------------------------------------------
__fastcall TProgressForm::~TProgressForm()
{
if( m_pThread )
delete m_pThread;
if( m_bmpTileLeft )
delete m_bmpTileLeft;
if( m_bmpTileRight )
delete m_bmpTileRight;
if( m_pTimer ){
delete m_pTimer;
}
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::FormCreate(TObject *Sender)
{
//绘制圆角窗体
HRGN hRgn = CreateRoundRectRgn( 0, 0, Width+1, Height+2, 20, 20 );
SetWindowRgn( Handle, hRgn, false );
DeleteObject( hRgn );
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if( Msg.Result==HTCLIENT && Msg.YPos<Top+24 && Msg.XPos<Left+274 )
Msg.Result = HTCAPTION;
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::ProgressPaint(TObject *Sender)
{
int x = 0;
//左侧平铺
if( m_nPos>0 ){
for( int i=0; i<m_nPos/m_nTileWidth+1; i++ ){
m_pbProgress->Canvas->Draw( x+m_nTileWidth*i, 0, m_bmpTileLeft );
}
x += m_nTileWidth;
}
//右侧平铺
x = m_nPos;
if( m_nPos<m_nMaxPos ){
for( int i=0; i<(m_nMaxPos-m_nPos)/m_nTileWidth+1; i++ ){
m_pbProgress->Canvas->Draw( x+m_nTileWidth*i, 0, m_bmpTileRight );
}
x += m_nTileWidth;
}
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::UMOperateFailed(TMessage &Message)
{
// m_pThread->Terminate();
// ModalResult = Message.WParam;
m_pThread->WaitFor();// >Terminate();
m_iOperationResult = Message.WParam;
if( m_iOperation==OPERATION_MM_SAVEMEDIA ){
m_iSaveState &= ~STATE_SAVING;
m_iSaveState |= STATE_SAVE_FAILED;
}
Canceled();
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::UMOperatePercent(TMessage &Message)
{
TRect rcRedraw( m_nPos, 0, m_nMaxPos, m_nTileHeight );
m_nPos = m_nNextMinPos + Message.WParam * (m_nNextMaxPos - m_nNextMinPos) / 100;
rcRedraw.right = m_nPos;
// m_pbProgress->Invalidate();
InvalidateRect( m_panelProgress->Handle, &rcRedraw, false );
if( m_iOperation==OPERATION_MM_SAVEMEDIA ){
if( m_iSaveState<STATE_CONFIRMING && Message.WParam>95 ){
StartConfirm();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::UMOperateComplete(TMessage &Message)
{
m_pThread->WaitFor();
m_iOperationResult = Message.WParam;
if( m_iOperation==OPERATION_MM_SAVEMEDIA ){
m_iSaveState &= ~STATE_SAVING;
m_iSaveState |= STATE_SAVE_SUCCESS;
if( m_iSaveState & STATE_CONFIRM_SUCCESS ){
ModalResult = mrOk;
}
else{
if( m_iFileHandle==0 && FileExists(m_strParam1) ){
m_iFileHandle = FileOpen( m_strParam1, fmOpenRead|fmShareExclusive );
}
if( m_iSaveState<STATE_CONFIRMING )
StartConfirm();
}
}
else{
ModalResult = mrOk;
}
// m_pThread->Terminate();
// ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::UMOperateNextRange(TMessage &Message)
{
m_nNextMinPos = Message.WParam * m_nMaxPos / 100;
m_nNextMaxPos = ( Message.LParam==0 ? m_nMaxPos : Message.LParam * m_nMaxPos / 100 );
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::UMRecordComplete(TMessage &Message)
{
m_MsgTransparent = Message;
m_pThread->WaitFor();
// m_pThread->Terminate();
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void TProgressForm::StartConfirm()
{
if( m_iSaveState<STATE_CONFIRMING ){
m_iSaveState |= STATE_CONFIRMING;
m_pTimer->Interval = 60000; //1分钟
m_pTimer->Enabled = true;
m_pConfirmThread = new TProgressThread( true, this );
m_pConfirmThread->Start();
DebugPrint( "Start confirm thread.\n" );
}
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::UMPaymentConfirmed(TMessage &Message)
{
m_pTimer->Enabled = false;
m_pConfirmThread->WaitFor();
// m_pConfirmThread->Terminate();
m_iSaveState &= ~STATE_CONFIRMING;
if( m_iConfirmResult==0 ){
m_iSaveState |= STATE_CONFIRM_SUCCESS;
if( m_iSaveState & STATE_SAVE_SUCCESS ){
if( m_iFileHandle>0 ){
FileClose( m_iFileHandle );
m_iFileHandle = 0;
}
ModalResult = mrOk;
}
else if( m_iSaveState & STATE_SAVE_FAILED )
Canceled();
DebugPrint( "Payment confirmed.\n" );
}
else{
m_iSaveState |= STATE_CONFIRM_FAILED;
m_iOperationResult = m_iConfirmResult;
//ModalResult = mrCancel;
Canceled();
}
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::MM_SaveMedia( int iSaveType, int iFileType, LPCTSTR strFileName,
int iOp, int nIdCount, UINT aIdStyle[] )
{
wcscpy( m_strParam1, strFileName );
if( iSaveType==0 ){
iSaveType = SAVE_COMPOSESONG;
m_lblCaption->Caption = L"正在生成歌曲";
}
else{
m_lblCaption->Caption = L"正在保存";
}
m_nParam1 = iFileType;
m_nParam2 = iSaveType;
m_nParam3 = nIdCount;
m_nParam4 = iOp;
m_pParam1 = aIdStyle;
m_iOperation = OPERATION_MM_SAVEMEDIA;
m_btnClose->Show();
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::MM_Save( int iSaveType, LPCTSTR strFileName, int iFileType )
{
wcscpy( m_strParam1, strFileName );
if( iSaveType==0 ){
iSaveType = SAVE_COMPOSESONG;
m_lblCaption->Caption = L"正在生成歌曲";
}
else{
m_lblCaption->Caption = L"正在保存";
}
m_nParam1 = iFileType;
m_nParam2 = iSaveType;
m_iOperation = OPERATION_MM_SAVE;
m_btnClose->Show();
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::MM_Load( LPCTSTR strFileName, int iFileType )
{
wcscpy( m_strParam1, strFileName );
m_iOperation = OPERATION_MM_LOAD;
m_nParam1 = iFileType;
m_lblCaption->Caption = L"正在处理";
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::Project_Save( LPCTSTR strFileName )
{
wcscpy( m_strParam1, strFileName );
m_iOperation = OPERATION_PROJ_SAVE;
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::Project_Load( LPCTSTR strFileName )
{
wcscpy( m_strParam1, strFileName );
m_iOperation = OPERATION_PROJ_LOAD;
m_lblCaption->Caption = L"正在打开";
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::User_Login()
{
m_iOperation = OPERATION_USER_LOGIN;
m_lblCaption->Caption = L"正在登录";
m_btnClose->Show();
m_pTimer->Enabled = true;
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::User_Register( int isEmailOrMobile )
{
m_nParam1 = isEmailOrMobile;
m_iOperation = OPERATION_USER_REGISTER;
m_lblCaption->Caption = L"正在注册";
m_btnClose->Show();
m_pTimer->Enabled = true;
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::User_CheckPayment( int iOperation, int nIdCount, UINT aIdStyle[],
int aStyleCost[], int* pCost , int* pBalance )
{
m_nParam1 = nIdCount;
m_pParam1 = aIdStyle;
m_pParam2 = aStyleCost;
m_pIntParam2 = pCost;
m_pIntParam1 = pBalance;
m_nParam2 = iOperation;
m_iOperation = OPERATION_USER_CHECKPAYMENT;
m_lblCaption->Caption = L"正在鉴权";
m_btnClose->Show();
m_pTimer->Enabled = true;
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::User_ConfirmPayment( int iOperation, int nIdCount, UINT aIdStyle[],
int* pBalance )
{
m_nParam1 = nIdCount;
m_pParam1 = aIdStyle;
m_pIntParam1 = pBalance;
m_nParam2 = iOperation;
m_iOperation = OPERATION_USER_CONFIRMPAYMENT;
m_lblCaption->Caption = L"正在支付";
m_btnClose->Show();
m_pTimer->Enabled = true;
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::User_SubmitQuestin( LPCSTR strQuestion )
{
//wcscpy( m_strParam, strQuestion );
strcpy( m_strBuff, strQuestion );
m_iOperation = OPERATION_USER_SUBMITQA;
m_lblCaption->Caption = L"正在提交";
m_btnClose->Show();
m_pTimer->Enabled = true;
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::User_StyleScore( UINT idStyle, int* pScrUser, int* pScrAverage )
{
//add laq
m_iOperation = OPERATION_USER_SUBMITSCORE;
if( *pScrUser<0 )
m_lblCaption->Caption = L"正在获取评分";
else
m_lblCaption->Caption = L"正在提交评分";
m_nParam1 = idStyle;
m_pIntParam1 = pScrUser;
m_pIntParam2 = pScrAverage;
m_pTimer->Enabled = true;
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
int __fastcall TProgressForm::User_UploadSong( LPCTSTR strFileName, TSHAREINFO* pShareInfo )
{
m_iOperation = OPERATION_USER_UPLOADSONG;
if( pShareInfo ){
wcscpy( m_strParam1, strFileName );
// m_pParam = (void*)pSongInfo;
m_lblCaption->Caption = L"正在上传";
m_pParam1 = (void*)pShareInfo;
}
else{
m_lblCaption->Caption = L"正在验证上传许可";
m_pTimer->Enabled = true;
}
m_btnClose->Show();
m_pThread->Start();
return ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::Operation()
{
switch( m_iOperation ){
case OPERATION_MM_SAVEMEDIA:
if( m_iSaveState==STATE_IDLE ){
m_iSaveState = STATE_SAVING;
f_MM_Save( Handle, m_nParam2, ((AnsiString)m_strParam1).c_str(), m_nParam1 );
}
else if( m_iSaveState & STATE_CONFIRMING ){
int nBalance;
m_iConfirmResult = f_CS_ConfirmPayment( g_infoUser.accountInfo.ID, m_nParam4,
m_nParam3, (UINT*)m_pParam1, &nBalance );
if( m_iConfirmResult==e_VerifyInsufficient || m_iConfirmResult==0 )
g_infoUser.accountInfo.balance = nBalance;
PostMessage( Handle, MSG_PAYMENTCONFIRMED, -1, 0 );
}
break;
case OPERATION_MM_SAVE:
f_MM_Save( Handle, m_nParam2, ((AnsiString)m_strParam1).c_str(), m_nParam1 );
break;
case OPERATION_MM_LOAD:
if( m_nParam1==FILETYPE_MIDI ){
m_iOperationResult = f_MM_LoadMidiMelody( Handle, ((AnsiString)m_strParam1).c_str() );
}
else{
m_iOperationResult = f_MM_LoadAudio(Handle, ((AnsiString)m_strParam1).c_str(),
g_iMelodyTimeSignature, g_nMelodyTempo);
}
if( m_iOperationResult!=S_OK )
PostMessage( Handle, MSG_OPERATE_FAILED, m_iOperationResult, 0 );
break;
case OPERATION_PROJ_SAVE:
if( SaveProject( ((AnsiString)m_strParam1).c_str(), PROJ_MODE_NORMAL, Handle )==TRUE ){
}
else{
}
break;
case OPERATION_PROJ_LOAD:
if( LoadProject( m_strParam1, Handle )==TRUE ){
}
else{
}
break;
case OPERATION_USER_LOGIN:
m_iOperationResult = f_CS_Login( &g_infoUser, true );
PostMessage( Handle, MSG_OPERATE_COMPLETE, m_iOperationResult, 0 );
break;
case OPERATION_USER_REGISTER:
m_iOperationResult = f_CS_Register( &g_infoUser, m_nParam1 );
if( m_iOperationResult==0 ){
PostMessage( Application->MainForm->Handle, MSG_NETWORKMESSAGE,
MAKELONG( 0, e_loginResponse ), (LPARAM)&g_infoUser );
}
PostMessage( Handle, MSG_OPERATE_COMPLETE, m_iOperationResult, 0 );
break;
case OPERATION_USER_CHECKPAYMENT:
m_iOperationResult = f_CS_CheckPayment( g_infoUser.accountInfo.ID, m_nParam2,
m_nParam1, (UINT*)m_pParam1, (int*)m_pParam2,
m_pIntParam2, m_pIntParam1 );
PostMessage( Handle, MSG_OPERATE_COMPLETE, m_iOperationResult, 0 );
break;
case OPERATION_USER_CONFIRMPAYMENT:
m_iOperationResult = f_CS_ConfirmPayment( g_infoUser.accountInfo.ID, m_nParam2,
m_nParam1, (UINT*)m_pParam1, m_pIntParam1 );
PostMessage( Handle, MSG_OPERATE_COMPLETE, m_iOperationResult, 0 );
break;
case OPERATION_USER_SUBMITQA:
m_iOperationResult = f_CS_SubmitQnA( g_infoUser.accountInfo.ID, m_strBuff );
PostMessage( Handle, MSG_OPERATE_COMPLETE, m_iOperationResult, 0 );
break;
case OPERATION_USER_SUBMITSCORE:
/* m_iOperationResult = f_CS_StyleScore( g_infoUser.accountInfo.ID,
m_nParam1, m_pIntParam1, m_pIntParam2 );
PostMessage( Handle, MSG_OPERATE_COMPLETE, 0, 0 );
*/ break;
case OPERATION_USER_UPLOADSONG:
{
TSONGINFO infoSong;
if( m_pParam1 ){
// memcpy( &infoSong, &g_infoSong, sizeof(TSONGINFO) );
string strTmp = GBToUTF8(g_infoSong.strSongName);
strcpy( infoSong.strSongName, strTmp.c_str() );
strTmp = GBToUTF8(g_infoSong.strSinger);
strcpy( infoSong.strSinger, strTmp.c_str() );
strTmp = GBToUTF8(g_infoSong.strOriginal);
strcpy( infoSong.strOriginal, strTmp.c_str() );
strTmp = GBToUTF8(g_infoSong.strArranger);
strcpy( infoSong.strArranger, strTmp.c_str() );
strTmp = GBToUTF8(g_infoSong.strLyricist);
strcpy( infoSong.strLyricist, strTmp.c_str() );
strTmp = GBToUTF8(g_infoSong.strComposer);
strcpy( infoSong.strComposer, strTmp.c_str() );
strTmp = GBToUTF8(g_infoSong.strDescription);
strcpy( infoSong.strDescription, strTmp.c_str() );
memcpy( infoSong.iMusicStyle, g_infoSong.iMusicStyle, sizeof(char)*4 );
memcpy( infoSong.aStyleIDs, g_infoSong.aStyleIDs, sizeof(UINT)*32 );
infoSong.iCreation = g_infoSong.iCreation;
infoSong.iSubmit = g_infoSong.iSubmit;
infoSong.size = g_infoSong.size;
infoSong.iTempo = g_infoSong.iTempo;
infoSong.iTS = g_infoSong.iTS;
infoSong.iSingerType = g_infoSong.iSingerType;
infoSong.cpjPrice = g_infoSong.cpjPrice;
infoSong.cpjVersion = g_infoSong.cpjVersion;
int lenght;
if( g_infoSong.strIconName ){
lenght = strlen(g_infoSong.strIconName);
infoSong.strIconName = new char[lenght+1];
strcpy( infoSong.strIconName, g_infoSong.strIconName );
infoSong.strIconName[lenght] = '\0';
}
if( g_infoSong.strLyric ){
strTmp = GBToUTF8(g_infoSong.strLyric);
lenght = strlen(strTmp.c_str());
infoSong.strLyric = new char[lenght+1];
strcpy( infoSong.strLyric, strTmp.c_str() );
infoSong.strLyric[lenght] = '\0';
}
if( g_infoSong.strCpjName ){
lenght = strlen(g_infoSong.strCpjName);
infoSong.strCpjName = new char[lenght+1];
strcpy( infoSong.strCpjName, g_infoSong.strCpjName );
infoSong.strCpjName[lenght] = '\0';
}
infoSong.strMp3Name = new char[((AnsiString)m_strParam1).Length()+1];
strcpy( infoSong.strMp3Name, ((AnsiString)m_strParam1).c_str() );
}
m_iOperationResult = f_CS_UploadSong( g_infoUser.accountInfo.ID,
m_pParam1 ? &infoSong : NULL,
Handle,
(TSHAREINFO*)m_pParam1 );
PostMessage( Handle, MSG_OPERATE_COMPLETE, m_iOperationResult, 0 );
/*
SAFE_DELETE(infoSong.strIconName)
SAFE_DELETE(infoSong.strLyric)
SAFE_DELETE(infoSong.strMp3Name)
*/
}
}
}
//---------------------------------------------------------------------------
void TProgressForm::Canceled()
{
DebugPrint( "Canceled.\n" );
if( m_iOperation==OPERATION_MM_SAVEMEDIA ){
if( m_iSaveState & STATE_SAVING ){
f_MM_UserCanceled();
m_pThread->WaitFor();
}
if( m_iSaveState & STATE_CONFIRMING ){
m_pTimer->Enabled = false;
f_CS_CancelOperation();
m_pConfirmThread->WaitFor();
}
if( m_iFileHandle>0 ){
FileClose( m_iFileHandle );
m_iFileHandle = 0;
}
if( FileExists( m_strParam1 ) )
DeleteFile( m_strParam1 );
}
else{
if( m_iOperation==OPERATION_MM_LOAD || m_iOperation==OPERATION_MM_SAVE ){
f_MM_UserCanceled();
}
else if( m_iOperation==OPERATION_USER_LOGIN
|| m_iOperation==OPERATION_USER_REGISTER
|| m_iOperation==OPERATION_USER_CHECKPAYMENT
|| m_iOperation==OPERATION_USER_CONFIRMPAYMENT
|| m_iOperation==OPERATION_USER_SUBMITQA
|| m_iOperation==OPERATION_USER_UPLOADSONG ){
m_pTimer->Enabled = false;
f_CS_CancelOperation();
}
m_pThread->WaitFor();
}
m_iOperation = 0;
ModalResult = mrCancel;
DebugPrint( "exit progress.\n" );
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::CloseClick(TObject *Sender)
{
m_iOperationResult = e_UserCanceled;
Canceled();
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::TimerProc(TObject* Sender)
{
if( m_pTimer->Interval==200 ){
m_nPos += 20;
if( m_nPos>=m_nMaxPos ){
m_nPos -= m_nMaxPos;
}
m_pbProgress->Invalidate();
}
else{
m_iOperationResult = e_WaitTimeout;
Canceled();
}
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
switch( Key ){
case VK_ESCAPE:
if( m_btnClose->Visible )
CloseClick( NULL );
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TProgressForm::FormClose(TObject *Sender, TCloseAction &Action)
{
if( m_iFileHandle>0 ){
FileClose( m_iFileHandle );
m_iFileHandle = 0;
}
}
//---------------------------------------------------------------------------
File diff suppressed because it is too large Load Diff
+112
View File
@@ -0,0 +1,112 @@
//---------------------------------------------------------------------------
#ifndef ProgressFormUnitH
#define ProgressFormUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include "PNGButton.hpp"
#include "GlobalUnit.h"
#include <Vcl.Graphics.hpp>
//---------------------------------------------------------------------------
class TProgressForm : public TForm
{
__published: // IDE-managed Components
TImage *m_imgBk;
TLabel *m_lblCaption;
Vcl::Extctrls::TPanel *m_panelProgress;
TPaintBox *m_pbProgress;
TPNGButton *m_btnClose;
void __fastcall ProgressPaint(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall CloseClick(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
TBitmap *m_bmpTileLeft,
*m_bmpTileRight;
TThread *m_pThread;
TTimer *m_pTimer;
int m_nTileWidth,
m_nTileHeight,
m_nMaxPos,
m_nPos,
m_iOperation,
m_iOperationResult;
TCHAR m_strParam1[256];
char m_strBuff[256];
void* m_pParam1, *m_pParam2;
int m_nNextMinPos,
m_nNextMaxPos;
UINT m_nParam1, m_nParam2;
int *m_pIntParam1, *m_pIntParam2;
//SaveMediaרÓÃ
UINT m_nParam3, m_nParam4;
TThread *m_pConfirmThread;
int m_iSaveState,
m_iConfirmResult,
m_iFileHandle;
void __fastcall TimerProc(TObject* Sender);
void StartConfirm();
void Canceled();
MESSAGE void __fastcall WMNCHitTest(TWMNCHitTest &Msg);
MESSAGE void __fastcall UMOperateFailed(TMessage &Message);
MESSAGE void __fastcall UMOperatePercent(TMessage &Message);
MESSAGE void __fastcall UMOperateComplete(TMessage &Message);
MESSAGE void __fastcall UMOperateNextRange(TMessage &Message);
MESSAGE void __fastcall UMRecordComplete(TMessage &Message);
MESSAGE void __fastcall UMPaymentConfirmed(TMessage &Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, WMNCHitTest)
MESSAGE_HANDLER(MSG_OPERATE_FAILED, TMessage, UMOperateFailed)
MESSAGE_HANDLER(MSG_OPERATE_PERCENT, TMessage, UMOperatePercent)
MESSAGE_HANDLER(MSG_OPERATE_COMPLETE, TMessage, UMOperateComplete)
MESSAGE_HANDLER(MSG_OPERATE_NEXTRANGE, TMessage, UMOperateNextRange)
MESSAGE_HANDLER(MSG_RECORD_COMPLETE, TMessage, UMRecordComplete)
MESSAGE_HANDLER(MSG_PAYMENTCONFIRMED, TMessage, UMPaymentConfirmed)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TProgressForm(TComponent* Owner);
__fastcall ~TProgressForm();
int __fastcall MM_SaveMedia( int iSaveType, int iFileType, LPCTSTR strFileName,
int iOp, int nIdCount, UINT aIdStyle[] );
int __fastcall MM_Save( int iSaveType, LPCTSTR strFileName, int iFileType );
int __fastcall MM_Load( LPCTSTR strFileName, int iFileType );
int __fastcall Project_Save( LPCTSTR strFileName );
int __fastcall Project_Load( LPCTSTR strFileName );
int __fastcall User_Register( int isEmailOrMobile );
int __fastcall User_Login();
int __fastcall User_CheckPayment( int iOperation, int nIdCount, UINT aIdStyle[],
int aStyleCost[], int* pCost, int* pBalance );
int __fastcall User_ConfirmPayment( int iOperation, int nIdCount, UINT aIdStyle[],
int* pUserBalance );
int __fastcall User_SubmitQuestin( LPCSTR strQuestion );
int __fastcall User_StyleScore( UINT idStyle, int* pScrUser, int* pScrAverage );//add by laq
int __fastcall User_UploadSong( LPCTSTR strFileName, TSHAREINFO* pShareInfo );
void __fastcall Operation();
void __fastcall SetOperationResult( int iRes ) { m_iOperationResult=iRes; };
int __fastcall GetOpertaionResult() { return m_iOperationResult; };
TMessage m_MsgTransparent;
};
//---------------------------------------------------------------------------
extern PACKAGE TProgressForm *ProgressForm;
//---------------------------------------------------------------------------
#endif
+35
View File
@@ -0,0 +1,35 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ProgressThreadUnit.h"
#include "ProgressFormUnit.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(&UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall TProgressThread::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall TProgressThread::TProgressThread(bool CreateSuspended, TForm* pForm)
: TThread(CreateSuspended)
{
m_pForm = pForm;
}
//---------------------------------------------------------------------------
void __fastcall TProgressThread::Execute()
{
//---- Place thread code here ----
((TProgressForm*)m_pForm)->Operation();
}
//---------------------------------------------------------------------------

Some files were not shown because too many files have changed in this diff Show More