📄 dccg.cpp
字号:
void wxDC::DoDrawSpline(wxList *points){ wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") ); if ( m_logicalFunction != wxCOPY ) return ; wxGraphicPath* path = m_graphicContext->CreatePath() ; wxList::compatibility_iterator node = points->GetFirst(); if (node == wxList::compatibility_iterator()) // empty list return; wxPoint *p = (wxPoint *)node->GetData(); wxCoord x1 = p->x; wxCoord y1 = p->y; node = node->GetNext(); p = (wxPoint *)node->GetData(); wxCoord x2 = p->x; wxCoord y2 = p->y; wxCoord cx1 = ( x1 + x2 ) / 2; wxCoord cy1 = ( y1 + y2 ) / 2; path->MoveToPoint( XLOG2DEVMAC( x1 ) , YLOG2DEVMAC( y1 ) ) ; path->AddLineToPoint( XLOG2DEVMAC( cx1 ) , YLOG2DEVMAC( cy1 ) ) ;#if !wxUSE_STL while ((node = node->GetNext()) != NULL)#else while ((node = node->GetNext()))#endif // !wxUSE_STL { p = (wxPoint *)node->GetData(); x1 = x2; y1 = y2; x2 = p->x; y2 = p->y; wxCoord cx4 = (x1 + x2) / 2; wxCoord cy4 = (y1 + y2) / 2; path->AddQuadCurveToPoint( XLOG2DEVMAC( x1 ) , YLOG2DEVMAC( y1 ) , XLOG2DEVMAC( cx4 ) , YLOG2DEVMAC( cy4 ) ) ; cx1 = cx4; cy1 = cy4; } path->AddLineToPoint( XLOG2DEVMAC( x2 ) , YLOG2DEVMAC( y2 ) ) ; m_graphicContext->StrokePath( path ) ; delete path ;}#endifvoid wxDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle ){ wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") ); if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) ) return ; if ( m_logicalFunction != wxCOPY ) return ; wxCoord x1, x2 , y1 , y2 ; x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset); y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset); wxGraphicPath* path = m_graphicContext->CreatePath() ; path->MoveToPoint( x1 , y1 ) ; for (int i = 1; i < n; i++) { x2 = XLOG2DEVMAC(points[i].x + xoffset); y2 = YLOG2DEVMAC(points[i].y + yoffset); path->AddLineToPoint( x2 , y2 ) ; } if ( x1 != x2 || y1 != y2 ) path->AddLineToPoint( x1, y1 ) ; path->CloseSubpath() ; m_graphicContext->DrawPath( path , fillStyle ) ; delete path ;}void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height){ wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") ); if ( m_logicalFunction != wxCOPY ) return ; wxCoord xx = XLOG2DEVMAC(x); wxCoord yy = YLOG2DEVMAC(y); wxCoord ww = m_signX * XLOG2DEVREL(width); wxCoord hh = m_signY * YLOG2DEVREL(height); // CMB: draw nothing if transformed w or h is 0 if (ww == 0 || hh == 0) return; // CMB: handle -ve width and/or height if (ww < 0) { ww = -ww; xx = xx - ww; } if (hh < 0) { hh = -hh; yy = yy - hh; } int penwidth = m_pen.GetWidth(); if ( penwidth == 0 ) penwidth = 1 ; if ( m_pen.GetStyle() == wxTRANSPARENT ) penwidth = 0 ; bool offset = ( penwidth % 2 ) == 1 ; wxGraphicPath* path = m_graphicContext->CreatePath() ; // if we are offsetting the entire rectangle is moved 0.5, so the border line gets off by 1 if ( offset ) path->AddRectangle( xx , yy , ww-1 , hh-1 ) ; else path->AddRectangle( xx , yy , ww , hh ) ; m_graphicContext->DrawPath( path ) ; delete path ;}void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius){ wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") ); if ( m_logicalFunction != wxCOPY ) return ; if (radius < 0.0) radius = - radius * ((width < height) ? width : height); wxCoord xx = XLOG2DEVMAC(x); wxCoord yy = YLOG2DEVMAC(y); wxCoord ww = m_signX * XLOG2DEVREL(width); wxCoord hh = m_signY * YLOG2DEVREL(height); // CMB: draw nothing if transformed w or h is 0 if (ww == 0 || hh == 0) return; // CMB: handle -ve width and/or height if (ww < 0) { ww = -ww; xx = xx - ww; } if (hh < 0) { hh = -hh; yy = yy - hh; } wxGraphicPath* path = m_graphicContext->CreatePath() ; if ( radius == 0) { path->AddRectangle( xx , yy , ww , hh ) ; m_graphicContext->DrawPath( path ) ; } else { path->MoveToPoint( xx + ww, yy + hh / 2); path->AddArcToPoint(xx + ww, yy + hh, xx + ww / 2,yy + hh, radius); path->AddArcToPoint(xx , yy + hh, xx , yy + hh / 2, radius); path->AddArcToPoint(xx , yy , xx + ww / 2, yy , radius); path->AddArcToPoint(xx + ww, yy , xx + ww, yy + hh / 2, radius); path->CloseSubpath(); m_graphicContext->DrawPath( path ) ; } delete path ;}void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height){ wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") ); if ( m_logicalFunction != wxCOPY ) return ; wxCoord xx = XLOG2DEVMAC(x); wxCoord yy = YLOG2DEVMAC(y); wxCoord ww = m_signX * XLOG2DEVREL(width); wxCoord hh = m_signY * YLOG2DEVREL(height); // CMB: draw nothing if transformed w or h is 0 if (ww == 0 || hh == 0) return; // CMB: handle -ve width and/or height if (ww < 0) { ww = -ww; xx = xx - ww; } if (hh < 0) { hh = -hh; yy = yy - hh; } wxGraphicPath* path = m_graphicContext->CreatePath() ; m_graphicContext->PushState() ; m_graphicContext->Translate(xx + ww / 2, yy + hh / 2); m_graphicContext->Scale(ww / 2 , hh / 2); path->AddArc( 0, 0, 1, 0 , 2 * M_PI , false ) ; m_graphicContext->DrawPath( path ) ; m_graphicContext->PopState() ; delete path ;}bool wxDC::CanDrawBitmap() const{ return true ;}bool wxDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask, wxCoord xsrcMask, wxCoord ysrcMask ){ wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") ); wxCHECK_MSG( source->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") ); if ( logical_func == wxNO_OP ) return true ; if (xsrcMask == -1 && ysrcMask == -1) { xsrcMask = xsrc; ysrcMask = ysrc; } wxCoord yysrc = source->YLOG2DEVMAC(ysrc) ; wxCoord xxsrc = source->XLOG2DEVMAC(xsrc) ; wxCoord wwsrc = source->XLOG2DEVREL(width) ; wxCoord hhsrc = source->YLOG2DEVREL(height) ; wxCoord yydest = YLOG2DEVMAC(ydest) ; wxCoord xxdest = XLOG2DEVMAC(xdest) ; wxCoord wwdest = XLOG2DEVREL(width) ; wxCoord hhdest = YLOG2DEVREL(height) ; wxMemoryDC* memdc = dynamic_cast<wxMemoryDC*>(source) ; if ( memdc && logical_func == wxCOPY ) { wxBitmap blit = memdc->GetSelectedObject() ; wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") ) ; wxCoord bmpwidth = blit.GetWidth(); wxCoord bmpheight = blit.GetHeight(); if ( xxsrc != 0 || yysrc != 0 || bmpwidth != wwsrc || bmpheight != hhsrc ) { wwsrc = wxMin( wwsrc , bmpwidth - xxsrc ) ; hhsrc = wxMin( hhsrc , bmpheight - yysrc ) ; if ( wwsrc > 0 && hhsrc > 0 ) { if ( xxsrc >= 0 && yysrc >= 0 ) { wxRect subrect( xxsrc, yysrc, wwsrc , hhsrc ) ; // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons blit = blit.GetSubBitmap( subrect ) ; } else { // in this case we'd probably have to adjust the different coordinates, but // we have to find out proper contract first blit = wxNullBitmap ; } } else { blit = wxNullBitmap ; } } if ( blit.Ok() ) { m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest ) ; } } else { wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") ) ; return false ; } return true;}void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, double angle){ wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );// wxCHECK_RET( m_macATSUIStyle != NULL, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") ); if ( str.length() == 0 ) return ; if ( m_logicalFunction != wxCOPY ) return ; int drawX = XLOG2DEVMAC(x) ; int drawY = YLOG2DEVMAC(y) ; m_graphicContext->DrawText( str, drawX ,drawY , angle ) ;}void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y){ wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") ); DoDrawRotatedText( strtext , x , y , 0.0 ) ;}bool wxDC::CanGetTextExtent() const{ wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") ); return true ;}void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height, wxCoord *descent, wxCoord *externalLeading , wxFont *theFont ) const{ wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") ); if ( theFont ) { m_graphicContext->SetFont( *theFont ) ; } wxCoord h , d , e , w ; m_graphicContext->GetTextExtent( str, &w, &h, &d, &e ) ; if ( height ) *height = YDEV2LOGREL( h ) ; if ( descent ) *descent =YDEV2LOGREL( d); if ( externalLeading ) *externalLeading = YDEV2LOGREL( e); if ( width ) *width = XDEV2LOGREL( w ) ; if ( theFont ) { m_graphicContext->SetFont( m_font ) ; }}bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const{ wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") ); m_graphicContext->GetPartialTextExtents( text, widths ) ; for ( size_t i = 0 ; i < widths.GetCount() ; ++i ) widths[i] = XDEV2LOGREL( widths[i] ); return true;}wxCoord wxDC::GetCharWidth(void) const{ wxCoord width ; DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL ) ; return width ;}wxCoord wxDC::GetCharHeight(void) const{ wxCoord height ; DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ) ; return height ;}void wxDC::Clear(void){ wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") ); if (m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT) { HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ; CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; switch ( m_backgroundBrush.MacGetBrushKind() ) { case kwxMacBrushTheme : {#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 if ( HIThemeSetFill != 0 ) { HIThemeSetFill( m_backgroundBrush.MacGetTheme(), NULL, cg, kHIThemeOrientationNormal ); CGContextFillRect(cg, rect); } else#endif { RGBColor color; GetThemeBrushAsColor( m_backgroundBrush.MacGetTheme(), 32, true, &color ); CGContextSetRGBFillColor( cg, (CGFloat) color.red / 65536, (CGFloat) color.green / 65536, (CGFloat) color.blue / 65536, 1 ); CGContextFillRect( cg, rect ); } // reset to normal value RGBColor col = MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ; CGContextSetRGBFillColor( cg, col.red / 65536.0, col.green / 65536.0, col.blue / 65536.0, 1.0 ); } break ; case kwxMacBrushThemeBackground : { wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 if ( UMAGetSystemVersion() >= 0x1030 ) { HIThemeBackgroundDrawInfo drawInfo ; drawInfo.version = 0 ; drawInfo.state = kThemeStateActive ; drawInfo.kind = m_backgroundBrush.MacGetThemeBackground( NULL ) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -