CLiEllipse.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #include "stdafx.h"
  2. #include"CLiEllipse.h"
  3. #include"EastDrawView.h"
  4. IMPLEMENT_SERIAL(CLiEllipse,CUnit,1)
  5. void CLiEllipse::DrawStatic(CDC*pDC)
  6. {
  7. CPen m_pen;
  8. CBrush m_brush;
  9. int oldDrawingMode=pDC->SetROP2(this->m_DrawingMode);
  10. m_pen.CreatePen(m_PenStyle,m_PenWidth,m_PenColor);
  11. CPen* pen=(CPen*)pDC->SelectObject(&m_pen);
  12. LOGBRUSH brushlog;
  13. brushlog.lbColor=m_BrushColor;
  14. brushlog.lbHatch=m_BrushHatch;
  15. brushlog.lbStyle=m_BrushStyle;
  16. m_brush.CreateBrushIndirect(&brushlog);
  17. SetBrushOrg(pDC,&m_brush);
  18. CBrush*brush=(CBrush*)pDC->SelectObject(&m_brush);
  19. int OldBkMode=pDC->SetBkMode(m_BkMode);
  20. COLORREF OldColor=pDC->SetBkColor(m_BackgroundColor);
  21. pDC->Ellipse(CRect(m_FirstPoint,m_SecondPoint));
  22. pDC->SelectObject(brush);
  23. pDC->SelectObject(pen);
  24. pDC->SetBkMode(OldBkMode);
  25. pDC->SetBkColor(OldColor);
  26. pDC->SetROP2(oldDrawingMode);
  27. }
  28. CLiEllipse::CRoundRectangle()
  29. {
  30. Initial();
  31. //m_Shape=0;
  32. m_BrushStyle=BS_HOLLOW;
  33. m_BrushHatch=HS_CROSS;
  34. }
  35. void CLiEllipse::Serialize(CArchive &ar)
  36. {
  37. CUnit::Serialize(ar);
  38. if(ar.IsStoring())
  39. {
  40. ar<<m_BrushStyle<<m_BkMode<<m_BrushHatch<<m_BrushColor;
  41. }
  42. else
  43. {
  44. ar>>m_BrushStyle>>m_BkMode>>m_BrushHatch>>m_BrushColor;
  45. }
  46. }
  47. BOOL CLiEllipse::IsInRgn(CPoint point)
  48. {
  49. CPoint FirstPoint;
  50. CPoint SecondPoint;
  51. FirstPoint.x=m_FirstPoint.x<m_SecondPoint.x?m_FirstPoint.x:m_SecondPoint.x;
  52. FirstPoint.y=m_FirstPoint.y<m_SecondPoint.y?m_FirstPoint.y:m_SecondPoint.y;
  53. SecondPoint.x=m_FirstPoint.x>m_SecondPoint.x?m_FirstPoint.x:m_SecondPoint.x;
  54. SecondPoint.y=m_FirstPoint.y>m_SecondPoint.y?m_FirstPoint.y:m_SecondPoint.y;
  55. m_FirstPoint=FirstPoint;
  56. m_SecondPoint=SecondPoint;
  57. CRgn rgn1;
  58. rgn1.CreateEllipticRgn(m_FirstPoint.x-4,m_FirstPoint.y-4,m_SecondPoint.x+4,m_SecondPoint.y+4);
  59. CRgn rgn2;
  60. rgn2.CreateEllipticRgn(m_FirstPoint.x+4,m_FirstPoint.y+4,m_SecondPoint.x-4,m_SecondPoint.y-4);
  61. return rgn1.PtInRegion(point)&&!rgn2.PtInRegion(point);
  62. }
  63. int CLiEllipse::IsOnMarginPoint(CPoint point)
  64. {
  65. CRect rect(point,point);
  66. rect.InflateRect(CSize(4,4));
  67. if(rect.PtInRect(CPoint(m_FirstPoint.x+(m_SecondPoint.x-m_FirstPoint.x)/2,m_FirstPoint.y)))
  68. {
  69. this->m_FoundPoint=CPoint(m_FirstPoint.x+(m_SecondPoint.x-m_FirstPoint.x)/2,m_FirstPoint.y);
  70. return 1;
  71. }
  72. if(rect.PtInRect(CPoint(m_SecondPoint.x,m_FirstPoint.y+(m_SecondPoint.y-m_FirstPoint.y)/2)))
  73. {
  74. this->m_FoundPoint=CPoint(m_SecondPoint.x,m_FirstPoint.y+(m_SecondPoint.y-m_FirstPoint.y)/2);
  75. return 2;
  76. }
  77. if(rect.PtInRect(CPoint(m_SecondPoint.x+(m_FirstPoint.x-m_SecondPoint.x)/2,m_SecondPoint.y)))
  78. {
  79. this->m_FoundPoint=CPoint(m_SecondPoint.x+(m_FirstPoint.x-m_SecondPoint.x)/2,m_SecondPoint.y);
  80. return 3;
  81. }
  82. if(rect.PtInRect(CPoint(m_FirstPoint.x,m_SecondPoint.y+(m_FirstPoint.y-m_SecondPoint.y)/2)))
  83. {
  84. this->m_FoundPoint=CPoint(m_FirstPoint.x,m_SecondPoint.y+(m_FirstPoint.y-m_SecondPoint.y)/2);
  85. return 4;
  86. }
  87. if(rect.PtInRect(CPoint((m_FirstPoint.x+m_SecondPoint.x)/2,(m_FirstPoint.y+m_SecondPoint.y)/2)))
  88. {
  89. this->m_FoundPoint=CPoint((m_FirstPoint.x+m_SecondPoint.x)/2,(m_FirstPoint.y+m_SecondPoint.y)/2);
  90. return 5;
  91. }
  92. return 0;
  93. }
  94. void CLiEllipse::ShowSelectPoint(CDC *pDC)
  95. {
  96. CBrush brush;
  97. brush.CreateSolidBrush(RGB(0,0,255));
  98. CPen m_pen;
  99. m_pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
  100. CPen *OldPen=pDC->SelectObject(&m_pen);
  101. int oldBkMode=pDC->SetBkMode(OPAQUE);
  102. CBrush *OldBrush=pDC->SelectObject(&brush);
  103. int oldDrawingMode=pDC->SetROP2(R2_NOTXORPEN);
  104. CRect rect;
  105. rect.SetRect(CPoint(m_FirstPoint.x+(m_SecondPoint.x-m_FirstPoint.x)/2,m_FirstPoint.y),CPoint(m_FirstPoint.x+(m_SecondPoint.x-m_FirstPoint.x)/2,m_FirstPoint.y));
  106. rect.InflateRect(3,3);
  107. pDC->Rectangle(rect);
  108. rect.SetRect(CPoint(m_SecondPoint.x,m_FirstPoint.y+(m_SecondPoint.y-m_FirstPoint.y)/2),CPoint(m_SecondPoint.x,m_FirstPoint.y+(m_SecondPoint.y-m_FirstPoint.y)/2));
  109. rect.InflateRect(3,3);
  110. pDC->Rectangle(rect);
  111. rect.SetRect(CPoint(m_SecondPoint.x+(m_FirstPoint.x-m_SecondPoint.x)/2,m_SecondPoint.y),CPoint(m_SecondPoint.x+(m_FirstPoint.x-m_SecondPoint.x)/2,m_SecondPoint.y));
  112. rect.InflateRect(3,3);
  113. pDC->Rectangle(rect);
  114. rect.SetRect(CPoint(m_FirstPoint.x,m_SecondPoint.y+(m_FirstPoint.y-m_SecondPoint.y)/2),CPoint(m_FirstPoint.x,m_SecondPoint.y+(m_FirstPoint.y-m_SecondPoint.y)/2));
  115. rect.InflateRect(3,3);
  116. pDC->Rectangle(rect);
  117. rect.SetRect(CPoint((m_FirstPoint.x+m_SecondPoint.x)/2,(m_FirstPoint.y+m_SecondPoint.y)/2),CPoint((m_FirstPoint.x+m_SecondPoint.x)/2,(m_FirstPoint.y+m_SecondPoint.y)/2));
  118. rect.InflateRect(3,3);
  119. pDC->SelectObject(OldBrush);
  120. brush.DeleteObject();
  121. brush.CreateSolidBrush(RGB(255,0,0));
  122. pDC->SelectObject(&brush);
  123. pDC->Rectangle(rect);
  124. pDC->SelectObject(OldPen);
  125. pDC->SetBkMode(oldBkMode);
  126. pDC->SelectObject(OldBrush);
  127. pDC->SetROP2(oldDrawingMode);
  128. }
  129. void CLiEllipse::DrawActive(CDC *pDC,CPoint point)
  130. {
  131. CPen m_pen;
  132. CBrush m_brush;
  133. m_pen.CreatePen(m_PenStyle,m_PenWidth,m_PenColor);
  134. CPen* pen=(CPen*)pDC->SelectObject(&m_pen);
  135. LOGBRUSH brushlog;
  136. brushlog.lbColor=m_BrushColor;
  137. brushlog.lbHatch=m_BrushHatch;
  138. brushlog.lbStyle=m_BrushStyle;
  139. m_brush.CreateBrushIndirect(&brushlog);
  140. SetBrushOrg(pDC,&m_brush);
  141. CBrush*brush=(CBrush*)pDC->SelectObject(&m_brush);
  142. int OldBkMode=pDC->SetBkMode(m_BkMode);
  143. COLORREF OldColor=pDC->SetBkColor(m_BackgroundColor);
  144. pDC->Ellipse(CRect(m_FirstPoint,m_SecondPoint));
  145. pDC->SelectObject(brush);
  146. pDC->SelectObject(pen);
  147. pDC->SetBkMode(OldBkMode);
  148. pDC->SetBkColor(OldColor);
  149. }
  150. void CLiEllipse::OnLButtonDown(CDC *pDC, CEastDrawView *pView, CPoint point)
  151. {
  152. if(m_HaveFindFirst)
  153. {
  154. pView->L_iPointCount=IsOnMarginPoint(point);
  155. if(pView->L_iPointCount!=0)
  156. {
  157. pView->m_bHaveFindSecond=true;
  158. pView->m_CurrentDrawTool=LiEllipse_Tool;
  159. pView->m_CurrentDrawStatus=Change_Status;
  160. switch(pView->L_iPointCount)
  161. {
  162. case 1:
  163. pView->m_FirstPoint=m_SecondPoint;
  164. pView->m_SecondPoint=m_FirstPoint;
  165. break;
  166. case 2:
  167. pView->m_FirstPoint=m_FirstPoint;
  168. pView->m_SecondPoint=m_SecondPoint;
  169. break;
  170. case 3:
  171. pView->m_FirstPoint=m_FirstPoint;
  172. pView->m_SecondPoint=m_SecondPoint;
  173. break;
  174. case 4:
  175. pView->m_FirstPoint=m_SecondPoint;
  176. pView->m_SecondPoint=m_FirstPoint;
  177. break;
  178. case 5:
  179. pView->m_FirstPoint=m_FirstPoint;
  180. pView->m_SecondPoint=m_SecondPoint;
  181. pView->m_CurrentDrawTool=LiEllipse_Tool;
  182. pView->m_CurrentDrawStatus=Drag_Status;
  183. break;
  184. }
  185. }//******if(L_iPointCount!=0)
  186. }//*************if(L_pLiEllipse->m_HaveFindFirst)
  187. if(!pView->m_bHaveFindSecond&&IsInRgn(point))
  188. {
  189. if(!m_HaveFindFirst)
  190. {
  191. m_HaveFindFirst=true;
  192. pView->m_bHaveFindFirst=true;
  193. ShowSelectPoint(pDC);
  194. }
  195. else
  196. {
  197. m_HaveFindFirst=false;
  198. pView->m_bHaveFindFirst=true;
  199. ShowSelectPoint(pDC);
  200. }
  201. }
  202. if(pView->m_bHaveFindSecond)
  203. {
  204. pView->m_pCurrentUnit=this;
  205. m_DrawingMode=pDC->GetROP2();
  206. DrawStatic(pDC);
  207. ShowSelectPoint(pDC);
  208. DrawOldReferencePoint(pDC,m_FoundPoint);
  209. }
  210. }
  211. void CLiEllipse::OnMouseMove(CDC *pDC, CEastDrawView *pView, CPoint point)
  212. {
  213. if(pView->m_CurrentDrawStatus==Drag_Status)
  214. {
  215. m_FirstPoint.Offset(pView->m_SecondPoint.x-pView->m_FirstPoint.x,pView->m_SecondPoint.y-pView->m_FirstPoint.y);
  216. m_SecondPoint.Offset(pView->m_SecondPoint.x-pView->m_FirstPoint.x,pView->m_SecondPoint.y-pView->m_FirstPoint.y);
  217. }
  218. else{
  219. this->DrawActive(pDC,point);
  220. pView->m_SecondPoint=point;
  221. m_SecondPoint=pView->m_SecondPoint;
  222. this->DrawActive(pDC,point);
  223. }
  224. }