Скачиваний:
11
Добавлен:
01.05.2014
Размер:
2.01 Кб
Скачать
#include "stdafx.h"
#include "CEllipse.h"

CEllipse :: CEllipse()
:CCircle(),ShapePosition()
{
	YRad = 0;
}

CEllipse :: CEllipse(int _X, int _Y, int _XRad, int _YRad)
:CCircle(_X, _Y, _XRad),ShapePosition(_X,_Y)
{
	YRad = _YRad;
}

CEllipse :: ~CEllipse()
{}

void CEllipse :: SetYRad(int _YRad)
{
	YRad = _YRad;
}

int CEllipse :: GetYRad() const
{
	return YRad;
}

double CEllipse :: GetArea() const
{
	return M_PI * GetXRad() * GetYRad();
}

int CEllipse :: getNumType()
{return 3;}

void CEllipse :: display(ostream & os)
{
	os << "Class CEllipse Information :" << endl << 
		 "X        :" << GetX() << endl <<
		 "Y        :" << GetY() << endl <<
		 "X-Radius :" << GetXRad() << endl <<
		 "Y-Radius :" << GetYRad() << endl <<
		 "Area     :" << GetArea() << endl;
}

void CEllipse ::Draw(CDC* pDC, Shape* figure,bool doLine)
{
CPen aPen; 
   COLORREF aColor=RGB(0,0,0);

   if(this == figure)                  
      aColor = RGB(255,0,0);

   if (doLine)
   {
		aColor = RGB(0,255,0);
   }

   if(!aPen.CreatePen(PS_SOLID, 1, aColor))
   {                                           
      AfxMessageBox("Pen creation failed drawing a rectangle", MB_OK);
      AfxAbort();
   }

   CPen* pOldPen = pDC->SelectObject(&aPen);  


   CPoint Start(GetX(),GetY());
   CPoint End(GetX()+2*GetXRad(),GetY()+2*GetYRad());

   CRect m_EnclosingRect(Start, End);
   m_EnclosingRect.NormalizeRect();	

	pDC->Ellipse(m_EnclosingRect);

	pDC->SelectObject(pOldPen);
}

CRect CEllipse ::GetBoundRect()
{
	CRect BoundingRect(GetX(),GetY(),GetX()+2*GetXRad(),GetY()+2*GetYRad());

	return BoundingRect;
}

void CEllipse ::writeAr(CArchive& ar)
{ar<<getNumType();
 ar<<GetX();
 ar<<GetY();
 ar<<GetXRad();
 ar<<GetYRad();
}

void CEllipse ::readAr(CArchive& ar)
{int _X,_Y;
int _XRad;
 ar>>_X;
 ar>>_Y;
 ar>>_XRad;
 ar>>YRad;

 SetX(_X);SetY(_Y);
 SetXRad(_XRad);
}

CString CEllipse::getName()
{return "Ellipse";}
Соседние файлы в папке lab22