//================================================================
// 2DPanel
//
// - Time panel
//
// AUTHOR:  Gabor Nagy
// DATE:    2024-May-11 00:55:57
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//================================================================
#ifndef _ETimeP_h
#define _ETimeP_h


#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
extern "C" {
#endif

typedef struct EtTimePanel_S  EtTimePanel;

typedef void  (*EtCallbackFunc)(EtTimePanel* PTimePanel, EPointer PCallData, EPointer PClientData);

typedef struct
{
	EtCallbackFunc  Function;
	EPointer        ClientData;
} EtTimePanelCallbackRec;


enum
{
	EtSLIDER_FRAME_INT = 1,
	EtSLIDER_FRAME_DOUBLE,
	EtSLIDER_SECONDS_DOUBLE
};


typedef struct
{
	EIndex   Hours;
	uint8_t  Minutes, Seconds, SubSeconds;  // SubSeconds is 2 digits after the seonds. It may be frames, or 1/100 seconds
} EtTimeCode;


struct EtTimePanel_S
{
	double                   Time, Frame, FramesPerSecond,
	                         StartFrame, EndFrame, FrameStep;
	XeApp                    App;
	XeWidget                 TopMatrixW, CustomMatrixW,
	                         ExtPanelW, FramesPerSecondW,
	                         CustomWidgetsMatrixW,
	                         TimeCodeFrameW, TimeCodeDrawW, TimeCodeRelativeBW,
	                         SliderPanelW,
	                         SliderW, StartFrameW, EndFrameW, FrameStepW,
	                         PlayModeFrameW,
	                         REWBW, BACKBW, STOPBW, PLAYBW, LOOPBW, PLAYPingpongBW, FFBW;

	EList_i32(, EtTimePanelCallbackRec, Callbacks);

	XeIntervalId             TimerId;

	uint8_t                  SliderType;
	uint8_t                  PlayMode;
	EBool                    PanelExtOn, LoopOn, PingpongOn, Paused,
	                         TimeCodeRelative;

	EtTimeCode               TimeCode;

	int                      (*GetTimeCode)(EtTimePanel* PTimePanel, EPointer PCallbackData);  // Callback to get the time code in the TimeCode member
	EPointer                 GetTimeCodeCallbackData;
};


typedef struct
{
	int      Reason;
	uint8_t  PlayMode, PreviousPlayMode;
	double   FramesPerSecond;
	double   Frame, StartFrame, EndFrame, Time;
} EtTimePanelCallbackStruct;


//------------------------
// Play modes
//------------------------
enum
{
	EtSTOP = 0,
	EtPLAY_BACKWARD,
	EtPLAY,
	EtLOOP,
	EtPINGPONG,

	EtPAUSE,
	EtRESUME
};


enum
{
	EtCR_SET_CURRENT_FRAME_BEFORE_SCALE_REDRAW,
	EtCR_SET_CURRENT_FRAME,
	EtCR_SET_START_FRAME,
	EtCR_SET_END_FRAME,
	EtCR_SET_FRAMES_PER_SEC,
	EtCR_SET_PM_TO_STOP,
	EtCR_SET_PM_TO_BACK,
	EtCR_SET_PM_TO_PLAY,
	EtCR_RESET_TIMECODE,
	EtCR_SET_RELATIVE_MODE
};


#define EtPANEL_ON         0x01
#define EtEXT_PANEL_ON     0x02
#define EaFPS              0x04  // Show frames per second TextField after Start/End frame
#define EtCUSTOM_PANEL_ON  0x08  // Create Matrix after FPS and Step widgets for custom widgets

extern void          EtTimePanel_SetPlayMode(EtTimePanel* PTimePanel, const uint8_t PPlayMode);
extern void          EtTimePanel_HideUnhide(EtTimePanel* PTimePanel, const uint16_t PFlags);
extern EtTimePanel*  EtTimePanel_New(const char* PName, XeWidget PParentW,  EArg* PArgs, int PArgCnt,  const double PCurrentFrame, const double PStartFrame, const double PEndFrame, const double PFramesPerSecond,  const char PSliderType,  const uint32_t PFlags);
extern void          EtTimePanel_Free(EtTimePanel* PTimePanel);

extern XeWidget	     EtTimePanel_CreateTimeCodeDisplay(EtTimePanel* PTimePanel, XeWidget PParentW);

extern void          EtTimePanel_AddCallback(EtTimePanel* PTimePanel,  EtCallbackFunc PFunction, EPointer PClientData);

extern void          EtTimePanel_SetTime(EtTimePanel* PTimePanel, const double PFrame, const EBool PNotify);
extern void          EtTimePanel_SetRangeAndTime(EtTimePanel* PTimePanel, const double LStartTime, const double LEndTime, const double PTime, const EBool PNotify);
extern void          EtTimePanel_SetRangeTimeAndFramerate(EtTimePanel* PTimePanel, const double LStartTime, const double LEndTime, const double PTime, const double PFramesPerSecond, const EBool PNotify);



#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
}	// Close scope of 'extern "C"' declaration
#endif

#endif // _ETimeP_h
