FullViewBtn.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:9k
源码类别:
绘图程序
开发平台:
Visual C++
- // FullViewBtn.cpp
- //
- #include "stdafx.h"
- #include "GraphSoft.h"
- #include "FullViewBtn.h"
- #include "GraphSoftDoc.h"
- #include "GraphSoftView.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFullViewBtn
- CFullViewBtn::CFullViewBtn()
- {
- m_leftbutton = FALSE ;
- m_flRatio=1;
- }
- CFullViewBtn::~CFullViewBtn()
- {
- }
- BEGIN_MESSAGE_MAP(CFullViewBtn, CButton)
- //{{AFX_MSG_MAP(CFullViewBtn)
- ON_WM_ERASEBKGND()
- ON_WM_KEYDOWN()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_PAINT()
- ON_WM_RBUTTONUP()
- ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
- ON_CONTROL_REFLECT(BN_DOUBLECLICKED, OnDoubleclicked)
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFullViewBtn
- void CFullViewBtn::OnClicked()
- {
- // TODO:
- }
- BOOL CFullViewBtn::OnEraseBkgnd(CDC* pDC)
- {
- CBrush newBrush;
- newBrush.CreateSolidBrush(RGB(255,255,255));
- CRect rect ;
- CBrush *pOldBrush = (CBrush*)pDC->SelectObject(&newBrush) ;
- // pDC->GetClipBox(&rect) ;
- this->GetClientRect(&rect) ;
- // rect = m_size ;
- rect.InflateRect(3,2);
- pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY) ;
- pDC->SelectObject(pOldBrush) ;
- newBrush.DeleteObject();
- // pDC->SetBkColor(COLORREF(RGB(0,0,0))) ;
- return TRUE ;
- // return CButton::OnEraseBkgnd(pDC);
- }
- void CFullViewBtn::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- CButton::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CFullViewBtn::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // CButton::OnLButtonDblClk(nFlags, point);
- }
- void CFullViewBtn::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: 偙偺埵抲偵儊僢僙乕僕 僴儞僪儔梡偺僐乕僪傪捛壛偡傞偐傑偨偼僨僼僅儖僩偺張棟傪屇傃弌偟偰偔偩偝偄
- // m_pt = m_viewinfo.dp2rp(&point) ;
- m_leftbutton = TRUE ;
- m_ptw = m_pt=point ;
- SetCapture() ;
- // CButton::OnLButtonDown(nFlags, point);
- }
- void CFullViewBtn::OnLButtonUp(UINT nFlags, CPoint point)
- {
- ReleaseCapture() ;
- CPoint pt;
- CDC *pDC = GetDC() ;
- int old_rop = pDC->SetROP2(R2_XORPEN);
- CPen DragPen ;
- CPen* pOldPen ;
- CBrush* pOldBrush ;
- DragPen.CreatePen(PS_SOLID,1,RGB(255,255,255)) ;
- pOldPen = (CPen*)pDC->SelectObject(&DragPen) ;
- pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH) ;
- CRect rect ;
- rect.top = min(m_pt.y,m_ptw.y) ;
- rect.bottom = max(m_pt.y,m_ptw.y) ;
- rect.left = min(m_pt.x,m_ptw.x) ;
- rect.right = max(m_pt.x,m_ptw.x) ;
- pDC->Rectangle(&rect) ;
- DragPen.DeleteObject();
- DragPen.CreatePen(PS_SOLID,1,RGB(255,0,255)) ;
- pDC->SelectObject(&DragPen) ;
- CRect rectView;
- if(m_targetrect!=m_MaxRect)//防止覆盖
- {
- CRect rectTmp = m_targetrect.GetRect();
- pDC->Rectangle(&rectTmp);
- }
- CGraphSoftView* pView=((CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView());
- if(fabs(m_pt.x-point.x)<2||fabs(m_pt.y-point.y)<2) {
- m_targetrect.OffsetRect(point.x-m_targetrect.CenterPoint().x,point.y-m_targetrect.CenterPoint().y);
- }
- else {
- float ratiox,ratioy;
- pView->GetClientRect(&rectView);
- ratiox = ((float)rect.Width())/rectView.Width() ;
- ratioy = ((float)rect.Height())/rectView.Height() ;
- if(ratiox>ratioy) m_flRatio = ratiox ;
- else m_flRatio = ratioy ;
- m_targetrect.left=rect.CenterPoint().x-m_flRatio*rectView.Width()/2;
- m_targetrect.right=rect.CenterPoint().x+m_flRatio*rectView.Width()/2;
- m_targetrect.top=rect.CenterPoint().y-m_flRatio*rectView.Height()/2;
- m_targetrect.bottom=rect.CenterPoint().y+m_flRatio*rectView.Height()/2;
- //pView->DrawCut();
- }
- // pView->DrawCut();
- CRect rectTmp = m_targetrect.GetRect();
- pDC->Rectangle(&rectTmp);
- float rate=((float)pView->m_rectMaxWindow.Width())/m_MaxRect.Width();
- pView->m_rectTarget.left=((float)m_targetrect.left-m_MaxRect.left)*rate;
- pView->m_rectTarget.right=((float)m_targetrect.right-m_MaxRect.left)*rate;
- pView->m_rectTarget.top=((float)m_targetrect.top-m_MaxRect.top)*rate;
- pView->m_rectTarget.bottom=((float)m_targetrect.bottom-m_MaxRect.top)*rate;
- rate=((float)m_MaxRect.Width())/m_targetrect.Width();
- CSize sz(pView->m_rectMaxWindow.Width()*rate,pView->m_rectMaxWindow.Height()*rate);
- pView->SetScrollSizes(MM_TEXT,sz);
- pView->m_rectMaxWindow.OffsetRect(-pView->m_rectMaxWindow.left,-pView->m_rectMaxWindow.top);
- pView->m_flRate=rate;
- rate= rate*pView->m_rectMaxWindow.Width()/m_MaxRect.Width();
- pView->m_rectMaxWindow.OffsetRect(rate*(m_targetrect.left-m_MaxRect.left),rate*(m_targetrect.top-m_MaxRect.top));
- pView->ScrollToPosition(pView->m_rectMaxWindow.TopLeft());
- pView->Invalidate(TRUE);
- m_leftbutton = FALSE ;
- pDC->SetROP2(old_rop);
- pDC->SelectObject(pOldPen) ;
- pDC->SelectObject(pOldBrush) ;
- ReleaseDC(pDC) ;
- // CButton::OnLButtonUp(nFlags, point);
- }
- void CFullViewBtn::OnMouseMove(UINT nFlags, CPoint point)
- {
- if(m_leftbutton) {
- CDC *pDC = GetDC() ;
- int old_rop = pDC->SetROP2(R2_XORPEN);
- CPen DragPen ;
- CPen* pOldPen ;
- CBrush* pOldBrush ;
- DragPen.CreatePen(PS_SOLID,1,RGB(255,255,255)) ;
- pOldPen = (CPen*)pDC->SelectObject(&DragPen) ;
- pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH) ;
- CRect rect ;
- rect.top = min(m_pt.y,m_ptw.y) ;
- rect.bottom = max(m_pt.y,m_ptw.y) ;
- rect.left = min(m_pt.x,m_ptw.x) ;
- rect.right = max(m_pt.x,m_ptw.x) ;
- pDC->Rectangle(&rect) ;
- m_ptw = point ;
- rect.top = min(m_pt.y,m_ptw.y) ;
- rect.bottom = max(m_pt.y,m_ptw.y) ;
- rect.left = min(m_pt.x,m_ptw.x) ;
- rect.right = max(m_pt.x,m_ptw.x) ;
- pDC->Rectangle(&rect) ;
- pDC->SelectObject(pOldPen) ;
- pDC->SelectObject(pOldBrush) ;
- ReleaseDC(pDC) ;
- }
- // CButton::OnMouseMove(nFlags, point);
- }
- void CFullViewBtn::OnPaint()
- {
- CPaintDC dc(this);
- CDC* pDC = &dc ;
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd() ;
- CPen DragPen ;
- CPen* pOldPen ;
- CBrush* pOldBrush ;
- DragPen.CreatePen(PS_SOLID,1,RGB(0,255,0)) ;
- pOldPen = (CPen*)pDC->SelectObject(&DragPen) ;
- pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH) ;
- CRect rectTmp = m_targetrect.GetRect();
- pDC->Rectangle(&rectTmp);
- CRect rectBtn,rectView,rectTarget;
- float ratiox,ratioy;
- CGraphSoftView* pView=((CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView());
- GetClientRect(&rectBtn);
- rectView=pView->m_rectMaxWindow;
- ratiox = ((float)rectBtn.Width())/rectView.Width() ;
- ratioy = ((float)rectBtn.Height())/rectView.Height() ;
- if(ratiox<ratioy) m_flRatio = ratiox ;
- else m_flRatio = ratioy ;
- rectTarget.left=rectBtn.CenterPoint().x-m_flRatio*rectView.Width()/2;
- rectTarget.right=rectBtn.CenterPoint().x+m_flRatio*rectView.Width()/2;
- rectTarget.top=rectBtn.CenterPoint().y-m_flRatio*rectView.Height()/2;
- rectTarget.bottom=rectBtn.CenterPoint().y+m_flRatio*rectView.Height()/2;
- DragPen.DeleteObject();
- DragPen.CreatePen(PS_SOLID,1,RGB(255,255,0)) ;
- pDC->SelectObject(&DragPen) ;
- pDC->Rectangle(&rectTarget);
- m_MaxRect=rectTarget;
- TRACE("MAXRECt:(%d,%d)--(%d,%d)n",m_MaxRect.left,m_MaxRect.top,m_MaxRect.right,m_MaxRect.bottom);
- if(m_targetrect.Width()==0){
- // int old_rop = pDC->SetROP2(R2_XORPEN);
- // DragPen.DeleteObject();
- // DragPen.CreatePen(PS_SOLID,1,RGB(255,0,255)) ;
- // pDC->SelectObject(&DragPen) ;
- // pDC->Rectangle(&rectTarget);
- // pDC->SetROP2(old_rop);
- m_targetrect=m_MaxRect;
- }
- pDC->SelectObject(pOldPen) ;
- pDC->SelectObject(pOldBrush) ;
- DrawGraph(pDC,rectTarget);
- }
- void CFullViewBtn::OnRButtonUp(UINT nFlags, CPoint point)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd() ;
- //屏幕显示整个图形
- // m_pView->Invalidate(TRUE);
- // CButton::OnRButtonUp(nFlags, point);
- }
- void CFullViewBtn::OnDoubleclicked()
- {
- //
- }
- int CFullViewBtn::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CButton::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- return 0;
- }
- void CFullViewBtn::DrawGraph(CDC* pDC,CRect rect)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd() ;
- CGraphSoftView* pView = (CGraphSoftView*)(pMainFrame->GetActiveView());
- CGraphSoftDoc* pDoc=pView->GetDocument();
- POSITION pos;
- CRect rectMax(0,0,800,650);
- rectMax=pView->m_rectMaxWindow;
- rectMax.OffsetRect(-rectMax.left,-rectMax.top);
- pos=pDoc->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=pDoc->m_shapeList.GetNext(pos);
- int flag = pShape->GetDrawPointsFlag();
- pShape->SetDrawPointsFlag(0);//全局视图中不绘画辅助点
- if(pShape->IsSelected()){
- pShape->DrawCutToRect(pDC,RGB(255,0,0),RGB(255,0,0),rectMax,rect);
- }else{
- pShape->DrawCutToRect(pDC,rectMax,rect);
- }
- pShape->SetDrawPointsFlag(flag);
- }
- }