MyDraw.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:37k
- #include "stdafx.h"
- #include "math.h"
- #include "MyDraw.h"
- #include "MyDefine.h"
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //图形对象信息
- CMyObjectInfo::CMyObjectInfo(BOOL del, BOOL selected)
- {
- m_del = del;
- m_selected = selected;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //被选择图形对象信息
- CMySelObjectInfo::CMySelObjectInfo(int type, int index)
- {
- m_type = type;
- m_index = index;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- IMPLEMENT_DYNCREATE(CMyOperate, CObject)
- CMyOperate::CMyOperate()
- {
- Proportion = 1.0;
- }
- CMyOperate::~CMyOperate()
- {
- DelAllLine();
- DelAllRect();
- DelAllCircle();
- DelAllArc();
- }
- void CMyOperate::Serialize(CArchive& ar)
- {
- int num;
- int index;
- CMyObjectInfo* pLineInfo;
- CMyObjectInfo* pRectInfo;
- CMyObjectInfo* pCircleInfo;
- CMyObjectInfo* pArcInfo;
- if(ar.IsStoring())
- {
- ar << m_LineArray.GetSize() << m_RectArray.GetSize()
- << m_CircleArray.GetSize() << m_ArcArray.GetSize();
- }
- else
- {
- ar >> num;
- for(index = 0; index < num; index++)
- {
- pLineInfo = new CMyObjectInfo(FALSE, FALSE);
- m_LineInfoArray.Add(pLineInfo);
- }
- ar >> num;
- for(index = 0; index < num; index++)
- {
- pRectInfo = new CMyObjectInfo(FALSE, FALSE);
- m_RectInfoArray.Add(pRectInfo);
- }
- ar >> num;
- for(index = 0; index < num; index++)
- {
- pCircleInfo = new CMyObjectInfo(FALSE, FALSE);
- m_CircleInfoArray.Add(pCircleInfo);
- }
- ar >> num;
- for(index = 0; index < num; index++)
- {
- pArcInfo = new CMyObjectInfo(FALSE, FALSE);
- m_ArcInfoArray.Add(pArcInfo);
- }
- }
- //注意当打开文件时,下面的Serialize()函数会自动创建CMyLine,CMyRect等对象
- m_LineArray.Serialize(ar);
- m_RectArray.Serialize(ar);
- m_CircleArray.Serialize(ar);
- m_ArcArray.Serialize(ar);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- void CMyOperate::RedrawAllObject(CDC* pDC)
- {
- RedrawLine(pDC);
- RedrawRect(pDC);
- RedrawCircle(pDC);
- RedrawArc(pDC);
- }
- void CMyOperate::SelectObject(CDC* pDC, CPoint point)
- {
- SelectLine(pDC, point);
- SelectRect(pDC, point);
- SelectCircle(pDC, point);
- SelectArc(pDC, point);
- }
- BOOL CMyOperate::UnselectObject()
- {
- BOOL flag = FALSE;
- int nIndex;
-
- if(UnselectLine())
- flag = TRUE;
- if(UnselectRect())
- flag = TRUE;
- if(UnselectCircle())
- flag = TRUE;
- if(UnselectArc())
- flag = TRUE;
-
- nIndex = m_SelObjInfoArray.GetSize();
- while(nIndex--)
- delete (CMySelObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- m_SelObjInfoArray.RemoveAll();
- return flag;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- //operate line
- void CMyOperate::DrawLineA(CDC* pDC)
- {
- //基于CDC
- pDC->SetROP2(R2_NOT);
- pDC->MoveTo(StartPoint);
- pDC->LineTo(oldEndPoint);
- pDC->MoveTo(StartPoint);
- pDC->LineTo(EndPoint);
-
- oldEndPoint = EndPoint;
- pDC->SetROP2(R2_COPYPEN);
- }
- void CMyOperate::DrawLineB(CDC* pDC)
- {
- //基于CDC
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(EndPoint.x, EndPoint.y);
- }
- void CMyOperate::DrawLineC(CDC* pDC)
- {
- //基于CDC
- CPen Pen;
- CPen* OldPen;
- Pen.CreatePen(LineStyle, 1, ForeColor);
- OldPen = pDC->SelectObject(&Pen);
- pDC->SetROP2(R2_COPYPEN);
- pDC->MoveTo(StartPoint);
- pDC->LineTo(EndPoint);
- pDC->SelectObject(OldPen);
- }
- void CMyOperate::DrawSelLine(CDC* pDC, CMyLine * pLine)
- {
- CPen* Pen;
- CPen* OldPen;
- CPoint start;
- CPoint end;
- CPoint middle;
- RECT rect;
- Pen = new CPen(PS_DOT, 1, pLine->m_color);
- OldPen = pDC->SelectObject(Pen);
-
- start.x = (long)(pLine->m_startX * Proportion) + EXTRA_WIDTH;
- start.y = size.cy - (long)(pLine->m_startY * Proportion) - EXTRA_HIGTH;
- end.x = (long)(pLine->m_endX * Proportion) + EXTRA_WIDTH;
- end.y = size.cy - (long)(pLine->m_endY * Proportion) - EXTRA_HIGTH;
- pDC->MoveTo(start);
- pDC->LineTo(end);
- pDC->SelectObject(OldPen);
- delete Pen;
- Pen = new CPen(PS_SOLID, 1, RGB(0, 0, 255));
- OldPen = pDC->SelectObject(Pen);
- pDC->SelectStockObject(NULL_BRUSH);
- rect.left = start.x - SEL_RECT_WIDTH;
- rect.top = start.y - SEL_RECT_WIDTH;
- rect.right = start.x + SEL_RECT_WIDTH + 1;
- rect.bottom = start.y + SEL_RECT_WIDTH + 1;
- pDC->Rectangle(&rect);
- middle.x = (start.x + end.x) / 2;
- middle.y = (start.y + end.y) / 2;
- rect.left = middle.x - SEL_RECT_WIDTH;
- rect.top = middle.y - SEL_RECT_WIDTH;
- rect.right = middle.x + SEL_RECT_WIDTH + 1;
- rect.bottom = middle.y + SEL_RECT_WIDTH + 1;
- pDC->Rectangle(&rect);
- rect.left = end.x - SEL_RECT_WIDTH;
- rect.top = end.y - SEL_RECT_WIDTH;
- rect.right = end.x + SEL_RECT_WIDTH + 1;
- rect.bottom = end.y + SEL_RECT_WIDTH + 1;
- pDC->Rectangle(&rect);
- pDC->SelectObject(OldPen);
- pDC->SetROP2(R2_COPYPEN);
- delete Pen;
- }
- void CMyOperate::RedrawLine(CDC* pDC)
- {
- CPen *Pen;
- CPen* OldPen;
- int index;
- CMyLine* pLine;
- CMyObjectInfo* pLineInfo;
- index = m_LineArray.GetSize();
- while(index--)
- {
- pLine = (CMyLine*)m_LineArray.GetAt(index);
- pLineInfo = (CMyObjectInfo*)m_LineInfoArray.GetAt(index);
- if(pLineInfo->m_del == TRUE)
- continue;
- if(pLineInfo->m_selected == TRUE)
- {
- DrawSelLine(pDC, pLine);
- continue;
- }
- Pen = new CPen(pLine->m_style, 1, pLine->m_color);
- OldPen = pDC->SelectObject(Pen);
- pDC->MoveTo((long)(pLine->m_startX * Proportion) + EXTRA_WIDTH,
- size.cy - (long)(pLine->m_startY * Proportion) - EXTRA_HIGTH);
- pDC->LineTo((long)(pLine->m_endX * Proportion) + EXTRA_WIDTH,
- size.cy - (long)(pLine->m_endY * Proportion) - EXTRA_HIGTH);
- //注意以下两句顺序不可颠倒
- pDC->SelectObject(OldPen);
- delete Pen;
- }
- }
- void CMyOperate::CancelDrawLine(CDC* pDC)
- {
- pDC->SetROP2(R2_NOT);
- pDC->MoveTo(StartPoint);
- pDC->LineTo(oldEndPoint);
-
- pDC->SetROP2(R2_COPYPEN);
- }
- void CMyOperate::SelectLine(CDC* pDC, CPoint point)
- {
- int nIndex;
- long distance;
- RECT rect;
- CMyObjectInfo* pLineInfo;
- CMySelObjectInfo* pSelObjInfo;
- CMyLine* pLine;
- for(nIndex = 0; nIndex < m_LineInfoArray.GetSize(); nIndex++)
- {
- pLineInfo = (CMyObjectInfo*)m_LineInfoArray.GetAt(nIndex);
- if(pLineInfo ->m_del == TRUE || pLineInfo ->m_selected ==TRUE)
- continue;
- pLine = (CMyLine*)m_LineArray.GetAt(nIndex);
- rect.left = (long)(pLine->m_startX * Proportion) + EXTRA_WIDTH;
- rect.top = size.cy - (long)(pLine->m_startY * Proportion) - EXTRA_HIGTH;
- rect.right = (long)(pLine->m_endX * Proportion) + EXTRA_WIDTH;
- rect.bottom = size.cy - (long)(pLine->m_endY * Proportion) - EXTRA_HIGTH;
- if( (point.x >= min(rect.left, rect.right) - SELECT_RANGE) && (point.x <= max(rect.left, rect.right) + SELECT_RANGE) &&
- (point.y >= min(rect.top, rect.bottom) - SELECT_RANGE) && (point.y <= max(rect.top, rect.bottom) + SELECT_RANGE) )
- {
- distance = (long)( abs( (rect.bottom - rect.top) * point.x - (rect.right - rect.left) * point.y + rect.top * (rect.right - rect.left) - rect.left * (rect.bottom - rect.top) )
- / sqrt( (rect.right - rect.left) * (rect.right - rect.left) + (rect.bottom - rect.top) * (rect.bottom - rect.top) ) );
- if(distance <= SELECT_RANGE)
- {
- DrawSelLine(pDC, pLine);
- pLineInfo->m_selected = TRUE;
- pSelObjInfo = new CMySelObjectInfo(OBJ_LINE, nIndex);
- m_SelObjInfoArray.Add(pSelObjInfo);
- }
- }
- }
- }
- BOOL CMyOperate::UnselectLine()
- {
- BOOL flag = FALSE;
- int nIndex;
- CMySelObjectInfo* pSelObjInfo;
- CMyObjectInfo* pLineInfo;
- for(nIndex = 0; nIndex < m_SelObjInfoArray.GetSize(); nIndex++)
- {
- pSelObjInfo = (CMySelObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- if(pSelObjInfo->m_type ==OBJ_LINE)
- {
- pLineInfo = (CMyObjectInfo*)m_LineInfoArray.GetAt(pSelObjInfo->m_index);
- pLineInfo->m_selected = FALSE;
- flag = TRUE;
- }
- }
- return flag;
- }
- void CMyOperate::AddLine()
- {
- float startx;
- float starty;
- float endx;
- float endy;
- startx = (StartPoint.x - EXTRA_WIDTH) / Proportion;
- starty = (size.cy - StartPoint.y - EXTRA_HIGTH) / Proportion;
- endx = (EndPoint.x - EXTRA_WIDTH) / Proportion;
- endy = (size.cy - EndPoint.y - EXTRA_HIGTH) / Proportion;
- CMyLine* pMyLine = new CMyLine(startx, starty, endx, endy, LineStyle, ForeColor);
- m_LineArray.Add(pMyLine);
- CMyObjectInfo * pLineInfo = new CMyObjectInfo(FALSE, FALSE);
- m_LineInfoArray.Add(pLineInfo);
- }
- CMyLine* CMyOperate::GetLine(int index)
- {
- if(index < 0 || index > m_LineArray.GetUpperBound())
- return 0;
- return (CMyLine*)m_LineArray.GetAt(index);
- }
- void CMyOperate::DelAllLine()
- {
- int index;
- index = m_LineArray.GetSize();
- while(index--)
- delete (CMyLine*)m_LineArray.GetAt(index);
- m_LineArray.RemoveAll();
-
- index = m_LineInfoArray.GetSize();
- while(index--)
- delete (CMyObjectInfo*)m_LineInfoArray.GetAt(index);
- m_LineInfoArray.RemoveAll();
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //operate rectangle
- void CMyOperate::DrawRectA(CDC* pDC)
- {
- //基于CDC
- pDC->SetROP2(R2_NOT);
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- CRect rect;
- rect.left = StartPoint.x;
- rect.top = StartPoint.y;
- rect.right = oldEndPoint.x;
- rect.bottom = oldEndPoint.y;
- rect.NormalizeRect();
- pDC->Rectangle(rect.left, rect.top, rect.right + 1, rect.bottom +1);
- rect.left = StartPoint.x;
- rect.top = StartPoint.y;
- rect.right = EndPoint.x;
- rect.bottom = EndPoint.y;
- rect.NormalizeRect();
- pDC->Rectangle(rect.left, rect.top, rect.right + 1, rect.bottom + 1);
- oldEndPoint = EndPoint;
- pDC->SetROP2(R2_COPYPEN);
- }
- void CMyOperate::DrawRectB(CDC* pDC)
- {
- //基于CDC
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- CRect rect;
- rect.left = StartPoint.x;
- rect.top = StartPoint.y;
- rect.right = EndPoint.x;
- rect.bottom = EndPoint.y;
- rect.NormalizeRect();
- pDC->Rectangle(rect.left, rect.top, rect.right + 1, rect.bottom + 1);
- }
- void CMyOperate::DrawRectC(CDC* pDC)
- {
- //基于CDC
- CPen Pen;
- CPen* OldPen;
-
- CRect rect;
- rect.left = StartPoint.x;
- rect.top = StartPoint.y;
- rect.right = EndPoint.x;
- rect.bottom = EndPoint.y;
- rect.NormalizeRect();
- Pen.CreatePen(LineStyle, 1, ForeColor);
- OldPen = pDC->SelectObject(&Pen);
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- pDC->SetROP2(R2_COPYPEN);
- //注意画矩形时,不包括右下角那一点,所以右下角x,y坐标加1
- pDC->Rectangle(rect.left, rect.top, rect.right + 1, rect.bottom + 1);
- pDC->SelectObject(OldPen);
- }
- void CMyOperate::CancelDrawRect(CDC* pDC)
- {
- pDC->SetROP2(R2_NOT);
- pDC->SelectStockObject(NULL_BRUSH);
- CRect rect;
- rect.left = StartPoint.x;
- rect.top = StartPoint.y;
- rect.right = EndPoint.x;
- rect.bottom = EndPoint.y;
- rect.NormalizeRect();
- //注意画矩形时,不包括右下角那一点,所以右下角x,y坐标加1
- pDC->Rectangle(rect.left, rect.top, rect.right + 1, rect.bottom + 1);
- pDC->SetROP2(R2_COPYPEN);
- }
- void CMyOperate::RedrawRect(CDC* pDC)
- {
- CPen *Pen;
- CPen* OldPen;
- int index;
- CRect rect;
- CMyRect* pRect;
- CMyObjectInfo* pRectInfo;
- index = m_RectArray.GetSize();
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- while(index--)
- {
- pRect = (CMyRect*)m_RectArray.GetAt(index);
- pRectInfo = (CMyObjectInfo*)m_RectInfoArray.GetAt(index);
- if(pRectInfo->m_del == TRUE)
- continue;
- if(pRectInfo->m_selected == TRUE)
- {
- DrawSelRect(pDC, pRect);
- continue;
- }
- Pen = new CPen(pRect->m_style, 1, pRect->m_color);
- OldPen = pDC->SelectObject(Pen);
- rect.left = (long)(pRect->m_startX * Proportion) + EXTRA_WIDTH;
- rect.right = (long)(pRect->m_endX * Proportion) + EXTRA_WIDTH;
- rect.top = size.cy - (long)(pRect->m_startY * Proportion) - EXTRA_HIGTH;
- rect.bottom = size.cy - (long)(pRect->m_endY * Proportion) - EXTRA_HIGTH;
- rect.NormalizeRect();
- //注意画矩形时,不包括右下角那一点,所以右下角x,y坐标加1
- pDC->Rectangle(rect.left, rect.top, rect.right + 1, rect.bottom + 1);
- //注意以下两句顺序不可颠倒
- pDC->SelectObject(OldPen);
- delete Pen;
- }
- }
- void CMyOperate::DrawSelRect(CDC* pDC, CMyRect* pRect)
- {
- CPen *Pen;
- CPen* OldPen;
- CRect rect;
- CPoint mid;
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- Pen = new CPen(PS_DOT, 1, pRect->m_color);
- OldPen = pDC->SelectObject(Pen);
-
- rect.left = (long)(pRect->m_startX * Proportion) + EXTRA_WIDTH;
- rect.right = (long)(pRect->m_endX * Proportion) + EXTRA_WIDTH;
- rect.top = size.cy - (long)(pRect->m_startY * Proportion) - EXTRA_HIGTH;
- rect.bottom = size.cy - (long)(pRect->m_endY * Proportion) - EXTRA_HIGTH;
- rect.NormalizeRect();
- //注意画矩形时,不包括右下角那一点,所以右下角x,y坐标加1
- pDC->Rectangle(rect.left, rect.top, rect.right + 1, rect.bottom + 1);
- pDC->SelectObject(OldPen);
- delete Pen;
- Pen = new CPen(PS_SOLID, 1, RGB(0, 0, 255));
- OldPen = pDC->SelectObject(Pen);
- pDC->Rectangle(rect.left - SEL_RECT_WIDTH, rect.top - SEL_RECT_WIDTH,
- rect.left + SEL_RECT_WIDTH + 1, rect.top + SEL_RECT_WIDTH + 1);
- pDC->Rectangle(rect.left - SEL_RECT_WIDTH, rect.bottom - SEL_RECT_WIDTH,
- rect.left + SEL_RECT_WIDTH + 1, rect.bottom + SEL_RECT_WIDTH + 1);
- pDC->Rectangle(rect.right - SEL_RECT_WIDTH, rect.top - SEL_RECT_WIDTH,
- rect.right + SEL_RECT_WIDTH + 1, rect.top + SEL_RECT_WIDTH + 1);
- pDC->Rectangle(rect.right - SEL_RECT_WIDTH, rect.bottom - SEL_RECT_WIDTH,
- rect.right + SEL_RECT_WIDTH + 1, rect.bottom + SEL_RECT_WIDTH + 1);
- mid.x = (rect.left + rect.right) / 2;
- mid.y = rect.top;
- pDC->Rectangle(mid.x - SEL_RECT_WIDTH, mid.y - SEL_RECT_WIDTH,
- mid.x + SEL_RECT_WIDTH + 1, mid.y + SEL_RECT_WIDTH + 1);
- mid.x = (rect.left + rect.right) / 2;
- mid.y = rect.bottom;
- pDC->Rectangle(mid.x - SEL_RECT_WIDTH, mid.y - SEL_RECT_WIDTH,
- mid.x + SEL_RECT_WIDTH + 1, mid.y + SEL_RECT_WIDTH + 1);
-
- mid.x = rect.left;
- mid.y = (rect.top + rect.bottom) / 2;
- pDC->Rectangle(mid.x - SEL_RECT_WIDTH, mid.y - SEL_RECT_WIDTH,
- mid.x + SEL_RECT_WIDTH + 1, mid.y + SEL_RECT_WIDTH + 1);
- mid.x = rect.right;
- mid.y = (rect.top + rect.bottom) / 2;
- pDC->Rectangle(mid.x - SEL_RECT_WIDTH, mid.y - SEL_RECT_WIDTH,
- mid.x + SEL_RECT_WIDTH + 1, mid.y + SEL_RECT_WIDTH + 1);
- //注意以下两句顺序不可颠倒
- pDC->SelectObject(OldPen);
- delete Pen;
- }
- void CMyOperate::SelectRect(CDC* pDC, CPoint point)
- {
- int nIndex;
- RECT rect;
- CMyObjectInfo* pRectInfo;
- CMySelObjectInfo* pSelObjInfo;
- CMyRect* pRect;
- for(nIndex = 0; nIndex < m_RectInfoArray.GetSize(); nIndex++)
- {
- pRectInfo = (CMyObjectInfo*)m_RectInfoArray.GetAt(nIndex);
- if(pRectInfo ->m_del == TRUE || pRectInfo ->m_selected ==TRUE)
- continue;
- pRect = (CMyRect*)m_RectArray.GetAt(nIndex);
- rect.left = (long)(pRect->m_startX * Proportion) + EXTRA_WIDTH;
- rect.top = size.cy - (long)(pRect->m_startY * Proportion) - EXTRA_HIGTH;
- rect.right = (long)(pRect->m_endX * Proportion) + EXTRA_WIDTH;
- rect.bottom = size.cy - (long)(pRect->m_endY * Proportion) - EXTRA_HIGTH;
- if( ( (point.x >= min(rect.left, rect.right) - SELECT_RANGE) && (point.x <= max(rect.left, rect.right) + SELECT_RANGE) &&
- (point.y >= min(rect.top, rect.bottom) - SELECT_RANGE) && (point.y <= max(rect.top, rect.bottom) + SELECT_RANGE) ) &&
- ( (point.x <= min(rect.left, rect.right) + SELECT_RANGE) || (point.x >= max(rect.left, rect.right) - SELECT_RANGE) ||
- (point.y <= min(rect.top, rect.bottom) + SELECT_RANGE) || (point.y >= max(rect.top, rect.bottom) - SELECT_RANGE) ) )
- {
- DrawSelRect(pDC, pRect);
- pRectInfo->m_selected = TRUE;
- pSelObjInfo = new CMySelObjectInfo(OBJ_RECT, nIndex);
- m_SelObjInfoArray.Add(pSelObjInfo);
- }
- }
- }
- BOOL CMyOperate::UnselectRect()
- {
- BOOL flag = FALSE;
- int nIndex;
- CMySelObjectInfo* pSelObjInfo;
- CMyObjectInfo* pRectInfo;
- for(nIndex = 0; nIndex < m_SelObjInfoArray.GetSize(); nIndex++)
- {
- pSelObjInfo = (CMySelObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- if(pSelObjInfo->m_type ==OBJ_RECT)
- {
- pRectInfo = (CMyObjectInfo*)m_RectInfoArray.GetAt(pSelObjInfo->m_index);
- pRectInfo->m_selected = FALSE;
- flag = TRUE;
- }
- }
- return flag;
- }
- void CMyOperate::AddRect()
- {
- float startx;
- float starty;
- float endx;
- float endy;
- CRect rect;
-
- rect.left = StartPoint.x - EXTRA_WIDTH;
- rect.top = size.cy - StartPoint.y - EXTRA_HIGTH;
- rect.right = EndPoint.x - EXTRA_WIDTH;
- rect.bottom = size.cy - EndPoint.y - EXTRA_HIGTH;
- rect.NormalizeRect();
- startx = (float)rect.left / Proportion;
- starty = (float)rect.top / Proportion;
- endx = (float)rect.right / Proportion;
- endy = (float)rect.bottom / Proportion;
- CMyRect* pMyRect = new CMyRect(startx, starty, endx, endy, LineStyle, ForeColor);
- m_RectArray.Add(pMyRect);
- CMyObjectInfo * pRectInfo = new CMyObjectInfo(FALSE, FALSE);
- m_RectInfoArray.Add(pRectInfo);
- }
- CMyRect* CMyOperate::GetRect(int index)
- {
- if(index < 0 || index > m_RectArray.GetUpperBound())
- return 0;
- return (CMyRect*)m_RectArray.GetAt(index);
- }
- void CMyOperate::DelAllRect()
- {
- int index;
- index = m_RectArray.GetSize();
- while(index--)
- delete (CMyRect*)m_RectArray.GetAt(index);
- m_RectArray.RemoveAll();
- index = m_RectInfoArray.GetSize();
- while(index--)
- delete (CMyObjectInfo*)m_RectInfoArray.GetAt(index);
- m_RectInfoArray.RemoveAll();
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void CMyOperate::DrawCircleA(CDC* pDC)
- {
- //基于CDC
- pDC->SetROP2(R2_NOT);
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(oldEndPoint.x, oldEndPoint.y);
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(EndPoint.x, EndPoint.y);
- RECT rect;
- rect.left = StartPoint.x - Radius;
- rect.top = StartPoint.y - Radius;
- rect.right = StartPoint.x + Radius;
- rect.bottom = StartPoint.y + Radius;
- pDC->Ellipse(rect.left, rect.top, rect.right, rect.bottom);
- Radius = (long)sqrt(pow((float)(StartPoint.x - EndPoint.x), 2) + pow((float)(StartPoint.y - EndPoint.y), 2));
- rect.left = StartPoint.x - Radius;
- rect.top = StartPoint.y - Radius;
- rect.right = StartPoint.x + Radius;
- rect.bottom = StartPoint.y + Radius;
- pDC->Ellipse(rect.left, rect.top, rect.right, rect.bottom);
- oldEndPoint = EndPoint;
- pDC->SetROP2(R2_COPYPEN);
- }
- void CMyOperate::DrawCircleB(CDC* pDC)
- {
- //基于CDC
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- pDC->MoveTo(StartPoint.x , StartPoint.y);
- pDC->LineTo(EndPoint.x, EndPoint.y);
- RECT rect;
- rect.left = StartPoint.x - Radius;
- rect.top = StartPoint.y - Radius;
- rect.right = StartPoint.x + Radius;
- rect.bottom = StartPoint.y + Radius;
- pDC->Ellipse(rect.left, rect.top, rect.right, rect.bottom);
- }
- void CMyOperate::DrawCircleC(CDC* pDC)
- {
- //基于CDC
- CPen Pen;
- CPen* OldPen;
- RECT rect;
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- //注意先擦除原有的未设置线形、颜色的圆
- pDC->SetROP2(R2_NOT);
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(EndPoint.x, EndPoint.y);
- rect.left = StartPoint.x - Radius;
- rect.top = StartPoint.y - Radius;
- rect.right = StartPoint.x + Radius;
- rect.bottom = StartPoint.y + Radius;
- pDC->Ellipse(rect.left, rect.top, rect.right, rect.bottom);
- pDC->SetROP2(R2_COPYPEN);
- Pen.CreatePen(LineStyle, 1, ForeColor);
- OldPen = pDC->SelectObject(&Pen);
- rect.left = StartPoint.x - Radius;
- rect.top = StartPoint.y - Radius;
- rect.right = StartPoint.x + Radius;
- rect.bottom = StartPoint.y + Radius;
- pDC->Ellipse(rect.left, rect.top, rect.right, rect.bottom);
- oldEndPoint = EndPoint;
- pDC->SelectObject(OldPen);
- }
- void CMyOperate::CancelDrawCircle(CDC* pDC)
- {
- //基于CDC
- pDC->SetROP2(R2_NOT);
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(EndPoint.x, EndPoint.y);
- RECT rect;
- rect.left = (StartPoint.x) - Radius;
- rect.top = (StartPoint.y) - Radius;
- rect.right = (StartPoint.x) + Radius;
- rect.bottom = (StartPoint.y) + Radius;
- pDC->Ellipse(rect.left, rect.top, rect.right, rect.bottom);
- pDC->SetROP2(R2_COPYPEN);
- }
- void CMyOperate::RedrawCircle(CDC* pDC)
- {
- CPen *Pen;
- CPen* OldPen;
- CPoint origin;
- long r;
- RECT rect;
- int index;
- CMyCircle* pCircle;
- CMyObjectInfo* pCircleInfo;
- index = m_CircleArray.GetSize();
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- while(index--)
- {
- pCircle = (CMyCircle*)m_CircleArray.GetAt(index);
- pCircleInfo = (CMyObjectInfo*)m_CircleInfoArray.GetAt(index);
- if(pCircleInfo->m_del == TRUE)
- continue;
- if(pCircleInfo->m_selected == TRUE)
- {
- DrawSelCircle(pDC, pCircle);
- continue;
- }
- Pen = new CPen(pCircle->m_style, 1, pCircle->m_color);
- OldPen = pDC->SelectObject(Pen);
- origin.x = (long)(pCircle->m_originX * Proportion) + EXTRA_WIDTH;
- origin.y = size.cy - (long)(pCircle->m_originY * Proportion) - EXTRA_HIGTH;
- r = (long)(pCircle->m_radius * Proportion);
- rect.left = origin.x - r;
- rect.top = origin.y - r;
- rect.right = origin.x + r;
- rect.bottom = origin.y + r;
- pDC->Ellipse(rect.left, rect.top, rect.right, rect.bottom);
- //注意以下两句顺序不可颠倒
- pDC->SelectObject(OldPen);
- delete Pen;
- }
- }
- void CMyOperate::DrawSelCircle(CDC* pDC, CMyCircle* pCircle)
- {
- CPen *Pen;
- CPen* OldPen;
- RECT rect;
- long r;
- CPoint origin;
- CPoint mid;
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
-
- origin.x = (long)(pCircle->m_originX * Proportion) + EXTRA_WIDTH;
- origin.y = size.cy - (long)(pCircle->m_originY * Proportion) - EXTRA_HIGTH;
- r = (long)(pCircle->m_radius * Proportion);
- rect.left = origin.x - r;
- rect.top = origin.y - r;
- rect.right = origin.x + r;
- rect.bottom = origin.y + r;
- //用异或擦除原有的圆
- Pen = new CPen(pCircle->m_style, 1, pCircle->m_color);
- OldPen = pDC->SelectObject(Pen);
- pDC->SetROP2(R2_NOT);
- pDC->Ellipse(rect.left, rect.top, rect.right, rect.bottom);
- pDC->SelectObject(OldPen);
- delete Pen;
- //重画线形为点线的圆
- Pen = new CPen(PS_DOT, 1, pCircle->m_color);
- OldPen = pDC->SelectObject(Pen);
- pDC->SetROP2(R2_COPYPEN);
- pDC->Ellipse(rect.left, rect.top, rect.right, rect.bottom);
- pDC->SelectObject(OldPen);
- delete Pen;
-
- Pen = new CPen(PS_SOLID, 1, RGB(0, 0, 255));
- OldPen = pDC->SelectObject(Pen);
- pDC->Rectangle(origin.x - SEL_RECT_WIDTH, origin.y - SEL_RECT_WIDTH,
- origin.x + SEL_RECT_WIDTH + 1, origin.y + SEL_RECT_WIDTH + 1);
- pDC->Rectangle(origin.x - SEL_RECT_WIDTH, origin.y - r - SEL_RECT_WIDTH ,
- origin.x + SEL_RECT_WIDTH + 1, origin.y - r + SEL_RECT_WIDTH + 1);
- pDC->Rectangle(origin.x - SEL_RECT_WIDTH, origin.y + r - SEL_RECT_WIDTH,
- origin.x + SEL_RECT_WIDTH + 1, origin.y + r + SEL_RECT_WIDTH + 1);
- pDC->Rectangle(origin.x - r - SEL_RECT_WIDTH, origin.y - SEL_RECT_WIDTH,
- origin.x - r + SEL_RECT_WIDTH + 1, origin.y + SEL_RECT_WIDTH + 1);
- pDC->Rectangle(origin.x + r - SEL_RECT_WIDTH, origin.y - SEL_RECT_WIDTH,
- origin.x + r + SEL_RECT_WIDTH + 1, origin.y + SEL_RECT_WIDTH + 1);
- //注意以下两句顺序不可颠倒
- OldPen = pDC->SelectObject(Pen);
- pDC->SelectObject(OldPen);
- delete Pen;
- }
- void CMyOperate::SelectCircle(CDC* pDC, CPoint point)
- {
- int nIndex;
- CPoint origin;
- long r;
- long distance;
- CMyObjectInfo* pCircleInfo;
- CMySelObjectInfo* pSelObjInfo;
- CMyCircle* pCircle;
- for(nIndex = 0; nIndex < m_CircleInfoArray.GetSize(); nIndex++)
- {
- pCircleInfo = (CMyObjectInfo*)m_CircleInfoArray.GetAt(nIndex);
- if(pCircleInfo ->m_del == TRUE || pCircleInfo ->m_selected ==TRUE)
- continue;
- pCircle = (CMyCircle*)m_CircleArray.GetAt(nIndex);
- origin.x = (long)(pCircle->m_originX * Proportion) + EXTRA_WIDTH;
- origin.y = size.cy - (long)(pCircle->m_originY * Proportion) - EXTRA_HIGTH;
- r = (long)(pCircle->m_radius * Proportion);
- distance = (long)sqrt( (origin.x - point.x) * (origin.x - point.x) + (origin.y - point.y) * (origin.y - point.y) );
- if(distance <= r + SELECT_RANGE && distance >= r - SELECT_RANGE)
- {
- DrawSelCircle(pDC, pCircle);
- pCircleInfo->m_selected = TRUE;
- pSelObjInfo = new CMySelObjectInfo(OBJ_CIRCLE, nIndex);
- m_SelObjInfoArray.Add(pSelObjInfo);
- }
- }
- }
- BOOL CMyOperate::UnselectCircle()
- {
- BOOL flag = FALSE;
- int nIndex;
- CMySelObjectInfo* pSelObjInfo;
- CMyObjectInfo* pCircleInfo;
- for(nIndex = 0; nIndex < m_SelObjInfoArray.GetSize(); nIndex++)
- {
- pSelObjInfo = (CMySelObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- if(pSelObjInfo->m_type ==OBJ_CIRCLE)
- {
- pCircleInfo = (CMyObjectInfo*)m_CircleInfoArray.GetAt(pSelObjInfo->m_index);
- pCircleInfo->m_selected = FALSE;
- flag = TRUE;
- }
- }
- return flag;
- }
- void CMyOperate::AddCircle()
- {
- float startx;
- float starty;
- float r;
-
- startx = (StartPoint.x - EXTRA_WIDTH) / Proportion;
- starty = (size.cy - StartPoint.y - EXTRA_HIGTH) / Proportion;
- r = Radius / Proportion;
- CMyCircle* pMyCircle = new CMyCircle(startx, starty, r, LineStyle, ForeColor);
- m_CircleArray.Add(pMyCircle);
- CMyObjectInfo* pCircleInfo = new CMyObjectInfo(FALSE, FALSE);
- m_CircleInfoArray.Add(pCircleInfo);
- }
- CMyCircle* CMyOperate::GetCircle(int index)
- {
- if(index < 0 || index > m_CircleArray.GetUpperBound())
- return 0;
- return (CMyCircle*)m_CircleArray.GetAt(index);
- }
- void CMyOperate::DelAllCircle()
- {
- int index;
- index = m_CircleArray.GetSize();
- while(index--)
- delete (CMyCircle*)m_CircleArray.GetAt(index);
- m_CircleArray.RemoveAll();
- index = m_CircleInfoArray.GetSize();
- while(index--)
- delete (CMyObjectInfo*)m_CircleInfoArray.GetAt(index);
- m_CircleInfoArray.RemoveAll();
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void CMyOperate::DrawArcA(CDC* pDC, int times)
- {
- static flag;
- double originX;
- double originY;
- double k1;
- double k2;
- double mid1X;
- double mid1Y;
- double mid2X;
- double mid2Y;
- long x1, y1, x2, y2;
- //基于CDC
- pDC->SetROP2(R2_NOT);
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- switch(times)
- {
- case 1:
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(oldMidPoint.x, oldMidPoint.y);
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(MidPoint.x, MidPoint.y);
- flag = 1;
- oldMidPoint = MidPoint;
- break;
- case 2:
- RECT rect;
- if(flag == 1)
- {
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(MidPoint.x, MidPoint.y);
- flag = 0;
- }
- if(OriginPoint.x != -1000 && OriginPoint.y != -1000)
- {
- rect.left = OriginPoint.x - Radius;
- rect.top = OriginPoint.y - Radius;
- rect.right = OriginPoint.x + Radius;
- rect.bottom = OriginPoint.y + Radius;
- x1 = MidPoint.x - StartPoint.x;
- y1 = MidPoint.y - StartPoint.y;
- x2 = oldEndPoint.x - StartPoint.x;
- y2 = oldEndPoint.y - StartPoint.y;
- if(x1*y2 - x2*y1 < 0)
- pDC->Arc(&rect, StartPoint, oldEndPoint);
- else
- pDC->Arc(&rect, oldEndPoint, StartPoint);
- }
- if(StartPoint.y == MidPoint.y)
- k1 = 1000000.0;
- else
- k1 = (- (double)(StartPoint.x - MidPoint.x) / (double)(StartPoint.y - MidPoint.y));
- if(EndPoint.y == MidPoint.y)
- k2 = 1000000.0;
- else
- k2 = (- (double)(EndPoint.x - MidPoint.x) / (double)(EndPoint.y - MidPoint.y));
- mid1X = (double)(StartPoint.x + MidPoint.x) / 2.0;
- mid1Y = (double)(StartPoint.y + MidPoint.y) / 2.0;
- mid2X = (double)(EndPoint.x + MidPoint.x) / 2.0;
- mid2Y = (double)(EndPoint.y + MidPoint.y) / 2.0;
- if(k1 == k2)
- {
- OriginPoint.x = -1000;
- OriginPoint.y = -1000;
- }
- else
- {
- if(k1 == 1000000.0)
- {
- originX = mid1X;
- originY = k2 * (originX - mid2X) + mid2Y;
- }
- else
- if(k2 == 1000000.0)
- {
- originX = mid2X;
- originY = k1 * (originX - mid1X) + mid1Y;
- }
- else
- {
- originX = ((k2 * mid2X - k1 * mid1X) - (mid2Y - mid1Y)) / (k2 - k1);
- originY = k2 * (originX - mid2X) + mid2Y;
- }
- Radius = (long)sqrt(pow((double)(originX - StartPoint.x), 2) + pow((double)(originY - StartPoint.y), 2));
- OriginPoint.x = (long)originX;
- OriginPoint.y = (long)originY ;
- rect.left = OriginPoint.x - Radius;
- rect.top = OriginPoint.y - Radius;
- rect.right = OriginPoint.x + Radius;
- rect.bottom = OriginPoint.y + Radius;
- x1 = MidPoint.x - StartPoint.x;
- y1 = MidPoint.y - StartPoint.y;
- x2 = EndPoint.x - StartPoint.x;
- y2 = EndPoint.y - StartPoint.y;
- //判断优弧
- if(x1*y2 - x2*y1 < 0)
- pDC->Arc(&rect, StartPoint, EndPoint);
- else
- pDC->Arc(&rect, EndPoint, StartPoint);
- oldEndPoint = EndPoint;
- }
- break;
- }
- pDC->SetROP2(R2_COPYPEN);
- }
- void CMyOperate::DrawArcB(CDC* pDC, int times)
- {
- long x1, y1, x2, y2;
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- switch(times)
- {
- case 1:
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(MidPoint.x, MidPoint.y);
- break;
- case 2:
- RECT rect;
- if(OriginPoint.x != -1000 && OriginPoint.y != -1000)
- {
- rect.left = OriginPoint.x - Radius;
- rect.top = OriginPoint.y - Radius;
- rect.right = OriginPoint.x + Radius;
- rect.bottom = OriginPoint.y + Radius;
- x1 = MidPoint.x - StartPoint.x;
- y1 = MidPoint.y - StartPoint.y;
- x2 = EndPoint.x - StartPoint.x;
- y2 = EndPoint.y - StartPoint.y;
- if(x1*y2 - x2*y1 < 0)
- pDC->Arc(&rect, StartPoint, EndPoint);
- else
- pDC->Arc(&rect, EndPoint, StartPoint);
- }
- break;
- }
- }
- void CMyOperate::DrawArcC(CDC* pDC)
- {
- CPen* Pen;
- CPen* OldPen;
- RECT rect;
- long x1, y1, x2, y2;
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- rect.left = OriginPoint.x - Radius;
- rect.top = OriginPoint.y - Radius;
- rect.right = OriginPoint.x + Radius;
- rect.bottom = OriginPoint.y + Radius;
- Pen = new CPen(LineStyle, 1, ForeColor);
- OldPen = pDC->SelectObject(Pen);
- x1 = MidPoint.x - StartPoint.x;
- y1 = MidPoint.y - StartPoint.y;
- x2 = EndPoint.x - StartPoint.x;
- y2 = EndPoint.y - StartPoint.y;
- if(x1*y2 - x2*y1 < 0)
- pDC->Arc(&rect, StartPoint, EndPoint);
- else
- pDC->Arc(&rect, EndPoint, StartPoint);
- pDC->SelectObject(OldPen);
- delete Pen;
- }
- void CMyOperate::CancelDrawArc(CDC* pDC, int times)
- {
- long x1, y1, x2, y2;
- //设置不填充状态
- pDC->SetROP2(R2_NOT);
- pDC->SelectStockObject(NULL_BRUSH);
- switch(times)
- {
- case 1:
- pDC->MoveTo(StartPoint.x, StartPoint.y);
- pDC->LineTo(MidPoint.x, MidPoint.y);
- break;
- case 2:
- RECT rect;
- if(OriginPoint.x != -1000 && OriginPoint.y != -1000)
- {
- rect.left = OriginPoint.x - Radius;
- rect.top = OriginPoint.y - Radius;
- rect.right = OriginPoint.x + Radius;
- rect.bottom = OriginPoint.y + Radius;
- x1 = MidPoint.x - StartPoint.x;
- y1 = MidPoint.y - StartPoint.y;
- x2 = EndPoint.x - StartPoint.x;
- y2 = EndPoint.y - StartPoint.y;
- if(x1*y2 - x2*y1 < 0)
- pDC->Arc(&rect, StartPoint, EndPoint);
- else
- pDC->Arc(&rect, EndPoint, StartPoint);
- }
- break;
- }
- pDC->SetROP2(R2_COPYPEN);
- }
- void CMyOperate::RedrawArc(CDC* pDC)
- {
- CPen *Pen;
- CPen* OldPen;
- CPoint origin;
- CPoint start;
- CPoint end;
- long r;
- RECT rect;
- int index;
- CMyArc* pArc;
- CMyObjectInfo* pArcInfo;
- index = m_ArcArray.GetSize();
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- while(index--)
- {
- pArc = (CMyArc*)m_ArcArray.GetAt(index);
- pArcInfo = (CMyObjectInfo*)m_ArcInfoArray.GetAt(index);
- if(pArcInfo->m_del == TRUE)
- continue;
- if(pArcInfo->m_selected == TRUE)
- {
- DrawSelArc(pDC, pArc);
- continue;
- }
- Pen = new CPen(pArc->m_style, 1, pArc->m_color);
- OldPen = pDC->SelectObject(Pen);
- origin.x = (long)(pArc->m_originX * Proportion) + EXTRA_WIDTH;
- origin.y = size.cy - (long)(pArc->m_originY * Proportion) - EXTRA_HIGTH;
- start.x = (long)(pArc->m_startX * Proportion) + EXTRA_WIDTH;
- start.y = size.cy - (long)(pArc->m_startY * Proportion) - EXTRA_HIGTH;
- end.x = (long)(pArc->m_endX * Proportion) + EXTRA_WIDTH;
- end.y = size.cy - (long)(pArc->m_endY * Proportion) - EXTRA_HIGTH;
- r = (long)(pArc->m_radius * Proportion);
- rect.left = origin.x - r;
- rect.top = origin.y - r;
- rect.right = origin.x + r;
- rect.bottom = origin.y + r;
- pDC->Arc(&rect, start, end);
- //注意以下两句顺序不可颠倒
- pDC->SelectObject(OldPen);
- delete Pen;
- }
- }
- void CMyOperate::DrawSelArc(CDC* pDC, CMyArc* pArc)
- {
- CPen *Pen;
- CPen* OldPen;
- RECT rect;
- long r;
- CPoint origin;
- CPoint start;
- CPoint end;
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- origin.x = (long)(pArc->m_originX * Proportion) + EXTRA_WIDTH;
- origin.y = size.cy - (long)(pArc->m_originY * Proportion) - EXTRA_HIGTH;
- start.x = (long)(pArc->m_startX * Proportion) + EXTRA_WIDTH;
- start.y = size.cy - (long)(pArc->m_startY * Proportion) - EXTRA_HIGTH;
- end.x = (long)(pArc->m_endX * Proportion) + EXTRA_WIDTH;
- end.y = size.cy - (long)(pArc->m_endY * Proportion) - EXTRA_HIGTH;
- r = (long)(pArc->m_radius * Proportion);
- rect.left = origin.x - r;
- rect.top = origin.y - r;
- rect.right = origin.x + r;
- rect.bottom = origin.y + r;
- //重画线形为点线的圆弧
- Pen = new CPen(PS_DOT, 1, pArc->m_color);
- OldPen = pDC->SelectObject(Pen);
- pDC->SetROP2(R2_COPYPEN);
- pDC->Arc(&rect, start, end);
- pDC->SelectObject(OldPen);
- delete Pen;
-
- Pen = new CPen(PS_SOLID, 1, RGB(0, 0, 255));
- OldPen = pDC->SelectObject(Pen);
- pDC->Rectangle(start.x - SEL_RECT_WIDTH, start.y - SEL_RECT_WIDTH ,
- start.x + SEL_RECT_WIDTH + 1, start.y + SEL_RECT_WIDTH + 1);
- pDC->Rectangle(end.x - SEL_RECT_WIDTH, end.y - SEL_RECT_WIDTH,
- end.x + SEL_RECT_WIDTH + 1, end.y + SEL_RECT_WIDTH + 1);
- //注意以下两句顺序不可颠倒
- OldPen = pDC->SelectObject(Pen);
- pDC->SelectObject(OldPen);
- delete Pen;
- }
- void CMyOperate::SelectArc(CDC* pDC, CPoint point)
- {
- long x1, y1, x2, y2;
- int nIndex;
- CPoint origin;
- long r;
- long distance;
- CPoint start;
- CPoint end;
- CMyObjectInfo* pArcInfo;
- CMySelObjectInfo* pSelObjInfo;
- CMyArc* pArc;
- for(nIndex = 0; nIndex < m_ArcInfoArray.GetSize(); nIndex++)
- {
- pArcInfo = (CMyObjectInfo*)m_ArcInfoArray.GetAt(nIndex);
- if(pArcInfo ->m_del == TRUE || pArcInfo ->m_selected ==TRUE)
- continue;
- pArc = (CMyArc*)m_ArcArray.GetAt(nIndex);
- origin.x = (long)(pArc->m_originX * Proportion) + EXTRA_WIDTH;
- origin.y = size.cy - (long)(pArc->m_originY * Proportion) - EXTRA_HIGTH;
- start.x = (long)(pArc->m_startX * Proportion) + EXTRA_WIDTH;
- start.y = size.cy - (long)(pArc->m_startY * Proportion) - EXTRA_HIGTH;
- end.x = (long)(pArc->m_endX * Proportion) + EXTRA_WIDTH;
- end.y = size.cy - (long)(pArc->m_endY * Proportion) - EXTRA_HIGTH;
- r = (long)(pArc->m_radius * Proportion);
- distance = (long)sqrt( (origin.x - point.x) * (origin.x - point.x) + (origin.y - point.y) * (origin.y - point.y) );
- if(distance >= r + SELECT_RANGE || distance <= r - SELECT_RANGE)
- continue;
- x1 = point.x - start.x;
- y1 = point.y - start.y;
- x2 = end.x - start.x;
- y2 = end.y - start.y;
- if(x1 * y2 - x2 * y1 < 0)
- {
- DrawSelArc(pDC, pArc);
- pArcInfo->m_selected = TRUE;
- pSelObjInfo = new CMySelObjectInfo(OBJ_ARC, nIndex);
- m_SelObjInfoArray.Add(pSelObjInfo);
- }
- }
- }
- BOOL CMyOperate::UnselectArc()
- {
- BOOL flag = FALSE;
- int nIndex;
- CMySelObjectInfo* pSelObjInfo;
- CMyObjectInfo* pArcInfo;
- for(nIndex = 0; nIndex < m_SelObjInfoArray.GetSize(); nIndex++)
- {
- pSelObjInfo = (CMySelObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- if(pSelObjInfo->m_type ==OBJ_ARC)
- {
- pArcInfo = (CMyObjectInfo*)m_ArcInfoArray.GetAt(pSelObjInfo->m_index);
- pArcInfo->m_selected = FALSE;
- flag = TRUE;
- }
- }
- return flag;
- }
- void CMyOperate::AddArc()
- {
- long x1, y1, x2, y2;
- float originx;
- float originy;
- float startx;
- float starty;
- float endx;
- float endy;
- float r;
- CMyArc* pMyArc;
-
- originx = (OriginPoint.x - EXTRA_WIDTH) / Proportion;
- originy = (size.cy - OriginPoint.y - EXTRA_HIGTH) / Proportion;
- startx = (StartPoint.x - EXTRA_WIDTH) / Proportion;
- starty = (size.cy - StartPoint.y - EXTRA_HIGTH) / Proportion;
- endx = (EndPoint.x - EXTRA_WIDTH) / Proportion;
- endy = (size.cy - EndPoint.y - EXTRA_HIGTH) / Proportion;
- r = Radius / Proportion;
- x1 = MidPoint.x - StartPoint.x;
- y1 = MidPoint.y - StartPoint.y;
- x2 = EndPoint.x - StartPoint.x;
- y2 = EndPoint.y - StartPoint.y;
- if(x1*y2 - x2*y1 < 0)
- pMyArc = new CMyArc(originx, originy, startx, starty, endx, endy, r, LineStyle, ForeColor);
- else
- pMyArc = new CMyArc(originx, originy, endx, endy, startx, starty, r, LineStyle, ForeColor);
-
- m_ArcArray.Add(pMyArc);
- CMyObjectInfo* pArcInfo = new CMyObjectInfo(FALSE, FALSE);
- m_ArcInfoArray.Add(pArcInfo);
- }
- CMyArc* CMyOperate::GetArc(int index)
- {
- if(index < 0 || index > m_ArcArray.GetUpperBound())
- return 0;
- return (CMyArc*)m_ArcArray.GetAt(index);
- }
- void CMyOperate::DelAllArc()
- {
- int index;
- index = m_ArcArray.GetSize();
- while(index--)
- delete (CMyArc*)m_ArcArray.GetAt(index);
- m_ArcArray.RemoveAll();
- index = m_ArcInfoArray.GetSize();
- while(index--)
- delete (CMyObjectInfo*)m_ArcInfoArray.GetAt(index);
- m_ArcInfoArray.RemoveAll();
- }