Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 31 / oot / OLEApp / Elements
.cpp// Implementations of the element classes
#include "stdafx.h"
#include "OurConstants.h"
#include "Elements.h"
// Get the bounding rectangle for an element
CRect CElement::GetBoundRect()
{
CRect BoundingRect; // Object to store bounding rectangle
BoundingRect = m_EnclosingRect; // Store the enclosing rectangle
// Increase the rectangle by the pen width
BoundingRect.InflateRect(m_Pen, m_Pen);
return BoundingRect; // Return the bounding rectangle
}
void CElement::setColor(COLORREF aColor){
m_Color = aColor;
}
COLORREF CElement::getColor(){
return m_Color;
}
CRect CElement::drawKey(CDC* pDC, string text){
CPoint point = CPoint(m_EnclosingRect.TopLeft().x, m_EnclosingRect.BottomRight().y);
CPen aPen;
if(!aPen.CreatePen(PS_SOLID, 1, RED))
{
// Pen creation failed. Abort the program.
AfxMessageBox("Pen creation failed drawing a line", MB_OK);
AfxAbort();
}
// now draw text
CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen
pDC->SetTextColor(RED);
CFont l_font;
l_font.CreatePointFont(140,"Arial");
CFont* l_old_font = pDC->SelectObject(&l_font);
/*
CSize size = pDC->GetTextExtent(text.c_str());
pDC->TextOut(point.x, point.y + size.cy + 2, text.c_str(), text.length());
CPoint dp1 = CPoint(point.x, point.y + 3);
CPoint dp2 = CPoint(point.x + size.cx, point.y + 3);
pDC->MoveTo(dp1);
pDC->LineTo(dp2);
CPoint rp1 = CPoint(point.x, point.y + size.cy + 1);
CPoint rp2 = CPoint(point.x + size.cx + 1, point.y + 1);
CRect rect = CRect(rp1, rp2);
*/
pDC->TextOut(point.x, point.y, text.c_str(), text.length());
pDC->SelectObject(l_old_font);
pDC->SelectObject(pOldPen);
l_font.DeleteObject();
//m_keyRectangle = rect;
return CRect();
}
CRect CElement::getKeyRectangle(){
return m_keyRectangle;
}
// CElement serialization
CArchive& CElement::save(CArchive& ar){
return ar << m_Color // Store the color,
<< m_EnclosingRect // and the enclosing rectangle,
<< m_Pen; // and the pen width
}
CArchive& CElement::load(CArchive& ar){
return ar >> m_Color // Retrieve the color,
>> m_EnclosingRect // and the enclosing rectangle,
>> m_Pen; // and the pen width
}
// initialize static fields
unsigned long int CElement::count = 0;
unsigned long int CElement::total = 0;
Соседние файлы в папке OLEApp