#include "stdafx.h"
#include "2DObject.h"

/************************************************************************
¶þÎ¬¿ÕÐÄÔ²Àà                                                                    
************************************************************************/
C2DCircle::C2DCircle()
{
	m_ptl = CPoint(0,0);
    m_ptr = CPoint(0,0);    
	m_byR = g_2DObj.m_byR[4];
	m_byG = g_2DObj.m_byG[4];
	m_byB = g_2DObj.m_byB[4];
	m_byLineStyle = g_2DObj.m_byLineStyle[4];
	m_wLineWidth  = g_2DObj.m_wLineWidth[4];
}

C2DCircle::C2DCircle(CPoint& ptl, CPoint& ptr)
{
	m_ptl = ptl;
	m_ptr = ptr;
	m_byR = g_2DObj.m_byR[4];
	m_byG = g_2DObj.m_byG[4];
	m_byB = g_2DObj.m_byB[4];
	m_byLineStyle = g_2DObj.m_byLineStyle[4];
	m_wLineWidth  = g_2DObj.m_wLineWidth[4];
}

C2DCircle::~C2DCircle()
{

}

void C2DCircle::Serialize( CFile* pFile, BOOL bSave /*= TRUE*/ )
{
	if (bSave)
	{
		C2DLine::Serialize(pFile,bSave);
		pFile->Write(&m_ptl,sizeof(CPoint));
        pFile->Write(&m_ptr,sizeof(CPoint));
	} 
	else
	{
		C2DLine::Serialize(pFile,bSave);
		pFile->Read(&m_ptl,sizeof(CPoint));
		pFile->Read(&m_ptr,sizeof(CPoint));
	}
}

void C2DCircle::Draw( CDC* pDC )
{
	CPen pen(m_byLineStyle,m_wLineWidth,GetClrRefFromByte(m_byR,m_byG,m_byB));
	CBrush* pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
    CBrush* pOlbBs = pDC->SelectObject(pBrush);
	CPen* pOldPen = pDC->SelectObject(&pen);
	pDC->Ellipse(m_ptl.x,m_ptl.y,m_ptr.x,m_ptr.y);
	pDC->SelectObject(pOlbBs);
	pDC->SelectObject(pOldPen);
}

UINT C2DCircle::GetClass()
{
	return CLASS_DRAW_CIRCLE;
}


void C2DCircle::GetPoint( int& x1,int& y1,int& x2,int& y2 )
{
	x1 = m_ptl.x;
	y1 = m_ptl.y;
	x2 = m_ptr.x;
	y2 = m_ptr.y;
}