⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dc.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            // the modes need this, otherwise we'll end up having really nice colors...            RGBColor    white = { 0xFFFF, 0xFFFF,0xFFFF} ;            RGBColor    black = { 0,0,0} ;            RGBForeColor( &black ) ;            RGBBackColor( &white ) ;        }        if ( useMask && source->m_macMask )        {            if ( mode == srcCopy )            {                if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) )                {                    CopyMask( GetPortBitMapForCopyBits( sourcePort ) ,                        GetPortBitMapForCopyBits( MAC_WXHBITMAP(source->m_macMask) ) ,                        GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,                        &srcrect, &srcrect , &dstrect ) ;                    UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) )  ) ;                }            }            else            {                RgnHandle clipRgn = NewRgn() ;                LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;                BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;                UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;                OffsetRgn( clipRgn , -srcrect.left + dstrect.left, -srcrect.top +  dstrect.top ) ;                if ( mode == kEmulatedMode )                {                    Pattern pat ;                    ::PenPat(GetQDGlobalsBlack(&pat));                    if ( logical_func == wxSET )                    {                        RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;                        ::RGBForeColor( &col  ) ;                        ::PaintRgn( clipRgn ) ;                    }                    else if ( logical_func == wxCLEAR )                    {                        RGBColor col= { 0x0000, 0x0000, 0x0000 } ;                        ::RGBForeColor( &col  ) ;                        ::PaintRgn( clipRgn ) ;                    }                    else if ( logical_func == wxINVERT )                    {                        MacInvertRgn( clipRgn ) ;                    }                    else                    {                        for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )                        {                            for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )                            {                                Point dstPoint = { dstrect.top + y , dstrect.left + x } ;                                Point srcPoint = { srcrect.top + y , srcrect.left + x } ;                                if ( PtInRgn( dstPoint , clipRgn ) )                                {                                    RGBColor srcColor ;                                    RGBColor dstColor ;                                    SetPort( (GrafPtr) sourcePort ) ;                                    GetCPixel(  srcPoint.h , srcPoint.v , &srcColor) ;                                    SetPort( (GrafPtr) m_macPort ) ;                                    GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;                                    wxMacCalculateColour( logical_func , srcColor ,  dstColor ) ;                                    SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;                                }                            }                        }                    }                }                else                {                    if ( invertDestinationFirst )                    {                        MacInvertRgn( clipRgn ) ;                    }                    CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,                        GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,                        &srcrect, &dstrect, mode, clipRgn ) ;                }                DisposeRgn( clipRgn ) ;            }        }        else        {            RgnHandle clipRgn = NewRgn() ;            SetRectRgn( clipRgn , dstrect.left , dstrect.top , dstrect.right , dstrect.bottom ) ;            if ( mode == kEmulatedMode )            {                Pattern pat ;                ::PenPat(GetQDGlobalsBlack(&pat));                if ( logical_func == wxSET )                {                    RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;                    ::RGBForeColor( &col  ) ;                    ::PaintRgn( clipRgn ) ;                }                else if ( logical_func == wxCLEAR )                {                    RGBColor col= { 0x0000, 0x0000, 0x0000 } ;                    ::RGBForeColor( &col  ) ;                    ::PaintRgn( clipRgn ) ;                }                else if ( logical_func == wxINVERT )                {                    MacInvertRgn( clipRgn ) ;                }                else                {                    for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )                    {                        for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )                        {                            Point dstPoint = { dstrect.top + y , dstrect.left + x } ;                            Point srcPoint = { srcrect.top + y , srcrect.left + x } ;                            {                                RGBColor srcColor ;                                RGBColor dstColor ;                                SetPort( (GrafPtr) sourcePort ) ;                                GetCPixel(  srcPoint.h , srcPoint.v , &srcColor) ;                                SetPort( (GrafPtr) m_macPort ) ;                                GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;                                wxMacCalculateColour( logical_func , srcColor ,  dstColor ) ;                                SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;                            }                        }                    }                }            }            else            {                if ( invertDestinationFirst )                {                    MacInvertRgn( clipRgn ) ;                }                CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,                    GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,                    &srcrect, &dstrect, mode, NULL ) ;            }            DisposeRgn( clipRgn ) ;        }        UnlockPixels( bmappixels ) ;    }    m_macPenInstalled = false ;    m_macBrushInstalled = false ;    m_macFontInstalled = false ;    return true;}#ifndef FixedToInt// as macro in FixMath.h for 10.3inline Fixed    IntToFixed( int inInt ){    return (((SInt32) inInt) << 16);}inline int    FixedToInt( Fixed inFixed ){    return (((SInt32) inFixed) >> 16);}#endifvoid  wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,                              double angle){    wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText  Invalid window dc") );    if (angle == 0.0 )    {        DrawText(str, x, y);        return;    }    if ( str.length() == 0 )        return ;    wxMacFastPortSetter helper(this) ;    MacInstallFont() ;    if ( 0 )    {        m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);        SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * m_font.GetMacFontSize()));        m_macAliasWasEnabled = true ;    }    OSStatus status = noErr ;    ATSUTextLayout atsuLayout ;    UniCharCount chars = str.length() ;#if wxUSE_UNICODE    status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.length() , str.length() , 1 ,        &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;#else    wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;    int wlen = wxWcslen( wchar.data() ) ;    status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) wchar.data() , 0 , wlen , wlen , 1 ,        &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;#endif    wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") );    int iAngle = int( angle );    int drawX = XLOG2DEVMAC(x) ;    int drawY = YLOG2DEVMAC(y) ;    ATSUTextMeasurement textBefore ;    ATSUTextMeasurement textAfter ;    ATSUTextMeasurement ascent ;    ATSUTextMeasurement descent ;    if ( abs(iAngle) > 0 )    {        Fixed atsuAngle = IntToFixed( iAngle ) ;        ATSUAttributeTag atsuTags[] =        {            kATSULineRotationTag ,        } ;        ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =        {            sizeof( Fixed ) ,        } ;        ATSUAttributeValuePtr    atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =        {            &atsuAngle ,        } ;        status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag),            atsuTags, atsuSizes, atsuValues ) ;    }    status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,        &textBefore , &textAfter, &ascent , &descent );    drawX += (int)(sin(angle/RAD2DEG) * FixedToInt(ascent));    drawY += (int)(cos(angle/RAD2DEG) * FixedToInt(ascent));    status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,        IntToFixed(drawX) , IntToFixed(drawY) );    wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") );    Rect rect ;    status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,        IntToFixed(drawX) , IntToFixed(drawY) , &rect );    wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );    OffsetRect( &rect , -m_macLocalOrigin.x , -m_macLocalOrigin.y ) ;    CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) );    CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) );    ::ATSUDisposeTextLayout(atsuLayout);}void  wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y){    wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText  Invalid DC"));    wxMacFastPortSetter helper(this) ;    long xx = XLOG2DEVMAC(x);    long yy = YLOG2DEVMAC(y);#if TARGET_CARBON    bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ;    if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || m_font.GetNoAntiAliasing() )        useDrawThemeText = false ;#endif    MacInstallFont() ;    if ( 0 )    {        m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);        SetAntiAliasedTextEnabled(true, 8);        m_macAliasWasEnabled = true ;    }    FontInfo fi ;    ::GetFontInfo( &fi ) ;#if TARGET_CARBON    if ( !useDrawThemeText )#endif        yy += fi.ascent ;    ::MoveTo( xx , yy );    if (  m_backgroundMode == wxTRANSPARENT )    {        ::TextMode( srcOr) ;    }    else    {        ::TextMode( srcCopy ) ;    }    int length = strtext.length() ;    int laststop = 0 ;    int i = 0 ;    int line = 0 ;    {#if 0 // we don't have to do all that here        while( i < length )        {            if( strtext[i] == 13 || strtext[i] == 10)            {                wxString linetext = strtext.Mid( laststop , i - laststop ) ;#if TARGET_CARBON                if ( useDrawThemeText )                {                    Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading)  ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ;                    wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ;                    if ( m_backgroundMode != wxTRANSPARENT )                    {                        Point bounds={0,0} ;                        Rect background = frame ;                        SInt16 baseline ;                        ::GetThemeTextDimensions( mString,                            kThemeCurrentPortFont,                            kThemeStateActive,                            false,                            &bounds,                            &baseline );                        background.right = background.left + bounds.h ;                        background.bottom = background.top + bounds.v ;                        ::EraseRect( &background ) ;                    }                    ::DrawThemeTextBox( mString,                        kThemeCurrentPortFont,                        kThemeStateActive,                        false,                        &frame,                        teJustLeft,                        nil );                    line++ ;                }                else#endif                {                    wxCharBuffer text = linetext.mb_str(wxConvLocal) ;                    ::DrawText( text , 0 , strlen(text) ) ;                    if ( m_backgroundMode != wxTRANSPARENT )                    {                        Point bounds={0,0} ;                        Rect background = frame ;                        SInt16 baseline ;                        ::GetThemeTextDimensions( mString,                            kThemeCurrentPortFont,                            kThemeStateActive,                            false,                            &bounds,                            &baseline );                        background.right = background.left + bounds.h ;                        background.bottom = background.top + bounds.v ;                        ::EraseRect( &background ) ;                    }                    line++ ;                    ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) );                }                laststop = i+1 ;            }            i++ ;        }        wxString linetext = strtext.Mid( laststop , i - laststop ) ;#endif // 0        wxString linetext = strtext ;#if TARGET_CARBON        if ( useDrawThemeText )        {            Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading)  ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ;            wxMacCFStringHolder mString( linetext , m_font.GetEncoding()) ;            if ( m_backgroundMode != wxTRANSPARENT )            {                Point bounds={0,0} ;                Rect background = frame ;                SInt16 baseline ;                ::GetThemeTextDimensions( mString,                    kThemeCurrentPortFont,                    kThemeStateActive,                    false,                    &bounds,                    &baseline );                background.right = background.left + bounds.h ;                background.bottom = background.top + bounds.v ;                ::EraseRect( &background ) ;            }            ::DrawThemeTextBox( mString,                kThemeCurrentPortFont,                kThemeStateActive,                false,                &frame,                teJustLeft,                nil );        }        else#endif        {            wxCharBuffer text = linetext.mb_str(wxConvLocal) ;            if ( m_backgroundMode != wxTRANSPARENT )            {                Rect frame = { yy - fi.ascent + line*(fi.descent + fi.ascent + fi.leading)  ,xx , yy - fi.ascent + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ;                short width = ::TextWidth( text , 0 , strlen(text) ) ;                frame.right = frame.left + width ;                ::EraseRect( &frame ) ;            }            ::DrawText( text , 0 , strlen(text) ) ;         }    }    ::TextMode( srcOr ) ;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -