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

#include "stdafx.h"
#include "Verbpo.h"
#include "StaticValueTempNormal.h"


// CStaticValueTempNormal
// StaticBPValueNormal.cpp : 实现文件

INT CStaticValueTempNormal::m_i32NormalWidth = 340, CStaticValueTempNormal::m_i32NormalHeight = 115;
INT CStaticValueTempNormal::m_i32BigWidth = 412, CStaticValueTempNormal::m_i32BigHeight = 145;

INT CStaticValueTempNormal::m_i32NormalX = 940, CStaticValueTempNormal::m_i32NormalY = 364;
INT CStaticValueTempNormal::m_i32BigX = 868, CStaticValueTempNormal::m_i32BigY = 256;


COLORREF CStaticValueTempNormal::m_rgbBlink = RGB(255, 140, 64);
COLORREF CStaticValueTempNormal::m_rgbText = RGB(210, 210, 210);

// CStaticValueTempNormal

IMPLEMENT_DYNAMIC(CStaticValueTempNormal, CStatic)

CStaticValueTempNormal::CStaticValueTempNormal()
{
	m_i32Unit = 0;
}

CStaticValueTempNormal::~CStaticValueTempNormal()
{
	font.DeleteObject();
	font.DeleteObject();
	fontResultBig.DeleteObject();
	dcMem.DeleteDC();
	bmp.DeleteObject();

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

int CStaticValueTempNormal::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	//	this->MoveWindow(0, 0, m_i32Width, m_i32Height);
	m_i32Width = CStaticValueTempNormal::m_i32NormalWidth;
	m_i32Height = CStaticValueTempNormal::m_i32NormalHeight;
	m_i32Style = 0;
	// 获得控件区域
	GetClientRect(&m_rectCtrl);
	//客户区DC，可以绘画及显示
	CClientDC pDC(this);
	//依附窗口DC创建兼容内存DC
	dcMem.CreateCompatibleDC(&pDC);
	//创建兼容位图
	bmp.CreateCompatibleBitmap(&pDC, CStaticValueTempNormal::m_i32BigWidth, CStaticValueTempNormal::m_i32BigHeight);
	dcMem.SelectObject(&bmp); //将位图选择进内存DC
	dcMem.FillSolidRect(0, 0, CStaticValueTempNormal::m_i32BigWidth, CStaticValueTempNormal::m_i32BigHeight, RGB(0, 0, 0));

	dcMem.FillSolidRect(0, 0, 2, CStaticValueTempNormal::m_i32NormalHeight, RGB(0, 0, 0));
	//dcMem.FillSolidRect(1200, 0, 2, 160, RGB(30, 200, 160));
	dcMem.FillSolidRect(70, 0, CStaticValueTempNormal::m_i32NormalWidth, 2, RGB(0, 0, 0));
	dcMem.FillSolidRect(0, CStaticValueTempNormal::m_i32NormalHeight - 2, CStaticValueTempNormal::m_i32NormalWidth, 2, RGB(0, 0, 0));

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

	fontResult.CreateFont(72,                                          //   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(100,                                          //   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(CStaticValueTempNormal::m_rgbText);
	dcMem.TextOut(5, 0, _T("体温"));

	m_i32Blink = 0;
	m_i32AlmFlag = 0;
	//	return CStatic::OnCreate(lpCreateStruct);
	return TRUE;
}




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



// CStaticValueTempNormal 消息处理程序


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

BOOL CStaticValueTempNormal::OnEraseBkgnd(CDC* pDC)
{

	return TRUE;
}



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

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

// 设置温度
int CStaticValueTempNormal::set_temp(INT16 t, UINT8 redraw)
{
	float f;
	CString a_cs;
	if ((m_i16Temp != t) || (redraw))
	{
		// 设置血氧饱和度
		m_i16Temp = t;


		if (t == CData::m_i16TempInvalidValue)
		{
			//-100代表无效值
			a_cs.Format(_T("%s"), _T("---"));
		}
		else
		{
			f = t;
			f = f / 10.0;
			a_cs.Format(_T("%2.1f"), f);
		}

		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(4, 30, 180, 70, RGB(0, 0, 0));
			dcMem.SelectObject(&fontResult);
			dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
			dcMem.TextOut(4, 30, a_cs);
		}
		else
		{
			dcMem.FillSolidRect(4, 40, 210, 100, RGB(0, 0, 0));
			dcMem.SelectObject(&fontResultBig);
			dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
			dcMem.TextOut(4, 40, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}


// 设置温度上限
int CStaticValueTempNormal::set_temp_alm_H(INT16 h, UINT8 redraw)
{
	float f;
	CString a_cs;
	if ((m_i16TempH != h) || (redraw))
	{
		// 设置血氧饱和度上限
		m_i16TempH = h;

		f = h;
		f = f / 10.0;
		a_cs.Format(_T("%2.1f"), f);

		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(190, 35, 61, 30, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
			dcMem.TextOut(190, 35, a_cs);
		}
		else
		{
			dcMem.FillSolidRect(235, 40, 61, 30, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
			dcMem.TextOut(235, 40, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}


// 设置体温下限
int CStaticValueTempNormal::set_temp_alm_L(INT16 l, UINT8 redraw)
{
	float f;
	CString a_cs;
	if ((m_i16TempL != l) || (redraw))
	{
		// 设置血氧饱和度下限
		m_i16TempL = l;

		f = l;
		f = f / 10.0;
		a_cs.Format(_T("%2.1f"), f);

		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(190, 70, 61, 30, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
			dcMem.TextOut(190, 70, a_cs);

		}
		else
		{
			dcMem.FillSolidRect(235, 80, 61, 30, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
			dcMem.TextOut(235, 80, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}


// 设置体温单位
int CStaticValueTempNormal::set_temp_unit(INT16 u, UINT8 redraw)
{
	CString a_cs;
	if ((m_i16Unit != u) || (redraw))
	{
		m_i16Unit = u;
		if (u)
		{
			a_cs = _T("F");
			m_i32Unit = u;
		}
		else
		{
			a_cs = _T("C");
			m_i32Unit = u;
		}

		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(280, 70, 51, 30, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
			dcMem.TextOut(280, 70, a_cs);
		}
		else
		{
			dcMem.FillSolidRect(320, 80, 51, 30, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
			dcMem.TextOut(320, 80, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}


// 闪烁
void CStaticValueTempNormal::Blink()
{
	if (m_i32Blink)
	{
		m_i32BlinkNum++;
		//if (m_i32Style == 0)
		{
			if (m_i32BlinkNum & 1)
			{
				dcMem.FillSolidRect(0, 0, 2, m_i32Height, CStaticValueTempNormal::m_rgbText);
				//dcMem.FillSolidRect(1200, 0, 2, 160, CStaticValueECGNormal::m_rgbText);
				dcMem.FillSolidRect(70, 0, m_i32Width, 2, CStaticValueTempNormal::m_rgbText);
				dcMem.FillSolidRect(0, m_i32Height - 2, m_i32Width, m_i32Height, CStaticValueTempNormal::m_rgbText);
			}
			else
			{
				dcMem.FillSolidRect(0, 0, 2, m_i32Height, CStaticValueTempNormal::m_rgbBlink);
				//dcMem.FillSolidRect(1200, 0, 2, 160, CStaticValueECGNormal::m_rgbText);
				dcMem.FillSolidRect(70, 0, m_i32Width, 2, CStaticValueTempNormal::m_rgbBlink);
				dcMem.FillSolidRect(0, m_i32Height - 2, m_i32Width, m_i32Height, CStaticValueTempNormal::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 CStaticValueTempNormal::Redraw()
{
	if (m_i32ReDraw == 1)
	{
		m_i32ReDraw = 0;
		Invalidate(1);
	}
}

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


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

	if (m_i32Style == 0)
	{
		dcMem.FillSolidRect(0, 0, CStaticValueTempNormal::m_i32NormalWidth, CStaticValueTempNormal::m_i32NormalHeight, RGB(0, 0, 0));
		dcMem.FillSolidRect(5, 0, 40, 20, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
		dcMem.TextOut(5, 0, _T("体温"));
		m_i32Width = CStaticValueTempNormal::m_i32NormalWidth;
		m_i32Height = CStaticValueTempNormal::m_i32NormalHeight;
	}
	else
	{
		dcMem.FillSolidRect(0, 0, CStaticValueTempNormal::m_i32BigWidth, CStaticValueTempNormal::m_i32BigHeight, RGB(0, 0, 0));
		dcMem.FillSolidRect(5, 0, 40, 20, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(CStaticValueTempNormal::m_rgbText);
		dcMem.TextOut(5, 0, _T("体温"));
		m_i32Width = CStaticValueTempNormal::m_i32BigWidth;
		m_i32Height = CStaticValueTempNormal::m_i32BigHeight;
	}

	// 设置温度
	set_temp(m_i16Temp, 1);
	// 设置温度上限
	set_temp_alm_H(m_i16TempH, 1);
	// 设置体温下限
	set_temp_alm_L(m_i16TempL, 1);
	// 设置体温单位
	set_temp_unit(m_i16Unit, 1);
	Set_AlmFlag(m_i32AlmFlag, 1);
	UpdateWindow();
}

//设置、绘制报警开关标识
void CStaticValueTempNormal::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;
	}
}