Double buffering dc with user mapping mode
-
The following OnPaint code works very well with single buffering. With it I can zoom in and out, and pan the view. The drawing code doesn't have to be aware of the zoom factor or any other coordinate. But how do I turn this into double buffering ? what mapping mode whould I use on the memory dc ? CPaintDC outputdc( this ); // Client rect (size of window on screen) CRect clientRect; GetClientRect( &clientRect ); // Virtual rect (page coordinates) CRect virtualRect; virtualRect.left = m_CenterPos.x - (clientRect.Width()*m_fZoomFactor)/2; virtualRect.right = m_CenterPos.x + (clientRect.Width()*m_fZoomFactor)/2; virtualRect.top = m_CenterPos.y - (clientRect.Height()*m_fZoomFactor)/2; virtualRect.bottom = m_CenterPos.y + (clientRect.Height()*m_fZoomFactor)/2; // Sets the mapping mode for the specified center position and zoom factor SetMapMode(outputdc, MM_ISOTROPIC); SetWindowExtEx(outputdc, virtualRect.Width(), virtualRect.Height(), NULL); SetViewportExtEx(outputdc, clientRect.Width(), clientRect.Height(), NULL); SetWindowOrgEx(outputdc, virtualRect.left, virtualRect.top, NULL); // Draw EraseBackground( &outputdc, virtualRect ); m_GraphData.DrawData(&outputdc);
-
The following OnPaint code works very well with single buffering. With it I can zoom in and out, and pan the view. The drawing code doesn't have to be aware of the zoom factor or any other coordinate. But how do I turn this into double buffering ? what mapping mode whould I use on the memory dc ? CPaintDC outputdc( this ); // Client rect (size of window on screen) CRect clientRect; GetClientRect( &clientRect ); // Virtual rect (page coordinates) CRect virtualRect; virtualRect.left = m_CenterPos.x - (clientRect.Width()*m_fZoomFactor)/2; virtualRect.right = m_CenterPos.x + (clientRect.Width()*m_fZoomFactor)/2; virtualRect.top = m_CenterPos.y - (clientRect.Height()*m_fZoomFactor)/2; virtualRect.bottom = m_CenterPos.y + (clientRect.Height()*m_fZoomFactor)/2; // Sets the mapping mode for the specified center position and zoom factor SetMapMode(outputdc, MM_ISOTROPIC); SetWindowExtEx(outputdc, virtualRect.Width(), virtualRect.Height(), NULL); SetViewportExtEx(outputdc, clientRect.Width(), clientRect.Height(), NULL); SetWindowOrgEx(outputdc, virtualRect.left, virtualRect.top, NULL); // Draw EraseBackground( &outputdc, virtualRect ); m_GraphData.DrawData(&outputdc);
You should create a memory DC compatible with your output DC, draw whatever you need in the memory DC, then blit iits content on the output DC. SkyWalker
-
The following OnPaint code works very well with single buffering. With it I can zoom in and out, and pan the view. The drawing code doesn't have to be aware of the zoom factor or any other coordinate. But how do I turn this into double buffering ? what mapping mode whould I use on the memory dc ? CPaintDC outputdc( this ); // Client rect (size of window on screen) CRect clientRect; GetClientRect( &clientRect ); // Virtual rect (page coordinates) CRect virtualRect; virtualRect.left = m_CenterPos.x - (clientRect.Width()*m_fZoomFactor)/2; virtualRect.right = m_CenterPos.x + (clientRect.Width()*m_fZoomFactor)/2; virtualRect.top = m_CenterPos.y - (clientRect.Height()*m_fZoomFactor)/2; virtualRect.bottom = m_CenterPos.y + (clientRect.Height()*m_fZoomFactor)/2; // Sets the mapping mode for the specified center position and zoom factor SetMapMode(outputdc, MM_ISOTROPIC); SetWindowExtEx(outputdc, virtualRect.Width(), virtualRect.Height(), NULL); SetViewportExtEx(outputdc, clientRect.Width(), clientRect.Height(), NULL); SetWindowOrgEx(outputdc, virtualRect.left, virtualRect.top, NULL); // Draw EraseBackground( &outputdc, virtualRect ); m_GraphData.DrawData(&outputdc);