CPolyBezier.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #include "stdafx.h"
  2. #include "CPolyBezier.h"
  3. #include "EastDrawView.h"
  4. IMPLEMENT_SERIAL(CPolyBezier,CUnit,1)
  5. CPolyBezier::CPolyBezier()
  6. {
  7. CUnit::Initial();
  8. m_HaveDrawFirst=false;
  9. }
  10. void CPolyBezier::DrawActive(CDC *pDC, CPoint point)
  11. {
  12. CPen m_pen;
  13. CBrush m_brush;
  14. m_pen.CreatePen(m_PenStyle,m_PenWidth,m_PenColor);
  15. CPen* pen=(CPen*)pDC->SelectObject(&m_pen);
  16. LOGBRUSH brushlog;
  17. brushlog.lbColor=m_BrushColor;
  18. brushlog.lbHatch=m_BrushHatch;
  19. brushlog.lbStyle=m_BrushStyle;
  20. m_brush.CreateBrushIndirect(&brushlog);
  21. CBrush*brush=(CBrush*)pDC->SelectObject(&m_brush);
  22. int OldBkMode=pDC->SetBkMode(m_BkMode);
  23. COLORREF OldColor=pDC->SetBkColor(m_BackgroundColor);
  24. m_PointList=new CPoint[4];
  25. for(int i=3;i>0;i--)
  26. m_PointList[3-i]=m_PointArray.GetAt(m_PointArray.GetSize()-i);
  27. m_PointList[3]=point;
  28. pDC->PolyBezier(m_PointList,4);
  29. delete m_PointList;
  30. }
  31. void CPolyBezier::OnLButtonDown(CDC*pDC,CEastDrawView*pView,CPoint point)
  32. {
  33. if(pView->m_CurrentDrawStatus==Draw_Status)
  34. {
  35. switch(pView->m_LBDownTimes%3)
  36. {
  37. case 0:
  38. DrawActive(pDC,point);
  39. m_PointArray.SetAt(m_PointArray.GetSize()-1,point);
  40. DrawMaskPoint(pDC);
  41. break;
  42. case 1:
  43. m_PointArray.Add(point);
  44. m_PointArray.Add(point);
  45. m_PointArray.Add(point);
  46. break;
  47. case 2:
  48. m_PointArray.SetAt(m_PointArray.GetSize()-2,point);
  49. m_PointArray.SetAt(m_PointArray.GetSize()-1,point);
  50. break;
  51. }
  52. }//******if(pView->m_CurrentDrawStatus==Draw_Status)
  53. if(pView->m_CurrentDrawStatus==Select_Status)
  54. {
  55. if(this->m_HaveFindFirst)
  56. {
  57. pView->L_iPointCount=this->IsOnMarginPoint(point);
  58. if(pView->L_iPointCount!=0)
  59. {
  60. pView->m_CurrentDrawStatus=Change_Status;
  61. pView->m_bHaveFindSecond=true;
  62. pView->m_CurrentDrawTool=PolyBezier_Tool;
  63. pView->m_pCurrentUnit=this;
  64. this->DrawStatic(pDC);
  65. this->ShowSelectPoint(pDC);
  66. this->DrawOldReferencePoint(pDC,this->m_FoundPoint);
  67. }
  68. }
  69. if(!pView->m_bHaveFindSecond&&this->IsInRgn(point))
  70. {
  71. if(this->m_HaveFindFirst)
  72. {
  73. this->m_HaveFindFirst=false;
  74. pView->m_bHaveFindFirst=true;
  75. }
  76. else
  77. {
  78. this->m_HaveFindFirst=true;
  79. pView->m_bHaveFindFirst=true;
  80. }
  81. this->ShowSelectPoint(pDC);
  82. }
  83. }
  84. }
  85. void CPolyBezier::OnMouseMove(CDC *pDC, CEastDrawView *pView, CPoint point)
  86. {
  87. static int m_Pre=-1;
  88. if(pView->m_CurrentDrawStatus==Draw_Status)
  89. {
  90. if(!m_HaveDrawFirst)
  91. {
  92. DrawActive(pDC,pView->m_LastDownPoint);
  93. m_HaveDrawFirst=true;
  94. }
  95. if(pView->m_LBDownTimes%3==0&&pView->m_LBDownTimes/3!=m_Pre)
  96. {
  97. m_HaveDrawFirst=false;
  98. m_Pre=pView->m_LBDownTimes/3;
  99. }
  100. this->DrawActive(pDC,pView->m_FirstPoint);
  101. pView->m_FirstPoint=point;
  102. this->DrawActive(pDC,point);
  103. }//*******if(pView->m_CurrentDrawStatus==Draw_Status)
  104. if(pView->m_CurrentDrawStatus==Change_Status)
  105. {
  106. this->DrawStatic(pDC);
  107. pView->m_SecondPoint=point;
  108. m_PointArray.SetAt(pView->L_iPointCount-1,point);
  109. this->DrawStatic(pDC);
  110. }
  111. }
  112. void CPolyBezier::DrawStatic(CDC *pDC)
  113. {
  114. CPen m_pen;
  115. CBrush m_brush;
  116. int oldDrawingMode=pDC->SetROP2(this->m_DrawingMode);
  117. m_pen.CreatePen(m_PenStyle,m_PenWidth,m_PenColor);
  118. CPen* pen=(CPen*)pDC->SelectObject(&m_pen);
  119. LOGBRUSH brushlog;
  120. brushlog.lbColor=m_BrushColor;
  121. brushlog.lbHatch=m_BrushHatch;
  122. brushlog.lbStyle=m_BrushStyle;
  123. m_brush.CreateBrushIndirect(&brushlog);
  124. CBrush*brush=(CBrush*)pDC->SelectObject(&m_brush);
  125. int OldBkMode=pDC->SetBkMode(m_BkMode);
  126. COLORREF OldColor=pDC->SetBkColor(m_BackgroundColor);
  127. m_PointList=new CPoint[m_PointArray.GetSize()];
  128. for(int i=0;i<m_PointArray.GetSize();i++)
  129. m_PointList[i]=m_PointArray.GetAt(i);
  130. pDC->PolyBezier(m_PointList,m_PointArray.GetSize());
  131. delete m_PointList;
  132. }
  133. void CPolyBezier::ShowSelectPoint(CDC *pDC)
  134. {
  135. CBrush brush;
  136. brush.CreateSolidBrush(RGB(0,0,255));
  137. CPen m_pen;
  138. m_pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
  139. CPen *OldPen=pDC->SelectObject(&m_pen);
  140. int oldBkMode=pDC->SetBkMode(OPAQUE);
  141. CBrush *OldBrush=pDC->SelectObject(&brush);
  142. int oldDrawingMode=pDC->SetROP2(R2_NOTXORPEN);
  143. CRect rect;
  144. for(int i=0;i<m_PointArray.GetSize();i=i+3)
  145. {
  146. rect.SetRect(m_PointArray.GetAt(i),m_PointArray.GetAt(i));
  147. rect.InflateRect(3,3);
  148. pDC->Rectangle(rect);
  149. }
  150. pDC->SelectObject(OldBrush);
  151. brush.DeleteObject();
  152. brush.CreateSolidBrush(RGB(255,0,0));
  153. pDC->SelectObject(&brush);
  154. for(i=1;i<m_PointArray.GetSize()-1;i=i+3)
  155. {
  156. rect.SetRect(m_PointArray.GetAt(i),m_PointArray.GetAt(i));
  157. rect.InflateRect(3,3);
  158. pDC->Rectangle(rect);
  159. rect.SetRect(m_PointArray.GetAt(i+1),m_PointArray.GetAt(i+1));
  160. rect.InflateRect(3,3);
  161. pDC->Rectangle(rect);
  162. }
  163. pDC->SelectObject(OldPen);
  164. pDC->SetBkMode(oldBkMode);
  165. pDC->SelectObject(OldBrush);
  166. pDC->SetROP2(oldDrawingMode);
  167. }
  168. void CPolyBezier::DrawMaskPoint(CDC *pDC)
  169. {
  170. CBrush brush;
  171. brush.CreateSolidBrush(RGB(0,0,255));
  172. CPen m_pen;
  173. m_pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
  174. CPen *OldPen=pDC->SelectObject(&m_pen);
  175. int oldBkMode=pDC->SetBkMode(OPAQUE);
  176. CBrush *OldBrush=pDC->SelectObject(&brush);
  177. int oldDrawingMode=pDC->SetROP2(R2_NOTXORPEN);
  178. CRect rect;
  179. rect.SetRect(m_PointArray.GetAt(m_PointArray.GetSize()-3),m_PointArray.GetAt(m_PointArray.GetSize()-3));
  180. rect.InflateRect(3,3);
  181. pDC->Rectangle(rect);
  182. pDC->SelectObject(OldBrush);
  183. brush.DeleteObject();
  184. brush.CreateSolidBrush(RGB(255,0,0));
  185. pDC->SelectObject(&brush);
  186. rect.SetRect(m_PointArray.GetAt(m_PointArray.GetSize()-2),m_PointArray.GetAt(m_PointArray.GetSize()-2));
  187. rect.InflateRect(3,3);
  188. pDC->Rectangle(rect);
  189. rect.SetRect(m_PointArray.GetAt(m_PointArray.GetSize()-1),m_PointArray.GetAt(m_PointArray.GetSize()-1));
  190. rect.InflateRect(3,3);
  191. pDC->Rectangle(rect);
  192. pDC->SelectObject(OldPen);
  193. pDC->SetBkMode(oldBkMode);
  194. pDC->SelectObject(OldBrush);
  195. pDC->SetROP2(oldDrawingMode);
  196. }
  197. int CPolyBezier::IsOnMarginPoint(CPoint point)
  198. {
  199. CRect rect;
  200. rect.SetRect(point,point);
  201. rect.InflateRect(4,4);
  202. for(int i=0;i<m_PointArray.GetSize();i++)
  203. {
  204. if(rect.PtInRect(m_PointArray.GetAt(i)))
  205. {
  206. m_FoundPoint=m_PointArray.GetAt(i);
  207. return i+1;
  208. }
  209. }
  210. return 0;
  211. }
  212. BOOL CPolyBezier::IsInRgn(CPoint point)
  213. {
  214. CRect rect;
  215. rect.SetRect(point,point);
  216. rect.InflateRect(20,20);
  217. for(int i=0;i<m_PointArray.GetSize()-2;i=i+3)
  218. {
  219. if(rect.PtInRect(m_PointArray.GetAt(i)))
  220. return true;
  221. }
  222. return false;
  223. }
  224. void CPolyBezier::OnMenuitemOk(CDC *pDC, CEastDrawView *pView)
  225. {
  226. //pView->m_LBDownTimes=0;
  227. pView->m_CurrentDrawTool=PolyBezier_Tool;
  228. pView->m_CurrentDrawStatus=Select_Status;
  229. this->m_PointArray.Add(pView->m_ChangeingPoint);
  230. this->m_HaveFindFirst=true;
  231. pView->m_bHaveFindFirst=true;
  232. pView->ExchangeSave();
  233. CBrush brush;
  234. brush.CreateSolidBrush(RGB(0,0,255));
  235. CPen m_pen;
  236. m_pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
  237. CPen *OldPen=pDC->SelectObject(&m_pen);
  238. int oldBkMode=pDC->SetBkMode(OPAQUE);
  239. CBrush *OldBrush=pDC->SelectObject(&brush);
  240. int oldDrawingMode=pDC->SetROP2(R2_NOTXORPEN);
  241. CRect rect;
  242. rect.SetRect(pView->m_ChangeingPoint,pView->m_ChangeingPoint);
  243. rect.InflateRect(3,3);
  244. pDC->Rectangle(rect);
  245. pDC->SelectObject(OldBrush);
  246. }
  247. void CPolyBezier::Serialize(CArchive &ar)
  248. {
  249. CUnit::Serialize(ar);
  250. this->m_PointArray.Serialize(ar);
  251. }
  252. void CPolyBezier::OnContextMenu(CWnd *pWnd, CPoint point)
  253. {
  254. CEastDrawView*pView=(CEastDrawView*)pWnd;
  255. if(pView->m_CurrentDrawStatus==Draw_Status)
  256. {
  257. CMenu menuTextEdit;
  258. menuTextEdit.LoadMenu(IDR_MENU_OK);
  259. menuTextEdit.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,pWnd);
  260. }
  261. }