#ifndef EVENTSHOW_H_
#define EVENTSHOW_H_

#include "gType.h" 
#include "GraphBase.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "my_string.h"
#include "Device.h"
#include "EpDevice.h"
#include "StaticText.h"
#include "MainCtl.h"

#include "Runtime.h"
//#include "ControlCenter.h"

typedef union{
	unsigned int D32[6];
	unsigned char D8[24];
	struct {
		unsigned int   LD32;
		unsigned short HD16;
		unsigned short Rsv0;
		unsigned short Rsv1;
		unsigned short Rsv2;
	}DateTime;
	struct{
		unsigned char Second;
		unsigned char Minute;
		unsigned char Hour;	
		unsigned char Day;
		
		unsigned char Month;
		unsigned char Year;
		unsigned char iByte0;		
		unsigned char State;
		
		unsigned char PCtlNum;
		unsigned char P0;
		unsigned char P1;
		unsigned char P2;
		
		unsigned char mType;
		unsigned char dType;
		unsigned char Data0;
		unsigned char Data1;
		
		unsigned int UserCode;
		unsigned short AreaNum;
		unsigned short DumpShort;
	}Splite;	
}TieMsg;

typedef struct{
	short Left;
	short Top;
	short Width;
	short Height;
	short Right;
	short Bottom;
}TRectEvTitleTop, TRectEvTitleBottom, TRectVertScrrolBar;

typedef struct{
	short Left[5];
	short Top[5];
	short Width[5];
	short Height[5];
	short Right[5];
	short Bottom[5];
}TRectEvEntry;

typedef struct{
	short Left[2];
	short Top[2];
	short Width[2];
	short Height[2];
	short Right[2];
	short Bottom[2];
}TRectEvEntryTop, TRectEvEntryBottom;

class TEventShow{
	public:
		static constexpr unsigned int ColorTitle	= 0xFFA3918F;
		static constexpr unsigned int ColorTitleInSelected = clDeepBlue;
		static constexpr unsigned int ColorTitleFireNotOnSelected = 0xFF783030;
		static constexpr unsigned int ColorTitleText = clNearWhite;
		static constexpr unsigned int ColorBg = clDarkkGray;
		static constexpr TRectEvTitleTop	RectTitleTop ={
			.Left = 2,
			.Top = 46,
			.Width = 652,
			.Height = 40,
			.Right = 2 + 652 -1,
			.Bottom = 46 + 40 -1,
		};
		static constexpr TRectEvTitleBottom RectTitleBtm ={
			.Left = 2,
			.Top = 248,
			.Width = 710,
			.Height = 40,
			.Right = 2 + 710 -1,
			.Bottom = 248 + 40 -1,
		};
		static constexpr TRectVertScrrolBar RectVertScrrolBar ={
			.Left = 776,
			.Top = 80,
			.Width = 20,
			.Height = 360,
			.Right = 776 + 20 -1,
			.Bottom = 80 + 360 -1,
		};
		static constexpr TRectEvEntry RectEvEntryList = {
			.Left[0] =10,
			.Left[1] =10,
			.Left[2] =10,
			.Left[3] =10,
			.Left[4] =10,
			.Top[0] = 90 + 50 * 0,
			.Top[1] = 90 + 50 * 1,
			.Top[2] = 90 + 50 * 2,
			.Top[3] = 90 + 50 * 3,
			.Top[4] = 90 + 50 * 4,
			.Width[0] = 760,
			.Width[1] = 760,
			.Width[2] = 760,
			.Width[3] = 760,
			.Width[4] = 760,
			.Height[0] = 40,
			.Height[1] = 40,
			.Height[2] = 40,
			.Height[3] = 40,
			.Height[4] = 40,
			.Right[0] = 10 + 760 -1,
			.Right[1] = 10 + 760 -1,
			.Right[2] = 10 + 760 -1,
			.Right[3] = 10 + 760 -1,
			.Right[4] = 10 + 760 -1,
			.Bottom[0] = 90 + 50 * 0 + 40 -1,
			.Bottom[1] = 90 + 50 * 1 + 40 -1,
			.Bottom[2] = 90 + 50 * 2 + 40 -1,
			.Bottom[3] = 90 + 50 * 3 + 40 -1,
			.Bottom[4] = 90 + 50 * 4 + 40 -1,
		};
		static constexpr TRectEvEntryTop RectEvEntryTopList = {
			.Left[0] =10,
			.Left[1] =10,
			.Top[0] = 90 + 50 * 0,
			.Top[1] = 90 + 50 * 1,
			.Width[0] = 760,
			.Width[1] = 760,
			.Height[0] = 40,
			.Height[1] = 40,
			.Right[0] = 10 + 760 -1,
			.Right[1] = 10 + 760 -1,
			.Bottom[0] = 90 + 50 * 0 + 40 -1,
			.Bottom[1] = 90 + 50 * 1 + 40 -1,
		};
		static constexpr TRectEvEntryBottom RectEvEntryBtmList = {
			.Left[0] =10,
			.Left[1] =10,
			.Top[0] = 280 + 50 * 0,
			.Top[1] = 280 + 50 * 1,
			.Width[0] = 760,
			.Width[1] = 760,
			.Height[0] = 40,
			.Height[1] = 40,
			.Right[0] = 10 + 760 -1,
			.Right[1] = 10 + 760 -1,
			.Bottom[0] = 280 + 50 * 0 + 40 -1,
			.Bottom[1] = 280 + 50 * 1 + 40 -1,
		};

	public:
		
		unsigned int IsShowing;
		TStaticText Caption, SText;
		TRect Bound;
		TRect Content;
		TRect ContentUp;
		TRect ContentDown;
	
		short SelectedCol;
		short SelectedUpCol;
		short SelectedDownCol;
	
		unsigned int Color;
		
		unsigned int LinkDelayLineBClr[2];
		struct{
			int RefrashIndex;
			int ShowingIndex;
			int IsListUpdata;
			int StartCount;
			int FbCount;
			int DelayCount;
			int StopCount;
			int Count;
			int NewCount;
			int TopIndex;
			int ReqTopIndex;
			int BlankLine;
			int ShowRemainCnt;
			int TailRemain;
			int SelectedLine;
			int SelectedIndex;
			TieMsg  Body[10];
		}MsgList[5];
		TieMsg  MsgBuf[10];
		TieMsg  MsgBuf4OneDelay;
		short WhatSelected;
		unsigned char IsUpdata;
		unsigned char LastDrawSplite;
		unsigned char NoKeyInTick500mS;
		unsigned char NoNewEventTick500mS;
		
		unsigned char FirstFireHadDraw;
		unsigned char OutLineType;
		unsigned char IsOutlineChange;
		unsigned char Tick1000MsRdy;
		
		//struct{
		//	int Count;
		//	unsigned int 	Path[1000];
		//	unsigned char 	TimeSec[1000];
		//}StartCountDownList;
		
		//unsigned int TmpPath[1000];
		//unsigned char TmpTimeSec[1000];
		
		char Text[128];
		int NeedShowDescp;
		char TextDescp[128];
		char cText[128];
		int AutoRollTick;
		int IsShouldReturn;
		unsigned int DrawListNotDone[5];
		
		struct{
			unsigned int ManualType;
			unsigned int mType;
			unsigned int SubType;
			unsigned int aPath;
		}ConfirmMsg;
		
		unsigned char IsGoReset;
		unsigned char GoResetTick;
		int NoOpaUd[5];
		int FirstFireShowDescpInteval;
		union{
			unsigned int D32[16];
			char Text[64];
		}DescpText;
		unsigned int GolbalDelayValueOnShowing;
	private:
		const char *CapString[8];
		const char *CapStringDown[8];
		TDateTimeBytes DateTimeCovered;
	public:
		TEventShow(){};
		void Init(int x1, int y1, int aW, int aH, int OwnerX, int OwnerY, int BoderW, u32 aColor);
		
		void DrawSelf();	
		void FillText(unsigned char aWhat, unsigned int aIndex, unsigned int aLineNum);
		void FillTextEn(unsigned char aWhat, unsigned int aIndex, unsigned int aLineNum);
		void Show();
		void Hide();
			
		void CoverDateTimeIllegal(TieMsg Src, TDateTimeBytes *Dst);
		void CoverDateTimeIllegal(TEventMsg Src, TDateTimeBytes *Dst);
			
		void DrawOutLineAll();
		void DrawOutLineUpDown();
		void DrawAll();
		void DrawUp();
		void DrawDown();
			
		void DrawListUp();
		void DrawListDown();
		void DrawListAll();
		void DrawFirstFire();
		
		void DrawFig();
		void DrawListHeader();
		void DrawList();
		void DrawListFullRedraw(void);
		void AutoRollShow();
		void ShowCountDownTime();
		
		void MsgReset();
			
		int TryGetFireData(int GetListMode, int aInx);
		int TryGetFaultData(int GetListMode, int aInx);
		int TryGetSvData(int GetListMode, int aInx);
		int TryGetLinkageData(int GetListMode, int aInx);
		int TryGetMaskData(int GetListMode, int aInx);		
		
		void Task100Ms(void);
		int Task1000Ms(void);
			
		void TryFireGetNext(int IsForce);
		void TryLinkageGetNext(int IsForce);
		void TrySvGetNext(int IsForce);
		void TryFaultGetNext(int IsForce);
		void TryMaskGetNext(int IsForce);
		
		TGuiMsgReturn KeyIn(unsigned char aKey);
		void KeyJab();
		
		void CalcSelectedIndex(int aWhat);
		
		void ReNewTopIndex(short aIdx);
		int ManageState();
		
		int MakeFastCheck();
		
		void MakeShow();
		void ShowTask();
		
		int DoNoEvent();
		int DoNoOperate();
		int DoOperate();
		void CheckReturn();
		
		void MsgStartAddCountDownItem(unsigned int Path);
		void ManageStartCountDown();
		
		void StartToResetPrc();
		
		void FirstFireFillDescp();
		
		void MakeDelay180Sec();
		
		void ShowGolbalDelayTime();
		
		int ExtRequst(unsigned char Prm);
};


















#endif
