//---------------------------------------------------------------------------

#ifndef UnitMainH
#define UnitMainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Dialogs.hpp>
#include <ExtDlgs.hpp>
#include <ComCtrls.hpp>
#include "DataDownload.h"
#include "DirectShowClass.h"
#include "UnitVideo.h"
#include <jpeg.hpp>
#include <Buttons.hpp>
#include <ImgList.hpp>
#include "UnitDisplay.h"

typedef enum{
    PATTERN_SCALE_H = 0,
    PATTERN_SCALE_V,
    PATTERN_RGB,
    PATTERN_WHITE,
    PATTERN_RED,
    PATTERN_GREEN,
    PATTERN_BLUE,
    PATTERN_BORDER,
    PATTERN_MATRIX2,
    PATTERN_COUNTER,
    PATTERN_COUNTER_8,
    PATTERN_FOLDER,
    PATTERN_FILE,
/*
    PATTERN_R0,
    PATTERN_R1,
    PATTERN_R2,
    PATTERN_R3,
    PATTERN_R4,
    PATTERN_R5,
    PATTERN_R6,
    PATTERN_R7, */
    PATTERN_NUM
}PATTERN_TYPE;

//---------------------------------------------------------------------------
class TFormMain : public TForm
{
__published:	// IDE-managed Components
    TStatusBar *StatusBar;
    TPanel *PanelDisplay;
    TOpenDialog *OpenDialog;
    TPanel *PanelControl;
    TLabel *Label1;
    TComboBox *ComboBoxRes;
    TLabel *Label2;
    TComboBox *ComboBoxPatternType;
    TButton *ButtonPlay;
    TPaintBox *PaintBoxDisplay;
    TImage *ImageLogo;
    TPanel *PanelVideoControl;
    TTrackBar *TrackBarPlayer;
    TImageList *ImageListPlayer;
    TSpeedButton *SpeedButtonPlay;
    TSpeedButton *SpeedButtonPause;
    TSpeedButton *SpeedButtonStop;
    TSpeedButton *SpeedButtonStep;
    TTimer *TimerVideo;
    TTimer *TimerBrowse;
    TPanel *PanelBrowse;
    TComboBox *ComboBoxInterval;
    TLabel *Label3;
    void __fastcall ComboBoxPatternTypeChange(TObject *Sender);
    void __fastcall ComboBoxResChange(TObject *Sender);
    void __fastcall FormShow(TObject *Sender);
    void __fastcall StatusBarDrawPanel(TStatusBar *StatusBar,
          TStatusPanel *Panel, const TRect &Rect);
    void __fastcall ButtonPlayClick(TObject *Sender);
    void __fastcall FormPaint(TObject *Sender);
    void __fastcall FormResize(TObject *Sender);
    void __fastcall PaintBoxDisplayPaint(TObject *Sender);
    void __fastcall SpeedButtonPauseClick(TObject *Sender);
    void __fastcall SpeedButtonPlayClick(TObject *Sender);
    void __fastcall SpeedButtonStopClick(TObject *Sender);
    void __fastcall SpeedButtonStepClick(TObject *Sender);
    void __fastcall TrackBarPlayerChange(TObject *Sender);
    void __fastcall TimerVideoTimer(TObject *Sender);
    void __fastcall TimerBrowseTimer(TObject *Sender);
    void __fastcall ComboBoxIntervalChange(TObject *Sender);
private:	// User declarations
    Graphics::TBitmap *m_pBitmap;
    Graphics::TBitmap *m_pFileBitmap;
    TDataDownload m_DataDownload;
    TFormDisplay *m_pFormDisplay;
    TStringList *m_pFileList;
    int m_nBrowseIndex;
    PATTERN_TYPE m_szPatternType[32];
    PATTERN_TYPE m_nPrePatternType;
    virtual void __fastcall WndProc(Messages::TMessage &Message);
    TColor m_PanelColor[3];
    void __fastcall UIShowStatus(AnsiString strText, TColor color);
    void __fastcall UIShowInfo(AnsiString strText, TColor color);
    void __fastcall UIShowImageInfo(AnsiString strText, TColor color);

    bool __fastcall IsHotKeyActive(void);
public:		// User declarations
    __fastcall TFormMain(TComponent* Owner);
    __fastcall ~TFormMain();
protected:
    typedef struct{
        int nWidth;
        int nHeight;
        bool bCanStep;
        bool bPlaying;
        bool bStop;
        DWORD dwDur;
        DWORD dwPos;
    }VIDEO_INFO;
    VIDEO_INFO m_VideoInfo;
    bool m_bPlaying;
    bool m_bDownloadImage;
    bool m_bPlayFolder;
    AnsiString m_strBrowseFolder;
    AnsiString m_strFileFolder;
    TDirectShow *m_pDirectShow;
    TFormVideo *m_pFormVideo;
    float m_fDataRate;
    void __fastcall UIRedrawImage(void);
    void __fastcall UpdateBitmapContent(void);
    bool __fastcall DownloadImage(void);
    void __fastcall UIRefresh(void);
    void __fastcall FreeDirectShow(void);
    TRect __fastcall CalDisplayRect(int nImageWidth, int nImageHeight);
    void __fastcall PrepareDownloadData(void);
    void __fastcall UIDrawImage(void);
    void __fastcall UIPlayerUpdate(void);
    void __fastcall UIVideoProgressUpdate(void);
    void __fastcall UIVideoTimeUpdate(void);
    bool __fastcall LoadImage(AnsiString strFilename);
    void __fastcall BrowseImage(void);
    int __fastcall GetInterval(void);
    void __fastcall UIBuildPatternList(void);
    PATTERN_TYPE __fastcall UIGetPatternType(void);
    void __fastcall UISetPatternType(PATTERN_TYPE PatternType);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMain *FormMain;
//---------------------------------------------------------------------------
#endif


