RoundRect.cpp
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:42k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // RoundRect.cpp: implementation of the CRoundRect class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "GraphSoft.h"
  6. #include "RoundRect.h"
  7. #include "GlobalFunction.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. ///////////////////////////////////
  14. IMPLEMENT_SERIAL( CRoundRect, CShape, 0 )
  15. //////////////////////////////////////////////////////////////////////
  16. // Construction/Destruction
  17. //////////////////////////////////////////////////////////////////////
  18. ///////////////////////////////////////////////////////////////////////
  19. CRoundRect::CRoundRect()
  20. {
  21.  m_flFirstxTemp=m_flFirstx=0;
  22.  m_flFirstyTemp=m_flFirsty=0;
  23.  m_flSecondxTemp=m_flSecondx=0;
  24.  m_flSecondyTemp=m_flSecondy=0;
  25.      m_flThirdxTemp=m_flThirdx=0;
  26.  m_flThirdyTemp=m_flThirdy=0;
  27.  m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
  28.  m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
  29.  m_flForthxTemp=m_flForthx;
  30.  m_flForthyTemp=m_flForthy;
  31. }
  32. ////////////////////////////
  33. CRoundRect::CRoundRect(COLORREF color,int penWidth,float angle):CShape(color,penWidth,angle)
  34. {
  35. m_flFirstxTemp=m_flFirstx=0;
  36. m_flFirstyTemp=m_flFirsty=0;
  37. m_flSecondxTemp=m_flSecondx=0;
  38. m_flSecondyTemp=m_flSecondy=0;
  39. m_flThirdxTemp=m_flThirdx=0;
  40. m_flThirdyTemp=m_flThirdy=0;
  41. m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
  42. m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
  43. m_flForthxTemp=m_flForthx;
  44. m_flForthyTemp=m_flForthy;
  45. }
  46. //////////////////////////////
  47. CRoundRect::CRoundRect(CRoundRect * const pRoundRect):CShape(pRoundRect)
  48. {
  49. m_flFirstx=pRoundRect->m_flFirstx;
  50. m_flFirsty=pRoundRect->m_flFirsty;
  51. m_flSecondx=pRoundRect->m_flSecondx;
  52. m_flSecondy=pRoundRect->m_flSecondy;
  53. m_flThirdx=pRoundRect->m_flThirdx;
  54. m_flThirdy=pRoundRect->m_flThirdy;
  55.     ////
  56. m_flFirstxTemp=pRoundRect->m_flFirstxTemp;
  57. m_flFirstyTemp=pRoundRect->m_flFirstyTemp;
  58. m_flSecondxTemp=pRoundRect->m_flSecondxTemp;
  59. m_flSecondyTemp=pRoundRect->m_flSecondyTemp;
  60. m_flThirdxTemp=pRoundRect->m_flThirdxTemp;
  61. m_flThirdyTemp=pRoundRect->m_flThirdyTemp;
  62. m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
  63. m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
  64. m_flForthxTemp=m_flForthx;
  65. m_flForthyTemp=m_flForthy;
  66. }
  67. CRoundRect::~CRoundRect()
  68. {
  69. }
  70. //////////////////////////////////////////////////////////////////////
  71. //////////////////////////////////////////////////////////////////////
  72. //存储
  73. //////////////////////////////////////////////////////////////////////
  74.  void CRoundRect::Serialize( CArchive& ar)
  75.  {
  76.  CShape::Serialize( ar ) ;
  77.  if ( ar.IsLoading() ){  
  78.  ar>>m_flFirstx;
  79.  ar>>m_flFirsty;
  80.  ar>>m_flSecondx;
  81.  ar>>m_flSecondy;
  82.  ar>>m_flThirdx;
  83.  ar>>m_flThirdy;
  84.  //temp
  85.  m_flFirstxTemp=m_flFirstx;
  86.  m_flFirstyTemp=m_flFirsty;
  87.  m_flSecondxTemp=m_flSecondx;
  88.  m_flSecondyTemp=m_flSecondy;
  89.  m_flThirdxTemp=m_flThirdx;
  90.  m_flThirdyTemp=m_flThirdy;
  91.  m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
  92.  m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
  93.  m_flForthxTemp=m_flForthx;
  94.  m_flForthyTemp=m_flForthy;
  95.  } else {
  96.  ar<<m_flFirstx;
  97.  ar<<m_flFirsty;
  98.  ar<<m_flSecondx;
  99.  ar<<m_flSecondy;
  100.  ar<<m_flThirdx;
  101.  ar<<m_flThirdy;  
  102.  }
  103.  return ;
  104.  }
  105.  //////////////////////////////////////////////////////////////////////
  106.  //////////////////////////////////////////////////////////////////////
  107.  //绘画
  108.  //////////////////////////////////////////////////////////////////////
  109.  void CRoundRect::Draw(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth)
  110.  {  
  111.  CPen pen,*poldPen;
  112.  float fldis1,fldis2,flRadius;
  113.  CPoint ptArray1[3], ptArray2[3],ptArray3[3],ptArray4[3];
  114.  fldis1=GetDistance(m_flFirstxTemp,m_flFirstyTemp,m_flSecondxTemp,m_flSecondyTemp);
  115.      fldis2=GetDistance(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp);
  116.      if(fldis1<1){
  117.  fldis1=1;
  118.      }
  119.  if(fldis2<1){
  120.  fldis2=1;
  121.      }
  122.  flRadius=min(fldis1,fldis2)/7.0;
  123.  
  124.  //分别得到四个角处的三个点,用于绘画贝齐埃曲线
  125.  ptArray1[1]=CPoint(m_flFirstxTemp,m_flFirstyTemp);
  126.  ptArray2[1]=CPoint(m_flSecondxTemp,m_flSecondyTemp);
  127.  ptArray3[1]=CPoint(m_flThirdxTemp,m_flThirdyTemp);
  128.  ptArray4[1]=CPoint(m_flFirstxTemp+m_flThirdxTemp-m_flSecondxTemp,m_flFirstyTemp+m_flThirdyTemp-m_flSecondyTemp);
  129.      
  130.  ptArray1[0]=CPoint(m_flFirstxTemp-flRadius*(m_flSecondxTemp-m_flThirdxTemp)/fldis2,m_flFirstyTemp-flRadius*(m_flSecondyTemp-m_flThirdyTemp)/fldis2);
  131.  ptArray2[0]=CPoint(m_flSecondxTemp-flRadius*(m_flSecondxTemp-m_flFirstxTemp)/fldis1,m_flSecondyTemp-flRadius*(m_flSecondyTemp-m_flFirstyTemp)/fldis1);
  132.  ptArray3[0]=CPoint(m_flThirdxTemp-flRadius*(m_flThirdxTemp-m_flSecondxTemp)/fldis2,m_flThirdyTemp-flRadius*(m_flThirdyTemp-m_flSecondyTemp)/fldis2);
  133.  ptArray4[0]=CPoint(m_flThirdxTemp-(1-flRadius/fldis1)*((m_flSecondxTemp-m_flFirstxTemp)),m_flThirdyTemp-(1-flRadius/fldis1)*(m_flSecondyTemp-m_flFirstyTemp));
  134.  
  135.  ptArray1[2]=CPoint(m_flFirstxTemp-flRadius*(m_flFirstxTemp-m_flSecondxTemp)/fldis1,m_flFirstyTemp-flRadius*(m_flFirstyTemp-m_flSecondyTemp)/fldis1);
  136.  ptArray2[2]=CPoint(m_flSecondxTemp-flRadius*(m_flSecondxTemp-m_flThirdxTemp)/fldis2,m_flSecondyTemp-flRadius*(m_flSecondyTemp-m_flThirdyTemp)/fldis2);
  137.  ptArray3[2]=CPoint(m_flThirdxTemp-flRadius*(m_flSecondxTemp-m_flFirstxTemp)/fldis1,m_flThirdyTemp-flRadius*(m_flSecondyTemp-m_flFirstyTemp)/fldis1);
  138.  ptArray4[2]=CPoint(m_flFirstxTemp-(1-flRadius/fldis2)*(m_flSecondxTemp-m_flThirdxTemp),m_flFirstyTemp-(1-flRadius/fldis2)*(m_flSecondyTemp-m_flThirdyTemp));
  139.  
  140.  pen.CreatePen(PS_SOLID,1, fillColor);
  141.  CBrush brush,*pOldBrush;
  142.  brush.CreateSolidBrush(fillColor);
  143.  pOldBrush=pDC->SelectObject(&brush);
  144.  poldPen=pDC->SelectObject(&pen);
  145.  if(m_nFillStyle==_shape_solid_fill){
  146.  //这里需要改善,至少可以合并成八个点的多边形
  147.  CPoint ptArray[4];
  148.  ptArray[0]=ptArray1[0];  
  149.  ptArray[1]=ptArray2[2];
  150.  ptArray[2]=ptArray3[0];  
  151.  ptArray[3]=ptArray4[2];  
  152.  AreaFill(pDC,4,ptArray,fillColor);
  153.  ptArray[0]=ptArray1[2];  
  154.  ptArray[1]=ptArray2[0];
  155.  ptArray[2]=ptArray3[2];  
  156.  ptArray[3]=ptArray4[0];
  157.  AreaFill(pDC,4,ptArray,fillColor);
  158.  ptArray[0]=CPoint(ptArray1[0].x+ptArray1[2].x-m_flFirstxTemp,ptArray1[0].y+ptArray1[2].y-m_flFirstyTemp);
  159.  ptArray[1]=CPoint(ptArray2[0].x+ptArray2[2].x-m_flSecondxTemp,ptArray2[0].y+ptArray2[2].y-m_flSecondyTemp);
  160.  ptArray[2]=CPoint(ptArray3[0].x+ptArray3[2].x-m_flThirdxTemp,ptArray3[0].y+ptArray3[2].y-m_flThirdyTemp);
  161.  ptArray[3]=CPoint(ptArray4[0].x+ptArray4[2].x-(m_flFirstxTemp+m_flThirdxTemp-m_flSecondxTemp),ptArray4[0].y+ptArray4[2].y-(m_flFirstyTemp+m_flThirdyTemp-m_flSecondyTemp));
  162.  pDC->Ellipse(ptArray[0].x-flRadius,ptArray[0].y-flRadius,ptArray[0].x+flRadius,ptArray[0].y+flRadius);  
  163.  pDC->Ellipse(ptArray[1].x-flRadius,ptArray[1].y-flRadius,ptArray[1].x+flRadius,ptArray[1].y+flRadius);  
  164.  pDC->Ellipse(ptArray[2].x-flRadius,ptArray[2].y-flRadius,ptArray[2].x+flRadius,ptArray[2].y+flRadius);  
  165.  pDC->Ellipse(ptArray[3].x-flRadius,ptArray[3].y-flRadius,ptArray[3].x+flRadius,ptArray[3].y+flRadius);  
  166.  
  167.  }
  168.  pen.DeleteObject();
  169.  pen.CreatePen(PS_SOLID,penWidth,color);  
  170.  pDC->SelectObject(&pen);          
  171.  pDC->SelectObject(pOldBrush);
  172.  
  173.  
  174.  pDC->MoveTo(ptArray1[2]);
  175.  pDC->LineTo(ptArray2[0]);
  176.  pDC->MoveTo(ptArray2[2]);
  177.  pDC->LineTo(ptArray3[0]);
  178.  pDC->MoveTo(ptArray3[2]);
  179.  pDC->LineTo(ptArray4[0]);
  180.  pDC->MoveTo(ptArray4[2]);
  181.  pDC->LineTo(ptArray1[0]);
  182.  
  183.  BezierCurve(pDC,ptArray1,3);
  184.  BezierCurve(pDC,ptArray2,3);
  185.  BezierCurve(pDC,ptArray3,3);
  186.  BezierCurve(pDC,ptArray4,3);
  187.  
  188.  if(GetDrawPointsFlag()==1){
  189.  DrawPoints(pDC,color);
  190.  }
  191.  
  192.  pDC->SelectObject(poldPen);  
  193.  }
  194.  ///////////////////////////////////////////
  195.  void CRoundRect::DrawPointsCutTo(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo)
  196.  {
  197.  //得到移动扩缩后的关键数据
  198.  float flFirstx,flFirsty,flSecondx,flSecondy,flThirdx,flThirdy,flForthx,flForthy;
  199.  //移动
  200.  
  201.  float stepx=m_rectTo.left-m_rectFrom.left;
  202.  float stepy=m_rectTo.top-m_rectFrom.top;
  203.  flFirstx=m_flFirstxTemp+stepx;
  204.  flFirsty=m_flFirstyTemp+stepy;
  205.  flSecondx=m_flSecondxTemp+stepx;
  206.  flSecondy=m_flSecondyTemp+stepy;
  207.  flThirdx=m_flThirdxTemp+stepx;
  208.  flThirdy=m_flThirdyTemp+stepy;
  209.  flForthx=m_flForthxTemp+stepx;
  210.  flForthy=m_flForthyTemp+stepy;
  211.  //扩缩
  212.  float cx,cy,flScale;
  213.  cx=m_rectTo.left;
  214.  cy=m_rectTo.top;  
  215.  if(m_rectFrom.Width()<0.01){
  216.  m_rectFrom.right=m_rectFrom.left +1;
  217.  }
  218.  if(m_rectFrom.Height()<0.01){
  219.  m_rectFrom.bottom=m_rectFrom.top +1;
  220.  }
  221.  flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
  222.  //flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
  223.  flFirstx=(flFirstx-cx)*flScale+cx;
  224.  flFirsty=(flFirsty-cy)*flScale+cy;
  225.  flSecondx=(flSecondx-cx)*flScale+cx;
  226.  flSecondy=(flSecondy-cy)*flScale+cy;
  227.  flThirdx=(flThirdx-cx)*flScale+cx;
  228.  flThirdy=(flThirdy-cy)*flScale+cy;  
  229.  flForthx=(flForthx-cx)*flScale+cx;
  230.  flForthy=(flForthy-cy)*flScale+cy;
  231.  CPen pen,*poldPen;
  232.  pen.CreatePen(PS_SOLID,1, color);
  233.  poldPen=pDC->SelectObject(&pen);
  234.  {
  235.  pDC->MoveTo(flFirstx,flFirsty-1-GetPenWidth());
  236.  pDC->LineTo(flFirstx,flFirsty+2+GetPenWidth());
  237.  pDC->MoveTo(flFirstx-1-GetPenWidth(),flFirsty);
  238.  pDC->LineTo(flFirstx+2+GetPenWidth(),flFirsty);
  239.  
  240.  pDC->MoveTo(flSecondx,flSecondy-1-GetPenWidth());
  241.  pDC->LineTo(flSecondx,flSecondy+2+GetPenWidth());
  242.  pDC->MoveTo(flSecondx-1-GetPenWidth(),flSecondy);
  243.  pDC->LineTo(flSecondx+2+GetPenWidth(),flSecondy);
  244.  
  245.  pDC->MoveTo(flThirdx,flThirdy-1-GetPenWidth());
  246.  pDC->LineTo(flThirdx,flThirdy+2+GetPenWidth());
  247.  pDC->MoveTo(flThirdx-1-GetPenWidth(),flThirdy);
  248.  pDC->LineTo(flThirdx+2+GetPenWidth(),flThirdy);
  249.  
  250.  pDC->MoveTo(flForthx,flForthy-1-GetPenWidth());
  251.  pDC->LineTo(flForthx,flForthy+2+GetPenWidth());
  252.  pDC->MoveTo(flForthx-1-GetPenWidth(),flForthy);
  253.  pDC->LineTo(flForthx+2+GetPenWidth(),flForthy);
  254.  }  
  255.  pDC->SelectObject(poldPen);      
  256.  return;
  257.  }
  258. void CRoundRect::DrawPoints(CDC *pDC,COLORREF color)
  259. {
  260. float flForthx,flForthy;
  261. flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
  262. flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
  263. CPen pen,*poldPen;
  264.     pen.CreatePen(PS_SOLID,1, color);
  265. poldPen=pDC->SelectObject(&pen);
  266. {
  267. pDC->MoveTo(m_flFirstxTemp,m_flFirstyTemp-1-GetPenWidth());
  268. pDC->LineTo(m_flFirstxTemp,m_flFirstyTemp+2+GetPenWidth());
  269. pDC->MoveTo(m_flFirstxTemp-1-GetPenWidth(),m_flFirstyTemp);
  270. pDC->LineTo(m_flFirstxTemp+2+GetPenWidth(),m_flFirstyTemp);
  271. pDC->MoveTo(m_flSecondxTemp,m_flSecondyTemp-1-GetPenWidth());
  272. pDC->LineTo(m_flSecondxTemp,m_flSecondyTemp+2+GetPenWidth());
  273. pDC->MoveTo(m_flSecondxTemp-1-GetPenWidth(),m_flSecondyTemp);
  274. pDC->LineTo(m_flSecondxTemp+2+GetPenWidth(),m_flSecondyTemp);
  275. pDC->MoveTo(m_flThirdxTemp,m_flThirdyTemp-1-GetPenWidth());
  276. pDC->LineTo(m_flThirdxTemp,m_flThirdyTemp+2+GetPenWidth());
  277. pDC->MoveTo(m_flThirdxTemp-1-GetPenWidth(),m_flThirdyTemp);
  278. pDC->LineTo(m_flThirdxTemp+2+GetPenWidth(),m_flThirdyTemp);
  279. pDC->MoveTo(flForthx,flForthy-1-GetPenWidth());
  280. pDC->LineTo(flForthx,flForthy+2+GetPenWidth());
  281. pDC->MoveTo(flForthx-1-GetPenWidth(),flForthy);
  282. pDC->LineTo(flForthx+2+GetPenWidth(),flForthy);
  283. }  
  284. pDC->SelectObject(poldPen);      
  285. return;
  286. }
  287.  ////////////////////////////////////////////
  288.  void CRoundRect::DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth,CFlRect m_rectFrom,CRect m_rectTo)
  289.  {
  290.  // if(!IsInRect(m_rectFrom)){
  291.  // return;
  292.  // }
  293.  //得到移动扩缩后的关键数据
  294.  float flFirstx,flFirsty,flSecondx,flSecondy,flThirdx,flThirdy,flForthx,flForthy;
  295.  //移动
  296.  
  297.  float stepx=m_rectTo.left-m_rectFrom.left;
  298.  float stepy=m_rectTo.top-m_rectFrom.top;
  299.  flFirstx=m_flFirstxTemp+stepx;
  300.  flFirsty=m_flFirstyTemp+stepy;
  301.  flSecondx=m_flSecondxTemp+stepx;
  302.  flSecondy=m_flSecondyTemp+stepy;
  303.  flThirdx=m_flThirdxTemp+stepx;
  304.  flThirdy=m_flThirdyTemp+stepy;
  305.  flForthx=m_flForthxTemp+stepx;
  306.  flForthy=m_flForthyTemp+stepy;
  307.  //扩缩
  308.  float cx,cy,flScale;
  309.  cx=m_rectTo.left;
  310.  cy=m_rectTo.top;  
  311.  if(m_rectFrom.Width()<0.01){
  312.  m_rectFrom.right=m_rectFrom.left +1;
  313.  }
  314.  if(m_rectFrom.Height()<0.01){
  315.  m_rectFrom.bottom=m_rectFrom.top +1;
  316.  }
  317.  flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
  318.  //flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
  319.  flFirstx=(flFirstx-cx)*flScale+cx;
  320.  flFirsty=(flFirsty-cy)*flScale+cy;
  321.  flSecondx=(flSecondx-cx)*flScale+cx;
  322.  flSecondy=(flSecondy-cy)*flScale+cy;
  323.  flThirdx=(flThirdx-cx)*flScale+cx;
  324.  flThirdy=(flThirdy-cy)*flScale+cy;  
  325.  flForthx=(flForthx-cx)*flScale+cx;
  326.  flForthy=(flForthy-cy)*flScale+cy;
  327.  
  328.  CPen pen,*poldPen;
  329.  float fldis1,fldis2,flRadius;
  330.  CPoint ptArray1[3], ptArray2[3],ptArray3[3],ptArray4[3];
  331.  fldis1=GetDistance(flFirstx,flFirsty,flSecondx,flSecondy);
  332.      fldis2=GetDistance(flSecondx,flSecondy,flThirdx,flThirdy);
  333.      if(fldis1<1){
  334.  fldis1=1;
  335.      }
  336.  if(fldis2<1){
  337.  fldis2=1;
  338.      }
  339.  flRadius=min(fldis1,fldis2)/7.0;
  340.  
  341.  //分别得到四个角处的三个点,用于绘画贝齐埃曲线
  342.  ptArray1[1]=CPoint(flFirstx,flFirsty);
  343.  ptArray2[1]=CPoint(flSecondx,flSecondy);
  344.  ptArray3[1]=CPoint(flThirdx,flThirdy);
  345.  ptArray4[1]=CPoint(flForthx,flForthy);
  346.      
  347.  ptArray1[0]=CPoint(flFirstx-flRadius*(flSecondx-flThirdx)/fldis2,flFirsty-flRadius*(flSecondy-flThirdy)/fldis2);
  348.  ptArray2[0]=CPoint(flSecondx-flRadius*(flSecondx-flFirstx)/fldis1,flSecondy-flRadius*(flSecondy-flFirsty)/fldis1);
  349.  ptArray3[0]=CPoint(flThirdx-flRadius*(flThirdx-flSecondx)/fldis2,flThirdy-flRadius*(flThirdy-flSecondy)/fldis2);
  350.  ptArray4[0]=CPoint(flThirdx-(1-flRadius/fldis1)*((flSecondx-flFirstx)),flThirdy-(1-flRadius/fldis1)*(flSecondy-flFirsty));
  351.  
  352.  ptArray1[2]=CPoint(flFirstx-flRadius*(flFirstx-flSecondx)/fldis1,flFirsty-flRadius*(flFirsty-flSecondy)/fldis1);
  353.  ptArray2[2]=CPoint(flSecondx-flRadius*(flSecondx-flThirdx)/fldis2,flSecondy-flRadius*(flSecondy-flThirdy)/fldis2);
  354.  ptArray3[2]=CPoint(flThirdx-flRadius*(flSecondx-flFirstx)/fldis1,flThirdy-flRadius*(flSecondy-flFirsty)/fldis1);
  355.  ptArray4[2]=CPoint(flFirstx-(1-flRadius/fldis2)*(flSecondx-flThirdx),flFirsty-(1-flRadius/fldis2)*(flSecondy-flThirdy));
  356.  
  357.  pen.CreatePen(PS_SOLID,1, fillColor);
  358.  CBrush brush,*pOldBrush;
  359.  brush.CreateSolidBrush(fillColor);
  360.  pOldBrush=pDC->SelectObject(&brush);
  361.  poldPen=pDC->SelectObject(&pen);
  362.  if(m_nFillStyle==_shape_solid_fill){
  363.  //这里需要改善,至少可以合并成八个点的多边形
  364.  CPoint ptArray[4];
  365.  ptArray[0]=ptArray1[0];  
  366.  ptArray[1]=ptArray2[2];
  367.  ptArray[2]=ptArray3[0];  
  368.  ptArray[3]=ptArray4[2];  
  369.  AreaFill(pDC,4,ptArray,fillColor);
  370.  ptArray[0]=ptArray1[2];  
  371.  ptArray[1]=ptArray2[0];
  372.  ptArray[2]=ptArray3[2];  
  373.  ptArray[3]=ptArray4[0];
  374.  AreaFill(pDC,4,ptArray,fillColor);
  375.  ptArray[0]=CPoint(ptArray1[0].x+ptArray1[2].x-flFirstx,ptArray1[0].y+ptArray1[2].y-flFirsty);
  376.  ptArray[1]=CPoint(ptArray2[0].x+ptArray2[2].x-flSecondx,ptArray2[0].y+ptArray2[2].y-flSecondy);
  377.  ptArray[2]=CPoint(ptArray3[0].x+ptArray3[2].x-flThirdx,ptArray3[0].y+ptArray3[2].y-flThirdy);
  378.  ptArray[3]=CPoint(ptArray4[0].x+ptArray4[2].x-(flFirstx+flThirdx-flSecondx),ptArray4[0].y+ptArray4[2].y-(flFirsty+flThirdy-flSecondy));
  379.  pDC->Ellipse(ptArray[0].x-flRadius,ptArray[0].y-flRadius,ptArray[0].x+flRadius,ptArray[0].y+flRadius);  
  380.  pDC->Ellipse(ptArray[1].x-flRadius,ptArray[1].y-flRadius,ptArray[1].x+flRadius,ptArray[1].y+flRadius);  
  381.  pDC->Ellipse(ptArray[2].x-flRadius,ptArray[2].y-flRadius,ptArray[2].x+flRadius,ptArray[2].y+flRadius);  
  382.  pDC->Ellipse(ptArray[3].x-flRadius,ptArray[3].y-flRadius,ptArray[3].x+flRadius,ptArray[3].y+flRadius);  
  383.  
  384.  }
  385.  pen.DeleteObject();
  386.  pen.CreatePen(PS_SOLID,penWidth,color);  
  387.  pDC->SelectObject(&pen);          
  388.  pDC->SelectObject(pOldBrush);  
  389.  
  390.  pDC->MoveTo(ptArray1[2]);
  391.  pDC->LineTo(ptArray2[0]);
  392.  pDC->MoveTo(ptArray2[2]);
  393.  pDC->LineTo(ptArray3[0]);
  394.  pDC->MoveTo(ptArray3[2]);
  395.  pDC->LineTo(ptArray4[0]);
  396.  pDC->MoveTo(ptArray4[2]);
  397.  pDC->LineTo(ptArray1[0]);
  398.  
  399.  BezierCurve(pDC,ptArray1,3);
  400.  BezierCurve(pDC,ptArray2,3);
  401.  BezierCurve(pDC,ptArray3,3);
  402.  BezierCurve(pDC,ptArray4,3);  
  403.  
  404.  
  405.  if(GetDrawPointsFlag()==1){
  406.  DrawPointsCutTo(pDC,color,m_rectFrom,m_rectTo);
  407.  }
  408.  
  409.  pDC->SelectObject(poldPen);  
  410.  }
  411.  //////////////////////////////////////////////////////////////////////
  412.  void CRoundRect::RoundRectangle(CDC *pDC,CPoint LeftTop,CPoint RightBottom,COLORREF color)
  413.  {
  414. /*  CPoint  LT,RB,center[4];
  415.  int Radius;
  416.  LT.x=LeftTop.x<RightBottom.x?LeftTop.x:RightBottom.x;//取两点
  417.  LT.y=LeftTop.y<RightBottom.y?LeftTop.y:RightBottom.y;
  418.  RB.x=LeftTop.x>RightBottom.x?LeftTop.x:RightBottom.x;
  419.  RB.y=LeftTop.y>RightBottom.y?LeftTop.y:RightBottom.y;    
  420.  
  421.  Radius=(RB.x-LT.x)/7<(RB.y-LT.y)/7?(RB.x-LT.x)/7:(RB.y-LT.y)/7;
  422.  center[0].x=LT.x+Radius;
  423.  center[0].y=LT.y+Radius;
  424.  center[1].x=RB.x-Radius;
  425.  center[1].y=LT.y+Radius;
  426.  center[2].x=LT.x+Radius;
  427.  center[2].y=RB.y-Radius;
  428.  center[3].x=RB.x-Radius;
  429.  center[3].y=RB.y-Radius;
  430.  
  431.  pDC->MoveTo(LT.x+Radius,LT.y);
  432.  pDC->LineTo(RB.x-Radius,LT.y);
  433.  pDC->MoveTo(LT.x,LT.y+Radius);
  434.  pDC->LineTo(LT.x,RB.y-Radius);
  435.  pDC->MoveTo(LT.x+Radius,RB.y);
  436.  pDC->LineTo(RB.x-Radius,RB.y);
  437.  pDC->MoveTo(RB.x,LT.y+Radius);
  438.  pDC->LineTo(RB.x,RB.y-Radius);   
  439.  
  440.  int x,y,di,i;
  441.  x=0;
  442.  y=Radius;
  443.  di=3-2*Radius;
  444.  while(x<=y)//画出四个圆角
  445.  {
  446.  for(i=0;i<1;i++)
  447.  {
  448.  pDC->SetPixel(center[3].x+x+i,center[3].y+y,color);
  449.  pDC->SetPixel(center[1].x+x+i,center[1].y-y,color);
  450.  pDC->SetPixel(center[2].x-x+i,center[2].y+y,color);
  451.  pDC->SetPixel(center[0].x-x+i,center[0].y-y,color);
  452.  pDC->SetPixel(center[3].x+y+i,center[3].y+x,color);
  453.  pDC->SetPixel(center[1].x+y+i,center[1].y-x,color);
  454.  pDC->SetPixel(center[2].x-y+i,center[2].y+x,color);
  455.  pDC->SetPixel(center[0].x-y+i,center[0].y-x,color);
  456.  
  457.  pDC->SetPixel(center[3].x+x,center[3].y+y+i,color);
  458.  pDC->SetPixel(center[1].x+x,center[1].y-y+i,color);
  459.  pDC->SetPixel(center[2].x-x,center[2].y+y+i,color);
  460.  pDC->SetPixel(center[0].x-x,center[0].y-y+i,color);
  461.  pDC->SetPixel(center[3].x+y,center[3].y+x+i,color);
  462.  pDC->SetPixel(center[1].x+y,center[1].y-x+i,color);
  463.  pDC->SetPixel(center[2].x-y,center[2].y+x+i,color);
  464.  pDC->SetPixel(center[0].x-y,center[0].y-x+i,color);
  465.  }
  466.  if(di<0)
  467.  {
  468.  di+=4*x+6;
  469.  }
  470.  else
  471.  {
  472.  di+=4*(x-y)+10;
  473.  y--;
  474.  }
  475.  x++;
  476.  }
  477.  */
  478.  }
  479.  //////////////////////////////////////////////////////////////////////
  480.  void CRoundRect::CreatGraph(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
  481.  {  
  482.  if(flArrayX.GetSize()<2){
  483.  return;
  484.  }
  485.  CShape::CreatGraph(flArrayX,flArrayY,nPenWidth,color,fillColor,nStyle);
  486.  m_flFirstxTemp=m_flFirstx=flArrayX.GetAt(0);
  487.  m_flFirstyTemp=m_flFirsty=flArrayY.GetAt(0);
  488.  m_flSecondxTemp=m_flSecondx=flArrayX.GetAt(0);
  489.  m_flSecondyTemp=m_flSecondy=flArrayY.GetAt(1);
  490.  m_flThirdxTemp=m_flThirdx=flArrayX.GetAt(1);
  491.  m_flThirdyTemp=m_flThirdy=flArrayY.GetAt(1);
  492.  
  493.  m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
  494.  m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
  495.  m_flForthxTemp=m_flForthx;
  496.  m_flForthyTemp=m_flForthy;
  497.  }
  498.  void CRoundRect::SetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
  499.  {
  500.  m_flFirstxTemp=m_flFirstx=flArrayX.GetAt(0);
  501.  m_flFirstyTemp=m_flFirsty=flArrayY.GetAt(0);
  502.  m_flSecondxTemp=m_flSecondx=flArrayX.GetAt(1);
  503.  m_flSecondyTemp=m_flSecondy=flArrayY.GetAt(1);
  504.  m_flThirdxTemp=m_flThirdx=flArrayX.GetAt(2);
  505.  m_flThirdyTemp=m_flThirdy=flArrayY.GetAt(2);
  506.  
  507.  m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
  508.  m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
  509.  m_flForthxTemp=m_flForthx;
  510.  m_flForthyTemp=m_flForthy;
  511.  }
  512.  void CRoundRect::GetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
  513.  {
  514.  flArrayX.RemoveAll();
  515.  flArrayY.RemoveAll();
  516.  
  517.  flArrayX.Add(m_flFirstxTemp);
  518.  flArrayX.Add(m_flSecondxTemp);
  519.  flArrayX.Add(m_flThirdxTemp);
  520.  
  521.  flArrayY.Add(m_flFirstyTemp);
  522.  flArrayY.Add(m_flSecondyTemp);
  523.  flArrayY.Add(m_flThirdyTemp);
  524.  }
  525.  //////////////////////////////////////////////////////////////////////
  526.  void CRoundRect::CreatGraph(CArray<CPoint,CPoint>& ptArray,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
  527.  {  
  528.  if(ptArray.GetSize()<2){
  529.  return;
  530.  }
  531.  CShape::CreatGraph(ptArray,nPenWidth,color,fillColor,nStyle);
  532.  m_flFirstxTemp=m_flFirstx=((CPoint)ptArray.GetAt(0)).x;
  533.  m_flFirstyTemp=m_flFirsty=((CPoint)ptArray.GetAt(0)).y;
  534.  m_flThirdxTemp=m_flThirdx=((CPoint)ptArray.GetAt(1)).x;
  535.  m_flThirdyTemp=m_flThirdy=((CPoint)ptArray.GetAt(1)).y;
  536.  m_flSecondxTemp=m_flSecondx=((CPoint)ptArray.GetAt(0)).x;
  537.  m_flSecondyTemp=m_flSecondy=((CPoint)ptArray.GetAt(1)).y;
  538.  m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
  539.  m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
  540.  m_flForthxTemp=m_flForthx;
  541.  m_flForthyTemp=m_flForthy;
  542.  }
  543.  CShape* CRoundRect::GetCopy()
  544.  {
  545.  CShape* pGraph=new CRoundRect(this);
  546.  return pGraph;  
  547.  }
  548. //////////////////////////////////////////////////////////////////////
  549.  //////////////////////////////////////////////////////////////////////
  550.  void CRoundRect::Move(CDC *pDC,float stepx,float stepy)
  551.  {
  552.  RefreshData(m_bModified);
  553. //  CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  554.  m_flFirstx+=stepx;
  555.  m_flFirsty+=stepy;
  556.  m_flSecondx+=stepx;
  557.  m_flSecondy+=stepy;
  558.  m_flThirdx+=stepx;
  559.  m_flThirdy+=stepy;
  560.  //temp
  561.  m_flFirstxTemp+=stepx;
  562.  m_flFirstyTemp+=stepy;
  563.  m_flSecondxTemp+=stepx;
  564.  m_flSecondyTemp+=stepy;
  565.  m_flThirdxTemp+=stepx;
  566.  m_flThirdyTemp+=stepy;
  567.  m_flForthx+=stepx;
  568.  m_flForthy+=stepy;
  569.  m_flForthxTemp=m_flForthx;
  570.  m_flForthyTemp=m_flForthy;
  571.  }
  572.  void CRoundRect::PartMove(CDC *pDC,float PrevX,float PrevY,float CurX,float CurY)
  573.  {
  574.  if(m_nSelectPtNum>-1){
  575. //  CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  576.  float flX,flY;
  577.  float flDisA,flDisB;  
  578.  switch(m_nSelectPtNum) {
  579.  case 0:
  580.  flX = m_flThirdx;
  581.  flY = m_flThirdy;             
  582.  flDisA=GetDistance(m_flThirdx,m_flThirdy,m_flFirstx,m_flFirsty);
  583.  flDisB=GetDistance(m_flThirdx,m_flThirdy,CurX,CurY);  
  584.  break;
  585.  case 1:
  586.  flX = m_flForthx;
  587.  flY = m_flForthy;             
  588.  flDisA=GetDistance(m_flForthx,m_flForthy,m_flSecondx,m_flSecondy);
  589.  flDisB=GetDistance(m_flForthx,m_flForthy,CurX,CurY);
  590.  break;
  591.  case 2:
  592.  flX = m_flFirstx;
  593.  flY = m_flFirsty;             
  594.  flDisA=GetDistance(m_flFirstx,m_flFirsty,m_flThirdx,m_flThirdy);
  595.  flDisB=GetDistance(m_flFirstx,m_flFirsty,CurX,CurY);
  596.  break;
  597.  case 3:
  598.  flX = m_flSecondx;
  599.  flY = m_flSecondy;             
  600.  flDisA=GetDistance(m_flSecondx,m_flSecondy,m_flForthx,m_flForthy);
  601.  flDisB=GetDistance(m_flSecondx,m_flSecondy,CurX,CurY);
  602.  break;  
  603.  }
  604.  if(flDisA<1){
  605.  flDisA=1;
  606.  }
  607.  Magnify(pDC,flX,flY,flDisB/flDisA);
  608.  //CShape::Draw(pDC);
  609.  }else if(m_nSelectLineNum>-1){
  610. //  CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  611. float flCut1x,flCut1y,flCut2x,flCut2y;
  612.  float flX1[4],flY1[4],flX2[4],flY2[4];
  613.  switch(m_nSelectLineNum) {
  614.  case 0:
  615.  flX1[0]=m_flForthx;
  616.  flY1[0]=m_flForthy;
  617.  flX1[1]=CurX;
  618.  flY1[1]=CurY;    
  619.  flX1[2] = m_flFirstx;
  620.  flY1[2] = m_flFirsty;
  621.  flX1[3] = m_flSecondx;
  622.  flY1[3] = m_flSecondy;
  623.  flX2[0]=m_flThirdx;
  624.  flY2[0]=m_flThirdy;
  625.  flX2[1]=CurX;
  626.  flY2[1]=CurY;    
  627.  flX2[2] = m_flFirstx;
  628.  flY2[2] = m_flFirsty;
  629.  flX2[3] = m_flSecondx;
  630.  flY2[3] = m_flSecondy;
  631.  if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
  632.  if(fabs(flCut1x-m_flForthx)>=0.01){
  633.  m_flFirstxTemp=(m_flFirstx-m_flForthx)*((float)CurX-flCut1x)/(flCut1x-m_flForthx)+m_flFirstx;
  634.  } 
  635.  if(fabs(flCut1y-m_flForthy)>=0.01){
  636.  m_flFirstyTemp=(m_flFirsty-m_flForthy)*((float)CurY-flCut1y)/(flCut1y-m_flForthy)+m_flFirsty;
  637.  }
  638.  if(fabs(flCut2x-m_flThirdx)>=0.01){
  639. m_flSecondxTemp=(m_flSecondx-m_flThirdx)*((float)CurX-flCut2x)/(flCut2x-m_flThirdx)+m_flSecondx;
  640.  }
  641.  if(fabs(flCut2y-m_flThirdy)>=0.01){
  642.   m_flSecondyTemp=(m_flSecondy-m_flThirdy)*((float)CurY-flCut2y)/(flCut2y-m_flThirdy)+m_flSecondy;
  643.  }
  644.  }
  645.  break;
  646.  case 1:
  647.  flX1[0]=m_flFirstx;
  648.  flY1[0]=m_flFirsty;
  649.  flX1[1]=CurX;
  650.  flY1[1]=CurY;    
  651.  flX1[2] = m_flSecondx;
  652.  flY1[2] = m_flSecondy;
  653.  flX1[3] = m_flThirdx;
  654.  flY1[3] = m_flThirdy;
  655.  flX2[0]=m_flForthx;
  656.  flY2[0]=m_flForthy;
  657.  flX2[1]=CurX;
  658.  flY2[1]=CurY;    
  659.  flX2[2] = flX1[2];
  660.  flY2[2] = flY1[2];
  661.  flX2[3] = flX1[3];
  662.  flY2[3] = flY1[3];
  663.  
  664.  if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
  665.  
  666.  if(fabs(flCut1x-m_flFirstx)>=0.01){
  667.  m_flSecondxTemp=(m_flSecondx-m_flFirstx)*((float)CurX-flCut1x)/(flCut1x-m_flFirstx)+m_flSecondx;
  668.  } 
  669.  if(fabs(flCut1y-m_flFirsty)>=0.01){
  670.      m_flSecondyTemp=(m_flSecondy-m_flFirsty)*((float)CurY-flCut1y)/(flCut1y-m_flFirsty)+m_flSecondy;
  671.  }
  672.  if(fabs(flCut2x-m_flForthx)>=0.01){
  673.  m_flThirdxTemp=(m_flThirdx-m_flForthx)*((float)CurX-flCut2x)/(flCut2x-m_flForthx)+m_flThirdx;
  674.  }
  675.  if(fabs(flCut2y-m_flForthy)>=0.01){
  676.  m_flThirdyTemp=(m_flThirdy-m_flForthy)*((float)CurY-flCut2y)/(flCut2y-m_flForthy)+m_flThirdy;
  677.  }
  678.  }
  679.  break;
  680.  case 2:
  681.  flX1[0]=m_flSecondx;
  682.  flY1[0]=m_flSecondy;
  683.  flX1[1]=CurX;
  684.  flY1[1]=CurY;    
  685.  flX1[2] = m_flThirdx;
  686.  flY1[2] = m_flThirdy;
  687.  flX1[3] = m_flForthx;
  688.  flY1[3] = m_flForthy;
  689.  flX2[0]=m_flFirstx;
  690.  flY2[0]=m_flFirsty;
  691.  flX2[1]=CurX;
  692.  flY2[1]=CurY;    
  693.  flX2[2] = flX1[2];
  694.  flY2[2] = flY1[2];
  695.  flX2[3] = flX1[3];
  696.  flY2[3] = flY1[3];
  697.  if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
  698.  
  699.  if(fabs(flCut1x-m_flSecondx)>=0.01){
  700.  m_flThirdxTemp=(m_flThirdx-m_flSecondx)*((float)CurX-flCut1x)/(flCut1x-m_flSecondx)+m_flThirdx;
  701.  } 
  702.  if(fabs(flCut1y-m_flSecondy)>=0.01){
  703. m_flThirdyTemp=(m_flThirdy-m_flSecondy)*((float)CurY-flCut1y)/(flCut1y-m_flSecondy)+m_flThirdy;
  704.  }
  705.  if(fabs(flCut2x-m_flFirstx)>=0.01){
  706.  m_flForthxTemp=(m_flForthx-m_flFirstx)*((float)CurX-flCut2x)/(flCut2x-m_flFirstx)+m_flForthx;
  707.  }
  708.  if(fabs(flCut2y-m_flFirsty)>=0.01){
  709.  m_flForthyTemp=(m_flForthy-m_flFirsty)*((float)CurY-flCut2y)/(flCut2y-m_flFirsty)+m_flForthy;
  710.  }
  711.  }
  712.  break;
  713.  case 3:
  714.  flX1[0]=m_flThirdx;
  715.  flY1[0]=m_flThirdy;
  716.  flX1[1]=CurX;
  717.  flY1[1]=CurY;    
  718.  flX1[2] = m_flForthx;
  719.  flY1[2] = m_flForthy;
  720.  flX1[3] = m_flFirstx;
  721.  flY1[3] = m_flFirsty;
  722.  flX2[0]=m_flSecondx;
  723.  flY2[0]=m_flSecondy;
  724.  flX2[1]=CurX;
  725.  flY2[1]=CurY;    
  726.  flX2[2] = flX1[2];
  727.  flY2[2] = flY1[2];
  728.  flX2[3] = flX1[3];
  729.  flY2[3] = flY1[3];
  730.  if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
  731.  
  732.  if(fabs(flCut1x-m_flThirdx)>=0.01){
  733.  m_flForthxTemp=(m_flForthx-m_flThirdx)*((float)CurX-flCut1x)/(flCut1x-m_flThirdx)+m_flForthx;
  734.  } 
  735.  if(fabs(flCut1y-m_flThirdy)>=0.01){
  736.  m_flForthyTemp=(m_flForthy-m_flThirdy)*((float)CurY-flCut1y)/(flCut1y-m_flThirdy)+m_flForthy;
  737.  }
  738.  if(fabs(flCut2x-m_flSecondx)>=0.01){
  739.  m_flFirstxTemp=(m_flFirstx-m_flSecondx)*((float)CurX-flCut2x)/(flCut2x-m_flSecondx)+m_flFirstx;
  740.  }
  741.  if(fabs(flCut2y-m_flSecondy)>=0.01){
  742. m_flFirstyTemp=(m_flFirsty-m_flSecondy)*((float)CurY-flCut2y)/(flCut2y-m_flSecondy)+m_flFirsty;
  743.  }
  744.  }  
  745.  break;  
  746.  }
  747.  //CShape::Draw(pDC);
  748.  }
  749.  }
  750.  /////////////////////////////////////////////
  751.  //function Rotate(...)
  752.  //Rotate flAngle degrees around the ptCenter given as a param
  753.  ////////////////////////////////////////////
  754.  void CRoundRect::Rotate(CDC *pDC,float CX,float CY,float flAngle)
  755.  {
  756.  if(m_flScaleTemp!=1){
  757.  RefreshData(TRUE);
  758.  }
  759.  
  760.  //  CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  761.  
  762.  m_ptRotateCenterTemp=CPoint(CX,CY);
  763.  m_flAngleTemp=flAngle;
  764.  m_bModified=TRUE;
  765.  
  766.  m_flFirstxTemp=((m_flFirstx-CX)*cos(flAngle)-(m_flFirsty-CY)*sin(flAngle))+CX;
  767.  m_flFirstyTemp=((m_flFirsty-CY)*cos(flAngle)+(m_flFirstx-CX)*sin(flAngle))+CY;
  768.  m_flSecondxTemp=((m_flSecondx-CX)*cos(flAngle)-(m_flSecondy-CY)*sin(flAngle))+CX;
  769.  m_flSecondyTemp=((m_flSecondy-CY)*cos(flAngle)+(m_flSecondx-CX)*sin(flAngle))+CY;
  770.  m_flThirdxTemp=((m_flThirdx-CX)*cos(flAngle)-(m_flThirdy-CY)*sin(flAngle))+CX;
  771.  m_flThirdyTemp=((m_flThirdy-CY)*cos(flAngle)+(m_flThirdx-CX)*sin(flAngle))+CY;
  772.  
  773.  m_flForthxTemp=((m_flForthx-CX)*cos(flAngle)-(m_flForthy-CY)*sin(flAngle))+CX;
  774.  m_flForthyTemp=((m_flForthy-CY)*cos(flAngle)+(m_flForthx-CX)*sin(flAngle))+CY;
  775.  //Draw(pDC);
  776.  }
  777.  /////////////////////////////////////////////
  778.  //function Magnify(...)
  779.  //Magnify flScale times relative to the ptCenter given as a param
  780.  ////////////////////////////////////////////
  781.  void CRoundRect::Magnify(CDC *pDC,float CX,float CY,float flScale)
  782.  {
  783.  if(m_flAngleTemp!=0){
  784.  RefreshData(TRUE);
  785.  }
  786.  //  CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));  
  787.  m_ptMagnifyCenterTemp=CPoint(CX,CY);
  788.  m_flScaleTemp=flScale;
  789.  m_bModified=TRUE;
  790.  
  791.  m_flFirstxTemp=(m_flFirstx-CX)*flScale+CX;
  792.  m_flFirstyTemp=(m_flFirsty-CY)*flScale+CY;
  793.  m_flSecondxTemp=(m_flSecondx-CX)*flScale+CX;
  794.  m_flSecondyTemp=(m_flSecondy-CY)*flScale+CY;
  795.  m_flThirdxTemp=(m_flThirdx-CX)*flScale+CX;
  796.  m_flThirdyTemp=(m_flThirdy-CY)*flScale+CY;  
  797.  
  798.  m_flForthxTemp=(m_flForthx-CX)*flScale+CX;
  799.  m_flForthyTemp=(m_flForthy-CY)*flScale+CY;  
  800.  //Draw(pDC);
  801.  }
  802.  void CRoundRect::TopToBottom(CDC* pDC,CRect rect)
  803.  {
  804.  RefreshData(m_bModified);
  805. //  CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  806.  m_flFirstyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flFirstyTemp;
  807.  m_flSecondyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flSecondyTemp;
  808.  m_flThirdyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flThirdyTemp;
  809.  
  810.  m_flFirsty=rect.top/1000.0+rect.bottom/1000.0-m_flFirsty;
  811.  m_flSecondy=rect.top/1000.0+rect.bottom/1000.0-m_flSecondy;
  812.  m_flThirdy=rect.top/1000.0+rect.bottom/1000.0-m_flThirdy;
  813.  
  814.  m_flForthyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flForthyTemp;  
  815.  m_flForthy=rect.top/1000.0+rect.bottom/1000.0-m_flForthy;
  816. // CShape::Draw(pDC);
  817.  }
  818.  void CRoundRect::LeftToRight(CDC* pDC,CRect rect)
  819.  {
  820.  RefreshData(m_bModified);
  821. //  CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  822.  m_flFirstxTemp=rect.left/1000.0+rect.right/1000.0-m_flFirstxTemp;
  823.  m_flSecondxTemp=rect.left/1000.0+rect.right/1000.0-m_flSecondxTemp;
  824.  m_flThirdxTemp=rect.left/1000.0+rect.right/1000.0-m_flThirdxTemp;
  825.  
  826.  m_flFirstx=rect.left/1000.0+rect.right/1000.0-m_flFirstx;
  827.  m_flSecondx=rect.left/1000.0+rect.right/1000.0-m_flSecondx;
  828.  m_flThirdx=rect.left/1000.0+rect.right/1000.0-m_flThirdx;
  829.  
  830.  m_flForthxTemp=rect.left/1000.0+rect.right/1000.0-m_flForthxTemp;  
  831.  m_flForthx=rect.left/1000.0+rect.right/1000.0-m_flForthx;
  832. //  CShape::Draw(pDC);
  833.  } 
  834.  ///
  835.  void CRoundRect::RefreshData(bool bRefresh)
  836.  {
  837.  if(bRefresh){
  838.  
  839.  m_flFirstx = m_flFirstxTemp;
  840.      m_flFirsty = m_flFirstyTemp;
  841.  m_flSecondx = m_flSecondxTemp ;
  842.  m_flSecondy = m_flSecondyTemp;
  843.  m_flThirdx = m_flThirdxTemp;
  844.  m_flThirdy = m_flThirdyTemp;
  845.  m_flForthx = m_flForthxTemp;
  846.  m_flForthy = m_flForthyTemp;  
  847.  m_bModified=FALSE;
  848.  m_ptMagnifyCenterTemp=CPoint(0,0);
  849.  m_flScaleTemp=1;
  850.  m_ptRotateCenterTemp=CPoint(0,0);
  851.  m_flAngleTemp=0;
  852.  }
  853.  }
  854.  //////////////////////////////////////////////////////////////////////
  855.  //////////////////////////////////////////////////////////////////////
  856.  /////////////////////////////////////////////
  857.  //function------IsInRect
  858.  //return value
  859.  //0----------out
  860.  //1----------cut
  861.  //2----------in
  862.  /////////////////////////////////////////////
  863.  int CRoundRect::IsInRect(CRect rect)
  864.  {
  865.  INT nRltVal=0,nTemp;;
  866.  float fldis1,fldis2,flRadius;
  867.  CPoint ptArray1[3], ptArray2[3],ptArray3[3],ptArray4[3];
  868.  fldis1=GetDistance(m_flFirstxTemp,m_flFirstyTemp,m_flThirdxTemp,m_flThirdyTemp);
  869.      fldis2=GetDistance(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp);
  870.      flRadius=min(fldis1,fldis2)/7.0;
  871.  
  872.  //分别得到四个角处的三个点  
  873.      //拟时针前点
  874.  ptArray1[0]=CPoint(m_flFirstxTemp-(m_flSecondxTemp-m_flThirdxTemp)/7,m_flFirstyTemp-(m_flSecondyTemp-m_flThirdyTemp)/7);
  875.  ptArray2[0]=CPoint(m_flSecondxTemp-(m_flSecondxTemp-m_flFirstxTemp)/7,m_flSecondyTemp-(m_flSecondyTemp-m_flFirstyTemp)/7);
  876.  ptArray3[0]=CPoint(m_flThirdxTemp-(m_flThirdxTemp-m_flSecondxTemp)/7,m_flThirdyTemp-(m_flThirdyTemp-m_flSecondyTemp)/7);
  877.  ptArray4[0]=CPoint(m_flThirdxTemp-6.0*((m_flSecondxTemp-m_flFirstxTemp))/7,m_flThirdyTemp-6.0*(m_flSecondyTemp-m_flFirstyTemp)/7);
  878.  //顺时针前点
  879.  ptArray1[1]=CPoint(m_flFirstxTemp-(m_flFirstxTemp-m_flSecondxTemp)/7,m_flFirstyTemp-(m_flFirstyTemp-m_flSecondyTemp)/7);
  880.  ptArray2[1]=CPoint(m_flSecondxTemp-(m_flSecondxTemp-m_flThirdxTemp)/7,m_flSecondyTemp-(m_flSecondyTemp-m_flThirdyTemp)/7);
  881.  ptArray3[1]=CPoint(m_flThirdxTemp-(m_flSecondxTemp-m_flFirstxTemp)/7,m_flThirdyTemp-(m_flSecondyTemp-m_flFirstyTemp)/7);
  882.  ptArray4[1]=CPoint(m_flFirstxTemp-6.0*(m_flSecondxTemp-m_flThirdxTemp)/7,m_flFirstyTemp-6.0*(m_flSecondyTemp-m_flThirdyTemp)/7);
  883.  //角圆中心点
  884.  ptArray1[2]=CPoint(ptArray1[0].x+ptArray1[1].x-m_flFirstxTemp,ptArray1[0].y+ptArray1[1].y-m_flFirstyTemp);
  885.  ptArray2[2]=CPoint(ptArray2[0].x+ptArray2[1].x-m_flSecondxTemp,ptArray2[0].y+ptArray2[1].y-m_flSecondyTemp);
  886.  ptArray3[2]=CPoint(ptArray3[0].x+ptArray3[1].x-m_flThirdxTemp,ptArray3[0].y+ptArray3[1].y-m_flThirdyTemp);
  887.  ptArray4[2]=CPoint(ptArray4[0].x+ptArray4[1].x-(m_flFirstxTemp+m_flThirdxTemp-m_flSecondxTemp),ptArray4[0].y+ptArray4[1].y-(m_flFirstyTemp+m_flThirdyTemp-m_flSecondyTemp));
  888.  //四条边
  889.  if((nTemp=GetLineStateToRect(ptArray1[1],ptArray2[0],rect))!=0){
  890.  nRltVal= nRltVal|nTemp;
  891.  }
  892.  if((nTemp=GetLineStateToRect(ptArray2[1],ptArray3[0],rect))!=0){
  893.  nRltVal= nRltVal|nTemp;
  894.  }
  895.  if((nTemp=GetLineStateToRect(ptArray3[1],ptArray4[0],rect))!=0){
  896.  nRltVal= nRltVal|nTemp;
  897.  }
  898.  if((nTemp=GetLineStateToRect(ptArray4[1],ptArray1[0],rect))!=0){
  899.  nRltVal= nRltVal|nTemp;
  900.  } 
  901.      //四个角
  902. nTemp=0;
  903. nTemp=CircleStateToRect(rect,ptArray1[2],flRadius);
  904. nRltVal= nRltVal|nTemp;
  905. nTemp=CircleStateToRect(rect,ptArray2[2],flRadius);
  906. nRltVal= nRltVal|nTemp;
  907. nTemp=CircleStateToRect(rect,ptArray3[2],flRadius);
  908. nRltVal= nRltVal|nTemp;
  909. nTemp=CircleStateToRect(rect,ptArray4[2],flRadius);
  910. nRltVal= nRltVal|nTemp;  
  911. if(nRltVal==3){
  912. nRltVal=1;
  913. }else if(nRltVal==0){
  914. CPoint pt[4];
  915. pt[0].x=rect.left;
  916. pt[0].y=rect.top;
  917. pt[1].x=rect.right;
  918. pt[1].y=rect.top;
  919. pt[2].x=rect.right;
  920. pt[2].y=rect.bottom;
  921. pt[3].x=rect.left;
  922. pt[3].y=rect.bottom;
  923. if(IsPointinRegion(pt[0])&&IsPointinRegion(pt[1])&&
  924. IsPointinRegion(pt[2])&&IsPointinRegion(pt[3])&&
  925. m_nFillStyle==_shape_solid_fill){
  926. nRltVal=1;      
  927. }
  928. }  
  929.  return nRltVal;
  930.  }
  931.  CRect CRoundRect::GetBoundaryRect()
  932.  {
  933.  CRect rect;
  934.  float flForthx,flForthy;
  935.  flForthx=m_flForthxTemp;
  936.  flForthy=m_flForthyTemp;  
  937.  rect.left=1000*min(m_flFirstxTemp,min(m_flSecondxTemp,min(m_flThirdxTemp,flForthx)));
  938.  rect.right=1000*max(m_flFirstxTemp,max(m_flSecondxTemp,max(m_flThirdxTemp,flForthx)));
  939.  rect.top=1000*min(m_flFirstyTemp,min(m_flSecondyTemp,min(m_flThirdyTemp,flForthy)));
  940.  rect.bottom=1000*max(m_flFirstyTemp,max(m_flSecondyTemp,max(m_flThirdyTemp,flForthy)));
  941.  
  942.  return rect;
  943.  }
  944.  CPoint CRoundRect::GetCenterPoint()
  945.  {
  946.  CRect rect=GetBoundaryRect();
  947.  return rect.CenterPoint();
  948.  }
  949.  int CRoundRect::IsPointinRegion(POINT point)
  950.  {
  951.  int nRltVal=0;
  952.  float flForthx,flForthy;
  953.  flForthx=m_flForthxTemp;
  954.  flForthy=m_flForthyTemp;  
  955.  if(point.y>min(m_flFirstyTemp,m_flSecondyTemp)&&point.y<max(m_flFirstyTemp,m_flSecondyTemp))
  956.  {
  957.  if((m_flSecondxTemp-(m_flSecondxTemp-m_flFirstxTemp)*(m_flSecondyTemp-point.y)/(m_flSecondyTemp-m_flFirstyTemp))>=point.x){
  958.  nRltVal+=1;
  959.  }
  960.  }
  961.  if(point.y>min(m_flThirdyTemp,m_flSecondyTemp)&&point.y<max(m_flThirdyTemp,m_flSecondyTemp))
  962.  {
  963.  if((m_flSecondxTemp-(m_flSecondxTemp-m_flThirdxTemp)*(m_flSecondyTemp-point.y)/(m_flSecondyTemp-m_flThirdyTemp))>=point.x){
  964.  nRltVal+=1;
  965.  }
  966.  }
  967.  if(point.y>min(m_flThirdyTemp,flForthy)&&point.y<max(m_flThirdyTemp,flForthy))
  968.  {
  969.  if((flForthx-(flForthx-m_flThirdxTemp)*(flForthy-point.y)/(flForthy-m_flThirdyTemp))>=point.x){
  970.  nRltVal+=1;
  971.  }
  972.  }
  973.  if(point.y>min(m_flFirstyTemp,flForthy)&&point.y<max(m_flFirstyTemp,flForthy))
  974.  {
  975.  if((flForthx-(flForthx-m_flFirstxTemp)*(flForthy-point.y)/(flForthy-m_flFirstyTemp))>=point.x){
  976.  nRltVal+=1;
  977.  }
  978.  }
  979.  if(nRltVal!=1){
  980.  nRltVal=0;
  981.  }
  982.  return nRltVal;  
  983.  }
  984.  //
  985.  int CRoundRect::CircleStateToRect(CRect rect,CPoint ptCenter,float flRadius)
  986.  {
  987.  int nRltVal=0;
  988.  CPoint ptRectLT=rect.TopLeft();
  989.  CPoint ptRectRB=rect.BottomRight();
  990.  CPoint ptRectLB,ptRectRT;
  991.  ptRectLB.x=rect.left;
  992.  ptRectLB.y=rect.bottom;
  993.  ptRectRT.x=rect.right;
  994.  ptRectRT.y=rect.top;  
  995.  
  996.  if(GetDistance(ptCenter,ptRectLT)>flRadius&&GetDistance(ptCenter,ptRectRB)>flRadius&&
  997.  GetDistance(ptCenter,ptRectLB)>flRadius&&GetDistance(ptCenter,ptRectRT)>flRadius&&rect.PtInRect(ptCenter)){
  998.  nRltVal=2;
  999.  }
  1000.  int flag =0;
  1001.  if(GetDistance(ptCenter,ptRectLT)<=flRadius){
  1002.  flag++;
  1003.  }
  1004.  if(GetDistance(ptCenter,ptRectRB)<=flRadius){
  1005.  flag++;
  1006.  }
  1007.  if(GetDistance(ptCenter,ptRectLB)<=flRadius){
  1008.  flag++;
  1009.  }
  1010.  if(GetDistance(ptCenter,ptRectRT)<=flRadius){
  1011.  flag++;
  1012.  }
  1013.  if(0<flag&&flag<4){
  1014.  nRltVal=1;
  1015.  }
  1016.  return nRltVal;
  1017.  }
  1018.  //////
  1019.  int CRoundRect::GetPtState(float flx,float fly,float flRate)
  1020.  {  
  1021.  //on out point
  1022.  if(IsPtInRect(m_flFirstxTemp-3*flRate,m_flFirstyTemp-3*flRate,m_flFirstxTemp+3*flRate,m_flFirstyTemp+3*flRate,flx,fly)){
  1023.  m_nSelectPtNum=0;
  1024.  m_nSelectLineNum=-1;
  1025.  return 1;
  1026.  }
  1027.  if(IsPtInRect(m_flSecondxTemp-3*flRate,m_flSecondyTemp-3*flRate,m_flSecondxTemp+3*flRate,m_flSecondyTemp+3*flRate,flx,fly)){
  1028.  m_nSelectPtNum=1;
  1029.  m_nSelectLineNum=-1;
  1030.  return 1;
  1031.  }  
  1032.  if(IsPtInRect(m_flThirdxTemp-3*flRate,m_flThirdyTemp-3*flRate,m_flThirdxTemp+3*flRate,m_flThirdyTemp+3*flRate,flx,fly)){
  1033.  m_nSelectPtNum=2;
  1034.  m_nSelectLineNum=-1;
  1035.  return 1;
  1036.  }  
  1037.  if(IsPtInRect(m_flForthxTemp-3*flRate,m_flForthyTemp-3*flRate,m_flForthxTemp+3*flRate,m_flForthyTemp+3*flRate,flx,fly)){
  1038.  m_nSelectPtNum=3;
  1039.  m_nSelectLineNum=-1;
  1040.  return 1;
  1041.  }
  1042.  
  1043.  //on out line
  1044.  if(GetPtStateToBigLine(m_flFirstxTemp,m_flFirstyTemp,m_flSecondxTemp,m_flSecondyTemp,5*flRate,flx,fly)){
  1045.  m_nSelectPtNum=-1;
  1046.  m_nSelectLineNum=0;
  1047.  return 2;
  1048.  }
  1049.  if(GetPtStateToBigLine(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp,5*flRate,flx,fly)){
  1050.  m_nSelectPtNum=-1;
  1051.  m_nSelectLineNum=1;
  1052.  return 2;
  1053.  }
  1054.  if(GetPtStateToBigLine(m_flThirdxTemp,m_flThirdyTemp,m_flForthxTemp,m_flForthyTemp,5*flRate,flx,fly)){
  1055.  m_nSelectPtNum=-1;
  1056.  m_nSelectLineNum=2;
  1057.  return 2;
  1058.  }
  1059.  if(GetPtStateToBigLine(m_flForthxTemp,m_flForthyTemp,m_flFirstxTemp,m_flFirstyTemp,5*flRate,flx,fly)){
  1060.  m_nSelectPtNum=-1;
  1061.  m_nSelectLineNum=3;
  1062.  return 2;
  1063.  }      
  1064.  //out
  1065.  
  1066. m_nSelectPtNum=-1;
  1067. m_nSelectLineNum=-1;
  1068.  return 0;
  1069.  }
  1070.  float CRoundRect::GetSelectLineRate()
  1071.  {
  1072.  if(m_nSelectLineNum==0||m_nSelectLineNum==2){
  1073.  return -GetLineRate(m_flFirstxTemp,m_flFirstyTemp,m_flSecondxTemp,m_flSecondyTemp);
  1074.  }
  1075.  if(m_nSelectLineNum==1||m_nSelectLineNum==3){
  1076.  return -GetLineRate(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp);
  1077.  }
  1078.  return 0;
  1079.  }
  1080.  
  1081.  //////////////////////////////////////////////////////////////////////
  1082.  // MODULE   :ExPort
  1083.  // ABSTRACT :Export to a txt file
  1084.  // FUNCTION :File->Export...
  1085.  // NOTE     :
  1086.  // RETURN   :
  1087.  // ARGUMENTS:
  1088.  //              I/O           TYPE      NAME       EXPLANATION
  1089.  //               O            FILE*    outStream    Out put File
  1090.  // CREATE   :  FNST)handwolf  2004-4-14
  1091.  // UPDATE   :  
  1092.  //          : 
  1093.  //////////////////////////////////////////////////////////////////////
  1094.  
  1095.  void CRoundRect::ExPort(FILE* outStream)//增加导出txt功能时用
  1096.  {
  1097.  fprintf(outStream, " CRoundRect n");//一定要输入类名
  1098.  CShape::ExPort(outStream);
  1099.  fprintf( outStream, "%f %f %f %f %f %fn",m_flFirstx, m_flFirsty, m_flSecondx, m_flSecondy,m_flThirdx,m_flThirdy);
  1100.  }
  1101.  
  1102.  //////////////////////////////////////////////////////////////////////
  1103.  // MODULE   :ImPort
  1104.  // ABSTRACT :ImPort from a txt file
  1105.  // FUNCTION :File->ImPort...
  1106.  // NOTE     :
  1107.  // RETURN   :
  1108.  // ARGUMENTS:
  1109.  //              I/O           TYPE      NAME       EXPLANATION
  1110.  //               I            FILE*    inStream    in put File
  1111.  // CREATE   :  FNST)handwolf  2004-4-14
  1112.  // UPDATE   :  
  1113.  //          : 
  1114.  //////////////////////////////////////////////////////////////////////
  1115.  void CRoundRect::ImPort(FILE* inStream)
  1116.  {
  1117.  CShape::ImPort(inStream);
  1118.  fscanf(inStream, "%f %f %f %f %f %f",&m_flFirstx, &m_flFirsty, &m_flSecondx, &m_flSecondy,&m_flThirdx,&m_flThirdy);
  1119.  m_flFirstxTemp=m_flFirstx;
  1120.  m_flFirstyTemp=m_flFirsty;
  1121.  m_flSecondxTemp=m_flSecondx;
  1122.  m_flSecondyTemp=m_flSecondy;
  1123.  m_flThirdxTemp=m_flThirdx;
  1124.  m_flThirdyTemp=m_flThirdy;
  1125.  
  1126.  m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
  1127.  m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
  1128.  m_flForthxTemp=m_flForthx;
  1129.  m_flForthyTemp=m_flForthy;
  1130.  }
  1131.  CString CRoundRect::GetNameString()
  1132.  {
  1133.  CString str;
  1134.  str.LoadString(IDS_ROUNDRECT);
  1135.  return str;
  1136.  }
  1137.  //////////////////////////////////////////////////////////////////////
  1138.  //End of File//////////////////////