七巧板讲义.doc_第1页
七巧板讲义.doc_第2页
七巧板讲义.doc_第3页
七巧板讲义.doc_第4页
七巧板讲义.doc_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、 新建工程二、 新建拼板类1. 新建MFC类2. 定义成员变量与类方法全局变量:MAX_POINTS /最大点数 CHIP_WIDTH /原始正方形边长DELTA /起始位置 成员变量:1) 拼板类型:int m_nType2) 拼板点总数:int m_pointCount3) 拼板点数组:CPoint m_pointListMAX_POINTS类方法:1) void SetChip(int type, POINT *ppointList, int count); /显式初始化拼板对象2) void DrawChip(CDC* pDC); /画拼板3) BOOL PtInChip(POINT point); /判断一点是否在拼板中4) LPCRECT GetRect(void); /返回拼板所在矩形范围5) voidRotation(); /旋转拼板 旋转前 旋转后旋转中心横坐标:所在矩形左侧横坐标+所在矩形宽度/2旋转中心纵坐标:所在矩形下侧纵坐标+所在矩形高度/2对每一个点进行坐标转换:相对旋转中心水平位移:原横坐标-旋转中心横坐标相对旋转中心垂直位移:原纵坐标-旋转中心纵坐标 转换后横坐标=旋转中心横坐标+水平位移*cos(旋转角度)-垂直位移*sin(旋转角度) 转换后纵坐标=旋转中心纵坐标+水平位移*cos(旋转角度)+垂直位移*sin(旋转角度)void Chip:Rotation()CRect rect;CRgn rgn;rgn.CreatePolygonRgn(m_pointList, m_nPointCount, ALTERNATE);rgn.GetRgnBox(&rect);double x = rect.left+rect.Width()/2;/ 计算旋转中D心double y = rect.top+rect.Height()/2;double dx, dy;for(int i=0; im_nPointCount; i+)/ 旋转各点dx = m_pointListi.x-x;dy = m_pointListi.y-y;m_pointListi.x = (int)(x+dx*0.7071-dy*0.7071);m_pointListi.y = (int)(y+dx*0.7071+dy*0.7071);6) void MoveTo(CSize offset); /移动拼板一定位移7) void Serialize(CArchive& ar); /实现可串行化void Chip:Serialize(CArchive& ar)if(ar.IsStoring()ar m_nType;ar m_nPointCount;for(int i=0; im_nPointCount; i+)ar m_nType;ar m_nPointCount;for(int i=0; i m_pointListi;3. 实现类方法三、 文档类保存状态数据全局变量:CHIP_COUNT /拼板数成员变量:Chip m_chipListCHIP_COUNT /拼板对象数组成员函数:void Reset() /重置拼板位置void CqqbTestDoc:Reset()POINTpointListMAX_POINTS;pointList0.x = DELTA;pointList0.y = DELTA;pointList1.x = DELTA+CHIP_WIDTH;pointList1.y = DELTA;pointList2.x = DELTA+CHIP_WIDTH/2;pointList2.y = DELTA+CHIP_WIDTH/2;m_chipList0.SetChip(1, pointList, 3);/第一个大三角形pointList0.x = DELTA;pointList0.y = DELTA;pointList1.x = DELTA;pointList1.y = DELTA+CHIP_WIDTH;pointList2.x = DELTA+CHIP_WIDTH/2;pointList2.y = DELTA+CHIP_WIDTH/2;m_chipList1.SetChip(2, pointList, 3);/第二个大三角形pointList0.x = DELTA+CHIP_WIDTH;pointList0.y = DELTA;pointList1.x = DELTA+CHIP_WIDTH;pointList1.y = DELTA+CHIP_WIDTH/2;pointList2.x = DELTA+(CHIP_WIDTH*3)/4;pointList2.y = DELTA+CHIP_WIDTH/4;m_chipList2.SetChip(3, pointList, 3);/第一个小三角形pointList0.x = DELTA+CHIP_WIDTH/2;pointList0.y = DELTA+CHIP_WIDTH/2;pointList1.x = DELTA+CHIP_WIDTH/4;pointList1.y = DELTA+(CHIP_WIDTH*3)/4;pointList2.x = DELTA+(CHIP_WIDTH*3)/4;pointList2.y = DELTA+(CHIP_WIDTH*3)/4;m_chipList3.SetChip(4, pointList, 3);/第二个小三角形pointList0.x = DELTA+CHIP_WIDTH;pointList0.y = DELTA+CHIP_WIDTH/2;pointList1.x = DELTA+CHIP_WIDTH;pointList1.y = DELTA+CHIP_WIDTH;pointList2.x = DELTA+CHIP_WIDTH/2;pointList2.y = DELTA+CHIP_WIDTH;m_chipList4.SetChip(5, pointList, 3);/中三角形pointList0.x = DELTA+(CHIP_WIDTH*3)/4;pointList0.y = DELTA+CHIP_WIDTH/4;pointList1.x = DELTA+CHIP_WIDTH/2;pointList1.y = DELTA+CHIP_WIDTH/2;pointList2.x = DELTA+(CHIP_WIDTH*3)/4;pointList2.y = DELTA+(CHIP_WIDTH*3)/4;pointList3.x = DELTA+CHIP_WIDTH;pointList3.y = DELTA+CHIP_WIDTH/2;m_chipList5.SetChip(6, pointList, 4);/正方形pointList0.x = DELTA;pointList0.y = DELTA+CHIP_WIDTH;pointList1.x = DELTA+CHIP_WIDTH/4;pointList1.y = DELTA+(CHIP_WIDTH*3)/4;pointList2.x = DELTA+(CHIP_WIDTH*3)/4;pointList2.y = DELTA+(CHIP_WIDTH*3)/4;pointList3.x = DELTA+CHIP_WIDTH/2;pointList3.y = DELTA+CHIP_WIDTH;m_chipList6.SetChip(7, pointList, 4);/平行四边形重写函数:void DeleteContents() /删除文档时要重置拼板位置四、 视图区画图成员变量:1) 选中标志:BOOL m_bCaptured2) 鼠标所在点:CPoint m_pointMouse3) 当前拼板索引:int m_nCurrIndex消息映射:ON_WM_LBUTTONDOWN() /鼠标左键按下响应ON_WM_LBUTTONUP() /鼠标左键松开时响应ON_WM_RBUTTONDOWN() /鼠标右键按下时响应ON_WM_MOUSEMOVE() /鼠标移动时响应重写虚函数:OnDraw()五、 添加鼠标响应void CqqbTestView:OnLButtonDown(UINT nFlags, CPoint point)/ TODO: 在此添加消息处理程序代码和或调用默认值CqqbTestDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);for(int i=0;im_chipListi.PtInChip(point)SetCapture();m_bCaptured = TRUE;m_pointMouse = point;m_nCurrIndex = i;break;CView:OnLButtonDown(nFlags, point);void CqqbTestView:OnLButtonUp(UINT nFlags, CPoint point)/ TODO: 在此添加消息处理程序代码和或调用默认值:ReleaseCapture();m_bCaptured = FALSE;CView:OnLButtonUp(nFlags, point);void CqqbTestView:OnRButtonDown(UINT nFlags, CPoint point)CqqbTestDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: 在此添加消息处理程序代码和或调用默认值for(int i=0;im_chipListi.PtInChip(point)InvalidateRect(pDoc-m_chipListi.GetRect();pDoc-m_chipListi.Rotation();InvalidateRect(pDoc-m_chipListi.GetRect(),FALSE);pDoc-SetModifiedFlag();break;CView:OnRButtonDown(nFlags, point);void CqqbTestView:OnMouseMove(UINT nFlags, CPoint point)/ TODO: 在此添加消息处理程序代码和或调用默认值if(m_bCaptured)CqqbTestDoc *pDoc = GetDocument();ASSERT_VALID(pDoc);InvalidateRect(pDoc-m_chipListm_nCurrIndex.GetRect();CSiz

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论