// StaticValueRespNormal.cpp : 实现文件
//

#include "stdafx.h"
#include "Verbpo.h"
#include "StaticValueRespNormal.h"

INT CStaticValueRespNormal::m_i32NormalWidth = 190, CStaticValueRespNormal::m_i32NormalHeight = 145;
INT CStaticValueRespNormal::m_i32BigWidth = 230, CStaticValueRespNormal::m_i32BigHeight = 182;

INT CStaticValueRespNormal::m_i32NormalX = 940, CStaticValueRespNormal::m_i32NormalY = 598;
INT CStaticValueRespNormal::m_i32BigX = 868, CStaticValueRespNormal::m_i32BigY = 561;


COLORREF CStaticValueRespNormal::m_rgbBlink = RGB(255, 140, 64);
COLORREF CStaticValueRespNormal::m_rgbText = RGB(220, 220, 10);

// CStaticValueRespNormal

IMPLEMENT_DYNAMIC(CStaticValueRespNormal, CStatic)

CStaticValueRespNormal::CStaticValueRespNormal()
{

}

CStaticValueRespNormal::~CStaticValueRespNormal()
{
	font.DeleteObject();
	font.DeleteObject();

	dcMem.DeleteDC();
	bmp.DeleteObject();

	bitmapAlm.DeleteObject();
	dcMemAlm.DeleteDC();
}

int CStaticValueRespNormal::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	//	this->MoveWindow(0, 0, m_i32Width, m_i32Height);
	// 获得控件区域
	m_i32Width = CStaticValueRespNormal::m_i32NormalWidth;
	m_i32Height = CStaticValueRespNormal::m_i32NormalHeight;
	m_i32Style = 0;

	GetClientRect(&m_rectCtrl);
	//客户区DC，可以绘画及显示
	CClientDC pDC(this);
	//依附窗口DC创建兼容内存DC
	dcMem.CreateCompatibleDC(&pDC);
	//创建兼容位图
	bmp.CreateCompatibleBitmap(&pDC, CStaticValueRespNormal::m_i32BigWidth, CStaticValueRespNormal::m_i32BigHeight);
	dcMem.SelectObject(&bmp); //将位图选择进内存DC
	dcMem.FillSolidRect(0, 0, CStaticValueRespNormal::m_i32BigWidth, CStaticValueRespNormal::m_i32BigHeight, RGB(0, 0, 0));

	dcMem.FillSolidRect(0, 0, 2, CStaticValueRespNormal::m_i32NormalHeight, RGB(0, 0, 0));
	dcMem.FillSolidRect(CStaticValueRespNormal::m_i32NormalWidth - 2, 0, CStaticValueRespNormal::m_i32NormalWidth, CStaticValueRespNormal::m_i32NormalHeight, RGB(0, 0, 0));
	dcMem.FillSolidRect(70, 0, CStaticValueRespNormal::m_i32NormalWidth, 2, RGB(0, 0, 0));
	dcMem.FillSolidRect(0, CStaticValueRespNormal::m_i32NormalHeight - 3, CStaticValueRespNormal::m_i32NormalWidth, CStaticValueRespNormal::m_i32NormalHeight - 1, RGB(0, 0, 0));

	bitmapAlm.LoadBitmap(IDB_BITMAP_ALM);
	dcMemAlm.CreateCompatibleDC(&pDC);
	dcMemAlm.SelectObject(&bitmapAlm);

	fontResult.CreateFont(80,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		FALSE,                                           //   bItalic     
		FALSE,                                           //   bUnderline     
		0,                                                   //   cStrikeOut     
		ANSI_CHARSET,                             //   nCharSet     
		OUT_DEFAULT_PRECIS,                 //   nOutPrecision     
		CLIP_DEFAULT_PRECIS,               //   nClipPrecision     
		DEFAULT_QUALITY,                       //   nQuality     
		DEFAULT_PITCH | FF_SWISS,     //   nPitchAndFamily       
		_T("宋体"));

	fontResultBig.CreateFont(90,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		FALSE,                                           //   bItalic     
		FALSE,                                           //   bUnderline     
		0,                                                   //   cStrikeOut     
		ANSI_CHARSET,                             //   nCharSet     
		OUT_DEFAULT_PRECIS,                 //   nOutPrecision     
		CLIP_DEFAULT_PRECIS,               //   nClipPrecision     
		DEFAULT_QUALITY,                       //   nQuality     
		DEFAULT_PITCH | FF_SWISS,     //   nPitchAndFamily       
		_T("宋体"));

	font.CreateFont(24,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		FALSE,                                           //   bItalic     
		FALSE,                                           //   bUnderline     
		0,                                                   //   cStrikeOut     
		ANSI_CHARSET,                             //   nCharSet     
		OUT_DEFAULT_PRECIS,                 //   nOutPrecision     
		CLIP_DEFAULT_PRECIS,               //   nClipPrecision     
		DEFAULT_QUALITY,                       //   nQuality     
		DEFAULT_PITCH | FF_SWISS,     //   nPitchAndFamily       
		_T("宋体"));

	dcMem.FillSolidRect(5, 0, 40, 20, RGB(0, 0, 0));
	dcMem.SelectObject(&font);
	dcMem.SetTextColor(CStaticValueRespNormal::m_rgbText);
	dcMem.TextOut(5, 0, _T("呼吸"));

	dcMem.FillSolidRect(140, 110, 40, 32, RGB(0, 0, 0));
	dcMem.SelectObject(&font);
	dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));
	dcMem.TextOut(140, 110, _T("RPM"));
	m_i32BlinkNum = 0;
	m_i32Blink = 0;
	m_i32AlmFlag = 0;
	//	return CStatic::OnCreate(lpCreateStruct);
	return TRUE;
}



BEGIN_MESSAGE_MAP(CStaticValueRespNormal, CStatic)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_CREATE()
	ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()



// CStaticValueRespNormal 消息处理程序

void  CStaticValueRespNormal::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	this->GetParent()->PostMessage(WM_STATIC_VALUE_RESP_NORMAL_DBLCLK, 0, 0);
}

BOOL CStaticValueRespNormal::OnEraseBkgnd(CDC* pDC)
{

	return TRUE;
}

void CStaticValueRespNormal::OnPaint()
{
	CPaintDC pDC(this);

	pDC.BitBlt(0, 0, m_i32Width, m_i32Height, &dcMem, 0, 0, SRCCOPY);
	//	CStatic::OnPaint();
}

// CStaticValueRespNormal 消息处理程序




// 设置呼吸律
int CStaticValueRespNormal::set_RR(INT16 r, UINT8 redraw)
{
	CString a_cs;
	if ((m_i16RR != r) || (redraw))
	{
		m_i16RR = r;
		if (r == CData::m_i16RRInvalidValue)
		{
			//-100代表无效值
			a_cs.Format(_T("%s"), _T("---"));
		}
		else
		{
			if (r < 0)
				r = 0;
			else if (r>150)
				r = 150;

			a_cs.Format(_T("%d"), r);
		}

		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(4, 45, 131, 81, RGB(0, 0, 0));

			dcMem.SelectObject(&fontResult);
			dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));
			dcMem.TextOut(4, 45, a_cs);
		}
		else
		{
			dcMem.FillSolidRect(15, 75, 131, 81, RGB(0, 0, 0));

			dcMem.SelectObject(&fontResultBig);
			dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));
			dcMem.TextOut(15, 75, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}


// 设置呼吸率上限
int CStaticValueRespNormal::set_resp_alm_H(INT16 h, UINT8 redraw)
{
	CString a_cs;
	if ((m_i16RRH != h) || (redraw))
	{
		m_i16RRH = h;
		if (h < 0)
			h = 0;
		else if (h>100)
			h = 100;

		a_cs.Format(_T("%d"), h);


		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(140, 30, 40, 32, RGB(0, 0, 0));

			dcMem.SelectObject(&font);
			dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));
			dcMem.TextOut(140, 30, a_cs);
		}
		else
		{
			dcMem.FillSolidRect(160, 30, 40, 32, RGB(0, 0, 0));

			dcMem.SelectObject(&font);
			dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));
			dcMem.TextOut(160, 30, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}


// 设置呼吸率下限
int CStaticValueRespNormal::set_resp_alm_L(INT16 l, UINT8 redraw)
{
	CString a_cs;
	if ((m_i16RRL != l) || (redraw))
	{
		m_i16RRL = l;

		if (l < 0)
			l = 0;
		else if (l>100)
			l = 100;

		a_cs.Format(_T("%d"), l);

		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(140, 70, 40, 32, RGB(0, 0, 0));

			dcMem.SelectObject(&font);
			dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));
			dcMem.TextOut(140, 70, a_cs);
		}
		else
		{
			dcMem.FillSolidRect(160, 70, 40, 32, RGB(0, 0, 0));

			dcMem.SelectObject(&font);
			dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));
			dcMem.TextOut(160, 70, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}


// 闪烁
void CStaticValueRespNormal::Blink()
{
	if (m_i32Blink)
	{
		m_i32BlinkNum++;
		//if (m_i32Style == 0)
		{
			if (m_i32BlinkNum & 1)
			{
				dcMem.FillSolidRect(0, 0, 2, m_i32Height, CStaticValueRespNormal::m_rgbText);
				//dcMem.FillSolidRect(1200, 0, 2, 160, CStaticValueECGNormal::m_rgbText);
				dcMem.FillSolidRect(70, 0, m_i32Width, 2, CStaticValueRespNormal::m_rgbText);
				dcMem.FillSolidRect(0, m_i32Height - 2, m_i32Width, m_i32Height, CStaticValueRespNormal::m_rgbText);
			}
			else
			{
				dcMem.FillSolidRect(0, 0, 2, m_i32Height, CStaticValueRespNormal::m_rgbBlink);
				//dcMem.FillSolidRect(1200, 0, 2, 160, CStaticValueECGNormal::m_rgbText);
				dcMem.FillSolidRect(70, 0, m_i32Width, 2, CStaticValueRespNormal::m_rgbBlink);
				dcMem.FillSolidRect(0, m_i32Height - 2, m_i32Width, m_i32Height, CStaticValueRespNormal::m_rgbBlink);
			}
		}

	}
	else
	{
		m_i32BlinkNum = 0;


		dcMem.FillSolidRect(0, 0, 2, m_i32Height, RGB(0, 0, 0));
		//dcMem.FillSolidRect(1200, 0, 2, 160, CStaticValueECGNormal::m_rgbText);
		dcMem.FillSolidRect(70, 0, m_i32Width, 2, RGB(0, 0, 0));
		dcMem.FillSolidRect(0, m_i32Height - 2, m_i32Width, m_i32Height, RGB(0, 0, 0));


	}
	m_i32ReDraw = 1;
}

// 重画
void CStaticValueRespNormal::Redraw()
{
	if (m_i32ReDraw == 1)
	{
		m_i32ReDraw = 0;
		Invalidate(1);
	}
}

void CStaticValueRespNormal::Set_Blink(int Blink)
{
	m_i32Blink = Blink;
	//m_i32BlinkNum = 0;
}



void CStaticValueRespNormal::Set_Style(INT style)
{
	m_i32Style = style;


	if (m_i32Style == 0)
	{
		dcMem.FillSolidRect(0, 0, CStaticValueRespNormal::m_i32NormalWidth, CStaticValueRespNormal::m_i32NormalHeight, RGB(0, 0, 0));
		dcMem.FillSolidRect(5, 0, 40, 20, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));

		dcMem.FillSolidRect(5, 0, 40, 20, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(CStaticValueRespNormal::m_rgbText);
		dcMem.TextOut(5, 0, _T("呼吸"));

		dcMem.FillSolidRect(140, 110, 40, 32, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));
		dcMem.TextOut(140, 110, _T("RPM"));

		m_i32Width = CStaticValueRespNormal::m_i32NormalWidth;
		m_i32Height = CStaticValueRespNormal::m_i32NormalHeight;
	}
	else
	{
		dcMem.FillSolidRect(0, 0, CStaticValueRespNormal::m_i32BigWidth, CStaticValueRespNormal::m_i32BigHeight, RGB(0, 0, 0));
		dcMem.FillSolidRect(5, 0, 40, 20, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));

		dcMem.FillSolidRect(5, 0, 40, 20, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(CStaticValueRespNormal::m_rgbText);
		dcMem.TextOut(5, 0, _T("呼吸"));

		dcMem.FillSolidRect(160, 120, 40, 32, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(RGB(0xEE, 0xEE, 0x62));
		dcMem.TextOut(160, 120, _T("RPM"));

		m_i32Width = CStaticValueRespNormal::m_i32BigWidth;
		m_i32Height = CStaticValueRespNormal::m_i32BigHeight;
	}

	// 设置呼吸律
	set_RR(m_i16RR, 1);
	// 设置呼吸率上限
	set_resp_alm_H(m_i16RRH, 1);
	// 设置呼吸率下限
	set_resp_alm_L(m_i16RRL, 1);
	Set_AlmFlag(m_i32AlmFlag, 1);
	UpdateWindow();
}

//设置、绘制报警开关标识
void CStaticValueRespNormal::Set_AlmFlag(INT a, UINT8 redraw)
{

	if ((m_i32AlmFlag != a) || (redraw))
	{
		m_i32AlmFlag = a;
		if (m_i32Style == 0)
		{
			if (a)
				dcMem.FillSolidRect(70, 0, 30, 30, RGB(0, 0, 0));
			else
				dcMem.BitBlt(70, 0, 30, 30, &dcMemAlm, 0, 0, SRCCOPY);
		}
		else
		{
			if (a)
				dcMem.FillSolidRect(70, 0, 30, 30, RGB(0, 0, 0));
			else
				dcMem.BitBlt(70, 0, 30, 30, &dcMemAlm, 0, 0, SRCCOPY);
		}

		m_i32ReDraw = 1;
	}
}