RoundRect.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:42k
源码类别:
绘图程序
开发平台:
Visual C++
- // RoundRect.cpp: implementation of the CRoundRect class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "GraphSoft.h"
- #include "RoundRect.h"
- #include "GlobalFunction.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- ///////////////////////////////////
- IMPLEMENT_SERIAL( CRoundRect, CShape, 0 )
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- CRoundRect::CRoundRect()
- {
- m_flFirstxTemp=m_flFirstx=0;
- m_flFirstyTemp=m_flFirsty=0;
- m_flSecondxTemp=m_flSecondx=0;
- m_flSecondyTemp=m_flSecondy=0;
- m_flThirdxTemp=m_flThirdx=0;
- m_flThirdyTemp=m_flThirdy=0;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- ////////////////////////////
- CRoundRect::CRoundRect(COLORREF color,int penWidth,float angle):CShape(color,penWidth,angle)
- {
- m_flFirstxTemp=m_flFirstx=0;
- m_flFirstyTemp=m_flFirsty=0;
- m_flSecondxTemp=m_flSecondx=0;
- m_flSecondyTemp=m_flSecondy=0;
- m_flThirdxTemp=m_flThirdx=0;
- m_flThirdyTemp=m_flThirdy=0;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- //////////////////////////////
- CRoundRect::CRoundRect(CRoundRect * const pRoundRect):CShape(pRoundRect)
- {
- m_flFirstx=pRoundRect->m_flFirstx;
- m_flFirsty=pRoundRect->m_flFirsty;
- m_flSecondx=pRoundRect->m_flSecondx;
- m_flSecondy=pRoundRect->m_flSecondy;
- m_flThirdx=pRoundRect->m_flThirdx;
- m_flThirdy=pRoundRect->m_flThirdy;
- ////
- m_flFirstxTemp=pRoundRect->m_flFirstxTemp;
- m_flFirstyTemp=pRoundRect->m_flFirstyTemp;
- m_flSecondxTemp=pRoundRect->m_flSecondxTemp;
- m_flSecondyTemp=pRoundRect->m_flSecondyTemp;
- m_flThirdxTemp=pRoundRect->m_flThirdxTemp;
- m_flThirdyTemp=pRoundRect->m_flThirdyTemp;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- CRoundRect::~CRoundRect()
- {
- }
- //////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- //存储
- //////////////////////////////////////////////////////////////////////
- void CRoundRect::Serialize( CArchive& ar)
- {
- CShape::Serialize( ar ) ;
- if ( ar.IsLoading() ){
- ar>>m_flFirstx;
- ar>>m_flFirsty;
- ar>>m_flSecondx;
- ar>>m_flSecondy;
- ar>>m_flThirdx;
- ar>>m_flThirdy;
- //temp
- m_flFirstxTemp=m_flFirstx;
- m_flFirstyTemp=m_flFirsty;
- m_flSecondxTemp=m_flSecondx;
- m_flSecondyTemp=m_flSecondy;
- m_flThirdxTemp=m_flThirdx;
- m_flThirdyTemp=m_flThirdy;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- } else {
- ar<<m_flFirstx;
- ar<<m_flFirsty;
- ar<<m_flSecondx;
- ar<<m_flSecondy;
- ar<<m_flThirdx;
- ar<<m_flThirdy;
- }
- return ;
- }
- //////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- //绘画
- //////////////////////////////////////////////////////////////////////
- void CRoundRect::Draw(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth)
- {
- CPen pen,*poldPen;
- float fldis1,fldis2,flRadius;
- CPoint ptArray1[3], ptArray2[3],ptArray3[3],ptArray4[3];
- fldis1=GetDistance(m_flFirstxTemp,m_flFirstyTemp,m_flSecondxTemp,m_flSecondyTemp);
- fldis2=GetDistance(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp);
- if(fldis1<1){
- fldis1=1;
- }
- if(fldis2<1){
- fldis2=1;
- }
- flRadius=min(fldis1,fldis2)/7.0;
- //分别得到四个角处的三个点,用于绘画贝齐埃曲线
- ptArray1[1]=CPoint(m_flFirstxTemp,m_flFirstyTemp);
- ptArray2[1]=CPoint(m_flSecondxTemp,m_flSecondyTemp);
- ptArray3[1]=CPoint(m_flThirdxTemp,m_flThirdyTemp);
- ptArray4[1]=CPoint(m_flFirstxTemp+m_flThirdxTemp-m_flSecondxTemp,m_flFirstyTemp+m_flThirdyTemp-m_flSecondyTemp);
- ptArray1[0]=CPoint(m_flFirstxTemp-flRadius*(m_flSecondxTemp-m_flThirdxTemp)/fldis2,m_flFirstyTemp-flRadius*(m_flSecondyTemp-m_flThirdyTemp)/fldis2);
- ptArray2[0]=CPoint(m_flSecondxTemp-flRadius*(m_flSecondxTemp-m_flFirstxTemp)/fldis1,m_flSecondyTemp-flRadius*(m_flSecondyTemp-m_flFirstyTemp)/fldis1);
- ptArray3[0]=CPoint(m_flThirdxTemp-flRadius*(m_flThirdxTemp-m_flSecondxTemp)/fldis2,m_flThirdyTemp-flRadius*(m_flThirdyTemp-m_flSecondyTemp)/fldis2);
- ptArray4[0]=CPoint(m_flThirdxTemp-(1-flRadius/fldis1)*((m_flSecondxTemp-m_flFirstxTemp)),m_flThirdyTemp-(1-flRadius/fldis1)*(m_flSecondyTemp-m_flFirstyTemp));
- ptArray1[2]=CPoint(m_flFirstxTemp-flRadius*(m_flFirstxTemp-m_flSecondxTemp)/fldis1,m_flFirstyTemp-flRadius*(m_flFirstyTemp-m_flSecondyTemp)/fldis1);
- ptArray2[2]=CPoint(m_flSecondxTemp-flRadius*(m_flSecondxTemp-m_flThirdxTemp)/fldis2,m_flSecondyTemp-flRadius*(m_flSecondyTemp-m_flThirdyTemp)/fldis2);
- ptArray3[2]=CPoint(m_flThirdxTemp-flRadius*(m_flSecondxTemp-m_flFirstxTemp)/fldis1,m_flThirdyTemp-flRadius*(m_flSecondyTemp-m_flFirstyTemp)/fldis1);
- ptArray4[2]=CPoint(m_flFirstxTemp-(1-flRadius/fldis2)*(m_flSecondxTemp-m_flThirdxTemp),m_flFirstyTemp-(1-flRadius/fldis2)*(m_flSecondyTemp-m_flThirdyTemp));
- pen.CreatePen(PS_SOLID,1, fillColor);
- CBrush brush,*pOldBrush;
- brush.CreateSolidBrush(fillColor);
- pOldBrush=pDC->SelectObject(&brush);
- poldPen=pDC->SelectObject(&pen);
- if(m_nFillStyle==_shape_solid_fill){
- //这里需要改善,至少可以合并成八个点的多边形
- CPoint ptArray[4];
- ptArray[0]=ptArray1[0];
- ptArray[1]=ptArray2[2];
- ptArray[2]=ptArray3[0];
- ptArray[3]=ptArray4[2];
- AreaFill(pDC,4,ptArray,fillColor);
- ptArray[0]=ptArray1[2];
- ptArray[1]=ptArray2[0];
- ptArray[2]=ptArray3[2];
- ptArray[3]=ptArray4[0];
- AreaFill(pDC,4,ptArray,fillColor);
- ptArray[0]=CPoint(ptArray1[0].x+ptArray1[2].x-m_flFirstxTemp,ptArray1[0].y+ptArray1[2].y-m_flFirstyTemp);
- ptArray[1]=CPoint(ptArray2[0].x+ptArray2[2].x-m_flSecondxTemp,ptArray2[0].y+ptArray2[2].y-m_flSecondyTemp);
- ptArray[2]=CPoint(ptArray3[0].x+ptArray3[2].x-m_flThirdxTemp,ptArray3[0].y+ptArray3[2].y-m_flThirdyTemp);
- 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));
- pDC->Ellipse(ptArray[0].x-flRadius,ptArray[0].y-flRadius,ptArray[0].x+flRadius,ptArray[0].y+flRadius);
- pDC->Ellipse(ptArray[1].x-flRadius,ptArray[1].y-flRadius,ptArray[1].x+flRadius,ptArray[1].y+flRadius);
- pDC->Ellipse(ptArray[2].x-flRadius,ptArray[2].y-flRadius,ptArray[2].x+flRadius,ptArray[2].y+flRadius);
- pDC->Ellipse(ptArray[3].x-flRadius,ptArray[3].y-flRadius,ptArray[3].x+flRadius,ptArray[3].y+flRadius);
- }
- pen.DeleteObject();
- pen.CreatePen(PS_SOLID,penWidth,color);
- pDC->SelectObject(&pen);
- pDC->SelectObject(pOldBrush);
- pDC->MoveTo(ptArray1[2]);
- pDC->LineTo(ptArray2[0]);
- pDC->MoveTo(ptArray2[2]);
- pDC->LineTo(ptArray3[0]);
- pDC->MoveTo(ptArray3[2]);
- pDC->LineTo(ptArray4[0]);
- pDC->MoveTo(ptArray4[2]);
- pDC->LineTo(ptArray1[0]);
- BezierCurve(pDC,ptArray1,3);
- BezierCurve(pDC,ptArray2,3);
- BezierCurve(pDC,ptArray3,3);
- BezierCurve(pDC,ptArray4,3);
- if(GetDrawPointsFlag()==1){
- DrawPoints(pDC,color);
- }
- pDC->SelectObject(poldPen);
- }
- ///////////////////////////////////////////
- void CRoundRect::DrawPointsCutTo(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo)
- {
- //得到移动扩缩后的关键数据
- float flFirstx,flFirsty,flSecondx,flSecondy,flThirdx,flThirdy,flForthx,flForthy;
- //移动
- float stepx=m_rectTo.left-m_rectFrom.left;
- float stepy=m_rectTo.top-m_rectFrom.top;
- flFirstx=m_flFirstxTemp+stepx;
- flFirsty=m_flFirstyTemp+stepy;
- flSecondx=m_flSecondxTemp+stepx;
- flSecondy=m_flSecondyTemp+stepy;
- flThirdx=m_flThirdxTemp+stepx;
- flThirdy=m_flThirdyTemp+stepy;
- flForthx=m_flForthxTemp+stepx;
- flForthy=m_flForthyTemp+stepy;
- //扩缩
- float cx,cy,flScale;
- cx=m_rectTo.left;
- cy=m_rectTo.top;
- if(m_rectFrom.Width()<0.01){
- m_rectFrom.right=m_rectFrom.left +1;
- }
- if(m_rectFrom.Height()<0.01){
- m_rectFrom.bottom=m_rectFrom.top +1;
- }
- flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
- //flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
- flFirstx=(flFirstx-cx)*flScale+cx;
- flFirsty=(flFirsty-cy)*flScale+cy;
- flSecondx=(flSecondx-cx)*flScale+cx;
- flSecondy=(flSecondy-cy)*flScale+cy;
- flThirdx=(flThirdx-cx)*flScale+cx;
- flThirdy=(flThirdy-cy)*flScale+cy;
- flForthx=(flForthx-cx)*flScale+cx;
- flForthy=(flForthy-cy)*flScale+cy;
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- {
- pDC->MoveTo(flFirstx,flFirsty-1-GetPenWidth());
- pDC->LineTo(flFirstx,flFirsty+2+GetPenWidth());
- pDC->MoveTo(flFirstx-1-GetPenWidth(),flFirsty);
- pDC->LineTo(flFirstx+2+GetPenWidth(),flFirsty);
- pDC->MoveTo(flSecondx,flSecondy-1-GetPenWidth());
- pDC->LineTo(flSecondx,flSecondy+2+GetPenWidth());
- pDC->MoveTo(flSecondx-1-GetPenWidth(),flSecondy);
- pDC->LineTo(flSecondx+2+GetPenWidth(),flSecondy);
- pDC->MoveTo(flThirdx,flThirdy-1-GetPenWidth());
- pDC->LineTo(flThirdx,flThirdy+2+GetPenWidth());
- pDC->MoveTo(flThirdx-1-GetPenWidth(),flThirdy);
- pDC->LineTo(flThirdx+2+GetPenWidth(),flThirdy);
- pDC->MoveTo(flForthx,flForthy-1-GetPenWidth());
- pDC->LineTo(flForthx,flForthy+2+GetPenWidth());
- pDC->MoveTo(flForthx-1-GetPenWidth(),flForthy);
- pDC->LineTo(flForthx+2+GetPenWidth(),flForthy);
- }
- pDC->SelectObject(poldPen);
- return;
- }
- void CRoundRect::DrawPoints(CDC *pDC,COLORREF color)
- {
- float flForthx,flForthy;
- flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- {
- pDC->MoveTo(m_flFirstxTemp,m_flFirstyTemp-1-GetPenWidth());
- pDC->LineTo(m_flFirstxTemp,m_flFirstyTemp+2+GetPenWidth());
- pDC->MoveTo(m_flFirstxTemp-1-GetPenWidth(),m_flFirstyTemp);
- pDC->LineTo(m_flFirstxTemp+2+GetPenWidth(),m_flFirstyTemp);
- pDC->MoveTo(m_flSecondxTemp,m_flSecondyTemp-1-GetPenWidth());
- pDC->LineTo(m_flSecondxTemp,m_flSecondyTemp+2+GetPenWidth());
- pDC->MoveTo(m_flSecondxTemp-1-GetPenWidth(),m_flSecondyTemp);
- pDC->LineTo(m_flSecondxTemp+2+GetPenWidth(),m_flSecondyTemp);
- pDC->MoveTo(m_flThirdxTemp,m_flThirdyTemp-1-GetPenWidth());
- pDC->LineTo(m_flThirdxTemp,m_flThirdyTemp+2+GetPenWidth());
- pDC->MoveTo(m_flThirdxTemp-1-GetPenWidth(),m_flThirdyTemp);
- pDC->LineTo(m_flThirdxTemp+2+GetPenWidth(),m_flThirdyTemp);
- pDC->MoveTo(flForthx,flForthy-1-GetPenWidth());
- pDC->LineTo(flForthx,flForthy+2+GetPenWidth());
- pDC->MoveTo(flForthx-1-GetPenWidth(),flForthy);
- pDC->LineTo(flForthx+2+GetPenWidth(),flForthy);
- }
- pDC->SelectObject(poldPen);
- return;
- }
- ////////////////////////////////////////////
- void CRoundRect::DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth,CFlRect m_rectFrom,CRect m_rectTo)
- {
- // if(!IsInRect(m_rectFrom)){
- // return;
- // }
- //得到移动扩缩后的关键数据
- float flFirstx,flFirsty,flSecondx,flSecondy,flThirdx,flThirdy,flForthx,flForthy;
- //移动
- float stepx=m_rectTo.left-m_rectFrom.left;
- float stepy=m_rectTo.top-m_rectFrom.top;
- flFirstx=m_flFirstxTemp+stepx;
- flFirsty=m_flFirstyTemp+stepy;
- flSecondx=m_flSecondxTemp+stepx;
- flSecondy=m_flSecondyTemp+stepy;
- flThirdx=m_flThirdxTemp+stepx;
- flThirdy=m_flThirdyTemp+stepy;
- flForthx=m_flForthxTemp+stepx;
- flForthy=m_flForthyTemp+stepy;
- //扩缩
- float cx,cy,flScale;
- cx=m_rectTo.left;
- cy=m_rectTo.top;
- if(m_rectFrom.Width()<0.01){
- m_rectFrom.right=m_rectFrom.left +1;
- }
- if(m_rectFrom.Height()<0.01){
- m_rectFrom.bottom=m_rectFrom.top +1;
- }
- flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
- //flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
- flFirstx=(flFirstx-cx)*flScale+cx;
- flFirsty=(flFirsty-cy)*flScale+cy;
- flSecondx=(flSecondx-cx)*flScale+cx;
- flSecondy=(flSecondy-cy)*flScale+cy;
- flThirdx=(flThirdx-cx)*flScale+cx;
- flThirdy=(flThirdy-cy)*flScale+cy;
- flForthx=(flForthx-cx)*flScale+cx;
- flForthy=(flForthy-cy)*flScale+cy;
- CPen pen,*poldPen;
- float fldis1,fldis2,flRadius;
- CPoint ptArray1[3], ptArray2[3],ptArray3[3],ptArray4[3];
- fldis1=GetDistance(flFirstx,flFirsty,flSecondx,flSecondy);
- fldis2=GetDistance(flSecondx,flSecondy,flThirdx,flThirdy);
- if(fldis1<1){
- fldis1=1;
- }
- if(fldis2<1){
- fldis2=1;
- }
- flRadius=min(fldis1,fldis2)/7.0;
- //分别得到四个角处的三个点,用于绘画贝齐埃曲线
- ptArray1[1]=CPoint(flFirstx,flFirsty);
- ptArray2[1]=CPoint(flSecondx,flSecondy);
- ptArray3[1]=CPoint(flThirdx,flThirdy);
- ptArray4[1]=CPoint(flForthx,flForthy);
- ptArray1[0]=CPoint(flFirstx-flRadius*(flSecondx-flThirdx)/fldis2,flFirsty-flRadius*(flSecondy-flThirdy)/fldis2);
- ptArray2[0]=CPoint(flSecondx-flRadius*(flSecondx-flFirstx)/fldis1,flSecondy-flRadius*(flSecondy-flFirsty)/fldis1);
- ptArray3[0]=CPoint(flThirdx-flRadius*(flThirdx-flSecondx)/fldis2,flThirdy-flRadius*(flThirdy-flSecondy)/fldis2);
- ptArray4[0]=CPoint(flThirdx-(1-flRadius/fldis1)*((flSecondx-flFirstx)),flThirdy-(1-flRadius/fldis1)*(flSecondy-flFirsty));
- ptArray1[2]=CPoint(flFirstx-flRadius*(flFirstx-flSecondx)/fldis1,flFirsty-flRadius*(flFirsty-flSecondy)/fldis1);
- ptArray2[2]=CPoint(flSecondx-flRadius*(flSecondx-flThirdx)/fldis2,flSecondy-flRadius*(flSecondy-flThirdy)/fldis2);
- ptArray3[2]=CPoint(flThirdx-flRadius*(flSecondx-flFirstx)/fldis1,flThirdy-flRadius*(flSecondy-flFirsty)/fldis1);
- ptArray4[2]=CPoint(flFirstx-(1-flRadius/fldis2)*(flSecondx-flThirdx),flFirsty-(1-flRadius/fldis2)*(flSecondy-flThirdy));
- pen.CreatePen(PS_SOLID,1, fillColor);
- CBrush brush,*pOldBrush;
- brush.CreateSolidBrush(fillColor);
- pOldBrush=pDC->SelectObject(&brush);
- poldPen=pDC->SelectObject(&pen);
- if(m_nFillStyle==_shape_solid_fill){
- //这里需要改善,至少可以合并成八个点的多边形
- CPoint ptArray[4];
- ptArray[0]=ptArray1[0];
- ptArray[1]=ptArray2[2];
- ptArray[2]=ptArray3[0];
- ptArray[3]=ptArray4[2];
- AreaFill(pDC,4,ptArray,fillColor);
- ptArray[0]=ptArray1[2];
- ptArray[1]=ptArray2[0];
- ptArray[2]=ptArray3[2];
- ptArray[3]=ptArray4[0];
- AreaFill(pDC,4,ptArray,fillColor);
- ptArray[0]=CPoint(ptArray1[0].x+ptArray1[2].x-flFirstx,ptArray1[0].y+ptArray1[2].y-flFirsty);
- ptArray[1]=CPoint(ptArray2[0].x+ptArray2[2].x-flSecondx,ptArray2[0].y+ptArray2[2].y-flSecondy);
- ptArray[2]=CPoint(ptArray3[0].x+ptArray3[2].x-flThirdx,ptArray3[0].y+ptArray3[2].y-flThirdy);
- ptArray[3]=CPoint(ptArray4[0].x+ptArray4[2].x-(flFirstx+flThirdx-flSecondx),ptArray4[0].y+ptArray4[2].y-(flFirsty+flThirdy-flSecondy));
- pDC->Ellipse(ptArray[0].x-flRadius,ptArray[0].y-flRadius,ptArray[0].x+flRadius,ptArray[0].y+flRadius);
- pDC->Ellipse(ptArray[1].x-flRadius,ptArray[1].y-flRadius,ptArray[1].x+flRadius,ptArray[1].y+flRadius);
- pDC->Ellipse(ptArray[2].x-flRadius,ptArray[2].y-flRadius,ptArray[2].x+flRadius,ptArray[2].y+flRadius);
- pDC->Ellipse(ptArray[3].x-flRadius,ptArray[3].y-flRadius,ptArray[3].x+flRadius,ptArray[3].y+flRadius);
- }
- pen.DeleteObject();
- pen.CreatePen(PS_SOLID,penWidth,color);
- pDC->SelectObject(&pen);
- pDC->SelectObject(pOldBrush);
- pDC->MoveTo(ptArray1[2]);
- pDC->LineTo(ptArray2[0]);
- pDC->MoveTo(ptArray2[2]);
- pDC->LineTo(ptArray3[0]);
- pDC->MoveTo(ptArray3[2]);
- pDC->LineTo(ptArray4[0]);
- pDC->MoveTo(ptArray4[2]);
- pDC->LineTo(ptArray1[0]);
- BezierCurve(pDC,ptArray1,3);
- BezierCurve(pDC,ptArray2,3);
- BezierCurve(pDC,ptArray3,3);
- BezierCurve(pDC,ptArray4,3);
- if(GetDrawPointsFlag()==1){
- DrawPointsCutTo(pDC,color,m_rectFrom,m_rectTo);
- }
- pDC->SelectObject(poldPen);
- }
- //////////////////////////////////////////////////////////////////////
- void CRoundRect::RoundRectangle(CDC *pDC,CPoint LeftTop,CPoint RightBottom,COLORREF color)
- {
- /* CPoint LT,RB,center[4];
- int Radius;
- LT.x=LeftTop.x<RightBottom.x?LeftTop.x:RightBottom.x;//取两点
- LT.y=LeftTop.y<RightBottom.y?LeftTop.y:RightBottom.y;
- RB.x=LeftTop.x>RightBottom.x?LeftTop.x:RightBottom.x;
- RB.y=LeftTop.y>RightBottom.y?LeftTop.y:RightBottom.y;
- Radius=(RB.x-LT.x)/7<(RB.y-LT.y)/7?(RB.x-LT.x)/7:(RB.y-LT.y)/7;
- center[0].x=LT.x+Radius;
- center[0].y=LT.y+Radius;
- center[1].x=RB.x-Radius;
- center[1].y=LT.y+Radius;
- center[2].x=LT.x+Radius;
- center[2].y=RB.y-Radius;
- center[3].x=RB.x-Radius;
- center[3].y=RB.y-Radius;
- pDC->MoveTo(LT.x+Radius,LT.y);
- pDC->LineTo(RB.x-Radius,LT.y);
- pDC->MoveTo(LT.x,LT.y+Radius);
- pDC->LineTo(LT.x,RB.y-Radius);
- pDC->MoveTo(LT.x+Radius,RB.y);
- pDC->LineTo(RB.x-Radius,RB.y);
- pDC->MoveTo(RB.x,LT.y+Radius);
- pDC->LineTo(RB.x,RB.y-Radius);
- int x,y,di,i;
- x=0;
- y=Radius;
- di=3-2*Radius;
- while(x<=y)//画出四个圆角
- {
- for(i=0;i<1;i++)
- {
- pDC->SetPixel(center[3].x+x+i,center[3].y+y,color);
- pDC->SetPixel(center[1].x+x+i,center[1].y-y,color);
- pDC->SetPixel(center[2].x-x+i,center[2].y+y,color);
- pDC->SetPixel(center[0].x-x+i,center[0].y-y,color);
- pDC->SetPixel(center[3].x+y+i,center[3].y+x,color);
- pDC->SetPixel(center[1].x+y+i,center[1].y-x,color);
- pDC->SetPixel(center[2].x-y+i,center[2].y+x,color);
- pDC->SetPixel(center[0].x-y+i,center[0].y-x,color);
- pDC->SetPixel(center[3].x+x,center[3].y+y+i,color);
- pDC->SetPixel(center[1].x+x,center[1].y-y+i,color);
- pDC->SetPixel(center[2].x-x,center[2].y+y+i,color);
- pDC->SetPixel(center[0].x-x,center[0].y-y+i,color);
- pDC->SetPixel(center[3].x+y,center[3].y+x+i,color);
- pDC->SetPixel(center[1].x+y,center[1].y-x+i,color);
- pDC->SetPixel(center[2].x-y,center[2].y+x+i,color);
- pDC->SetPixel(center[0].x-y,center[0].y-x+i,color);
- }
- if(di<0)
- {
- di+=4*x+6;
- }
- else
- {
- di+=4*(x-y)+10;
- y--;
- }
- x++;
- }
- */
- }
- //////////////////////////////////////////////////////////////////////
- void CRoundRect::CreatGraph(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
- {
- if(flArrayX.GetSize()<2){
- return;
- }
- CShape::CreatGraph(flArrayX,flArrayY,nPenWidth,color,fillColor,nStyle);
- m_flFirstxTemp=m_flFirstx=flArrayX.GetAt(0);
- m_flFirstyTemp=m_flFirsty=flArrayY.GetAt(0);
- m_flSecondxTemp=m_flSecondx=flArrayX.GetAt(0);
- m_flSecondyTemp=m_flSecondy=flArrayY.GetAt(1);
- m_flThirdxTemp=m_flThirdx=flArrayX.GetAt(1);
- m_flThirdyTemp=m_flThirdy=flArrayY.GetAt(1);
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- void CRoundRect::SetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
- {
- m_flFirstxTemp=m_flFirstx=flArrayX.GetAt(0);
- m_flFirstyTemp=m_flFirsty=flArrayY.GetAt(0);
- m_flSecondxTemp=m_flSecondx=flArrayX.GetAt(1);
- m_flSecondyTemp=m_flSecondy=flArrayY.GetAt(1);
- m_flThirdxTemp=m_flThirdx=flArrayX.GetAt(2);
- m_flThirdyTemp=m_flThirdy=flArrayY.GetAt(2);
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- void CRoundRect::GetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
- {
- flArrayX.RemoveAll();
- flArrayY.RemoveAll();
- flArrayX.Add(m_flFirstxTemp);
- flArrayX.Add(m_flSecondxTemp);
- flArrayX.Add(m_flThirdxTemp);
- flArrayY.Add(m_flFirstyTemp);
- flArrayY.Add(m_flSecondyTemp);
- flArrayY.Add(m_flThirdyTemp);
- }
- //////////////////////////////////////////////////////////////////////
- void CRoundRect::CreatGraph(CArray<CPoint,CPoint>& ptArray,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
- {
- if(ptArray.GetSize()<2){
- return;
- }
- CShape::CreatGraph(ptArray,nPenWidth,color,fillColor,nStyle);
- m_flFirstxTemp=m_flFirstx=((CPoint)ptArray.GetAt(0)).x;
- m_flFirstyTemp=m_flFirsty=((CPoint)ptArray.GetAt(0)).y;
- m_flThirdxTemp=m_flThirdx=((CPoint)ptArray.GetAt(1)).x;
- m_flThirdyTemp=m_flThirdy=((CPoint)ptArray.GetAt(1)).y;
- m_flSecondxTemp=m_flSecondx=((CPoint)ptArray.GetAt(0)).x;
- m_flSecondyTemp=m_flSecondy=((CPoint)ptArray.GetAt(1)).y;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- CShape* CRoundRect::GetCopy()
- {
- CShape* pGraph=new CRoundRect(this);
- return pGraph;
- }
- //////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- void CRoundRect::Move(CDC *pDC,float stepx,float stepy)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_flFirstx+=stepx;
- m_flFirsty+=stepy;
- m_flSecondx+=stepx;
- m_flSecondy+=stepy;
- m_flThirdx+=stepx;
- m_flThirdy+=stepy;
- //temp
- m_flFirstxTemp+=stepx;
- m_flFirstyTemp+=stepy;
- m_flSecondxTemp+=stepx;
- m_flSecondyTemp+=stepy;
- m_flThirdxTemp+=stepx;
- m_flThirdyTemp+=stepy;
- m_flForthx+=stepx;
- m_flForthy+=stepy;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- void CRoundRect::PartMove(CDC *pDC,float PrevX,float PrevY,float CurX,float CurY)
- {
- if(m_nSelectPtNum>-1){
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- float flX,flY;
- float flDisA,flDisB;
- switch(m_nSelectPtNum) {
- case 0:
- flX = m_flThirdx;
- flY = m_flThirdy;
- flDisA=GetDistance(m_flThirdx,m_flThirdy,m_flFirstx,m_flFirsty);
- flDisB=GetDistance(m_flThirdx,m_flThirdy,CurX,CurY);
- break;
- case 1:
- flX = m_flForthx;
- flY = m_flForthy;
- flDisA=GetDistance(m_flForthx,m_flForthy,m_flSecondx,m_flSecondy);
- flDisB=GetDistance(m_flForthx,m_flForthy,CurX,CurY);
- break;
- case 2:
- flX = m_flFirstx;
- flY = m_flFirsty;
- flDisA=GetDistance(m_flFirstx,m_flFirsty,m_flThirdx,m_flThirdy);
- flDisB=GetDistance(m_flFirstx,m_flFirsty,CurX,CurY);
- break;
- case 3:
- flX = m_flSecondx;
- flY = m_flSecondy;
- flDisA=GetDistance(m_flSecondx,m_flSecondy,m_flForthx,m_flForthy);
- flDisB=GetDistance(m_flSecondx,m_flSecondy,CurX,CurY);
- break;
- }
- if(flDisA<1){
- flDisA=1;
- }
- Magnify(pDC,flX,flY,flDisB/flDisA);
- //CShape::Draw(pDC);
- }else if(m_nSelectLineNum>-1){
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- float flCut1x,flCut1y,flCut2x,flCut2y;
- float flX1[4],flY1[4],flX2[4],flY2[4];
- switch(m_nSelectLineNum) {
- case 0:
- flX1[0]=m_flForthx;
- flY1[0]=m_flForthy;
- flX1[1]=CurX;
- flY1[1]=CurY;
- flX1[2] = m_flFirstx;
- flY1[2] = m_flFirsty;
- flX1[3] = m_flSecondx;
- flY1[3] = m_flSecondy;
- flX2[0]=m_flThirdx;
- flY2[0]=m_flThirdy;
- flX2[1]=CurX;
- flY2[1]=CurY;
- flX2[2] = m_flFirstx;
- flY2[2] = m_flFirsty;
- flX2[3] = m_flSecondx;
- flY2[3] = m_flSecondy;
- if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
- if(fabs(flCut1x-m_flForthx)>=0.01){
- m_flFirstxTemp=(m_flFirstx-m_flForthx)*((float)CurX-flCut1x)/(flCut1x-m_flForthx)+m_flFirstx;
- }
- if(fabs(flCut1y-m_flForthy)>=0.01){
- m_flFirstyTemp=(m_flFirsty-m_flForthy)*((float)CurY-flCut1y)/(flCut1y-m_flForthy)+m_flFirsty;
- }
- if(fabs(flCut2x-m_flThirdx)>=0.01){
- m_flSecondxTemp=(m_flSecondx-m_flThirdx)*((float)CurX-flCut2x)/(flCut2x-m_flThirdx)+m_flSecondx;
- }
- if(fabs(flCut2y-m_flThirdy)>=0.01){
- m_flSecondyTemp=(m_flSecondy-m_flThirdy)*((float)CurY-flCut2y)/(flCut2y-m_flThirdy)+m_flSecondy;
- }
- }
- break;
- case 1:
- flX1[0]=m_flFirstx;
- flY1[0]=m_flFirsty;
- flX1[1]=CurX;
- flY1[1]=CurY;
- flX1[2] = m_flSecondx;
- flY1[2] = m_flSecondy;
- flX1[3] = m_flThirdx;
- flY1[3] = m_flThirdy;
- flX2[0]=m_flForthx;
- flY2[0]=m_flForthy;
- flX2[1]=CurX;
- flY2[1]=CurY;
- flX2[2] = flX1[2];
- flY2[2] = flY1[2];
- flX2[3] = flX1[3];
- flY2[3] = flY1[3];
- if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
- if(fabs(flCut1x-m_flFirstx)>=0.01){
- m_flSecondxTemp=(m_flSecondx-m_flFirstx)*((float)CurX-flCut1x)/(flCut1x-m_flFirstx)+m_flSecondx;
- }
- if(fabs(flCut1y-m_flFirsty)>=0.01){
- m_flSecondyTemp=(m_flSecondy-m_flFirsty)*((float)CurY-flCut1y)/(flCut1y-m_flFirsty)+m_flSecondy;
- }
- if(fabs(flCut2x-m_flForthx)>=0.01){
- m_flThirdxTemp=(m_flThirdx-m_flForthx)*((float)CurX-flCut2x)/(flCut2x-m_flForthx)+m_flThirdx;
- }
- if(fabs(flCut2y-m_flForthy)>=0.01){
- m_flThirdyTemp=(m_flThirdy-m_flForthy)*((float)CurY-flCut2y)/(flCut2y-m_flForthy)+m_flThirdy;
- }
- }
- break;
- case 2:
- flX1[0]=m_flSecondx;
- flY1[0]=m_flSecondy;
- flX1[1]=CurX;
- flY1[1]=CurY;
- flX1[2] = m_flThirdx;
- flY1[2] = m_flThirdy;
- flX1[3] = m_flForthx;
- flY1[3] = m_flForthy;
- flX2[0]=m_flFirstx;
- flY2[0]=m_flFirsty;
- flX2[1]=CurX;
- flY2[1]=CurY;
- flX2[2] = flX1[2];
- flY2[2] = flY1[2];
- flX2[3] = flX1[3];
- flY2[3] = flY1[3];
- if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
- if(fabs(flCut1x-m_flSecondx)>=0.01){
- m_flThirdxTemp=(m_flThirdx-m_flSecondx)*((float)CurX-flCut1x)/(flCut1x-m_flSecondx)+m_flThirdx;
- }
- if(fabs(flCut1y-m_flSecondy)>=0.01){
- m_flThirdyTemp=(m_flThirdy-m_flSecondy)*((float)CurY-flCut1y)/(flCut1y-m_flSecondy)+m_flThirdy;
- }
- if(fabs(flCut2x-m_flFirstx)>=0.01){
- m_flForthxTemp=(m_flForthx-m_flFirstx)*((float)CurX-flCut2x)/(flCut2x-m_flFirstx)+m_flForthx;
- }
- if(fabs(flCut2y-m_flFirsty)>=0.01){
- m_flForthyTemp=(m_flForthy-m_flFirsty)*((float)CurY-flCut2y)/(flCut2y-m_flFirsty)+m_flForthy;
- }
- }
- break;
- case 3:
- flX1[0]=m_flThirdx;
- flY1[0]=m_flThirdy;
- flX1[1]=CurX;
- flY1[1]=CurY;
- flX1[2] = m_flForthx;
- flY1[2] = m_flForthy;
- flX1[3] = m_flFirstx;
- flY1[3] = m_flFirsty;
- flX2[0]=m_flSecondx;
- flY2[0]=m_flSecondy;
- flX2[1]=CurX;
- flY2[1]=CurY;
- flX2[2] = flX1[2];
- flY2[2] = flY1[2];
- flX2[3] = flX1[3];
- flY2[3] = flY1[3];
- if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
- if(fabs(flCut1x-m_flThirdx)>=0.01){
- m_flForthxTemp=(m_flForthx-m_flThirdx)*((float)CurX-flCut1x)/(flCut1x-m_flThirdx)+m_flForthx;
- }
- if(fabs(flCut1y-m_flThirdy)>=0.01){
- m_flForthyTemp=(m_flForthy-m_flThirdy)*((float)CurY-flCut1y)/(flCut1y-m_flThirdy)+m_flForthy;
- }
- if(fabs(flCut2x-m_flSecondx)>=0.01){
- m_flFirstxTemp=(m_flFirstx-m_flSecondx)*((float)CurX-flCut2x)/(flCut2x-m_flSecondx)+m_flFirstx;
- }
- if(fabs(flCut2y-m_flSecondy)>=0.01){
- m_flFirstyTemp=(m_flFirsty-m_flSecondy)*((float)CurY-flCut2y)/(flCut2y-m_flSecondy)+m_flFirsty;
- }
- }
- break;
- }
- //CShape::Draw(pDC);
- }
- }
- /////////////////////////////////////////////
- //function Rotate(...)
- //Rotate flAngle degrees around the ptCenter given as a param
- ////////////////////////////////////////////
- void CRoundRect::Rotate(CDC *pDC,float CX,float CY,float flAngle)
- {
- if(m_flScaleTemp!=1){
- RefreshData(TRUE);
- }
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_ptRotateCenterTemp=CPoint(CX,CY);
- m_flAngleTemp=flAngle;
- m_bModified=TRUE;
- m_flFirstxTemp=((m_flFirstx-CX)*cos(flAngle)-(m_flFirsty-CY)*sin(flAngle))+CX;
- m_flFirstyTemp=((m_flFirsty-CY)*cos(flAngle)+(m_flFirstx-CX)*sin(flAngle))+CY;
- m_flSecondxTemp=((m_flSecondx-CX)*cos(flAngle)-(m_flSecondy-CY)*sin(flAngle))+CX;
- m_flSecondyTemp=((m_flSecondy-CY)*cos(flAngle)+(m_flSecondx-CX)*sin(flAngle))+CY;
- m_flThirdxTemp=((m_flThirdx-CX)*cos(flAngle)-(m_flThirdy-CY)*sin(flAngle))+CX;
- m_flThirdyTemp=((m_flThirdy-CY)*cos(flAngle)+(m_flThirdx-CX)*sin(flAngle))+CY;
- m_flForthxTemp=((m_flForthx-CX)*cos(flAngle)-(m_flForthy-CY)*sin(flAngle))+CX;
- m_flForthyTemp=((m_flForthy-CY)*cos(flAngle)+(m_flForthx-CX)*sin(flAngle))+CY;
- //Draw(pDC);
- }
- /////////////////////////////////////////////
- //function Magnify(...)
- //Magnify flScale times relative to the ptCenter given as a param
- ////////////////////////////////////////////
- void CRoundRect::Magnify(CDC *pDC,float CX,float CY,float flScale)
- {
- if(m_flAngleTemp!=0){
- RefreshData(TRUE);
- }
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_ptMagnifyCenterTemp=CPoint(CX,CY);
- m_flScaleTemp=flScale;
- m_bModified=TRUE;
- m_flFirstxTemp=(m_flFirstx-CX)*flScale+CX;
- m_flFirstyTemp=(m_flFirsty-CY)*flScale+CY;
- m_flSecondxTemp=(m_flSecondx-CX)*flScale+CX;
- m_flSecondyTemp=(m_flSecondy-CY)*flScale+CY;
- m_flThirdxTemp=(m_flThirdx-CX)*flScale+CX;
- m_flThirdyTemp=(m_flThirdy-CY)*flScale+CY;
- m_flForthxTemp=(m_flForthx-CX)*flScale+CX;
- m_flForthyTemp=(m_flForthy-CY)*flScale+CY;
- //Draw(pDC);
- }
- void CRoundRect::TopToBottom(CDC* pDC,CRect rect)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_flFirstyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flFirstyTemp;
- m_flSecondyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flSecondyTemp;
- m_flThirdyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flThirdyTemp;
- m_flFirsty=rect.top/1000.0+rect.bottom/1000.0-m_flFirsty;
- m_flSecondy=rect.top/1000.0+rect.bottom/1000.0-m_flSecondy;
- m_flThirdy=rect.top/1000.0+rect.bottom/1000.0-m_flThirdy;
- m_flForthyTemp=rect.top/1000.0+rect.bottom/1000.0-m_flForthyTemp;
- m_flForthy=rect.top/1000.0+rect.bottom/1000.0-m_flForthy;
- // CShape::Draw(pDC);
- }
- void CRoundRect::LeftToRight(CDC* pDC,CRect rect)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_flFirstxTemp=rect.left/1000.0+rect.right/1000.0-m_flFirstxTemp;
- m_flSecondxTemp=rect.left/1000.0+rect.right/1000.0-m_flSecondxTemp;
- m_flThirdxTemp=rect.left/1000.0+rect.right/1000.0-m_flThirdxTemp;
- m_flFirstx=rect.left/1000.0+rect.right/1000.0-m_flFirstx;
- m_flSecondx=rect.left/1000.0+rect.right/1000.0-m_flSecondx;
- m_flThirdx=rect.left/1000.0+rect.right/1000.0-m_flThirdx;
- m_flForthxTemp=rect.left/1000.0+rect.right/1000.0-m_flForthxTemp;
- m_flForthx=rect.left/1000.0+rect.right/1000.0-m_flForthx;
- // CShape::Draw(pDC);
- }
- ///
- void CRoundRect::RefreshData(bool bRefresh)
- {
- if(bRefresh){
- m_flFirstx = m_flFirstxTemp;
- m_flFirsty = m_flFirstyTemp;
- m_flSecondx = m_flSecondxTemp ;
- m_flSecondy = m_flSecondyTemp;
- m_flThirdx = m_flThirdxTemp;
- m_flThirdy = m_flThirdyTemp;
- m_flForthx = m_flForthxTemp;
- m_flForthy = m_flForthyTemp;
- m_bModified=FALSE;
- m_ptMagnifyCenterTemp=CPoint(0,0);
- m_flScaleTemp=1;
- m_ptRotateCenterTemp=CPoint(0,0);
- m_flAngleTemp=0;
- }
- }
- //////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////
- //function------IsInRect
- //return value
- //0----------out
- //1----------cut
- //2----------in
- /////////////////////////////////////////////
- int CRoundRect::IsInRect(CRect rect)
- {
- INT nRltVal=0,nTemp;;
- float fldis1,fldis2,flRadius;
- CPoint ptArray1[3], ptArray2[3],ptArray3[3],ptArray4[3];
- fldis1=GetDistance(m_flFirstxTemp,m_flFirstyTemp,m_flThirdxTemp,m_flThirdyTemp);
- fldis2=GetDistance(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp);
- flRadius=min(fldis1,fldis2)/7.0;
- //分别得到四个角处的三个点
- //拟时针前点
- ptArray1[0]=CPoint(m_flFirstxTemp-(m_flSecondxTemp-m_flThirdxTemp)/7,m_flFirstyTemp-(m_flSecondyTemp-m_flThirdyTemp)/7);
- ptArray2[0]=CPoint(m_flSecondxTemp-(m_flSecondxTemp-m_flFirstxTemp)/7,m_flSecondyTemp-(m_flSecondyTemp-m_flFirstyTemp)/7);
- ptArray3[0]=CPoint(m_flThirdxTemp-(m_flThirdxTemp-m_flSecondxTemp)/7,m_flThirdyTemp-(m_flThirdyTemp-m_flSecondyTemp)/7);
- ptArray4[0]=CPoint(m_flThirdxTemp-6.0*((m_flSecondxTemp-m_flFirstxTemp))/7,m_flThirdyTemp-6.0*(m_flSecondyTemp-m_flFirstyTemp)/7);
- //顺时针前点
- ptArray1[1]=CPoint(m_flFirstxTemp-(m_flFirstxTemp-m_flSecondxTemp)/7,m_flFirstyTemp-(m_flFirstyTemp-m_flSecondyTemp)/7);
- ptArray2[1]=CPoint(m_flSecondxTemp-(m_flSecondxTemp-m_flThirdxTemp)/7,m_flSecondyTemp-(m_flSecondyTemp-m_flThirdyTemp)/7);
- ptArray3[1]=CPoint(m_flThirdxTemp-(m_flSecondxTemp-m_flFirstxTemp)/7,m_flThirdyTemp-(m_flSecondyTemp-m_flFirstyTemp)/7);
- ptArray4[1]=CPoint(m_flFirstxTemp-6.0*(m_flSecondxTemp-m_flThirdxTemp)/7,m_flFirstyTemp-6.0*(m_flSecondyTemp-m_flThirdyTemp)/7);
- //角圆中心点
- ptArray1[2]=CPoint(ptArray1[0].x+ptArray1[1].x-m_flFirstxTemp,ptArray1[0].y+ptArray1[1].y-m_flFirstyTemp);
- ptArray2[2]=CPoint(ptArray2[0].x+ptArray2[1].x-m_flSecondxTemp,ptArray2[0].y+ptArray2[1].y-m_flSecondyTemp);
- ptArray3[2]=CPoint(ptArray3[0].x+ptArray3[1].x-m_flThirdxTemp,ptArray3[0].y+ptArray3[1].y-m_flThirdyTemp);
- 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));
- //四条边
- if((nTemp=GetLineStateToRect(ptArray1[1],ptArray2[0],rect))!=0){
- nRltVal= nRltVal|nTemp;
- }
- if((nTemp=GetLineStateToRect(ptArray2[1],ptArray3[0],rect))!=0){
- nRltVal= nRltVal|nTemp;
- }
- if((nTemp=GetLineStateToRect(ptArray3[1],ptArray4[0],rect))!=0){
- nRltVal= nRltVal|nTemp;
- }
- if((nTemp=GetLineStateToRect(ptArray4[1],ptArray1[0],rect))!=0){
- nRltVal= nRltVal|nTemp;
- }
- //四个角
- nTemp=0;
- nTemp=CircleStateToRect(rect,ptArray1[2],flRadius);
- nRltVal= nRltVal|nTemp;
- nTemp=CircleStateToRect(rect,ptArray2[2],flRadius);
- nRltVal= nRltVal|nTemp;
- nTemp=CircleStateToRect(rect,ptArray3[2],flRadius);
- nRltVal= nRltVal|nTemp;
- nTemp=CircleStateToRect(rect,ptArray4[2],flRadius);
- nRltVal= nRltVal|nTemp;
- if(nRltVal==3){
- nRltVal=1;
- }else if(nRltVal==0){
- CPoint pt[4];
- pt[0].x=rect.left;
- pt[0].y=rect.top;
- pt[1].x=rect.right;
- pt[1].y=rect.top;
- pt[2].x=rect.right;
- pt[2].y=rect.bottom;
- pt[3].x=rect.left;
- pt[3].y=rect.bottom;
- if(IsPointinRegion(pt[0])&&IsPointinRegion(pt[1])&&
- IsPointinRegion(pt[2])&&IsPointinRegion(pt[3])&&
- m_nFillStyle==_shape_solid_fill){
- nRltVal=1;
- }
- }
- return nRltVal;
- }
- CRect CRoundRect::GetBoundaryRect()
- {
- CRect rect;
- float flForthx,flForthy;
- flForthx=m_flForthxTemp;
- flForthy=m_flForthyTemp;
- rect.left=1000*min(m_flFirstxTemp,min(m_flSecondxTemp,min(m_flThirdxTemp,flForthx)));
- rect.right=1000*max(m_flFirstxTemp,max(m_flSecondxTemp,max(m_flThirdxTemp,flForthx)));
- rect.top=1000*min(m_flFirstyTemp,min(m_flSecondyTemp,min(m_flThirdyTemp,flForthy)));
- rect.bottom=1000*max(m_flFirstyTemp,max(m_flSecondyTemp,max(m_flThirdyTemp,flForthy)));
- return rect;
- }
- CPoint CRoundRect::GetCenterPoint()
- {
- CRect rect=GetBoundaryRect();
- return rect.CenterPoint();
- }
- int CRoundRect::IsPointinRegion(POINT point)
- {
- int nRltVal=0;
- float flForthx,flForthy;
- flForthx=m_flForthxTemp;
- flForthy=m_flForthyTemp;
- if(point.y>min(m_flFirstyTemp,m_flSecondyTemp)&&point.y<max(m_flFirstyTemp,m_flSecondyTemp))
- {
- if((m_flSecondxTemp-(m_flSecondxTemp-m_flFirstxTemp)*(m_flSecondyTemp-point.y)/(m_flSecondyTemp-m_flFirstyTemp))>=point.x){
- nRltVal+=1;
- }
- }
- if(point.y>min(m_flThirdyTemp,m_flSecondyTemp)&&point.y<max(m_flThirdyTemp,m_flSecondyTemp))
- {
- if((m_flSecondxTemp-(m_flSecondxTemp-m_flThirdxTemp)*(m_flSecondyTemp-point.y)/(m_flSecondyTemp-m_flThirdyTemp))>=point.x){
- nRltVal+=1;
- }
- }
- if(point.y>min(m_flThirdyTemp,flForthy)&&point.y<max(m_flThirdyTemp,flForthy))
- {
- if((flForthx-(flForthx-m_flThirdxTemp)*(flForthy-point.y)/(flForthy-m_flThirdyTemp))>=point.x){
- nRltVal+=1;
- }
- }
- if(point.y>min(m_flFirstyTemp,flForthy)&&point.y<max(m_flFirstyTemp,flForthy))
- {
- if((flForthx-(flForthx-m_flFirstxTemp)*(flForthy-point.y)/(flForthy-m_flFirstyTemp))>=point.x){
- nRltVal+=1;
- }
- }
- if(nRltVal!=1){
- nRltVal=0;
- }
- return nRltVal;
- }
- //
- int CRoundRect::CircleStateToRect(CRect rect,CPoint ptCenter,float flRadius)
- {
- int nRltVal=0;
- CPoint ptRectLT=rect.TopLeft();
- CPoint ptRectRB=rect.BottomRight();
- CPoint ptRectLB,ptRectRT;
- ptRectLB.x=rect.left;
- ptRectLB.y=rect.bottom;
- ptRectRT.x=rect.right;
- ptRectRT.y=rect.top;
- if(GetDistance(ptCenter,ptRectLT)>flRadius&&GetDistance(ptCenter,ptRectRB)>flRadius&&
- GetDistance(ptCenter,ptRectLB)>flRadius&&GetDistance(ptCenter,ptRectRT)>flRadius&&rect.PtInRect(ptCenter)){
- nRltVal=2;
- }
- int flag =0;
- if(GetDistance(ptCenter,ptRectLT)<=flRadius){
- flag++;
- }
- if(GetDistance(ptCenter,ptRectRB)<=flRadius){
- flag++;
- }
- if(GetDistance(ptCenter,ptRectLB)<=flRadius){
- flag++;
- }
- if(GetDistance(ptCenter,ptRectRT)<=flRadius){
- flag++;
- }
- if(0<flag&&flag<4){
- nRltVal=1;
- }
- return nRltVal;
- }
- //////
- int CRoundRect::GetPtState(float flx,float fly,float flRate)
- {
- //on out point
- if(IsPtInRect(m_flFirstxTemp-3*flRate,m_flFirstyTemp-3*flRate,m_flFirstxTemp+3*flRate,m_flFirstyTemp+3*flRate,flx,fly)){
- m_nSelectPtNum=0;
- m_nSelectLineNum=-1;
- return 1;
- }
- if(IsPtInRect(m_flSecondxTemp-3*flRate,m_flSecondyTemp-3*flRate,m_flSecondxTemp+3*flRate,m_flSecondyTemp+3*flRate,flx,fly)){
- m_nSelectPtNum=1;
- m_nSelectLineNum=-1;
- return 1;
- }
- if(IsPtInRect(m_flThirdxTemp-3*flRate,m_flThirdyTemp-3*flRate,m_flThirdxTemp+3*flRate,m_flThirdyTemp+3*flRate,flx,fly)){
- m_nSelectPtNum=2;
- m_nSelectLineNum=-1;
- return 1;
- }
- if(IsPtInRect(m_flForthxTemp-3*flRate,m_flForthyTemp-3*flRate,m_flForthxTemp+3*flRate,m_flForthyTemp+3*flRate,flx,fly)){
- m_nSelectPtNum=3;
- m_nSelectLineNum=-1;
- return 1;
- }
- //on out line
- if(GetPtStateToBigLine(m_flFirstxTemp,m_flFirstyTemp,m_flSecondxTemp,m_flSecondyTemp,5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=0;
- return 2;
- }
- if(GetPtStateToBigLine(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp,5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=1;
- return 2;
- }
- if(GetPtStateToBigLine(m_flThirdxTemp,m_flThirdyTemp,m_flForthxTemp,m_flForthyTemp,5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=2;
- return 2;
- }
- if(GetPtStateToBigLine(m_flForthxTemp,m_flForthyTemp,m_flFirstxTemp,m_flFirstyTemp,5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=3;
- return 2;
- }
- //out
- m_nSelectPtNum=-1;
- m_nSelectLineNum=-1;
- return 0;
- }
- float CRoundRect::GetSelectLineRate()
- {
- if(m_nSelectLineNum==0||m_nSelectLineNum==2){
- return -GetLineRate(m_flFirstxTemp,m_flFirstyTemp,m_flSecondxTemp,m_flSecondyTemp);
- }
- if(m_nSelectLineNum==1||m_nSelectLineNum==3){
- return -GetLineRate(m_flSecondxTemp,m_flSecondyTemp,m_flThirdxTemp,m_flThirdyTemp);
- }
- return 0;
- }
- //////////////////////////////////////////////////////////////////////
- // MODULE :ExPort
- // ABSTRACT :Export to a txt file
- // FUNCTION :File->Export...
- // NOTE :
- // RETURN :
- // ARGUMENTS:
- // I/O TYPE NAME EXPLANATION
- // O FILE* outStream Out put File
- // CREATE : FNST)handwolf 2004-4-14
- // UPDATE :
- // :
- //////////////////////////////////////////////////////////////////////
- void CRoundRect::ExPort(FILE* outStream)//增加导出txt功能时用
- {
- fprintf(outStream, " CRoundRect n");//一定要输入类名
- CShape::ExPort(outStream);
- fprintf( outStream, "%f %f %f %f %f %fn",m_flFirstx, m_flFirsty, m_flSecondx, m_flSecondy,m_flThirdx,m_flThirdy);
- }
- //////////////////////////////////////////////////////////////////////
- // MODULE :ImPort
- // ABSTRACT :ImPort from a txt file
- // FUNCTION :File->ImPort...
- // NOTE :
- // RETURN :
- // ARGUMENTS:
- // I/O TYPE NAME EXPLANATION
- // I FILE* inStream in put File
- // CREATE : FNST)handwolf 2004-4-14
- // UPDATE :
- // :
- //////////////////////////////////////////////////////////////////////
- void CRoundRect::ImPort(FILE* inStream)
- {
- CShape::ImPort(inStream);
- fscanf(inStream, "%f %f %f %f %f %f",&m_flFirstx, &m_flFirsty, &m_flSecondx, &m_flSecondy,&m_flThirdx,&m_flThirdy);
- m_flFirstxTemp=m_flFirstx;
- m_flFirstyTemp=m_flFirsty;
- m_flSecondxTemp=m_flSecondx;
- m_flSecondyTemp=m_flSecondy;
- m_flThirdxTemp=m_flThirdx;
- m_flThirdyTemp=m_flThirdy;
- m_flForthx=m_flThirdxTemp+m_flFirstxTemp-m_flSecondxTemp;
- m_flForthy=m_flThirdyTemp+m_flFirstyTemp-m_flSecondyTemp;
- m_flForthxTemp=m_flForthx;
- m_flForthyTemp=m_flForthy;
- }
- CString CRoundRect::GetNameString()
- {
- CString str;
- str.LoadString(IDS_ROUNDRECT);
- return str;
- }
- //////////////////////////////////////////////////////////////////////
- //End of File//////////////////////