Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 24 / lab22 / CEllipseTxT
.cpp#include "stdafx.h"
#include "CEllipseTxT.h"
CEllipseTxt :: CEllipseTxt()
:CEllipse(), CText(),ShapePosition()
{
}
CEllipseTxt :: CEllipseTxt(int _X, int _Y, int _XRad, int _YRad, CString _str)
:CEllipse(_X, _Y, _XRad, _YRad), CText(_X,_Y,_str),ShapePosition(_X,_Y)
{
}
CEllipseTxt :: ~CEllipseTxt()
{}
int CEllipseTxt :: getNumType()
{return 4;
}
void CEllipseTxt :: display(std::ostream& os)
{
os << "Class CEllipseTxT Information :" << endl <<
"X :" << GetX() << endl <<
"Y :" << GetY() << endl <<
"X-Radius :" << GetXRad() << endl <<
"Y-Radius :" << GetYRad() << endl <<
"Area :" << GetArea() << endl <<
"String: " << GetStr() << endl;
}
int CEllipseTxt::GetX() const
{return CEllipse::GetX();
}
int CEllipseTxt::GetY() const
{return CEllipse::GetY();
}
void CEllipseTxt::SetX(int _X)
{CEllipse::SetX(_X);
}
void CEllipseTxt::SetY(int _Y)
{CEllipse::SetY(_Y);
}
void CEllipseTxt::Move(int dx,int dy)
{CEllipse::Move(dx,dy);
}
void CEllipseTxt::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);
pDC->SetTextColor(aColor);
int width=pDC->GetTextExtent(GetStr()).cx;
pDC->TextOut(GetX()+GetXRad()-width/2,GetY()+GetYRad()-GetHeight(),GetStr());
}
CRect CEllipseTxt::GetBoundRect()
{
CRect BoundingRect(GetX(),GetY(),GetX()+2*GetXRad(),GetY()+2*GetYRad());
return BoundingRect;
}
void CEllipseTxt::writeAr(CArchive& ar)
{ar<<getNumType();
ar<<GetX();
ar<<GetY();
ar<<GetXRad();
ar<<GetYRad();
ar<<GetStr();
}
void CEllipseTxt::readAr(CArchive& ar)
{int _X,_Y;
int _XRad,_YRad;
CString _str;
ar>>_X;
ar>>_Y;
ar>>_XRad;
ar>>_YRad;
ar>>_str;
SetX(_X);SetY(_Y);
SetXRad(_XRad);
SetYRad(_YRad);
SetStr(_str);
}
CString CEllipseTxt::getName()
{return "Ellipse with text";}
Соседние файлы в папке lab22