//***************************************************************************** // // Function Name: CHeadlineSheet::OnPaint // // Description: WM_PAINT handler // // Returns: VOID // // Exceptions: None // //***************************************************************************** // void CHeadlineSheet::OnPaint( ) { PAINTSTRUCT ps; HDC hdc = ::BeginPaint( GetSafeHwnd( ), &ps ); // Put it in a DcDrawingSurface RDcDrawingSurface drawingSurface; drawingSurface.Initialize( hdc ); // Create a transform R2dTransform transform; // Scale to the device DPI RRealSize deviceDPI = drawingSurface.GetDPI( ); transform.PreScale( (YFloatType)deviceDPI.m_dx / kSystemDPI, (YFloatType)deviceDPI.m_dy / kSystemDPI ); // Get the preview rectangle RRealRect previewRect; GetPreviewRect( &previewRect ); // Offset the transform by the top left corner of the preview rect transform.PreTranslate( previewRect.m_Left, previewRect.m_Top ); // Render the preview headline m_pPreviewHeadline->Render( drawingSurface, transform, RRealRect( previewRect.WidthHeight( ) ), previewRect.WidthHeight( ) ); drawingSurface.DetachDCs( ); ::EndPaint( GetSafeHwnd( ), &ps ); }
void RRotateDialog::RotateDisplay( int iPos ) { if ( iPos == m_iPrevPos ) return; // We need to use the RBitmap::Rotate() function, so to do that, convert to // Renaissance types. CClientDC clientDC( &m_staticDisplay ); HDC hClientDC = clientDC.GetSafeHdc(); RDcDrawingSurface drawSurface; drawSurface.Initialize( hClientDC, hClientDC ); R2dTransform transform; // Prepare the image on an offscreen DC RAutoDrawingSurface drawSurfaceOffscreen; RRealRect rRealStaticRect(m_rectStaticDisplay); BOOLEAN fPrepared = drawSurfaceOffscreen.Prepare( &drawSurface, transform, rRealStaticRect ); RDrawingSurface* pSurface = ( (fPrepared)? &drawSurfaceOffscreen : &drawSurface ); // Paint the offscreen DC white RColor rColor = RSolidColor( kWhite ); pSurface->SetFillColor( rColor ); pSurface->SetPenColor( rColor ); pSurface->FillRectangle( m_rectStaticDisplay ); YAngle flRadiansRotation = ::DegreesToRadians( YFloatType( iPos ) ); // The rotation leaves a black background, so blit with a mask. The mask // has to be created the same size as the original (not rotated) bitmap // size, so create it and then rotate it. RBitmapImage bmpRotated; RBitmapImage bmpMaskRotated; RImageLibrary rLibrary; rLibrary.Rotate( m_rBitmapImage, bmpRotated, bmpMaskRotated, flRadiansRotation ); RIntSize sizeBmpRotated; sizeBmpRotated.m_dx = bmpRotated.GetWidthInPixels(); sizeBmpRotated.m_dy = bmpRotated.GetHeightInPixels(); RIntRect rectSource; RIntRect rectDest; DeriveSourceAndDestinationRects( sizeBmpRotated, rectSource, rectDest ); bmpRotated.RenderWithMask( *pSurface, bmpMaskRotated, rectSource, rectDest ); if ( fPrepared ) drawSurfaceOffscreen.Release(); drawSurface.DetachDCs(); m_iPrevPos = iPos; }
void CCaptionPainter::DrawCustomNcBtn( UINT btnType, int state ) { CRect rcSrc, rcDest; CPImageControl *curImgCtrl = NULL; switch (btnType) { case CAC_HTCLOSE: rcSrc = rcDest = m_rcCloseBtn; // make src rectangle zero based rcSrc -= CPoint(m_rcCloseBtn.left, m_rcCloseBtn.top); curImgCtrl = m_pCloseBxImgCtrl; break; case HTMINBUTTON: rcSrc = rcDest = m_rcMinBtn; // make src rectangle zero based rcSrc -= CPoint(m_rcMinBtn.left, m_rcMinBtn.top); curImgCtrl = m_pMinBxImgCtrl; break; case HTMAXBUTTON: rcSrc = rcDest = m_rcMaxBtn; // make src rectangle zero based rcSrc -= CPoint(m_rcMaxBtn.left, m_rcMaxBtn.top); curImgCtrl = (m_pParentDlg->IsZoomed() ? m_pRestoreBxImgCtrl : m_pMaxBxImgCtrl); break; case HTSYSMENU: default: return; } if (curImgCtrl) { CWindowDC dcWin((CWnd*)m_pParentDlg); // window DC //create a drawing surface from my dc RDcDrawingSurface destDS; destDS.Initialize(dcWin.m_hDC, dcWin.m_hAttribDC); curImgCtrl->Draw(state, destDS, rcSrc, rcDest); destDS.RestoreDefaults(); } }
void RWinColorPaletteWell::OnPaint( ) { CPaintDC dc( this ); CRect rect; GetClientRect( rect ); if (m_crColor.GetFillMethod() != RColor::kTransparent) { // The bounding rect is in logical units, so we // need to create a transform to scale from logical // units to device units. We also divide by 2 to // account for the scaling in the bounding rect to // make the texture more visible in such a small area. RRealSize dpi( ::GetScreenDPI() ); R2dTransform transform; transform.PostScale( dpi.m_dx / kSystemDPI * 0.5, dpi.m_dy / kSystemDPI * 0.5 ); RColor crFillColor = m_crColor; crFillColor *= transform; RIntRect rRect( rect ); RDcDrawingSurface ds; ds.Initialize( (HDC) dc ); RColor oldColor = ds.GetFillColor(); ds.SetFillColor( crFillColor ); ds.FillRectangle( rRect ); ds.SetFillColor( oldColor ); ds.DetachDCs(); } else { dc.FillSolidRect( rect, RGB( 255, 255, 255 ) ); CString strText ; GetWindowText( strText ); CRect rcTextRect( rect ); rcTextRect.DeflateRect( 1, 1 ); CFont* pFont = dc.SelectObject( GetParent()->GetFont() ); dc.DrawText( strText, rcTextRect, DT_CENTER | DT_VCENTER ); dc.SelectObject( pFont ); } dc.MoveTo( rect.left, rect.bottom - 1 ); dc.LineTo( rect.left, rect.top ); dc.LineTo( rect.right, rect.top ); }
//////////////// // Draw min, max/restore, close buttons. // Returns total width of buttons drawn. // int CCaptionPainter::DrawCustomButtons(CDC* dc, CRect& capRect) { ASSERT(m_pParentDlg); CWnd& wnd = (CWnd&)*m_pParentDlg; DWORD dwStyle = wnd.GetStyle(); if (!(dwStyle & WS_CAPTION)) return 0; if (!(dwStyle & WS_SYSMENU)) // does it contain controls in the title bar? return 0; RDcDrawingSurface destDS; destDS.Initialize(dc->m_hDC, dc->m_hAttribDC); // do the close box int btnDim = capRect.Height() - (2 * kCtrlInset); CRect rcSrc(0, 0, btnDim, btnDim); CRect rcDest(rcSrc); rcDest.OffsetRect(capRect.left + capRect.Width() - (btnDim + kCtrlInset) , capRect.top + kCtrlInset); // move right m_rcCloseBtn = rcDest; m_pCloseBxImgCtrl->SetControlSize(rcSrc, m_pTitleBkImgCtrl); m_pCloseBxImgCtrl->Draw(CPImageControl::UP, destDS, rcSrc, rcDest); // Max/restore button is like close box; just shift rectangle left // Also does help button, if any. BOOL bMaxBox = dwStyle & WS_MAXIMIZEBOX; if (bMaxBox || (wnd.GetExStyle() & WS_EX_CONTEXTHELP)) { rcDest.OffsetRect(-(btnDim + kCtrlInset), 0); CPImageControl* pImgCtrl; if ( bMaxBox != FALSE ) pImgCtrl = (wnd.IsZoomed() ? m_pRestoreBxImgCtrl : m_pMaxBxImgCtrl); else ASSERT(0);//pImgCtrl = m_pHelpBxImgCtrl; if (pImgCtrl) { pImgCtrl->SetControlSize(rcSrc, m_pTitleBkImgCtrl); pImgCtrl->Draw(CPImageControl::UP, destDS, rcSrc, rcDest); } m_rcMaxBtn = rcDest; } // Minimize button has 2 pixel border on all sides but right. if (dwStyle & WS_MINIMIZEBOX) { rcDest -= CPoint(btnDim, 0); m_pMinBxImgCtrl->SetControlSize(rcSrc, m_pTitleBkImgCtrl); m_pMinBxImgCtrl->Draw(CPImageControl::UP, destDS, rcSrc, rcDest); m_rcMinBtn = rcDest; } destDS.RestoreDefaults( ); return capRect.Width() - rcDest.left - 2; }
void RWinColorPalette::OnPaint( ) { CPaintDC dc( this ); RDcDrawingSurface ds; ds.Initialize( (HDC) dc ) ; CRect rcWindow; GetClientRect( rcWindow ); RIntRect rcClient( rcWindow ); RBitmapImage& biPalette = GetPaletteBitmapImage(); biPalette.LockImage( ); biPalette.Render( ds, rcClient ); biPalette.UnlockImage( ); ds.DetachDCs(); CClientDC dcClient( this ); ds.Initialize( (HDC) dcClient ) ; RColor crOldFill = ds.GetFillColor(); RColor crOldPen = ds.GetPenColor(); if (m_ptSelected.m_x >= 0 && m_ptSelected.m_y >= 0) { // // Draw selected cell RIntRect rcSelected( m_ptSelected.m_x + 1, m_ptSelected.m_y + 1, m_ptSelected.m_x + kCellSize.m_dx - 1, m_ptSelected.m_y + kCellSize.m_dy - 1 ); RSolidColor crBlack( kBlack ); RSolidColor crHilight( GetSysColor( COLOR_BTNHILIGHT ) ); ds.Draw3dRect( rcSelected, crBlack, crHilight ); RSolidColor crShadow( GetSysColor( COLOR_BTNSHADOW ) ); rcSelected.m_Top -= 1; rcSelected.m_Left -= 1; ds.Draw3dRect( rcSelected, crShadow, crHilight ); if (GetFocus() == this) { RSolidColor rSolid = GetSysColor( COLOR_HIGHLIGHT ); RColor rSelected( rSolid ); rcSelected.Inflate( RIntSize( 1, 1 ), RIntSize( 2, 2 ) ); ds.SetPenColor( RColor( rSelected ) ); ds.FrameRectangle( rcSelected ); } } if (m_crHilited != (COLORREF) -1L) { // Draw color chip m_rcColorChip = RIntRect( m_ptHilited.m_x, m_ptHilited.m_y, m_ptHilited.m_x + 2 * kCellSize.m_dx, m_ptHilited.m_y + 2 * kCellSize.m_dy ); YIntDimension xOffset( 2 * kCellSize.m_dx ); YIntDimension yOffset( 2 * kCellSize.m_dy ); if (m_rcColorChip.m_Right + xOffset > rcWindow.right) { xOffset = -3 * kCellSize.m_dx; } if (m_rcColorChip.m_Bottom + yOffset > rcWindow.bottom) { yOffset = -3 * kCellSize.m_dy; } m_rcColorChip.Offset( RIntSize( xOffset, yOffset ) ); RColor crFill = RSolidColor( m_crHilited ); RColor crPen = RSolidColor( kWhite ); ds.SetPenColor( crPen ); ds.SetFillColor( crFill ); ds.FillRectangle( m_rcColorChip ); ds.FrameRectangle( m_rcColorChip ); } else { m_rcColorChip = RIntRect( 0, 0, 1, 1 ); } ds.SetPenColor( crOldPen ); ds.SetFillColor( crOldFill ); ds.DetachDCs(); }