#pragma once

#include "Data.h"



// CThreadDataAlmRec

class CThreadDraw : public CWinThread
{
	DECLARE_DYNCREATE(CThreadDraw)

protected:
	CThreadDraw();         
	virtual ~CThreadDraw();

public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();
	virtual int Run();
	INT m_i32Init;
	int m_i32Exit;
	void init_dc(CDC* pDC);
	//尝试将绘制趋势共存图拷贝出来
	INT try_copy_dc(CDC* pDC);
	void Erase();
	//添加绘制趋势共存图所用的数据
	void add_data(UINT8 *wave, INT l, INT16 rr, INT16 hr, INT16 spo2);
	//切换趋势共存图的显示方式 呼吸波 呼吸率
	void show_change(INT a);
	//切换趋势共存图的时间
	void time_change(INT a);
	//绘制趋势共存图
	void draw();
private:
	CCriticalSection m_csDC;
	
	INT m_i32DrawFlag;
	INT m_i32Redraw;
	CDC dcMem; //用于缓冲作图的内存DC 
	CBitmap bmp;

	//趋势共存图 显示方式为呼吸率 的背景
	CDC dcMemBK; //用于缓冲作图的内存DC 
	CBitmap bmpBK;
	//趋势共存图 显示方式为呼吸波 的背景
	CDC dcMemBK2; //用于缓冲作图的内存DC 
	CBitmap bmpBK2;
	CCriticalSection m_csShow;
	INT m_i32Show;
	INT m_i32Time;
	CFont font;
	CFont fontSet;



	CPen *penECGLine;
	CPen *penRespLine;
	CPen *penSpo2Line;
	CPen *penBK, *penGrid;
	INT16 *m_pi16HRBuf;
	INT m_i32HRBufW, m_i32HRBufR, m_i32HRBufL;
	INT16 *m_pi16Spo2;
	INT m_i32Spo2BufW, m_i32Spo2BufR, m_i32Spo2BufL;
	INT16 *m_pi16RR;
	INT m_i32RRBufW, m_i32RRBufR, m_i32RRBufL;
	UINT16 m_u16HRNum;
	CPoint *m_pCPonit;
	INT16 *m_pRespWaveBuff1;
	INT m_i32RespWaveBuffW1, m_i32RespWaveBuffR1, m_i32RespWaveBuffL1;
	INT16 *m_pRespWaveBuff2;
	INT m_i32RespWaveBuffW2, m_i32RespWaveBuffR2, m_i32RespWaveBuffL2;
	UINT16 m_u16RespWaveSum, m_u16RespWaveNum;


	INT16 *m_pi16HRAddBuf;
	INT m_i32HRAddBufW, m_i32HRAddBufR, m_i32HRAddBufL;
	INT16 *m_pi16Spo2AddBuf;
	INT m_i32Spo2AddBufW, m_i32Spo2AddBufR, m_i32Spo2AddBufL;
	INT16 *m_pi16RRAddBuf;
	INT m_i32RRAddBufW, m_i32RRAddBufR, m_i32RRAddBufL;
	INT16 *m_pRespWaveAddBuff1;
	INT m_i32RespWaveAddBuffW1, m_i32RespWaveAddBuffR1, m_i32RespWaveAddBuffL1;
	INT16 *m_pRespWaveAddBuff2;
	INT m_i32RespWaveAddBuffW2, m_i32RespWaveAddBuffR2, m_i32RespWaveAddBuffL2;
	

	void get_data();
	//绘制呼吸波形
	void Draw_Wave();
	//趋势共存图 绘制 心律
	void Draw_HR();
	//趋势共存图 绘制 血氧饱和度
	void Draw_Spo2();
	//趋势共存图 绘制 呼吸率
	void Draw_RR();
	//绘制时间轴
	void Draw_Time();
protected:
	DECLARE_MESSAGE_MAP()

	
};


