
#ifndef __UISCREEN_H
#define __UISCREEN_H

#include "uipanel.h"
#include "uifiledialog.h"
#include "uikeyboard.h"
#include "uimessagebox.h"
#include "uiproject.h"
#include "uiserial.h"
#include "uiabout.h"
#include "uiblack.h"
#include "uifirmware.h"
#include "uiexport.h"
#include "uiprogress.h"
#include "uilook.h"
#include "uilookfile.h"
#include "uishutter.h"
#include "uitimecode.h"
#include "uitimecode2.h"
#include "uimodes.h"
#include "uisdimodes.h"
#include "uiprefs.h"
#include "lut.h"
#include "smpte.h"
#include "loupe.h"
#include "histogram.h"
#include "uiiridas.h"
#include "uimacrolist.h"
#include "uidlgmetadata.h"
#include "uidlgsceneshottake.h"
#include "uidlgwhitebalance.h"
#include "uiuserwb.h"
#include "uimetadatactrl.h"
#include "uidisplayprefs.h"
#include "uidlgrepair.h"
#include "uidlgdefectivepixmap.h"
#include "uidlgmulticammode.h"
#include "uidlgcamconnect.h"
#include "uidlgfindfilematch.h"
#include "uiqualityctrl.h"
#include "uiparallaxshift.h"
#include "uiguidesdlg.h"
#include "uidisplaymodes.h"
#include "uidisplaymodeslist.h"
#include "uihighblacklevel.h"
#include "screenlogger.h"

#define UI_TOP_LEFT 5
#define UI_TOP_X2 330
#define UI_TOP_X3 435
#define UI_TOP_X4 510
#define UI_TOP_CENTER 640
#define UI_TOP_X5 775
#define UI_TOP_X6 835
#define UI_TOP_X7 885
#define UI_TOP_X8 985
#define UI_TOP_X9 1110
#define UI_TOP_RIGHT 1260

#define UI_TOP_Y1 9
#define UI_TOP_Y2 37

#define INNER_CONTAINER_W 16
#define AUDIO_LEVEL_SLIDER_W 26
#define INNER_CONTAINER_H 195
#define CONTAINER_W	(INNER_CONTAINER_W+6)
#define CONTAINER_H	(INNER_CONTAINER_H+6)

#define CONTAINER_Y	153
#define CONTAINER_RED_H 14
#define CONTAINER_YELLOW_H 51
#define CONTAINER_GREEN_H 130

#define OVER_X 1194
#define OVER_Y 101
#define OVER_W 61
#define OVER_H 24

#define INNER_CONTAINER_FS_W 140
#define INNER_CONTAINER_FS_H 11
#define CONTAINER_FS_W	( INNER_CONTAINER_FS_W + 4 )
#define CONTAINER_FS_H	( INNER_CONTAINER_FS_H + 3 )

#define CONTAINER_FS_Y 810
#define CONTAINER_FS_X 750
#define CONTAINER_FS_RED_W 10
#define CONTAINER_FS_YELLOW_W 36
#define CONTAINER_FS_GREEN_W 94

#define OVER_FS_W 50
#define OVER_FS_H 20

// border
#define CONTAINER_BORDER 3

#define ZOOM_W 75
#define ZOOM_H 88

typedef enum EScreenMode {
	SCREEN_MODE_PREVIEW = 0,
	SCREEN_MODE_PLAY
};

typedef enum EVideoDisplayMode {
	VIDEO_DISPLAY_NORMAL = 0,
	VIDEO_DISPLAY_FULL_OVERLAY,
	VIDEO_DISPLAY_FULL,
	VIDEO_DISPLAY_IRIDAS
};

typedef struct TRightPanelInfo {
	float part_gb;
	float total_gb;
	float part_audio;
	float time;
	bool drive_full;
} TRightPanelInfo;
	
#define MOD_TABLE_ENTRIES 17


typedef enum EKeyboardController {
	KEYBOARD_CONTROLLER_NONE = 0,
	KEYBOARD_CONTROLLER_PARALLAX,
	KEYBOARD_CONTROLLER_LAST,
};

class CUIScreen {

public:

	CUIScreen();
	~CUIScreen();
	void Render( void );
	bool Init( void );
	void OnClick( int x, int y );
	void OnRightClick( void );
	void OnKeydown( DWORD key );
	void OnVK( DWORD key );
	void SetScreenMode( EScreenMode mode ) { mMode = mode; }
	EScreenMode GetMode( void )  { return mMode; }
	void SetVideoDisplayMode( EVideoDisplayMode mode ) { mVideoDisplayMode = mode; }
	DWORD GetVideoDisplayMode( void )  { return mVideoDisplayMode; }
	void IncDisplayMode( void );
	void IncDisplay3DMode( void );
	void IncLeftRightMode( void );
	void DeleteClip( void );
	void FileIOError();
	void OverwriteClip();
	void OnBlackDialog( void );
	void BlackWarning( void );
	void NoBuffers( void );
	void LostConnection( int cam );
	void SmallFileError( DWORD size );
	void FileExportError();
	void ExportDestDriveError( bool ntfsLimit );
	void CreateDirectoryError();
	void OpenGLStateChanged();
	void MessageBoxCancel( void );
	void MessageBoxOk( void );
	void MessageBoxOk2( void );
	void ProjectCancel( void );
	void SerialDone( void );
	void AboutDone( void );
	void FirmwareDone( void );
	void ProjectOk();
	void DeleteExportDialog( void );
	void ShowExportError();
	bool ExportOk( void );
	void ProgressCancel( void );
	void ShutterClose( void );
	void TimecodeClose( bool doit );
	void Timecode2Close( bool doit );
	void ModesCancel( void );
	void ModesOk( void );
	void EditText( char *text );
	bool SetDiskUsage(char *drive, float &free_mb, float &total_mb, float &pct);
	void RenderAudioMeter( void );
	void RenderAudioMeterFullScreen( void );
	void RenderAudioMeterPanel( void );
	void RenderExposureMeter( void );
	void SetUtilityMode( bool on );
	void UpdateButtonStates( void );
	void OpenFileDialog( EFileType type, char *destText );
	void OpenMacroListDialog( DWORD index );
	void OpenDisplayModesDialog( DWORD index );
	void LoadPrefs( void );
	void LoadIridas( char *filename, int index );
	void Quit( void );
	void SaveIridas();
	void SavePlayerLook();
	void NoLTCDevice();
	void ChangeSystemTime();
	void LoadModes( void );
	void NewProject( void );
	void LoadLooks( void );
	void LoadMacros( void );
	void LoadDispModes();
	void SendSerial( void );
	void AboutBox( void );
	void UpdateFirmware( void );
	void ExportClip( void );
	void UpdateConnectProgress();
	void ConnectProgress();
	void ConnectDone();
	void UpdateProgressDialog( int part, int whole );
	void UpdateProgressDialog( int part, int whole, char * filename );
	void ShutterDialog( void );
	void TimecodeDialog( void );
	void Timecode2Dialog( void );
	void OpenMetadataDialog();
	void CloseMetadataDialog();
	void OnMetadataDialogOK();
	void OpenSceneShotTakeDialog();
	void CloseSceneShotTakeDialog();
	void OnSceneShotTakeDialogOK();
	void OpenWhiteBalanceDialog();
	void CloseWhiteBalanceDialog();
	void OpenUserWBDialog();
	void CloseUserWBDialog();
	void OnWhiteBalanceUser( int pos );
	void CloseFileDialog( void );
	void CloseMacroListDialog( void );
	void CloseDisplayModesDialog();
	void CloseDisplayModesListDialog();
	void CloseKeyboard( char *text );
	void ClosePrefs( bool doit );
	void CloseBlack( bool doit, bool allGains );
	void CloseReconnect( bool doit, bool connect );
	void CloseModes( bool doit, bool custom );
	void OpenSDIModes();
	void CloseSDIModes( bool doit );
	void ToggleRecording( void );
	void StartRecording( void );
	void StopRecording( void );
	void OnIncPlay( int delta );
	void DoRecording( bool startRecording );
	void SetFrameStoreMode( bool status );
	void SetProjectManagerMode( bool status );
	void SetCamSetupMode( bool status );
	void SetLoadLookMode( bool status );
	void SetCamAlignMode( bool status );
	void SetWhiteBalanceMode( bool status );
	void IncreaseTakeNumber();
	void ToggleStatusbarMode();
	void LoadClipInfoEditor();
	void CloseMetaDataCtrl();
	void LoadDisplayPrefs();
	void CloseDisplayPrefs( bool action );
	void OpenRepairDialog();
	void CloseRepairDialog( bool action );
	void OpenDefectivePixelmapDialog();
	void OpenFindFileMatchDialog();
	void CloseDefectivePixelmapDialog( bool action );
	void CloseDlgFindFileMatch( bool action );
	void OpenMultiCamDialog();
	void CloseMultiCamDialog( bool action );
	void OpenCamConnectionDialog( int index, char * msg );
	void CloseCamConnectionDialog();
	void InitializeProjectMetadata( char * filepath );
	void OpenParallaxShiftDlg();
	void OpenHighBlackLevelDlg();
	void CloseHighBlackLevelDlg( bool action );
	void CloseParallaxShiftDlg();
	void Load3DAlignmentGuidesDlg();
	void Close3DAlignmentGuidesDlg( bool action );
	void Adjust3DGuidesPercentage( float value );
    void SetOverlayText( char *text, int durationInSeconds );
    void ClearOverlayText( void );
    void RenderOverlayText( void );
	void DrawFlipText( char * text );
	int Get3DDisplayChannel();
	bool CheckDestDriveSpace( char * inFile );
	void StartupFullScreenMode();
	void MessageBoxContinue();
	void MouseMoveRightClick( int deltaX, int deltaY );
    void SetSobel( bool state );
    void SetSobelExternal( bool state );

	CUIFileDialog *mFileDialog;
	CUIMacroListDialog *mMacroListDialog;
	CUIDisplayModesListDialog *mDisplayModesListDialog;
	CUIKeyboard *mKeyboard;
	CUIPrefs *mPrefs;
	CUIModesDialog *mModesDialog;
	bool IsRecording( void ) { return mIsRecording; }
	CUIMessageBox *mMessageBox;
	CUITextButton *mPlayModeButton;
	CUITextButton *mExitPlayModeButton;
	CUITextButton *mSaveButton;
	CUITextButton *mLoadButton;
	CUITextButton *mGrabButton;
	CUITextButton *mRecall100Button;
	CUITextButton *mRecall50Button;
	CUITextButton *mExportDNG;
	CUITextButton *mQuitButton;
	CUIProgressDialog *mProgressDialog;
	CUIBlackDialog *mBlackDialog;
	CUIMetaDataCtrl *mMetaDataCtrl;
	CUIDisplayPrefs *mDisplayPrefsDialog;
	CUIGuidesDlg *mGuidesDialog;
	TRightPanelInfo mRightPanelInfo;

	// New for 2.0 version
	CUIDlgMetadata *mMetadataDialog;
	CUIDlgSceneShotTake *mSceneShotTakeDialog;
	CUIDlgWhiteBalance *mWhiteBalanceDialog;
	CUISDIModesDialog *mSDIModesDialog;
	CUIDlgRepair *mRepairDialog;
	CUIDlgDefectivePixMap *mDefectivePixelmapDlg;
	CUIDlgFindFileMatch *mFindFileMatchDlg;
	CUIDlgMultiCamMode *mMultiCamModeDlg;
	CUIDlgCamConnect *mCamConnectionDlg;
	CUIUserWB *mUserWBDialog;
	CUIParallaxShiftDialog *mParallaxShiftDlg;
	CUIHighBlackLevelDlg *mHighBlackLevelDialog;
	CUITextButton *mFrameStore;
	CUITextButton *mFrameStorePlay;
	CUITextButton *mProjectManager;
	CUITextButton *mABCamSetup;
	CUITextButton *mNewProject;
	CUITextButton *mOpenProject;
	CUITextButton *mMetadata;
	CUITextButton *mSceneShotTake;
	CUITextButton *mSlatePreview;;
	CUITextButton *mWhiteBalance;
	CUITextButton *mShutterControl;
	CUITextButton *mWhiteBalance3200;
	CUITextButton *mWhiteBalance5600;
	CUITextButton *mWhiteBalanceUser1;
	CUITextButton *mWhiteBalanceUser2;
	CUITextButton *mWhiteBalanceSet;
	CUITextButton *mWhiteBalanceAdjust;
	CUITextButton *mSpotFocusMeter;
	CUITextButton *mClipInfoEditor;
	CUITextButton *mExportClip;
	CUITextButton *mColorCorrect;
	CUITextButton *mFlipCamA;
	CUITextButton *mFlipCamB;
	CUITextButton *mParallaxShift;
	CUITextButton *mSDIModes;
	CUITextButton *mLoadLookDlg;
	CUITextButton *mLoadLooks;
	CUITextButton *mLookAsShot;
	CUITextButton *mLoadLookBtnA;
	CUITextButton *mLoadLookBtnB;
	CUITextButton *mLoadLookBtnC;
	CUITextButton *mLoadLookBtnD;
	CUITextButton *mCamAlignModeBtn;
	CUITextButton *mRecFS;
	CUITextButton *mPlayFS;
	CUITextButton *mLoadFileFS;

	EScreenMode mMode;

private:

	void HandleGuiVK( DWORD key );
	void HandleGuiKeydown( DWORD key );
	void InitLeftPanel( void );
	void InitRightFramestorePanel( void );
	void InitRightCamSetupPanel( void );
	void InitWhiteBalancePanel( void );
	void InitRightProjectPanel( void );
	void InitRightPlayPanel();
	void InitRightLoadLookPanel();
	void InitCamAlignPanel();
	void InitMeterPanel( void );
	void InitBottomPanel( void );
	void InitCenterPanel( void );
	void InitFullPanel( void );
	void InitFSPlayPanel();
	void InitFSRecPanel();
	void InitCenterZoomPanel( void );
	void InitFullZoomPanel( void );
	void InitParallaxShiftPanel();
	//void InitHotspotPanel( CUIPanel *panel, float x, float y, float w, float h );

	void InitLeftPlayPanel( void );
	void InitBottomPlayPanel( void );
	void InitBottomPlayPanelFS();

	void InitLeftUtilityPanel( void );
	void InitRightUtilityPanel( void );
	void InitBottomUtilityPanel( void );

	void RenderTopPanel( void );
	void RenderMeterPanel( void );
	void RenderBottomMeterPanel();
	void RenderRAMBuffer( void );
	void RenderRAMBufferFullScreen();
	void RenderDiskMeterFullScreen();
	void InitAudioLut(void);
	void TurnOffSidePanelsForRecord();

	int mAudioHeight[32768];
    EKeyboardController mKeyboardController;

	CUIPanel *mLeftPanel;
	CUIPanel *mMeterPanel;
	CUIPanel *mBottomPanel;
	CUIPanel *mCenterPanel;
	CUIPanel *mFullPanel;
	CUIPanel *mCenterZoomPanel;
	CUIPanel *mFullZoomPanel;

	CUIPanel *mFSPlayPanel;
	CUIPanel *mFSRecPanel;

	CUIPanel *mLeftPlayPanel;
	CUIPanel *mBottomPlayPanel;
	CUIPanel *mBottomPlayPanelFS;

	CUIPanel *mLeftUtilityPanel;
	CUIPanel *mRightUtilityPanel;
	CUIPanel *mRightFramestorePanel;
	CUIPanel *mRightCamSetupPanel;
	CUIPanel *mWhiteBalancePanel;
	CUIPanel *mRightProjectPanel;
	CUIPanel *mRightPlayPanel;
	CUIPanel *mBottomUtilityPanel;
	CUIPanel *mRightLoadLookPanel;
	CUIPanel *mParallaxShiftPanel;
	CUIPanel *mCamAlignPanel;

	CUIMessageBox *mMessageBox2;
	CUIProjectDialog *mProjectDialog;
	CUISerialDialog *mSerialDialog;
	CUIAboutDialog *mAboutDialog;
	CUIFirmwareDialog *mFirmwareDialog;
	CUIExportDialog *mExportDialog;
	CUIShutterDialog *mShutterDialog;
	CUITimecodeDialog *mTimecodeDialog;
	CUITimecodeDialog2 *mTimecode2Dialog;
	CUITextButton *mRecordButton;
	CUITextButton *mLoadModesButton;
	CUITextButton *mGainButton;

	CUIHotSpotButton *mToggleStatusbarMode;
	CUIHotSpotButton *mExposureMeter;
	CUIHotSpotButton *mToggleSobel;
	CUIHotSpotButton *mSceneShotTakeHS;
	CUIHotSpotButton *mFullScreen;
	CUIHotSpotButton *mToggleLut3D;
	CUIHotSpotButton *mGuides;
	CUIHotSpotButton *mIncDisplay3DMode;
	CUIHotSpotButton *mIncLeftRightMode;
	CUIHotSpotButton *mZoom;
	CUIHotSpotButton *mToggleHistogram;
	CUIHotSpotButton *mAudioInputInc;;
	CUIHotSpotButton *mAudioInputDec;
	CUIHotSpotButton *mDiskTimeMeterSwitch;
	CUIButton *mHotspotList;
	
	DWORD mVideoDisplayMode;
	bool mIsRecording;
	bool mUtilityMode;
	bool mFrameStoreMode;
	bool mProjectManagerMode;
	bool mCamSetupMode;
	bool mLoadLookMode;
	bool mWhiteBalanceMode;
	bool mCamAlignMode;
	int mActiveLook;
	DWORD mAudioOverTicks;
    char  mOverlayText[MAX_LOGGER_LINES][256];
    DWORD mOverlayTextEndTimeMS;

	CUITextButton *mUtilityButton;
};


extern void OnSetWhiteBalance( int index );
extern void OnExposureMeterClick( int x, int y );
extern void OnZoomClick( int x, int y );
extern void OnToggleSobel( int x, int y );
extern void OnToggleColorBars( int x, int y );
extern void OnToggleHistogram( int x, int y );
extern void OnToggleLut3D( int x,int y );
extern void OnReset(int x, int y);
extern void OnGuidesClick(int x, int y);
extern void OnFullScreenClick(int x, int y);
extern void OnPlayModeClick(int x, int y);
extern void OnGainMinusClick(int x, int y);
extern void OnGainPlusClick(int x, int y);
extern void OnClickPlayFile(int, int );
extern void OnRecordClick(int, int );
extern void OnSetWhite(int, int );
extern void OnDeleteClip(int, int );
extern void OnSetBlack(int, int );
extern void OnReconnect( int cam );
extern void OnOpenProject(int, int );
extern void OnNewProject(int, int );
extern void OnMetadata( int, int );
extern void OnCamSetupMode( int, int );
extern void OnParallaxShift( int, int );
extern void On3DAlignmentSettings( int, int );
extern void OnFlipCamA( int, int );
extern void OnFlipCamB( int, int );
extern void OnSceneShotTake( int, int );
extern void OnSlatePreview( int, int );
extern void OnLoadLooks(int, int );
extern void OnLoadAsShot( int, int );
extern void OnLoadLookA( int, int );
extern void OnLoadLookB( int, int );
extern void OnLoadLookC( int, int );
extern void OnLoadLookD( int, int );
extern void OnLoadMacros(int, int );
extern void OnLoadDispModes( int, int );
extern void OnSendSerial(int, int );
extern void OnAboutBox(int, int );
extern void OnUpdateFirmware(int, int );
extern void OnExportClip(int, int );
extern void OnExitUtilityMenu(int, int );
extern void OnEnterUtilityMenu(int, int );
extern void OnShutterDialog(int, int );
extern void OnTimecodeDialog(int, int );
extern void OnTimecode2Dialog(int, int );
extern void OnDisplayPrefsDialog( int, int );
extern void OnBlackCalibration( int, int );
extern void OnMulticamMode( int, int );
extern void OnLoadPrefs(int, int );
extern void OnLoadIridas(int, int );
extern void OnIncDisplay3DMode(int, int );
extern void OnIncLeftRightMode(int, int );
extern void OnToggleStatusbarMode( int, int );
extern void OnQuit(int, int );
extern void OnRepairFile( int, int );
extern void OnLoadModes(int, int );
extern void OnSDIModes(int, int );
extern void OnSetWB3200( int, int );
extern void OnSetWB5600( int, int );
extern void OnSetWBUser1( int, int );
extern void OnSetWBUser2( int, int );
extern void OnSetWBNone( int, int );
extern void OnWhiteBalanceAdjust( int, int );
extern void OnPlayStepBack(int,int);
extern void OnPlayFastBack(int,int);
extern void OnPlayPause(int,int);
extern void OnPlayPlay(int,int);
extern void OnPlayFastForward(int,int);
extern void OnPlayStepForward(int,int);
extern void UpdateButtonStates(void);
extern void OnPlayPrevious(int,int);
extern void OnPlayNext(int,int);
extern void OnQualityCtrl( int, int );
extern void SetWB( int newWB );
extern void OnExportClip( int, int );
extern void OnLoadIridasPlay( int, int );
extern void OnLoadClipInfoEditor( int, int );
extern void OnOpenRepairDialog( int, int );
extern void OnDefectivePixelMap( int, int );
extern void OnIncAudioInputLevel( int, int );
extern void OnDecAudioInputLevel( int, int );
extern void OnFullScreenRecClick( int, int );
extern void OnFullScreenPlayClick( int, int );
extern void OnSwitchDiskTimeMeter( int, int );


#endif 