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

#include "stdafx.h"
#include "Verbpo.h"
#include "StaticValueFANormal.h"


INT CStaticValueFANormal::m_i32NormalWidth = 150, CStaticValueFANormal::m_i32NormalHeight = 145;
INT CStaticValueFANormal::m_i32BigWidth = 182, CStaticValueFANormal::m_i32BigHeight = 182;

INT CStaticValueFANormal::m_i32NormalX = 1130, CStaticValueFANormal::m_i32NormalY = 598;
INT CStaticValueFANormal::m_i32BigX = 1099, CStaticValueFANormal::m_i32BigY = 561;





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


// CStaticValueFANormal

IMPLEMENT_DYNAMIC(CStaticValueFANormal, CStatic)

CStaticValueFANormal::CStaticValueFANormal()
{

}

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

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

int CStaticValueFANormal::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	//	this->MoveWindow(0, 0, m_i32Width, m_i32Height);
	m_i32Width = CStaticValueFANormal::m_i32NormalWidth;
	m_i32Height = CStaticValueFANormal::m_i32NormalHeight;
	m_i32Style = 0;

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

	//清除所有图像
	dcMem.FillSolidRect(0, 0, CStaticValueFANormal::m_i32BigWidth, CStaticValueFANormal::m_i32BigHeight, RGB(0, 0, 0));


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

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

	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("宋体"));
	fontResult.CreateFont(64,                                          //   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(CStaticValueFANormal::m_rgbText);
	dcMem.TextOut(5, 0, _T("空氧"));

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

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



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



// CStaticValueFANormal 消息处理程序

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

BOOL CStaticValueFANormal::OnEraseBkgnd(CDC* pDC)
{

	return TRUE;
}

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

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

// CStaticValueFANormal 消息处理程序




// 设置氧浓度值
int CStaticValueFANormal::set_FiO(INT16 f, UINT8 redraw)
{
	CString a_cs;
	if ((m_i16AirOxy != f) || (redraw))
	{
		// 设置氧浓度
		m_i16AirOxy = f;
		if (f == CData::m_i16AirOxyInvalidValue)
		{
			//-100代表无效值
			a_cs.Format(_T("%s"), _T("---"));
		}
		else
		{
			if (f < 0)
				f = 0;
			else if (f>100)
				f = 100;
			a_cs.Format(_T("%d"), f);
		}
	

		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(4, 45, 100, 71, RGB(0, 0, 0));
			dcMem.SelectObject(&fontResult);
			dcMem.SetTextColor(RGB(0xDD, 0xDD, 0xEE));
			dcMem.TextOut(4, 45, a_cs);
		}
		else
		{
			dcMem.FillSolidRect(4, 75, 130, 80, RGB(0, 0, 0));
			dcMem.SelectObject(&fontResultBig);
			dcMem.SetTextColor(RGB(0xDD, 0xDD, 0xEE));
			dcMem.TextOut(4, 75, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}

// 设置呼吸率上限
int CStaticValueFANormal::set_AirOxy_alm_H(INT16 h, UINT8 redraw)
{
	CString a_cs;
	if ((m_i16AirOxyH != h) || (redraw))
	{
		// 设置氧浓度上限
		m_i16AirOxyH = h;

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

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

		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(110, 30, 40, 32, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(RGB(0xDD, 0xDD, 0xEE));
			dcMem.TextOut(110, 30, a_cs);
		}
		else
		{
			dcMem.FillSolidRect(140, 45, 40, 32, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(RGB(0xDD, 0xDD, 0xEE));
			dcMem.TextOut(140, 45, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}


// 设置呼吸率下限
int CStaticValueFANormal::set_AirOxy_alm_L(INT16 l, UINT8 redraw)
{
	CString a_cs;
	if ((m_i16AirOxyL != l) || (redraw))
	{
		// 设置氧浓度下限
		m_i16AirOxyL = l;

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

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

		if (m_i32Style == 0)
		{
			dcMem.FillSolidRect(110, 70, 40, 32, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(RGB(0xDD, 0xDD, 0xEE));
			dcMem.TextOut(110, 70, a_cs);
		}
		else
		{
			dcMem.FillSolidRect(140, 85, 40, 32, RGB(0, 0, 0));
			dcMem.SelectObject(&font);
			dcMem.SetTextColor(RGB(0xDD, 0xDD, 0xEE));
			dcMem.TextOut(140, 85, a_cs);
		}
		m_i32ReDraw = 1;
	}

	return 0;
}

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

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



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

	if (m_i32Style == 0)
	{
		dcMem.FillSolidRect(0, 0, CStaticValueFANormal::m_i32NormalWidth, CStaticValueFANormal::m_i32NormalHeight, RGB(0, 0, 0));
		dcMem.FillSolidRect(5, 0, 40, 20, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(CStaticValueFANormal::m_rgbText);
		dcMem.TextOut(5, 0, _T("空氧"));
		dcMem.FillSolidRect(110, 110, 40, 32, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(RGB(0xDD, 0xDD, 0xEE));
		dcMem.TextOut(110, 110, _T("%"));
		m_i32Width = CStaticValueFANormal::m_i32NormalWidth;
		m_i32Height = CStaticValueFANormal::m_i32NormalHeight;
	}
	else
	{
		dcMem.FillSolidRect(0, 0, CStaticValueFANormal::m_i32BigWidth, CStaticValueFANormal::m_i32BigHeight, RGB(0, 0, 0));
		dcMem.FillSolidRect(5, 0, 40, 20, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(CStaticValueFANormal::m_rgbText);
		dcMem.TextOut(5, 0, _T("空氧"));
		dcMem.FillSolidRect(140, 90, 40, 32, RGB(0, 0, 0));
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(RGB(0xDD, 0xDD, 0xEE));
		dcMem.TextOut(140, 90, _T("%"));
		m_i32Width = CStaticValueFANormal::m_i32BigWidth;
		m_i32Height = CStaticValueFANormal::m_i32BigHeight;
	}
	// 设置温度
	set_FiO(m_i16AirOxy,1);
	// 设置温度上限
	set_AirOxy_alm_H(m_i16AirOxyH, 1);
	// 设置体温下限
	set_AirOxy_alm_L(m_i16AirOxyL, 1);
	Set_AlmFlag(m_i32AlmFlag, 1);
	UpdateWindow();
}


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