使用的MFC,实现矢量图形编辑,主要代码:
父类
class Graphic : public CObject
{
DECLARE_SERIAL(Graphic)
public:
virtual void Draw(CDC* pDC);
Graphic(){};
Graphic(Graphic* component);
Graphic(POINT pte1,POINT pts1,int iFigureType1);
POINT ptS;//起点
POINT ptE;//终点
BOOL Tip;
int iFigureType;//画图类型
Graphic* component;
virtual void Serialize(CArchive& ar);
virtual ~Graphic();
};
其中一个子类MyLine
class MyLine:public Graphic
{
DECLARE_SERIAL(MyLine)
int ipenType;//画笔类型
COLORREF PenCor;//画笔颜色
MyLine(){};
MyLine(POINT pte1,POINT pts1,int ipenType1,COLORREF PenCor1);
~MyLine(){};
virtual void Serialize(CArchive&);
virtual void Draw(CDC* pDC);
};
MyDecorator类
class MyDecorator:public Graphic
{
public:
MyDecorator(){};
MyDecorator(Graphic* component);
~MyDecorator(){};
virtual void Draw(CDC* pDC);
private:
Graphic* _component;
};
他的子类MYRectTracker
class MYRectTracker:public MyDecorator
{
public:
MYRectTracker(){};
MYRectTracker(Graphic* component);
~MYRectTracker(){};
virtual void Draw(CDC* pDC);
};
主要函数
MyDecorator::MyDecorator(Graphic* component)
{
this->_component=component;
this->iFigureType=FIG_SEL;
}
MYRectTracker::MYRectTracker(Graphic* component):MyDecorator(component)
{
this->ptE=component->ptE;
this->ptS=component->ptS;
this->iFigureType=FIG_SEL;
}
void MyDecorator::Draw(CDC * pDC)
{
_component->Draw(pDC);
}
void MYRectTracker::Draw(CDC * pDC)
{
CRect rc(ptS.x, ptS.y, ptE.x, ptE.y);
CRectTracker* m_RectTracker=new CRectTracker(rc,8);
m_RectTracker->Draw(pDC);
}
文章评论(0条评论)
登录后参与讨论