BOOL CNCaptureView::_SetSelectRectClipInfo(const CPoint& point) { BOOL bRet = FALSE; CDrawTool* pCurDrawTools = CDrawCanvas<CNCaptureView>::GetCurrentTool(); if (pCurDrawTools->IsNeedClip()) { if(!GetSelection().empty()) { CDrawObject* pActiveDrawObject = GetSelection().front(); if (pActiveDrawObject) { m_bClipCursor = TRUE; CRect rcSelect = pActiveDrawObject->GetPosition(); rcSelect.NormalizeRect(); DocToClient(&rcSelect); CRect rcClipTarget = m_rcDrawTarget; rcClipTarget.OffsetRect( -rcClipTarget.TopLeft()); DocToClient(&rcClipTarget); ClientToScreen(&rcClipTarget); if (smMove == m_nCurrentSelectMode ) { rcClipTarget.right -= rcSelect.Width() ; rcClipTarget.bottom -= rcSelect.Height(); rcClipTarget.OffsetRect(point.x - rcSelect.left, point.y - rcSelect.top); } else if(smSize == m_nCurrentSelectMode)// || smNetSelectSize == m_nCurrentSelectMode) { //now do nothing } rcClipTarget.right += 1; rcClipTarget.bottom += 1; //FTLTRACE(TEXT("rcClipTarget= [%d,%d], [%d,%d], {%dx%d}\n"), rcClipTarget.left, rcClipTarget.top, // rcClipTarget.right, rcClipTarget.bottom, // rcClipTarget.Width(), rcClipTarget.Height()); API_VERIFY(::ClipCursor(&rcClipTarget)); } } } return bRet; }
void CNCaptureView::_SetScrollInfo(float newZoomScale, BOOL bUseCenterPoint) { if (m_pImage && !m_pImage->IsNull()) { BOOL bRet = FALSE; CRect rcClient; API_VERIFY(GetClientRect(&rcClient)); //save old ptLogical CPoint ptMouseDevice(0, 0); API_VERIFY(::GetCursorPos(&ptMouseDevice)); API_VERIFY(ScreenToClient(&ptMouseDevice)); if (!rcClient.PtInRect(ptMouseDevice) || bUseCenterPoint) { ptMouseDevice = rcClient.CenterPoint(); } CPoint ptOldLogical = ptMouseDevice; ClientToDoc(&ptOldLogical); //ptOldPos.Offset(m_rcDrawTarget.TopLeft()); SetZoomScale(newZoomScale); //FTLTRACE(TEXT("Zoom=%f, image=[%d,%d], sizeAll=[%d,%d]\n"), // s_FixedZoomScales[m_iFixedZoomIndex], m_pImage->GetWidth(), m_pImage->GetHeight(), // (int)((float)m_pImage->GetWidth() * s_FixedZoomScales[m_iFixedZoomIndex]), // (int)((float)m_pImage->GetHeight() * s_FixedZoomScales[m_iFixedZoomIndex])); SetScrollSize(m_pImage->GetWidth(), m_pImage->GetHeight(), TRUE, true); CPoint ptNewClient = ptOldLogical; //ptNewPos.Offset(-m_rcDrawTarget.TopLeft()); DocToClient(&ptNewClient); CPoint ptNewOffset = ptNewClient; ptNewOffset.Offset(-ptMouseDevice); SetScrollOffset(ptNewOffset.x, ptNewOffset.y); /* if (!GetSelection().empty()) { CTextObject* pTextObject = dynamic_cast<CTextObject*>(GetSelection().front()); if (pTextObject) { //SIZEL newExtent = {0}; //newExtent.cy = (double)pTextObject->GetPosition().Height() * 2540 * newZoomScale * 96; //newExtent.cx = (double)pTextObject->GetPosition().Width() * 2540 * newZoomScale * 96; pTextObject->GetRichEditPanel()->SetZoom(m_sizeAll.cx, m_sizeLogAll.cx); //pTextObject->GetRichEditPanel()->SetExtent(&newExtent, TRUE); } } */ //FTLTRACE(TEXT("ptMouseDevice=[%d,%d], ptOldLogical=[%d,%d], ptNewClient=[%d,%d], ptNewOffset=[%d,%d]\n"), // ptMouseDevice.x, ptMouseDevice.y, ptOldLogical.x, ptOldLogical.y, ptNewClient.x, ptNewClient.y, // ptNewOffset.x, ptNewOffset.y); _UpdateMousePosInfo(ptMouseDevice); SetCurrentToolType(CalcCurrentToolType()); //DrawObjectList& SelectObjects = GetSelection(); //if (SelectObjects.size() == 1 ) //{ // CDrawObject* pDrawObj = SelectObjects.front(); // if (dotSelectRect == pDrawObj->GetDrawObjType()) // { // CRect rcDevice = pDrawObj->GetPosition(); // DocToClient(&rcDevice); // ScrollToView(rcDevice); // } //} } else //make scrollbar disappear { SetZoomScale(s_FixedZoomScales[s_NormalZoomIndex]); SetScrollSize(1, 1, FALSE, FALSE); } }
void CDrawView::OnDraw(CDC* pDC) { CDrawDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CDC dc; CDC* pDrawDC = pDC; CBitmap bitmap; CBitmap* pOldBitmap; // only paint the rect that needs repainting CRect client; pDC->GetClipBox(client); //检取当前裁剪边界的最近限定矩形的大小 CRect rect = client; DocToClient(rect); rect.NormalizeRect(); TRACE("CDrawView::OnDraw\n"); if (!pDC->IsPrinting())//不加会闪屏 { // draw to offscreen bitmap for fast looking repaints if (dc.CreateCompatibleDC(pDC)) //创建一个与指定设备兼容的内存设备上下文环境 { if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))//创建与指定的设备环境相关的设备兼容的位图 { OnPrepareDC(&dc, NULL); pDrawDC = &dc; // offset origin more because bitmap is just piece of the whole drawing dc.OffsetViewportOrg(-rect.left, -rect.top);//相对于当前视区起点坐标修正视区起点坐标 pOldBitmap = dc.SelectObject(&bitmap); //选择一对象到指定的设备上下文环境中 dc.SetBrushOrg(rect.left % 8, rect.top % 8);//指定GDI将分配给下画笔应用程序选择到设备上下文的原点 // might as well clip to the same rectangle dc.IntersectClipRect(client); //创建了一个新的剪切区域,该区域是当前剪切区域和一个特定矩形的交集 } } } // paint background CBrush brush; if (!brush.CreateSolidBrush(pDoc->GetPaperColor())) return; brush.UnrealizeObject(); //重置一个逻辑调色板 pDrawDC->FillRect(client, &brush); //用指定的画刷填充矩形 Painter::GetInstancePtr()->SetCDC(pDrawDC); Painter::GetInstancePtr()->SetCWnd(this); if (!pDC->IsPrinting() && m_bGrid) DrawGrid(pDrawDC); g_pGuiManager->Draw(); if (pDrawDC != pDC) { pDC->SetViewportOrg(0, 0); pDC->SetWindowOrg(0,0); pDC->SetMapMode(MM_TEXT); dc.SetViewportOrg(0, 0); dc.SetWindowOrg(0,0); dc.SetMapMode(MM_TEXT); pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY); dc.SelectObject(pOldBitmap); } }