Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 23 / Text
.cpp// Copyright (C) 1991 - 1999 Rational Software Corporation
#include "stdafx.h"
#include "OurConstants.h"
#include "Text.h"
//##ModelId=4709256800AB
Text::Text(const char* txt, CPoint start, COLORREF aColor):
ID(++count_ID)
{
// TODO: Add your specialized code here.
this->start = start;
setText(txt);
color = aColor;
boundRect = CRect(
CPoint((int)start.x,(int)start.y),
CPoint((int)(start.x),(int)(start.y))
);
boundRect.NormalizeRect();
}
//##ModelId=470924BF01B5
Text::setText(const char* txt)
{
int i = 0;
while (txt[i]!='\0') {
txt[i++];
}
this->text=new char[i+1];
for (int j=0;j<i;j++) {
text[j]=txt[j];
}
text[i]='\0';
}
//##ModelId=470925300203
char* Text::getText() const
{
// TODO: Add your specialized code here.
int i = 0;
while (text[i]!='\0') {
text[i++];
}
char*txt = new char[i+1];
for (int j=0;j<i;j++) {
txt[j]=text[j];
}
txt[i]='\0';
return txt;
}
//##ModelId=470A15AA03B9
Text::~Text()
{
// TODO: Add your specialized code here.
delete text;
}
//##ModelId=470A2A86032C
long Text::count_ID = 0;
//##ModelId=470A2E39031C
void Text::draw(CDC* pDC, COLORREF color, int pen=0)
{
CFont l_font;
LOGFONT logFont;
logFont.lfHeight = 26;
logFont.lfWidth = 0;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = (pen==DEFAULT_PEN)?FW_NORMAL:FW_BOLD;
logFont.lfItalic = 0;
logFont.lfUnderline = 0;
logFont.lfStrikeOut = 0;
logFont.lfCharSet = ANSI_CHARSET;
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfQuality = PROOF_QUALITY;
logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
strcpy(logFont.lfFaceName, "Arial");
l_font.CreateFontIndirect(&logFont);
CFont* l_old_font = pDC->SelectObject(&l_font);
CSize size = pDC->GetTextExtent(text);
boundRect.SetRect(start.x,start.y-size.cy,start.x+size.cx,start.y);
// pDC->TextOut((int)start.x,(int)start.y,text,length());
// pDC->DrawText("text",4,boundRect,DT_CENTER);
// pDC->Rectangle(boundRect);
// pDC->SelectObject(l_old_font);
// TODO: Add your specialized code here.
// Create a pen for this object and
// initialize it to the object color and line width of 1 pixel
// CPen aPen;
// if(!pen) pen = DEFAULT_PEN;
// COLORREF aColor = color; // Initialize with element color
// if(!aPen.CreatePen(PS_SOLID, pen, aColor))
// {
// Pen creation failed. Abort the program.
// AfxMessageBox("Pen creation failed drawing a line", MB_OK);
// AfxAbort();
// }
// CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen
// pDC->MoveTo(CPoint(startX,startY));
// pDC->Rectangle(CRect(CPoint((int)startX,(int)startY),CPoint((int)startX+10,(int)startY+30)));
pDC->SetTextColor(color);
pDC->TextOut(start.x,start.y,text);
pDC->SelectObject(l_old_font); // Restore the old pen
l_font.DeleteObject();
}
//##ModelId=472F625A009C
double Text::area() {
return 0;
}
//##ModelId=472F625A00BB
void Text::move(CSize& size) {
start+=size;
boundRect+=size;
}
int Text::length()
{
int len = 0;
for (len = 0; text[len]!='\0'; len++);
return len;
}
Соседние файлы в папке Лабораторная работа 23