#include "pch.h"
#include "CShape.h"
IMPLEMENT_SERIAL(CSquare, CObject, 1)//实现类CSquare的序列化,指定版本为1
IMPLEMENT_SERIAL(CRectangle, CObject, 1)
IMPLEMENT_SERIAL(CCircle, CObject, 1)
IMPLEMENT_SERIAL(CEllipse, CObject, 1)
IMPLEMENT_SERIAL(CTriangle, CObject, 1)
IMPLEMENT_SERIAL(CText, CObject, 1)//同上
const double PI = 3.1415;
//基类
CShape::CShape()
{
Type = NOTSET;
OrgX = 0;
OrgY = 0;
BorderType = 0;
FillType = 6;
BorderWidth = 0;
BorderColor = RGB(255, 255, 255);
FillColor = RGB(255, 255, 255);
}
shape CShape::GetShape()
{
shape t;
t.Type = Type;
t.OrgX = OrgX;
t.OrgY = OrgY;
t.BorderType = BorderType;
t.FillType = FillType;
t.BorderColor = BorderColor;
t.BorderWidth = BorderWidth;
t.BorderColor = BorderColor;
t.FillColor = FillColor;
t.Str = "";
t.Height = 0;
t.Width = 0;
return t;
}
//正方形
CSquare::CSquare() :CShape::CShape()
{
Type = SQUARE; width = 0;
};
CSquare::CSquare(int x, int y, int w) :CShape::CShape()
{
Type = SQUARE;
OrgX = x;
OrgY = y;
width = w;
}
void CSquare::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << (WORD)Type;
ar << OrgX << OrgY;
ar << BorderColor;
ar << BorderType;
ar << BorderWidth;
ar << FillColor;
ar << FillType;
ar << width;
}
else
{
WORD w;
ar >> w;
Type = (ElementType)w;
ar >> OrgX >> OrgY;
ar >> BorderColor;
ar >> BorderType;
ar >> BorderWidth;
ar >> FillColor;
ar >> FillType;
ar >> width;
}
}
void CSquare::Draw(CDC* pDC)//绘制图形函数
{
CPen pen, * pOldPen;//画笔 对象和指针
pen.CreatePen(BorderType, BorderWidth, BorderColor);//初始化画笔的属性
pOldPen = (CPen*)pDC->SelectObject(&pen);//保存 画笔原来的数据 等会要还原原来的属性
CBrush brush, * pOldBrush;
if (FillType >= HS_HORIZONTAL && FillType <= HS_DIAGCROSS) //HS_HORIZONTAL = 0;HS_DIAGCROSS = 5; 宏定义 最大为5 代表每一个 填充的方式
brush.CreateHatchBrush(FillType, FillColor);
else
brush.CreateSolidBrush(FillColor);
pOldBrush = (CBrush*)pDC->SelectObject(&brush);
pDC->Rectangle(OrgX - width / 2, OrgY - width / 2, OrgX + width / 2, OrgY + width / 2);//两个顶点的坐标
pDC->SelectObject(pOldPen);//Old还原。这样做是为了其它Windows程序,因为有的Windows程序直接使用默认的画笔和画刷进行绘图
pDC->SelectObject(pOldBrush);
}
bool CSquare::IsMatched(CPoint pnt)//图元匹配函数
{
if (pnt.x > (OrgX - width / 2) && pnt.x < (OrgX + width / 2))
if (pnt.y > (OrgY - width / 2) && pnt.y < (OrgY + width / 2))
return true;
return false;
}
void CSquare::SetShapePos(int x, int y, int w, int h=0, CString s = L"")
{
OrgX = x;
OrgY = y;
width = w;
}
void CSquare::SetPen(int w = 0, int c = 0, COLORREF cc= RGB(255, 255, 255))
{
BorderColor = cc;
BorderType = c;
BorderWidth=w;
}
void CSquare::SetBrush( int c = 0, COLORREF cc = RGB(0, 0, 0))
{
FillColor = cc;
FillType = c;
}
shape CSquare::GetShape()
{
shape t=CShape::GetShape();
t.Width = width;
return t;
}
//长方形
CRectangle::CRectangle() :CShape::CShape()
{
Type = RECTANGLE;
width = 0; Height = 0;
}
CRectangle::CRectangle(int x, int y, int w, int h) : CShape::CShape()
{
Type = RECTANGLE;
OrgX = x;
OrgY = y;
width = w;
Height = h;
}
void CRectangle::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << (WORD)Type;
ar << OrgX << OrgY;//原点坐标
ar << BorderColor;//边界颜色
ar << BorderType;
ar << BorderWidth;//边界宽度
ar << FillColor;//
ar << FillType;
ar << width;
ar << Height;
}
else
{
WORD w;
ar >> w;
Type = (ElementType)w;
ar >> OrgX >> OrgY;//原点坐标
ar >> BorderColor;//边界颜色
ar >> BorderType;
ar >> BorderWidth;//边界宽度
ar >> FillColor;//
ar >> FillType;
ar >> width;
ar >> Height;
}
}
void CRectangle::Draw(CDC* pDC)//绘制图形函数
{
CPen pen, * pOldPen;//画笔 对象和指针
pen.CreatePen(BorderType, BorderWidth, BorderColor);//初始化画笔的属性
pOldPen = (CPen*)pDC->SelectObject(&pen);//保存 画笔原来的数据 等会要还原原来的属性
CBrush brush, * pOldBrush;
if (FillType >= HS_HORIZONTAL && FillType <= HS_DIAGCROSS) //HS_HORIZONTAL = 0;HS_DIAGCROSS = 5; 宏定义 最大为5 代表每一个 填充的方式
brush.CreateHatchBrush(FillType, FillColor);
else
brush.CreateSolidBrush(FillColor);
pOldBrush = (CBrush*)pDC->SelectObject(&brush);
pDC->Rectangle(OrgX - width / 2, OrgY - Height / 2, OrgX + width / 2, OrgY + Height / 2);//两个顶点的坐标
pDC->SelectObject(pOldPen);//Old还原。这样做是为了其它Windows程序,因为有的Windows程序直接使用默认的画笔和画刷进行绘图
pDC->SelectObject(pOldBrush);
}
bool CRectangle::IsMatched(CPoint pnt)//图元匹配函数
{
if (pnt.x > (OrgX - width / 2) && pnt.x < (OrgX + width / 2))
if (pnt.y > (OrgY - Height / 2) && pnt.y < (OrgY + Height / 2))
return true;
return false;
}
void CRectangle::SetShapePos(int x, int y, int w, int h=0, CString s = L"")
{
OrgX = x;
OrgY = y;
width = w;
Height = h;
}
void CRectangle::SetPen(int w = 0, int c = 0, COLORREF cc = RGB(255, 255, 255))
{
BorderColor = cc;
BorderType = c;
BorderWidth = w;
}
void CRectangle::SetBrush(int c = 0, COLORREF cc = RGB(0, 0, 0))
{
FillColor = cc;
FillType = c;
}
shape CRectangle::GetShape()
{
shape t = CShape::GetShape();
t.Width = width;
t.Height = Height;
return t;
}
//圆形
CCircle::CCircle() :CShape::CShape()
{
Type = CIRCLE;
R = 0;
};
CCircle::CCircle(int x, int y, int w) :CShape::CShape()
{
Type = CIRCLE;
OrgX = x;
OrgY = y;
R = w;
}
void CCircle::CCircle::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << (WORD)Type;
ar << OrgX << OrgY;//原点坐标
ar << BorderColor;//边界颜色
ar << BorderType;
ar << BorderWidth;//边界宽度
ar << FillColor;//
ar << FillType;
ar << R;
}
else
{
WORD w;
ar >> w;
Type = (ElementType)w;
ar >> OrgX >> OrgY;//原点坐标
ar >> BorderColor;//边界颜色
ar >> BorderType;
ar >> BorderWidth;//边界宽度
ar >> FillColor;//
ar >> FillType;
ar >> R;
}
}
void CCircle::Draw(CDC* pDC)//绘制图形函数
{
CPen pen, * pOldPen;//画笔 对象和指针
pOldPen = (CPen*)pDC->SelectObject(&pen);//保存 画笔原来的数据 等会要还原原来的属性
pen.CreatePen(BorderType, BorderWidth, BorderColor);//初始化画笔的属性
CBrush brush, * pOldBrush;
if (FillType >= HS_HORIZONTAL && FillType <= HS_DIAGCROSS) //HS_HORIZONTAL = 0;HS_DIAGCROSS = 5; 宏定义 最大为5 代表每一个 填充的方式
brush.CreateHatchBrush(FillType, FillColor);
else
brush.CreateSolidBrush(FillColor);
pOldBrush = (CBrush*)pDC->SelectObject(&brush);
pDC->Ellipse(OrgX - R, OrgY - R, OrgX + R, OrgY + R);
pDC->SelectObject(pOldPen);//Old还原。这样做是为了其它Windows程序,因为有的Windows程序直接使用默认的画笔和画刷进行绘图
pDC->SelectObject(pOldBrush);
}
bool CCircle::IsMatched(CPoint pnt)//图元匹配函数
{
if ((pow(pnt.x - OrgX, 2) + pow(pnt.y - OrgY, 2)) < pow(R, 2))
return true;
return false;
}
void CCircle::SetShapePos(int x, int y, int w, int h=0, CString s = L"")
{
OrgX = x;
OrgY = y;
R = w;
}
void CCircle::SetPen(int w = 0, int c = 0, COLORREF cc = RGB(255, 255, 255))
{
BorderColor = cc;
BorderType = c;
BorderWidth = w;
}
void CCircle::SetBrush(int c = 0, COLORREF cc = RGB(0, 0, 0))
{
FillColor = cc;
FillType = c;
}
shape CCircle::GetShape()
{
shape t = CShape::GetShape();
t.Width = R;
return t;
}
//椭圆
CEllipse::CEllipse() :CShape::CShape()
{
Type = ELLIPSE;
width = height = 0;
};
CEllipse::CEllipse(int x, int y, int w, int h) :CShape::CShape()
{
Type = ELLIPSE;
OrgX = x;
OrgY = y;
width = w;
height = h;
}
void CEllipse::CEllipse::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << (WORD)Type;
ar << OrgX << OrgY;//原点坐标
ar << BorderColor;//边界颜色
ar << BorderType;
ar << BorderWidth;//边界宽度
ar << FillColor;//
ar << FillType;
ar << width;
ar << height;
}
else
{
WORD w;
ar >> w;
Type = (ElementType)w;
ar >> OrgX >> OrgY;//原点坐标
ar >> BorderColor;//边界颜色
ar >> BorderType;
ar >> BorderWidth;//边界宽度
ar >> FillColor;//
ar >> FillType;
ar >> width;
ar >> height;
}
}
void CEllipse::Draw(CDC* pDC)//绘制图形函数
{
CPen pen, * pOldPen;//画笔 对象和指针
pen.CreatePen(BorderType, BorderWi
没有合适的资源?快使用搜索试试~ 我知道了~
大学生c++课设作业:基于MFC的图形编辑系统+源代码+文档说明
共30个文件
h:11个
cpp:8个
ico:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 32 浏览量
2024-01-03
19:46:57
上传
评论
收藏 155KB ZIP 举报
温馨提示
大学生c++课设作业:基于MFC的图形编辑系统+源代码+文档说明 - 小白不懂运行,下载完可以私聊问,可远程教学 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 --------
资源推荐
资源详情
资源评论
收起资源包目录
MFC_Shape-master.zip (30个子文件)
MFC_Shape-master
Drawing.sln 1KB
Drawing.aps 121KB
说明.md 90B
DrawingDoc.cpp 3KB
Drawing.vcxproj.user 228B
resource.h 1KB
framework.h 1KB
MainFrm.cpp 2KB
CShape.cpp 15KB
Vector2.cpp 193B
res
Drawing.rc2 670B
Toolbar.bmp 1KB
DrawingDoc.ico 5KB
Drawing.ico 66KB
pch.h 531B
Drawing.vcxproj.filters 3KB
CShapeDlg.h 880B
MainFrm.h 672B
Drawing.rc 30KB
Drawing.h 517B
Drawing.vcxproj 10KB
DrawingDoc.h 994B
Drawing.cpp 5KB
DrawingView.h 1KB
CShape.h 4KB
pch.cpp 153B
Vector2.h 152B
targetver.h 291B
CShapeDlg.cpp 6KB
DrawingView.cpp 5KB
共 30 条
- 1
资源评论
机智的程序员zero
- 粉丝: 2016
- 资源: 4228
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- com.Gaggle.fun.GooseGooseDuck.apk
- FastBrowser 基于CefSharp浏览器 Chromium内核 C#、WPF界面绘制, mp3、mp4播放
- apache-tomcat-8.5.100.tar.gz
- namehfyz1234
- 14727758_202405291911557049.csv.zip
- hfyzname1234
- 基于Java ME无线网络移动端的俄罗斯方块游戏的实现(源码+使用文档)
- 第九届上海市大学生网络安全大赛暨“磐石行动”2024第二届全国高校网络安全攻防活动 MISC wifi密码
- B07-GA503-2补充.zip
- 基于Java蚁群算法路由选择可视化(源码+使用文档)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功