📄 rectangle.cpp
字号:
#include "stdafx.h"
#include "math.h"
#include "VCad.h"
#include "VCadDoc.h"
#include "VCadView.h"
#include "Entity.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//定义 CRectangle 类
IMPLEMENT_SERIAL(CRectangle, CEntity, 0)
CRectangle::CRectangle()
{
Init() ;
}
CRectangle::CRectangle(const CRectangle& rect)
: CEntity(rect)
{
m_LeftTop = rect.m_LeftTop ;
m_RightBottom = rect.m_RightBottom ;
}
CRectangle::CRectangle(const Position& LeftTop,const Position& RightBottom)
{
Init() ;
m_LeftTop = LeftTop ;
m_RightBottom = RightBottom ;
}
CRectangle::~CRectangle()
{
}
CEntity* CRectangle::Copy()
{
CEntity* pEntity = new CRectangle(m_LeftTop, m_RightBottom);
return pEntity;
}
void CRectangle::Init()
{
CEntity::Init();
m_type = etRectangle;
m_LeftTop.Init();
m_RightBottom.Init();
}
int CRectangle::GetType()
{
return etRectangle ;
}
Position CRectangle::GetLeftTopPos()
{
return m_LeftTop;
}
Position CRectangle::GetRightBottomPos()
{
return m_RightBottom;
}
///////////////////////
void CRectangle::Draw(CDC * pDC, int drawMode /* = dmNormal */)
{
// 屏幕坐标的左上角点和右下角点
CPoint sltp, srbp;
// 将世界坐标转化为屏幕坐标
g_pView->WorldtoScreen(m_LeftTop, sltp) ;
g_pView->WorldtoScreen(m_RightBottom, srbp) ;
// 得到原来的绘图模式
int n = GetROP2(pDC->GetSafeHdc());
// 创建画笔的原则:
// 如果在正常的绘图模式下,使用成员变量创建画笔
// 如果是其它的模式,使用全局函数"SetDrawEnvir"创建画笔
CPen pen;
if( drawMode == dmNormal )
pen.CreatePen(m_lineStyle,m_lineWidth,m_color) ;
else
::SetDrawEnvir(pDC, drawMode, &pen);
// 得到原来的画笔
CPen* pOldPen = pDC->SelectObject(&pen) ;
pDC->SetMapMode(MM_LOENGLISH);
// 根据屏幕坐标绘制图元
pDC->MoveTo(sltp) ;
pDC->LineTo(sltp.x, srbp.y) ;
pDC->LineTo(srbp);
pDC->LineTo(srbp.x, sltp.y) ;
pDC->LineTo(sltp) ;
// 恢复原来的画笔
pDC->SelectObject(pOldPen) ;
// 恢复原来的绘图模式
pDC->SetROP2(n);
}
void CRectangle::Serialize(CArchive& ar)
{
CEntity::Serialize(ar);
m_LeftTop.Serialize(ar);
m_RightBottom.Serialize(ar);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -