X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fb9cc37fa88db0b04f5f66f714b9e17c6a383ed0..cd66beb3439485e49fac308f54dc10fe01c92895:/src/mac/carbon/graphics.cpp diff --git a/src/mac/carbon/graphics.cpp b/src/mac/carbon/graphics.cpp index df0cdf70e7..0766f67236 100644 --- a/src/mac/carbon/graphics.cpp +++ b/src/mac/carbon/graphics.cpp @@ -35,10 +35,6 @@ #include "wx/mac/private.h" -#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 -typedef float CGFloat; -#endif - //----------------------------------------------------------------------------- // constants //----------------------------------------------------------------------------- @@ -58,6 +54,20 @@ static const double RAD2DEG = 180.0 / M_PI; #pragma mark - #pragma mark wxMacCoreGraphicsPattern, ImagePattern, HatchPattern classes +OSStatus wxMacDrawCGImage( + CGContextRef inContext, + const HIRect * inBounds, + CGImageRef inImage) +{ +#ifdef __LP64__ + // todo flip + CGContextDrawImage(inContext, *inBounds, inImage ); + return noErr; +#else + return HIViewDrawCGImage( inContext, inBounds, inImage ); +#endif +} + // CGPattern wrapper class: always allocate on heap, never call destructor class wxMacCoreGraphicsPattern @@ -104,7 +114,7 @@ public : { wxASSERT( bmp && bmp->Ok() ); - Init( (CGImageRef) bmp->CGImageCreate() , transform ); + Init( (CGImageRef) bmp->CreateCGImage() , transform ); } // ImagePattern takes ownership of CGImageRef passed in @@ -119,7 +129,7 @@ public : virtual void Render( CGContextRef ctxRef ) { if (m_image != NULL) - HIViewDrawCGImage( ctxRef, &m_imageBounds, m_image ); + wxMacDrawCGImage( ctxRef, &m_imageBounds, m_image ); } protected : @@ -470,6 +480,26 @@ static const char *gs_stripedback_xpm[] = { wxBitmap gs_stripedback_bmp( wxImage( (const char* const* ) gs_stripedback_xpm ), -1 ) ; +// make sure we all use one class for all conversions from wx to native colour + +class wxMacCoreGraphicsColour +{ + public: + wxMacCoreGraphicsColour(); + wxMacCoreGraphicsColour(const wxBrush &brush); + ~wxMacCoreGraphicsColour(); + + void Apply( CGContextRef cgContext ); + protected: + void Init(); + wxMacCFRefHolder m_color; + wxMacCFRefHolder m_colorSpace; + + bool m_isPattern; + wxMacCFRefHolder m_pattern; + CGFloat* m_patternColorComponents; +} ; + wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour() { delete[] m_patternColorComponents; @@ -506,18 +536,7 @@ wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush &brush ) Init(); if ( brush.GetStyle() == wxSOLID ) { - if ( brush.MacGetBrushKind() == kwxMacBrushTheme ) - { - CGColorRef color ; - HIThemeBrushCreateCGColor( brush.MacGetTheme(), &color ); - m_color.Set( color ) ; - } - else - { - CGFloat components[4] = { brush.GetColour().Red() / 255.0 , brush.GetColour().Green() / 255.0 , - brush.GetColour().Blue() / 255.0 , brush.GetColour().Alpha() / 255.0 } ; - m_color.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ) ; - } + m_color.Set( brush.GetColour().CreateCGColor() ); } else if ( brush.IsHatch() ) { @@ -686,6 +705,8 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere { m_macATSUIStyle = NULL; +#ifdef wxMAC_USE_CORE_TEXT +#elif defined(wxMAC_USE_ATSU_TEXT) OSStatus status; status = ATSUCreateAndCopyStyle( (ATSUStyle) font.MacGetATSUStyle() , &m_macATSUIStyle ); @@ -695,7 +716,8 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere // we need the scale here ... Fixed atsuSize = IntToFixed( int( 1 * font.MacGetFontSize()) ); - RGBColor atsuColor = MAC_WXCOLORREF( col.GetPixel() ); + RGBColor atsuColor ; + col.GetRGBColor( &atsuColor ); ATSUAttributeTag atsuTags[] = { kATSUSizeTag , @@ -717,15 +739,21 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere atsuTags, atsuSizes, atsuValues); wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); +#elif defined(WXMAC_USE_CG_TEXT) +#endif } wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData() { +#ifdef wxMAC_USE_CORE_TEXT +#elif defined(wxMAC_USE_ATSU_TEXT) if ( m_macATSUIStyle ) { ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle); m_macATSUIStyle = NULL; } +#elif defined(WXMAC_USE_CG_TEXT) +#endif } // @@ -1297,9 +1325,12 @@ wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer* renderer int originX , originY; originX = originY = 0; window->MacWindowToRootWindow( &originX , &originY ); - Rect bounds; - GetWindowBounds( m_windowRef, kWindowContentRgn, &bounds ); + Rect bounds = { 0,0,0,0 }; +#ifdef __LP64__ +#else + GetWindowBounds( m_windowRef, kWindowContentRgn, &bounds ); +#endif m_windowTransform = CGAffineTransformMakeTranslation( 0 , bounds.bottom - bounds.top ); m_windowTransform = CGAffineTransformScale( m_windowTransform , 1 , -1 ); m_windowTransform = CGAffineTransformTranslate( m_windowTransform, originX, originY ) ; @@ -1413,18 +1444,14 @@ void wxMacCoreGraphicsContext::Clip( const wxRegion ®ion ) { if( m_cgContext ) { - HIShapeRef shape = HIShapeCreateWithQDRgn( (RgnHandle) region.GetWXHRGN() ); - HIShapeReplacePathInCGContext( shape, m_cgContext ); + HIShapeReplacePathInCGContext( region.GetWXHRGN() , m_cgContext ); CGContextClip( m_cgContext ); - CFRelease( shape ); } else { // this offsetting to device coords is not really correct, but since we cannot apply affine transforms // to regions we try at least to have correct translations - wxMacCFRefHolder hishape ; - hishape.Set( HIShapeCreateWithQDRgn( (RgnHandle) region.GetWXHRGN() )); - HIMutableShapeRef mutableShape = HIShapeCreateMutableCopy( hishape ); + HIMutableShapeRef mutableShape = HIShapeCreateMutableCopy( region.GetWXHRGN() ); CGPoint transformedOrigin = CGPointApplyAffineTransform( CGPointZero, m_windowTransform ); HIShapeOffset( mutableShape, transformedOrigin.x, transformedOrigin.y ); @@ -1627,7 +1654,7 @@ void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDo { EnsureIsValid(); - CGImageRef image = (CGImageRef)( bmp.CGImageCreate() ); + CGImageRef image = (CGImageRef)( bmp.CreateCGImage() ); HIRect r = CGRectMake( x , y , w , h ); if ( bmp.GetDepth() == 1 ) { @@ -1648,13 +1675,13 @@ void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDo else { ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->Apply(this); - HIViewDrawCGImage( m_cgContext , &r , image ); + wxMacDrawCGImage( m_cgContext , &r , image ); } } } else { - HIViewDrawCGImage( m_cgContext , &r , image ); + wxMacDrawCGImage( m_cgContext , &r , image ); } CGImageRelease( image ); } @@ -1688,7 +1715,17 @@ void wxMacCoreGraphicsContext::PopState() void wxMacCoreGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y ) { + if ( m_font.IsNull() ) + return; + + EnsureIsValid(); +#ifdef wxMAC_USE_CORE_TEXT + // TODO core text implementation here +#elif defined(wxMAC_USE_ATSU_TEXT) DrawText(str, x, y, 0.0); +#elif defined(WXMAC_USE_CG_TEXT) + // TODO core graphics text implementation here +#endif } void wxMacCoreGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ) @@ -1697,7 +1734,10 @@ void wxMacCoreGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDoub return; EnsureIsValid(); - +#ifdef wxMAC_USE_CORE_TEXT + // default implementation takes care of rotation and calls non rotated DrawText afterwards + wxGraphicsContext::DrawText( str, x, y, angle ); +#elif defined(wxMAC_USE_ATSU_TEXT) OSStatus status = noErr; ATSUTextLayout atsuLayout; UniCharCount chars = str.length(); @@ -1803,6 +1843,10 @@ void wxMacCoreGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDoub #if SIZEOF_WCHAR_T == 4 free( ubuf ); #endif +#elif defined(WXMAC_USE_CG_TEXT) + // default implementation takes care of rotation and calls non rotated DrawText afterwards + wxGraphicsContext::DrawText( str, x, y, angle ); +#endif } void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height, @@ -1822,6 +1866,9 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid if (str.empty()) return; +#ifdef wxMAC_USE_CORE_TEXT + // TODO core text implementation here +#elif defined(wxMAC_USE_ATSU_TEXT) OSStatus status = noErr; ATSUTextLayout atsuLayout; @@ -1876,6 +1923,9 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid #if SIZEOF_WCHAR_T == 4 free( ubuf ) ; #endif +#elif defined(WXMAC_USE_CG_TEXT) + // TODO core graphics text implementation here +#endif } void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const @@ -1886,6 +1936,9 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr if (text.empty()) return; +#ifdef wxMAC_USE_CORE_TEXT + // TODO core text implementation here +#elif defined(wxMAC_USE_ATSU_TEXT) ATSUTextLayout atsuLayout; UniCharCount chars = text.length(); UniChar* ubuf = NULL; @@ -1937,6 +1990,9 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr #if SIZEOF_WCHAR_T == 4 free( ubuf ) ; #endif +#elif defined(WXMAC_USE_CG_TEXT) + // TODO core graphics text implementation here +#endif } void * wxMacCoreGraphicsContext::GetNativeContext()