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

绘图程序

开发平台:

Visual C++

  1. // FullViewBtn.cpp  
  2. //
  3. #include "stdafx.h"
  4. #include "GraphSoft.h"
  5. #include "FullViewBtn.h"
  6. #include "GraphSoftDoc.h"
  7. #include "GraphSoftView.h"
  8. #include "MainFrm.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CFullViewBtn
  16. CFullViewBtn::CFullViewBtn()
  17. {
  18. m_leftbutton = FALSE ;
  19. m_flRatio=1;
  20. }
  21. CFullViewBtn::~CFullViewBtn()
  22. {
  23. }
  24. BEGIN_MESSAGE_MAP(CFullViewBtn, CButton)
  25. //{{AFX_MSG_MAP(CFullViewBtn)
  26. ON_WM_ERASEBKGND()
  27. ON_WM_KEYDOWN()
  28. ON_WM_LBUTTONDBLCLK()
  29. ON_WM_LBUTTONDOWN()
  30. ON_WM_LBUTTONUP()
  31. ON_WM_MOUSEMOVE()
  32. ON_WM_PAINT()
  33. ON_WM_RBUTTONUP()
  34. ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
  35. ON_CONTROL_REFLECT(BN_DOUBLECLICKED, OnDoubleclicked)
  36. ON_WM_CREATE()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CFullViewBtn 
  41. void CFullViewBtn::OnClicked() 
  42. {
  43. // TODO: 
  44. }
  45. BOOL CFullViewBtn::OnEraseBkgnd(CDC* pDC) 
  46. {
  47. CBrush newBrush;
  48. newBrush.CreateSolidBrush(RGB(255,255,255));
  49. CRect rect ;
  50. CBrush *pOldBrush = (CBrush*)pDC->SelectObject(&newBrush) ;
  51. // pDC->GetClipBox(&rect) ;
  52. this->GetClientRect(&rect) ;
  53. // rect = m_size ;
  54. rect.InflateRect(3,2);
  55. pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY) ;
  56. pDC->SelectObject(pOldBrush) ;
  57. newBrush.DeleteObject();
  58. // pDC->SetBkColor(COLORREF(RGB(0,0,0))) ;
  59. return TRUE ;
  60. // return CButton::OnEraseBkgnd(pDC);
  61. }
  62. void CFullViewBtn::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  63. {
  64. CButton::OnKeyDown(nChar, nRepCnt, nFlags);
  65. }
  66. void CFullViewBtn::OnLButtonDblClk(UINT nFlags, CPoint point) 
  67. {
  68. // CButton::OnLButtonDblClk(nFlags, point);
  69. }
  70. void CFullViewBtn::OnLButtonDown(UINT nFlags, CPoint point) 
  71. {
  72. // TODO: 偙偺埵抲偵儊僢僙乕僕 僴儞僪儔梡偺僐乕僪傪捛壛偡傞偐傑偨偼僨僼僅儖僩偺張棟傪屇傃弌偟偰偔偩偝偄
  73. // m_pt = m_viewinfo.dp2rp(&point) ;
  74. m_leftbutton = TRUE ;
  75. m_ptw = m_pt=point ;
  76. SetCapture() ;
  77. // CButton::OnLButtonDown(nFlags, point);
  78. }
  79. void CFullViewBtn::OnLButtonUp(UINT nFlags, CPoint point) 
  80. {
  81. ReleaseCapture() ;
  82.     CPoint pt;    
  83. CDC *pDC = GetDC() ;
  84. int old_rop = pDC->SetROP2(R2_XORPEN);
  85. CPen DragPen ;
  86. CPen* pOldPen ;
  87. CBrush* pOldBrush ;
  88. DragPen.CreatePen(PS_SOLID,1,RGB(255,255,255)) ;
  89. pOldPen = (CPen*)pDC->SelectObject(&DragPen) ;
  90. pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH) ;
  91. CRect rect ;
  92. rect.top = min(m_pt.y,m_ptw.y) ;
  93. rect.bottom = max(m_pt.y,m_ptw.y) ;
  94. rect.left = min(m_pt.x,m_ptw.x) ;
  95. rect.right = max(m_pt.x,m_ptw.x) ;
  96. pDC->Rectangle(&rect) ;
  97.     DragPen.DeleteObject();
  98. DragPen.CreatePen(PS_SOLID,1,RGB(255,0,255)) ;
  99.     pDC->SelectObject(&DragPen) ;
  100. CRect rectView;
  101. if(m_targetrect!=m_MaxRect)//防止覆盖
  102. {
  103. CRect rectTmp = m_targetrect.GetRect();    
  104. pDC->Rectangle(&rectTmp);
  105. }
  106. CGraphSoftView* pView=((CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView());
  107. if(fabs(m_pt.x-point.x)<2||fabs(m_pt.y-point.y)<2) {
  108. m_targetrect.OffsetRect(point.x-m_targetrect.CenterPoint().x,point.y-m_targetrect.CenterPoint().y);
  109. }
  110. else {
  111. float ratiox,ratioy;
  112. pView->GetClientRect(&rectView);
  113. ratiox = ((float)rect.Width())/rectView.Width() ;
  114. ratioy = ((float)rect.Height())/rectView.Height() ;
  115. if(ratiox>ratioy) m_flRatio = ratiox ;
  116. else              m_flRatio = ratioy ;
  117. m_targetrect.left=rect.CenterPoint().x-m_flRatio*rectView.Width()/2;
  118. m_targetrect.right=rect.CenterPoint().x+m_flRatio*rectView.Width()/2;
  119. m_targetrect.top=rect.CenterPoint().y-m_flRatio*rectView.Height()/2;
  120. m_targetrect.bottom=rect.CenterPoint().y+m_flRatio*rectView.Height()/2;
  121. //pView->DrawCut();
  122. }
  123. // pView->DrawCut();
  124. CRect rectTmp = m_targetrect.GetRect();    
  125. pDC->Rectangle(&rectTmp);
  126. float rate=((float)pView->m_rectMaxWindow.Width())/m_MaxRect.Width();
  127. pView->m_rectTarget.left=((float)m_targetrect.left-m_MaxRect.left)*rate;
  128. pView->m_rectTarget.right=((float)m_targetrect.right-m_MaxRect.left)*rate;
  129. pView->m_rectTarget.top=((float)m_targetrect.top-m_MaxRect.top)*rate;
  130. pView->m_rectTarget.bottom=((float)m_targetrect.bottom-m_MaxRect.top)*rate;
  131.     rate=((float)m_MaxRect.Width())/m_targetrect.Width();
  132. CSize sz(pView->m_rectMaxWindow.Width()*rate,pView->m_rectMaxWindow.Height()*rate);
  133. pView->SetScrollSizes(MM_TEXT,sz);
  134.     pView->m_rectMaxWindow.OffsetRect(-pView->m_rectMaxWindow.left,-pView->m_rectMaxWindow.top);
  135.     pView->m_flRate=rate;
  136. rate= rate*pView->m_rectMaxWindow.Width()/m_MaxRect.Width();
  137. pView->m_rectMaxWindow.OffsetRect(rate*(m_targetrect.left-m_MaxRect.left),rate*(m_targetrect.top-m_MaxRect.top));
  138. pView->ScrollToPosition(pView->m_rectMaxWindow.TopLeft());
  139. pView->Invalidate(TRUE);
  140. m_leftbutton = FALSE ;
  141. pDC->SetROP2(old_rop);
  142. pDC->SelectObject(pOldPen) ;
  143. pDC->SelectObject(pOldBrush) ;
  144. ReleaseDC(pDC) ;
  145. // CButton::OnLButtonUp(nFlags, point);
  146. }
  147. void CFullViewBtn::OnMouseMove(UINT nFlags, CPoint point) 
  148. {
  149. if(m_leftbutton) {
  150. CDC *pDC = GetDC() ;
  151. int old_rop = pDC->SetROP2(R2_XORPEN);
  152. CPen DragPen ;
  153. CPen* pOldPen ;
  154. CBrush* pOldBrush ;
  155. DragPen.CreatePen(PS_SOLID,1,RGB(255,255,255)) ;
  156. pOldPen = (CPen*)pDC->SelectObject(&DragPen) ;
  157. pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH) ;
  158. CRect rect ;
  159. rect.top = min(m_pt.y,m_ptw.y) ;
  160. rect.bottom = max(m_pt.y,m_ptw.y) ;
  161. rect.left = min(m_pt.x,m_ptw.x) ;
  162. rect.right = max(m_pt.x,m_ptw.x) ;
  163. pDC->Rectangle(&rect) ;
  164. m_ptw = point ;
  165. rect.top = min(m_pt.y,m_ptw.y) ;
  166. rect.bottom = max(m_pt.y,m_ptw.y) ;
  167. rect.left = min(m_pt.x,m_ptw.x) ;
  168. rect.right = max(m_pt.x,m_ptw.x) ;
  169. pDC->Rectangle(&rect) ;
  170. pDC->SelectObject(pOldPen) ;
  171. pDC->SelectObject(pOldBrush) ;
  172. ReleaseDC(pDC) ;
  173. }
  174. // CButton::OnMouseMove(nFlags, point);
  175. }
  176. void CFullViewBtn::OnPaint() 
  177. {
  178. CPaintDC dc(this); 
  179. CDC* pDC = &dc ;
  180. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd() ;   
  181. CPen DragPen ;
  182. CPen* pOldPen ;
  183. CBrush* pOldBrush ;
  184. DragPen.CreatePen(PS_SOLID,1,RGB(0,255,0)) ;
  185. pOldPen = (CPen*)pDC->SelectObject(&DragPen) ;
  186. pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH) ;
  187. CRect rectTmp = m_targetrect.GetRect();    
  188. pDC->Rectangle(&rectTmp);
  189. CRect rectBtn,rectView,rectTarget;
  190. float ratiox,ratioy;
  191. CGraphSoftView* pView=((CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView());
  192. GetClientRect(&rectBtn);
  193. rectView=pView->m_rectMaxWindow;
  194. ratiox = ((float)rectBtn.Width())/rectView.Width() ;
  195. ratioy = ((float)rectBtn.Height())/rectView.Height() ;
  196. if(ratiox<ratioy) m_flRatio = ratiox ;
  197. else              m_flRatio = ratioy ;
  198. rectTarget.left=rectBtn.CenterPoint().x-m_flRatio*rectView.Width()/2;
  199. rectTarget.right=rectBtn.CenterPoint().x+m_flRatio*rectView.Width()/2;
  200. rectTarget.top=rectBtn.CenterPoint().y-m_flRatio*rectView.Height()/2;
  201. rectTarget.bottom=rectBtn.CenterPoint().y+m_flRatio*rectView.Height()/2;    
  202. DragPen.DeleteObject();
  203. DragPen.CreatePen(PS_SOLID,1,RGB(255,255,0)) ;
  204. pDC->SelectObject(&DragPen) ;
  205. pDC->Rectangle(&rectTarget);
  206. m_MaxRect=rectTarget;
  207. TRACE("MAXRECt:(%d,%d)--(%d,%d)n",m_MaxRect.left,m_MaxRect.top,m_MaxRect.right,m_MaxRect.bottom);
  208.     if(m_targetrect.Width()==0){
  209. // int old_rop = pDC->SetROP2(R2_XORPEN);
  210. // DragPen.DeleteObject();
  211. // DragPen.CreatePen(PS_SOLID,1,RGB(255,0,255)) ;
  212. // pDC->SelectObject(&DragPen) ;
  213. // pDC->Rectangle(&rectTarget);
  214. // pDC->SetROP2(old_rop);
  215. m_targetrect=m_MaxRect;
  216.     }
  217. pDC->SelectObject(pOldPen) ;
  218. pDC->SelectObject(pOldBrush) ;
  219. DrawGraph(pDC,rectTarget);
  220. }
  221. void CFullViewBtn::OnRButtonUp(UINT nFlags, CPoint point) 
  222. {
  223. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd() ;
  224. //屏幕显示整个图形
  225. // m_pView->Invalidate(TRUE);
  226. // CButton::OnRButtonUp(nFlags, point);
  227. }
  228. void CFullViewBtn::OnDoubleclicked() 
  229. {
  230. //
  231. }
  232. int CFullViewBtn::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  233. {
  234. if (CButton::OnCreate(lpCreateStruct) == -1)
  235. return -1;
  236. // TODO: Add your specialized creation code here
  237. return 0;
  238. }
  239. void CFullViewBtn::DrawGraph(CDC* pDC,CRect rect)
  240. {
  241. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd() ; 
  242. CGraphSoftView* pView = (CGraphSoftView*)(pMainFrame->GetActiveView());
  243. CGraphSoftDoc* pDoc=pView->GetDocument();
  244. POSITION pos;
  245. CRect rectMax(0,0,800,650);
  246. rectMax=pView->m_rectMaxWindow;
  247. rectMax.OffsetRect(-rectMax.left,-rectMax.top);
  248. pos=pDoc->m_shapeList.GetHeadPosition();
  249. while (pos!=NULL) {
  250. CShape* pShape=pDoc->m_shapeList.GetNext(pos);
  251. int flag = pShape->GetDrawPointsFlag();
  252. pShape->SetDrawPointsFlag(0);//全局视图中不绘画辅助点
  253. if(pShape->IsSelected()){
  254.              pShape->DrawCutToRect(pDC,RGB(255,0,0),RGB(255,0,0),rectMax,rect);
  255. }else{
  256. pShape->DrawCutToRect(pDC,rectMax,rect);
  257. }
  258. pShape->SetDrawPointsFlag(flag);
  259. }
  260. }