/******************************************************************************** * Begin store the mouse movements into our stroke objects * ********************************************************************************/ void CWhiteBoardView::OnLButtonDown(UINT nFlags, CPoint point) { CWhiteBoardDoc* pDoc = GetDocument(); // the Document // Note: Do NOT use GetDC when sending coordinates from one // scroll view to another, the stroke will not display correctly CClientDC theDC(this); // the Device Context OnPrepareDC(&theDC); // prepare the Device Context bIsDrawing = true; // We are now drawing SetCapture(); // Keep the mouse focus // Covert the point to logical units (prevent mangling due to scrolling) theDC.DPtoLP(&point); // Create a new stroke starting at the current mouse location if (pDoc->m_pCurStroke == NULL) { pDoc->m_pCurStroke = new CStroke(point); pDoc->m_pCurStroke->mStrokeColor = pDoc->m_CurStrokeColor; pDoc->m_pCurStroke->mStrokeSize = pDoc->m_nCurStrokeSize; pDoc->m_StrokeList.AddTail( pDoc->m_pCurStroke ); } // Move the graphics pt to the stroke's first point (mouse position) theDC.MoveTo(point); mCurPoint = point; // Call the base case implementation CScrollView::OnLButtonDown(nFlags, point); }
ZDC ZSubPane::GetDC() { ZDC theDC(this->GetWindow()->GetWindowCanvas(), ZPoint::sZero); theDC.SetOrigin(this->ToWindow(ZPoint::sZero)); theDC.SetPatternOrigin(this->GetCumulativeTranslation()); theDC.SetClip(this->CalcVisibleBoundsRgn()); return theDC; }
/******************************************************************************** * Renders a single stroke. Used after receiving a stroke to void a full redraw * ********************************************************************************/ void CWhiteBoardView::DrawSingleStroke(CStroke *pStroke) { // Create a device context for the client window // (Do NOT use GetDC() when sending from one ScrollView to another) CClientDC theDC(this); OnPrepareDC(&theDC); // Tell the stroke to draw itself pStroke->DrawStroke(&theDC); }
ZDC ZSubPane::GetDC(ZDCRgn& outBoundsRgn) { ZDC theDC(this->GetWindow()->GetWindowCanvas(), ZPoint::sZero); theDC.SetOrigin(this->ToWindow(ZPoint::sZero)); theDC.SetPatternOrigin(this->GetCumulativeTranslation()); outBoundsRgn = this->CalcBoundsRgn(); if (this->GetVisible()) { if (fSuperPane) theDC.SetClip(outBoundsRgn & this->FromSuper(fSuperPane->CalcVisibleBoundsRgn())); else theDC.SetClip(outBoundsRgn); } return theDC; }
/******************************************************************************** * Whenever the mouse moves. We need to track the path of each stroke * ********************************************************************************/ void CWhiteBoardView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CStroke* pCurStroke = GetDocument()->m_pCurStroke; // Are we drawing? if (bIsDrawing) { // Prepare a DC CClientDC theDC(this); OnPrepareDC(&theDC); // Convert the point to Logical coords due to possible mangling (from scrolling) theDC.DPtoLP(&point); // Move the graphics position to the previous point theDC.MoveTo(mCurPoint); // Create the stroke's pen for drawing CPen thePen(PS_SOLID,pCurStroke->mStrokeSize,pCurStroke->mStrokeColor); CPen* pOldPen = theDC.SelectObject(&thePen); // Draw a line to the current mouse position theDC.LineTo(point); // Restore the old pen theDC.SelectObject(pOldPen); // Set the new current point mCurPoint = point; // If the current stroke isn't NULL (which it shouldn't be when drawing) // add the new point to the end of it's path if (pCurStroke != NULL) pCurStroke->m_PointList.AddTail( new CPoint(point) ); } // Call the base class implementation CScrollView::OnMouseMove(nFlags, point); }